it is for a game server tracker . I am trying to learn what some parts of it are as I wopuld like to make a server query for our communications server. I am not afraid to learn and am somewaht capable within php but not to this extent. I have searched and searched and thanks to you guys I have been given keywords to search for and as usual, you guys know what you are looking at and talking about. below is the function I am trying to learn from. Any pointers to tutorials or whatever are greatly appreciated.
function lgsl_query_09(&$server, &$lgsl_need, &$lgsl_fp)
{
//---------------------------------------------------------+
// SERIOUS SAM 2 RETURNS ALL PLAYER NAMES AS "Unknown Player" SO SKIP OR CONVERT ANY PLAYER REQUESTS
if ($server['b']['type'] == "serioussam2") { $lgsl_need['p'] = FALSE; if (!$lgsl_need['s'] && !$lgsl_need['e']) { $lgsl_need['s'] = TRUE; } }
//---------------------------------------------------------+
if ($lgsl_need['s'] || $lgsl_need['e'])
{
$lgsl_need['s'] = FALSE; $lgsl_need['e'] = FALSE;
fwrite($lgsl_fp, "\xFE\xFD\x00\x21\x21\x21\x21\xFF\x00\x00\x00");
$buffer = fread($lgsl_fp, 4096);
$buffer = substr($buffer, 5, -2); // REMOVE HEADER AND FOOTER
if (!$buffer) { return FALSE; }
$item = explode("\x00", $buffer);
foreach ($item as $item_key => $data_key)
{
if ($item_key % 2) { continue; } // SKIP EVEN KEYS
$data_key = strtolower($data_key);
$server['e'][$data_key] = $item[$item_key+1];
}
if (isset($server['e']['hostname'])) { $server['s']['name'] = $server['e']['hostname']; }
if (isset($server['e']['mapname'])) { $server['s']['map'] = $server['e']['mapname']; }
if (isset($server['e']['numplayers'])) { $server['s']['players'] = $server['e']['numplayers']; }
if (isset($server['e']['maxplayers'])) { $server['s']['playersmax'] = $server['e']['maxplayers']; }
if (isset($server['e']['password'])) { $server['s']['password'] = $server['e']['password']; }
if (!empty($server['e']['gamename'])) { $server['s']['game'] = $server['e']['gamename']; } // AARMY
if (!empty($server['e']['gsgamename'])) { $server['s']['game'] = $server['e']['gsgamename']; } // FEAR
if (!empty($server['e']['game_id'])) { $server['s']['game'] = $server['e']['game_id']; } // BFVIETNAM
if ($server['b']['type'] == "arma" || $server['b']['type'] == "arma2")
{
$server['s']['map'] = $server['e']['mission'];
}
elseif ($server['b']['type'] == "vietcong2")
{
$server['e']['extinfo_autobalance'] = ord($server['e']['extinfo'][18]) == 2 ? "off" : "on";
// [ 13 = Vietnam and RPG Mode 19 1b 99 9b ] [ 22 23 = Mounted MG Limit ]
// [ 27 = Idle Limit ] [ 18 = Auto Balance ] [ 55 = Chat and Blind Spectator 5a 5c da dc ]
}
}
//---------------------------------------------------------+
elseif ($lgsl_need['p'])
{
$lgsl_need['p'] = FALSE;
fwrite($lgsl_fp, "\xFE\xFD\x00\x21\x21\x21\x21\x00\xFF\x00\x00");
$buffer = fread($lgsl_fp, 4096);
$buffer = substr($buffer, 7, -1); // REMOVE HEADER / PLAYER TOTAL / FOOTER
if (!$buffer) { return FALSE; }
if (strpos($buffer, "\x00\x00") === FALSE) { return TRUE; } // NO PLAYERS
$buffer = explode("\x00\x00",$buffer, 2); // SPLIT FIELDS FROM ITEMS
$buffer[0] = str_replace("_", "", $buffer[0]); // REMOVE UNDERSCORES FROM FIELDS
$buffer[0] = str_replace("player", "name", $buffer[0]); // LGSL STANDARD
$field_list = explode("\x00",$buffer[0]); // SPLIT UP FIELDS
$item = explode("\x00",$buffer[1]); // SPLIT UP ITEMS
$item_position = 0;
$item_total = count($item);
$player_key = 0;
do
{
foreach ($field_list as $field)
{
$server['p'][$player_key][$field] = $item[$item_position];
$item_position ++;
}
$player_key ++;
}
while ($item_position < $item_total);
}
//---------------------------------------------------------+
return TRUE;
}
//------------------------------------------------------------------------------------------------------------+
//------------------------------------------------------------------------------------------------------------+