[TUT] BATTLEMETRICS (check list of games) status/map/players/most online/ server creat day/ AND MUCH MORE  

 

Levent Han
(@leventhan)
New Member Customer
Joined: 6 months ago
Posts: 0
16/01/2020 11:18 pm  

Hey guys, I'm LeventHAN.


Today I will explain you how you can use Querry String to check the following information (by using API / PHP).
Spoiler
What can I do with this?

  • Server Name
  • IP / PORT
  • ACTIVE PLAYERS
  • MAX. SLOT OF PLAYERS
  • COUNTRY OF SERVER
  • STATUS (online/offline)
  • Creat date of the server
  • If there are mods
    • modIDs
    • mod names
    • modHashes
  • And much more

Now BATTLEMETRICS is a website where they store all the info about server. If you own the server you can even use RCON by API like kicking players/shuting down a server/ banning/ locking/etc... For more info check this: <API DOCUMENTS>


Lets start with the tutorial. I will now explain just SOME of what you can do. But when you get the idea you will be able to do the same with the other API Endpoints.

  1. SERVER STATUS + WICH MAP ARE WE PLAYING IN THE SERVER
    1. First we will check the whole code

Like you see there are defines and also explanation (so I don't need to do it now lol)

BUT what I'm going to explain now is the structure of the following code snippet:

if($response['data']['attributes']['status'] == "online") {
echo "ONLINE"; 
} else {
echo "OFFLINE";
};

So we made a if...else statement...
Inside the if we see response and than 3 variables. DATA > ATTRIBUTES > STATUS (See below for explanation of this path)

Let's we check what the API result look like:

So I did now coloured the json respond for a ARMA 3 server. ( https://api.battlemetrics.com/servers/5090469 ) (Also I did use a json beautifier to see the result better)

If you check the colors you will see that some of them are the same. Well I wanted to show the paths. But you can just copy the response from JSON/API and put it in a json beautifier like: <JSON BEAUTIFY>
For example I need to check wich MAP the server is right now. 
We do this as follow:

<?php
$api = 'https://api.battlemetrics.com/servers/'; // the main API for servers.
$server = '5090469'; // the number of the server you will get the info from most of thime something like 5484856.
$api_full = $api . $server; // bringing them together.
$json = file_get_contents("$api_full"); // Putting the content of the file in a variable.
$response = json_decode($json, true); // decode the JSON feed

echo $response['data']['attributes']['details']['map'];
?>

> It will respond ALTIS. So we now know what people are playing (very usefull for csgo for example :P)


And here a extra code snippet to show the active players RIGHT NOW.

<?php
$api = 'https://api.battlemetrics.com/servers/'; // the main API for servers.
$server = '5090469'; // the number of the server you will get the info from most of thime something like 5484856.
$api_full = $api . $server; // bringing them together.
$json = file_get_contents("$api_full"); // Putting the content of the file in a variable.
$response = json_decode($json, true); // decode the JSON feed

echo $response['data']['attributes']['players'];
?>

 

I'm done I think... If you have question with API/JSON - PHP let me know I'm kinda good at it :))
AND also for other things regarding GLC v2

Spoiler


Quote
Topic Tags
Share: