Created
January 31, 2017 04:27
-
-
Save Nickster258/698c6a2f1600223bab86b154c3c5eb33 to your computer and use it in GitHub Desktop.
A simple API I made to fetch information regarding a CS:GO server
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
<?php | |
require __DIR__ . '/../SourceQuery/bootstrap.php'; | |
use xPaw\SourceQuery\SourceQuery; | |
header("content-type: text/html; charset=utf-8"); | |
if (!isset($_GET['ip']) OR !isset($_GET['port'])) { | |
try { | |
throw new InvalidArgumentException("'ip' and 'port' are a required argument!"); | |
} catch (Exception $e) { | |
echo $e->GetMessage(); | |
} | |
} else { | |
$Query = new SourceQuery( ); | |
try { | |
$Query->Connect( $_GET['ip'], $_GET['port'], 1, SourceQu ery::SOURCE ); | |
$info = $Query->GetInfo( ); | |
$players = $Query->GetPlayers( ); | |
//getPlayerCount=1 - Gets Player count minus Bot count | |
if ($_GET['getPlayerCount']=='1') { | |
$count = $info['Players'] - $info['Bots']; | |
echo $count; | |
//getAllPlayerCount=1 - Gets raw Player count | |
} elseif ($_GET['getAllPlayerCount']=='1') { | |
$countRaw = $info['Players']; | |
echo $countRaw; | |
//getPlayers=1 - Returns Player information | |
} elseif ($_GET['getPlayers']=='1') { | |
$json_players = json_encode($players, JSON_PRETT Y_PRINT|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES); | |
echo "<pre>$json_players</pre>"; | |
//getInfo=1 - Returns server information | |
} elseif ($_GET['getInfo']=='1') { | |
$json_info = json_encode($info, JSON_PRETTY_PRIN T); | |
echo "<pre>$json_info</pre>"; | |
} elseif ($_GET['getInfoRaw']=='1') { | |
print_r($info); | |
} elseif ($_GET['getPlayersRaw']=='1') { | |
print_r($players); | |
//Returns everything | |
} else { | |
$json_players = json_encode($info, JSON_PRETTY_P RINT); | |
echo "<pre>$json_players</pre>"; | |
$json_info = json_encode($players, JSON_PRETTY_P RINT|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES); | |
echo "<pre>$json_info</pre>"; | |
} | |
} catch (Exception $e) { | |
echo $e->GetMessage(); | |
} finally { | |
$Query->Disconnect(); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment