I have an function that will grab all info from a server and list in raw format using
print_r($game->getPlayers());
Now the output of this is like I say very raw..
Array ( [0] => Array ( [id] => 0 [name] => |NERV|The_Punisher [ip] => 62.173.77.103 [port] => 1621 [keyhash] => 41000e06f21ce1e436da0db94a1eb5c6 ) [1] => Array ( [id] => 1 [name] => =DSM= DrGonzo87 [ip] => 89.52.104.242 [port] => 2531 [keyhash] => 06bbdfed04000863f0860a8bf0874705 ) [2] => Array ( [id] => 2 [name] => MoM-Iceman [ip] => 85.228.200.240 [port] => 3237 [keyhash] => 4c3232d94a6a0e22e881d79b6c926fb3 ) )
What I am struggling with is being able to control the results and create an ordered list or even perhaps add to sql if required.
Any tips on this would be appreciated.
The code below:
function getPlayers()
{
$players = array();
$pattern = "/Id: {1,2}([0-9]{1,2}) - (.*?) is remote ip: ([0-9\.]{7,15}):([0-9]{1,5}) ->\s*CD-key hash: ([0-9a-f]{32})/";
$return_string = $this->invoke('admin.listplayers');
preg_match_all($pattern, $return_string, $matches);
foreach ($matches[1] as $key => $id) {
$players[$id]['id'] = $matches[1][$key];
$players[$id]['name'] = $matches[2][$key];
$players[$id]['ip'] = $matches[3][$key];
$players[$id]['port'] = $matches[4][$key];
$players[$id]['keyhash'] = $matches[5][$key];
}
ksort($players);
return $players;
}