Created
February 18, 2021 23:17
-
-
Save ner00/f6c93e57edb89362daab619362b1d015 to your computer and use it in GitHub Desktop.
lgsl_query - Check alt:V master server list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function lgsl_query_44(&$server, &$lgsl_need, &$lgsl_fp) | |
{ | |
//---------------------------------------------------------+ | |
// Check alt:V master server list | |
$url ="https://api.altv.mp/servers/list/"; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt ($ch, CURLOPT_TIMEOUT, 5); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
$data = curl_exec($ch); | |
curl_close($ch); | |
// Test if list contains $ip:$port | |
$ip = $server['b']['ip']; | |
$port = $server['b']['c_port']; | |
$xserver = "\"host\":\"$ip\",\"port\":$port"; | |
if(strpos($data, $xserver) !== false) { | |
$xdatas = json_decode($data, true); | |
$key = -1; | |
foreach ($xdatas as $xdata) { | |
$key++; | |
if ($xdata["host"] == $ip && $xdata["port"] == $port) { | |
// Extract info | |
$server['s']['name'] = $xdatas[$key]["name"]; | |
$server['s']['map'] = $xdatas[$key]["gameMode"]; | |
$server['s']['players'] = $xdatas[$key]["players"]; | |
$server['s']['playersmax'] = $xdatas[$key]["maxPlayers"]; | |
return true; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment