Jump to content
Sign in to follow this  
OXYD

ServerTracking

Recommended Posts

Salut , cum pot adauga jocul CS:GO , in lista pentru server tracking?

Am urmatorul cod , si nu stiu cum sa adaug si csgo (codul nu este creeat de mine)
 

Spoiler

<?php

 /*----------------------------------------------------------------------------------------------------------\

 |                                                                                                            |

 |                      [ LIVE GAME SERVER LIST ] [ © RICHARD PERRY FROM GREYCUBE.COM ]                       |

 |                                                                                                            |

 |    Released under the terms and conditions of the GNU General Public License Version 3 (http://gnu.org)    |

 |                                                                                                            |

 |-------------------------------------------------------------------------------------------------------------

 |        [ EDITOR STYLE SETTINGS: LUCIDA CONSOLE, SIZE 10, TAB = 2 SPACES, BOLD GLOBALLY TURNED OFF ]        |

 \-----------------------------------------------------------------------------------------------------------*/

//------------------------------------------------------------------------------------------------------------+

//------------------------------------------------------------------------------------------------------------+

  if (!function_exists('lgsl_version')) { // START OF DOUBLE LOAD PROTECTION

//------------------------------------------------------------------------------------------------------------+

//------------------------------------------------------------------------------------------------------------+

  function lgsl_type_list()

  {

    return array(

    "aarmy"         => "Americas Army",

    "aarmy3"        => "Americas Army 3",

    "arcasimracing" => "Arca Sim Racing",

    "arma"          => "ArmA: Armed Assault",

    "arma2"         => "ArmA 2",

    "avp2"          => "Aliens VS. Predator 2",

    "bfvietnam"     => "Battlefield Vietnam",

    "bf1942"        => "Battlefield 1942",

    "bf2"           => "Battlefield 2",

    "bf2142"        => "Battlefield 2142",

    "callofduty"    => "Call Of Duty",

    "callofdutyuo"  => "Call Of Duty: United Offensive",

    "callofdutywaw" => "Call Of Duty: World at War",

    "callofduty2"   => "Call Of Duty 2",

    "callofduty4"   => "Call Of Duty 4",

    "cncrenegade"   => "Command and Conquer: Renegade",

    "crysis"        => "Crysis",

    "crysiswars"    => "Crysis Wars",

    "cube"          => "Cube Engine",

    "doomskulltag"  => "Doom - Skulltag",

    "doomzdaemon"   => "Doom - ZDaemon",

    "doom3"         => "Doom 3",

    "dh2005"        => "Deer Hunter 2005",

    "farcry"        => "Far Cry",

    "fear"          => "F.E.A.R.",

    "flashpoint"    => "Operation Flashpoint",

    "freelancer"    => "Freelancer",

    "frontlines"    => "Frontlines: Fuel Of War",

    "f1c9902"       => "F1 Challenge 99-02",

    "gamespy1"      => "Generic GameSpy 1",

    "gamespy2"      => "Generic GameSpy 2",

    "gamespy3"      => "Generic GameSpy 3",

    "ghostrecon"    => "Ghost Recon",

    "graw"          => "Ghost Recon: Advanced Warfighter",

    "graw2"         => "Ghost Recon: Advanced Warfighter 2",

    "gtr2"          => "GTR 2",

    "had2"          => "Hidden and Dangerous 2",

    "halflife"      => "Half-Life - Steam",

    "halflifewon"   => "Half-Life - WON",

    "halo"          => "Halo",

    "il2"           => "IL-2 Sturmovik",

    "jediknight2"   => "JediKnight 2: Jedi Outcast",

    "jediknightja"  => "JediKnight: Jedi Academy",

    "killingfloor"  => "Killing Floor",

    "kingpin"       => "Kingpin: Life of Crime",

    "mohaa"         => "Medal of Honor: Allied Assault",

    "mohaab"        => "Medal of Honor: Allied Assault Breakthrough",

    "mohaas"        => "Medal of Honor: Allied Assault Spearhead",

    "mohpa"         => "Medal of Honor: Pacific Assault",

    "mta"           => "Multi Theft Auto",

    "nascar2004"    => "Nascar Thunder 2004",

    "neverwinter"   => "NeverWinter Nights",

    "neverwinter2"  => "NeverWinter Nights 2",

    "nexuiz"        => "Nexuiz",

    "openttd"       => "Open Transport Tycoon Deluxe",

    "painkiller"    => "PainKiller",

    "prey"          => "Prey",

    "quakeworld"    => "Quake World",

    "quakewars"     => "Enemy Territory: Quake Wars",

    "quake2"        => "Quake 2",

    "quake3"        => "Quake 3",

    "quake4"        => "Quake 4",

    "ravenshield"   => "Raven Shield",

    "redorchestra"  => "Red Orchestra",

    "rfactor"       => "RFactor",

    "samp"          => "San Andreas Multiplayer",

    "savage"        => "Savage",

    "savage2"       => "Savage 2",

    "serioussam"    => "Serious Sam",

    "serioussam2"   => "Serious Sam 2",

    "sof2"          => "Soldier of Fortune 2",

    "soldat"        => "Soldat",

    "source"        => "Counter-Strike 1.6",

    "stalker"       => "S.T.A.L.K.E.R.",

    "stalkercs"     => "S.T.A.L.K.E.R. Clear Sky",

    "startrekef"    => "StarTrek Elite-Force",

    "starwarsbf"    => "Star Wars: Battlefront",

    "starwarsbf2"   => "Star Wars: Battlefront 2",

    "starwarsrc"    => "Star Wars: Republic Commando",

    "swat4"         => "SWAT 4",

    "test"          => "Test ( For PHP Developers )",

    "teeworlds"     => "Teeworlds",

    "tribes"        => "Tribes ( Starsiege )",

    "tribes2"       => "Tribes 2",

    "tribesv"       => "Tribes Vengeance",

    "urbanterror"   => "UrbanTerror",

    "ut"            => "Unreal Tournament",

    "ut2003"        => "Unreal Tournament 2003",

    "ut2004"        => "Unreal Tournament 2004",

    "ut3"           => "Unreal Tournament 3",

    "vietcong"      => "Vietcong",

    "vietcong2"     => "Vietcong 2",

    "warsow"        => "Warsow",

    "warsowold"     => "Warsow ( 0.4.2 and older )",

    "wolfet"        => "Wolfenstein: Enemy Territory",

    "wolfrtcw"      => "Wolfenstein: Return To Castle Wolfenstein",

    "wolf2009"      => "Wolfenstein ( 2009 By Raven )");

  }

//------------------------------------------------------------------------------------------------------------+

//------------------------------------------------------------------------------------------------------------+

  function lgsl_protocol_list()

  {

    return array(

    "aarmy"         => "09",

    "aarmy_"        => "03",

    "aarmy3"        => "26",

    "arcasimracing" => "16",

    "arma"          => "09",

    "arma2"         => "09",

    "avp2"          => "03",

    "bfvietnam"     => "09",

    "bf1942"        => "03",

    "bf2"           => "06",

    "bf2142"        => "06",

    "callofduty"    => "02",

    "callofdutyuo"  => "02",

    "callofdutywaw" => "02",

    "callofduty2"   => "02",

    "callofduty4"   => "02",

    "cncrenegade"   => "03",

    "crysis"        => "06",

    "crysiswars"    => "06",

    "cube"          => "24",

    "doomskulltag"  => "27",

    "doomzdaemon"   => "28",

    "doom3"         => "10",

    "dh2005"        => "09",

    "had2"          => "03",

    "halflife"      => "05",

    "halflifewon"   => "05",

    "halo"          => "03",

    "il2"           => "03",

    "farcry"        => "08",

    "fear"          => "09",

    "flashpoint"    => "03",

    "freelancer"    => "14",

    "frontlines"    => "20",

    "f1c9902"       => "03",

    "gamespy1"      => "03",

    "gamespy2"      => "09",

    "gamespy3"      => "06",

    "ghostrecon"    => "19",

    "graw"          => "06",

    "graw2"         => "09",

    "gtr2"          => "15",

    "jediknight2"   => "02",

    "jediknightja"  => "02",

    "killingfloor"  => "13",

    "kingpin"       => "03",

    "mohaa"         => "03",

    "mohaab"        => "03",

    "mohaas"        => "03",

    "mohpa"         => "03",

    "mohaa_"        => "02",

    "mohaab_"       => "02",

    "mohaas_"       => "02",

    "mohpa_"        => "02",

    "mta"           => "08",

    "nascar2004"    => "09",

    "neverwinter"   => "09",

    "neverwinter2"  => "09",

    "nexuiz"        => "02",

    "openttd"       => "22",

    "painkiller"    => "08",

    "painkiller_"   => "09",

    "prey"          => "10",

    "quakeworld"    => "07",

    "quakewars"     => "10",

    "quake2"        => "02",

    "quake3"        => "02",

    "quake4"        => "10",

    "ravenshield"   => "04",

    "redorchestra"  => "13",

    "rfactor"       => "16",

    "samp"          => "12",

    "savage"        => "17",

    "savage2"       => "18",

    "serioussam"    => "03",

    "serioussam2"   => "09",

    "sof2"          => "02",

    "soldat"        => "08",

    "source"        => "05",

    "stalker"       => "06",

    "stalkercs"     => "09",

    "startrekef"    => "02",

    "starwarsbf"    => "09",

    "starwarsbf2"   => "09",

    "starwarsrc"    => "09",

    "swat4"         => "03",

    "test"          => "01",

    "teeworlds"     => "21",

    "tribes"        => "23",

    "tribes2"       => "25",

    "tribesv"       => "09",

    "warsow"        => "02",

    "warsowold"     => "02",

    "urbanterror"   => "02",

    "ut"            => "03",

    "ut2003"        => "13",

    "ut2003_"       => "03",

    "ut2004"        => "13",

    "ut2004_"       => "03",

    "ut3"           => "11",

    "vietcong"      => "03",

    "vietcong2"     => "09",

    "wolfet"        => "02",

    "wolfrtcw"      => "02",

    "wolf2009"      => "10");

    return $lgsl_protocol_list;

  }

//------------------------------------------------------------------------------------------------------------+

//------------------------------------------------------------------------------------------------------------+

  function lgsl_software_link($type, $ip, $c_port, $q_port, $s_port)

  {

    $lgsl_software_link = array(

    "aarmy"         => "qtracker://{IP}:{S_PORT}?game=ArmyOperations&action=show",

    "aarmy3"        => "qtracker://{IP}:{S_PORT}?game=AmericasArmy3&action=show",

    "arcasimracing" => "http://en.wikipedia.org/wiki/ARCA_Sim_Racing",

    "arma"          => "qtracker://{IP}:{S_PORT}?game=ArmedAssault&action=show",

    "arma2"         => "http://en.wikipedia.org/wiki/ARMA_2",

    "avp2"          => "qtracker://{IP}:{S_PORT}?game=AliensversusPredator2&action=show",

    "bfvietnam"     => "qtracker://{IP}:{S_PORT}?game=BattlefieldVietnam&action=show",

    "bf1942"        => "qtracker://{IP}:{S_PORT}?game=Battlefield1942&action=show",

    "bf2"           => "qtracker://{IP}:{S_PORT}?game=Battlefield2&action=show",

    "bf2142"        => "qtracker://{IP}:{S_PORT}?game=Battlefield2142&action=show",

    "callofduty"    => "qtracker://{IP}:{S_PORT}?game=CallOfDuty&action=show",

    "callofdutyuo"  => "qtracker://{IP}:{S_PORT}?game=CallOfDutyUnitedOffensive&action=show",

    "callofdutywaw" => "qtracker://{IP}:{S_PORT}?game=CallOfDutyWorldAtWar&action=show",

    "callofduty2"   => "qtracker://{IP}:{S_PORT}?game=CallOfDuty2&action=show",

    "callofduty4"   => "qtracker://{IP}:{S_PORT}?game=CallOfDuty4&action=show",

    "cncrenegade"   => "qtracker://{IP}:{S_PORT}?game=CommandConquerRenegade&action=show",

    "crysis"        => "qtracker://{IP}:{S_PORT}?game=Crysis&action=show",

    "crysiswars"    => "qtracker://{IP}:{S_PORT}?game=CrysisWars&action=show",

    "cube"          => "http://cubeengine.com",

    "doomskulltag"  => "http://skulltag.com",

    "doomzdaemon"   => "http://www.zdaemon.org",

    "doom3"         => "qtracker://{IP}:{S_PORT}?game=Doom3&action=show",

    "dh2005"        => "http://en.wikipedia.org/wiki/Deer_Hunter_(computer_game)",

    "farcry"        => "qtracker://{IP}:{S_PORT}?game=FarCry&action=show",

    "fear"          => "qtracker://{IP}:{S_PORT}?game=FEAR&action=show",

    "flashpoint"    => "qtracker://{IP}:{S_PORT}?game=OperationFlashpoint&action=show",

    "freelancer"    => "http://en.wikipedia.org/wiki/Freelancer_(computer_game)",

    "frontlines"    => "http://en.wikipedia.org/wiki/Frontlines:_Fuel_of_War",

    "f1c9902"       => "http://en.wikipedia.org/wiki/EA_Sports_F1_Series",

    "gamespy1"      => "http://www.greycube.com",

    "gamespy2"      => "http://www.greycube.com",

    "gamespy3"      => "http://www.greycube.com",

    "ghostrecon"    => "http://en.wikipedia.org/wiki/Tom_Clancy's_Ghost_Recon",

    "graw"          => "qtracker://{IP}:{S_PORT}?game=GhostRecon&action=show",

    "graw2"         => "http://en.wikipedia.org/wiki/Tom_Clancy's_Ghost_Recon_Advanced_Warfighter_2",

    "gtr2"          => "http://en.wikipedia.org/wiki/GTR2",

    "had2"          => "http://en.wikipedia.org/wiki/Hidden_&_Dangerous_2",

    "halflife"      => "qtracker://{IP}:{S_PORT}?game=HalfLife&action=show",

    "halflifewon"   => "qtracker://{IP}:{S_PORT}?game=HalfLife_WON2&action=show",

    "halo"          => "qtracker://{IP}:{S_PORT}?game=Halo&action=show",

    "il2"           => "http://en.wikipedia.org/wiki/IL-2_Sturmovik_(game)",

    "jediknight2"   => "qtracker://{IP}:{S_PORT}?game=JediKnight2&action=show",

    "jediknightja"  => "qtracker://{IP}:{S_PORT}?game=JediKnightJediAcademy&action=show",

    "killingfloor"  => "qtracker://{IP}:{S_PORT}?game=KillingFloor&action=show",

    "kingpin"       => "qtracker://{IP}:{S_PORT}?game=Kingpin&action=show",

    "mohaa"         => "qtracker://{IP}:{S_PORT}?game=MedalofHonorAlliedAssault&action=show",

    "mohaab"        => "qtracker://{IP}:{S_PORT}?game=MedalofHonorAlliedAssaultBreakthrough&action=show",

    "mohaas"        => "qtracker://{IP}:{S_PORT}?game=MedalofHonorAlliedAssaultSpearhead&action=show",

    "mohpa"         => "qtracker://{IP}:{S_PORT}?game=MedalofHonorPacificAssault&action=show",

    "mta"           => "http://en.wikipedia.org/wiki/Multi_Theft_Auto",

    "nascar2004"    => "http://en.wikipedia.org/wiki/NASCAR_Thunder_2004",

    "neverwinter"   => "qtracker://{IP}:{S_PORT}?game=NeverwinterNights&action=show",

    "neverwinter2"  => "qtracker://{IP}:{S_PORT}?game=NeverwinterNights&action=show",

    "nexuiz"        => "qtracker://{IP}:{S_PORT}?game=Nexuiz&action=show",

    "openttd"       => "http://wwww.openttd.org",

    "painkiller"    => "qtracker://{IP}:{S_PORT}?game=Painkiller&action=show",

    "prey"          => "qtracker://{IP}:{S_PORT}?game=Prey&action=show",

    "quakeworld"    => "qtracker://{IP}:{S_PORT}?game=QuakeWorld&action=show",

    "quakewars"     => "qtracker://{IP}:{S_PORT}?game=EnemyTerritoryQuakeWars&action=show",

    "quake2"        => "qtracker://{IP}:{S_PORT}?game=Quake2&action=show",

    "quake3"        => "qtracker://{IP}:{S_PORT}?game=Quake3&action=show",

    "quake4"        => "qtracker://{IP}:{S_PORT}?game=Quake4&action=show",

    "ravenshield"   => "http://en.wikipedia.org/wiki/Tom_Clancy's_Rainbow_Six_3",

    "redorchestra"  => "qtracker://{IP}:{S_PORT}?game=RedOrchestra&action=show",

    "rfactor"       => "rfactor://{IP}:{S_PORT}",

    "samp"          => "http://www.sa-mp.com",

    "savage"        => "http://en.wikipedia.org/wiki/Savage:_The_Battle_for_Newerth",

    "savage2"       => "http://en.wikipedia.org/wiki/Savage_2:_A_Tortured_Soul",

    "serioussam"    => "qtracker://{IP}:{S_PORT}?game=SeriousSam&action=show",

    "serioussam2"   => "qtracker://{IP}:{S_PORT}?game=Serious_Sam2&action=show",

    "sof2"          => "qtracker://{IP}:{S_PORT}?game=SoldierOfFortune2&action=show",

    "soldat"        => "http://www.soldat.pl",

    "source"        => "qtracker://{IP}:{S_PORT}?game=HalfLife2&action=show",

    "stalker"       => "qtracker://{IP}:{S_PORT}?game=STALKER_ShadowChernobyl&action=show",

    "stalkercs"     => "qtracker://{IP}:{S_PORT}?game=STALKER_ClearSky&action=show",

    "startrekef"    => "http://en.wikipedia.org/wiki/Star_Trek:_Voyager:_Elite_Force",

    "starwarsbf"    => "qtracker://{IP}:{S_PORT}?game=StarWarsBattlefront&action=show",

    "starwarsbf2"   => "qtracker://{IP}:{S_PORT}?game=StarWarsBattlefront2&action=show",

    "starwarsrc"    => "qtracker://{IP}:{S_PORT}?game=StarWarsRepublicCommando&action=show",

    "swat4"         => "qtracker://{IP}:{S_PORT}?game=SWAT4&action=show",

    "test"          => "http://www.greycube.com",

    "teeworlds"     => "http://www.teeworlds.com",

    "tribes"        => "qtracker://{IP}:{S_PORT}?game=Tribes&action=show",

    "tribes2"       => "qtracker://{IP}:{S_PORT}?game=Tribes2&action=show",

    "tribesv"       => "qtracker://{IP}:{S_PORT}?game=TribesVengeance&action=show",

    "urbanterror"   => "qtracker://{IP}:{S_PORT}?game=UrbanTerror&action=show",

    "ut"            => "qtracker://{IP}:{S_PORT}?game=UnrealTournament&action=show",

    "ut2003"        => "qtracker://{IP}:{S_PORT}?game=UnrealTournament2003&action=show",

    "ut2004"        => "qtracker://{IP}:{S_PORT}?game=UnrealTournament2004&action=show",

    "ut3"           => "qtracker://{IP}:{S_PORT}?game=UnrealTournament3&action=show",

    "vietcong"      => "qtracker://{IP}:{S_PORT}?game=Vietcong&action=show",

    "vietcong2"     => "qtracker://{IP}:{S_PORT}?game=Vietcong2&action=show",

    "warsow"        => "qtracker://{IP}:{S_PORT}?game=Warsow&action=show",

    "warsowold"     => "qtracker://{IP}:{S_PORT}?game=Warsow&action=show",

    "wolfet"        => "qtracker://{IP}:{S_PORT}?game=WolfensteinEnemyTerritory&action=show",

    "wolfrtcw"      => "qtracker://{IP}:{S_PORT}?game=ReturntoCastleWolfenstein&action=show",

    "wolf2009"      => "http://en.wikipedia.org/wiki/Wolfenstein_(2009_video_game)");

    // SOFTWARE PORT IS THE QUERY PORT UNLESS SET

    if (!$s_port) { $s_port = $q_port; }

    // TRY USING THE STANDARD LAUNCH LINK FOR ALTERNATE PROTOCOLS IF ONE IS NOT SET

    if (!isset($lgsl_software_link[$type])) { $type = str_replace("_", "", $type); }

    // INSERT DATA INTO STATIC LINK - CONVERT SPECIAL CHARACTERS - RETURN

    return htmlentities(str_replace(array("{IP}", "{C_PORT}", "{Q_PORT}", "{S_PORT}"), array($ip, $c_port, $q_port, $s_port), $lgsl_software_link[$type]), ENT_QUOTES);

  }

//------------------------------------------------------------------------------------------------------------+

//------------------------------------------------------------------------------------------------------------+

  function lgsl_port_conversion($type, $c_port, $q_port, $s_port)

  {

    switch ($type) // GAMES WHERE Q_PORT IS NOT EQUAL TO C_PORT

    {

      case "aarmy"         : $c_to_q = 1;     $c_def = 1716;    $q_def = 1717;    $c_to_s = 0;   break;

      case "aarmy3"        : $c_to_q = 0;     $c_def = 8777;    $q_def = 39300;   $c_to_s = 0;   break;

      case "arcasimracing" : $c_to_q = -100;  $c_def = 34397;   $q_def = 34297;   $c_to_s = 0;   break;

      case "bfvietnam"     : $c_to_q = 0;     $c_def = 15567;   $q_def = 23000;   $c_to_s = 0;   break;

      case "bf1942"        : $c_to_q = 0;     $c_def = 14567;   $q_def = 23000;   $c_to_s = 0;   break;

      case "bf2"           : $c_to_q = 0;     $c_def = 16567;   $q_def = 29900;   $c_to_s = 0;   break;

      case "bf2142"        : $c_to_q = 0;     $c_def = 17567;   $q_def = 29900;   $c_to_s = 0;   break;

      case "cube"          : $c_to_q = 1;     $c_def = 28785;   $q_def = 28786;   $c_to_s = 0;   break;

      case "dh2005"        : $c_to_q = 0;     $c_def = 23459;   $q_def = 34567;   $c_to_s = 0;   break;

      case "farcry"        : $c_to_q = 123;   $c_def = 49001;   $q_def = 49124;   $c_to_s = 0;   break;

      case "flashpoint"    : $c_to_q = 1;     $c_def = 2302;    $q_def = 2303;    $c_to_s = 0;   break;

      case "frontlines"    : $c_to_q = 2;     $c_def = 5476;    $q_def = 5478;    $c_to_s = 0;   break;

      case "ghostrecon"    : $c_to_q = 2;     $c_def = 2346;    $q_def = 2348;    $c_to_s = 0;   break;

      case "gtr2"          : $c_to_q = 1;     $c_def = 34297;   $q_def = 34298;   $c_to_s = 0;   break;

      case "had2"          : $c_to_q = 3;     $c_def = 11001;   $q_def = 11004;   $c_to_s = 0;   break;

      case "kingpin"       : $c_to_q = -10;   $c_def = 31510;   $q_def = 31500;   $c_to_s = 0;   break;

      case "killingfloor"  : $c_to_q = 1;     $c_def = 7708;    $q_def = 7709;    $c_to_s = 0;   break;

      case "mohaa"         : $c_to_q = 97;    $c_def = 12203;   $q_def = 12300;   $c_to_s = 0;   break;

      case "mohaab"        : $c_to_q = 97;    $c_def = 12203;   $q_def = 12300;   $c_to_s = 0;   break;

      case "mohaas"        : $c_to_q = 97;    $c_def = 12203;   $q_def = 12300;   $c_to_s = 0;   break;

      case "mohpa"         : $c_to_q = 97;    $c_def = 13203;   $q_def = 13300;   $c_to_s = 0;   break;

      case "mta"           : $c_to_q = 123;   $c_def = 22003;   $q_def = 22126;   $c_to_s = 0;   break;

      case "painkiller"    : $c_to_q = 123;   $c_def = 3455;    $q_def = 3578;    $c_to_s = 0;   break;

      case "ravenshield"   : $c_to_q = 1000;  $c_def = 7777;    $q_def = 8777;    $c_to_s = 0;   break;

      case "redorchestra"  : $c_to_q = 1;     $c_def = 7758;    $q_def = 7759;    $c_to_s = 0;   break;

      case "rfactor"       : $c_to_q = -100;  $c_def = 34397;   $q_def = 34297;   $c_to_s = 0;   break;

      case "serioussam"    : $c_to_q = 1;     $c_def = 25600;   $q_def = 25601;   $c_to_s = 0;   break;

      case "soldat"        : $c_to_q = 123;   $c_def = 23073;   $q_def = 23196;   $c_to_s = 0;   break;

      case "stalker"       : $c_to_q = 2;     $c_def = 5447;    $q_def = 5445;    $c_to_s = 0;   break;

      case "stalkercs"     : $c_to_q = 2;     $c_def = 5447;    $q_def = 5445;    $c_to_s = 0;   break;

      case "starwarsrc"    : $c_to_q = 0;     $c_def = 7777;    $q_def = 11138;   $c_to_s = 0;   break;

      case "swat4"         : $c_to_q = 1;     $c_def = 10780;   $q_def = 10781;   $c_to_s = 0;   break;

      case "tribesv"       : $c_to_q = 1;     $c_def = 7777;    $q_def = 7778;    $c_to_s = 0;   break;

      case "ut"            : $c_to_q = 1;     $c_def = 7777;    $q_def = 7778;    $c_to_s = 0;   break;

      case "ut2003"        : $c_to_q = 1;     $c_def = 7757;    $q_def = 7758;    $c_to_s = 10;  break;

      case "ut2003_"       : $c_to_q = 10;    $c_def = 7757;    $q_def = 7767;    $c_to_s = 0;   break;

      case "ut2004"        : $c_to_q = 1;     $c_def = 7777;    $q_def = 7778;    $c_to_s = 10;  break;

      case "ut2004_"       : $c_to_q = 10;    $c_def = 7777;    $q_def = 7787;    $c_to_s = 0;   break;

      case "ut3"           : $c_to_q = 0;     $c_def = 7777;    $q_def = 6500;    $c_to_s = 0;   break;

      case "vietcong"      : $c_to_q = 10000; $c_def = 5425;    $q_def = 15425;   $c_to_s = 0;   break;

      case "vietcong2"     : $c_to_q = 0;     $c_def = 5001;    $q_def = 19967;   $c_to_s = 0;   break;

      default              : $c_to_q = 0;     $c_def = 0;       $q_def = 0;       $c_to_s = 0;   break;

    }

    if     (!$c_port && !$q_port && $c_def)  { $c_port = $c_def; $q_port = $q_def; }

    if     (!$c_port &&  $q_port && $c_to_q) { $c_port = $q_port - $c_to_q; }

    elseif (!$c_port &&  $q_port && $c_def)  { $c_port = $c_def; }

    elseif (!$c_port &&  $q_port)            { $c_port = $q_port; }

    if     (!$q_port &&  $c_port && $c_to_q) { $q_port = $c_port + $c_to_q; }

    elseif (!$q_port &&  $c_port && $q_def)  { $q_port = $q_def; }

    elseif (!$q_port &&  $c_port)            { $q_port = $c_port; }

    if     (!$s_port &&  $c_to_s)            { $s_port = $c_port + $c_to_s; }

    return array(intval($c_port), intval($q_port), intval($s_port));

  }

//------------------------------------------------------------------------------------------------------------+

//------------------------------------------------------------------------------------------------------------+

  function lgsl_query_live($type, $ip, $c_port, $q_port, $s_port, $request)

  {

//---------------------------------------------------------+

    if (preg_match("/[^0-9a-z\.\-\[\]\:]/i", $ip))

    {

      exit("LGSL PROBLEM: INVALID IP OR HOSTNAME");

    }

    $lgsl_protocol_list = lgsl_protocol_list();

    if (!$lgsl_protocol_list[$type])

    {

      exit("LGSL PROBLEM: ".($type ? "INVALID TYPE '{$type}'" : "MISSING TYPE")." FOR {$ip}, {$c_port}, {$q_port}, {$s_port}");

    }

    $lgsl_function = "lgsl_query_{$lgsl_protocol_list[$type]}";

    if (!function_exists($lgsl_function))

    {

      exit("LGSL PROBLEM: FUNCTION DOES NOT EXIST FOR: {$type}");

    }

    if (!intval($q_port))

    {

      exit("LGSL PROBLEM: INVALID QUERY PORT");

    }

//---------------------------------------------------------+

    // SETUP SERVER ARRAYS AND FILL WITH ESSENTIALS

    $server                = array();

    $server['s']           = array();

    $server['e']           = array();

    $server['p']           = array();

    $server['b']           = array();

    $server['b']['type']   = $type;

    $server['b']['ip']     = $ip;

    $server['b']['c_port'] = $c_port;

    $server['b']['q_port'] = $q_port;

    $server['b']['s_port'] = $s_port;

    $server['b']['status'] = 1;

//---------------------------------------------------------+

    global $lgsl_config; // FEED IS SET IN THE CONFIG

    if ($lgsl_config['feed']['method'] && $lgsl_config['feed']['url'])

    {

      $status = lgsl_query_feed($server, $request, $lgsl_config['feed']['method'], $lgsl_config['feed']['url']);

    }

    elseif ($type == "test") // TEST BYPASSES CONNECTION CODE

    {

      $lgsl_need = array("s" => TRUE, "e" => TRUE, "p" => TRUE); $lgsl_fp = "";

      $status = call_user_func_array($lgsl_function, array(&$server, &$lgsl_need, &$lgsl_fp));

    }

    else

    {

      $status = lgsl_query_direct($server, $request, $lgsl_function);

    }

//---------------------------------------------------------+

    if (!$status) // SERVER OFFLINE

    {

      $server['b']['status'] = 0;

    }

    else // REMOVE REQUESTS NOT RETURNED

    {

      if (!$server['s']) { unset($server['s']); }

      if (!$server['e']) { unset($server['e']); }

      if (!$server['p'] && $server['s']['players'] != "0" && strpos($request, "p") === FALSE) { unset($server['p']); }
    }

//---------------------------------------------------------+

    // IS A CONSISTANT FORMAT EVEN IF SERVER IS OFFLINE

    if (isset($server['s']))

    {

      if (!$server['s']['game']) { $server['s']['game'] = $type; }

      $tmp = str_replace("\\", "/", $server['s']['map']); // REMOVE ANY

      $tmp = explode("/", $tmp);                          // FOLDERS

      $server['s']['map'] = array_pop($tmp);              // FROM MAP

      if (strtolower($server['s']['password']) == "false") { $server['s']['password'] = 0; }

      if (strtolower($server['s']['password']) == "true")  { $server['s']['password'] = 1; }

      $server['s']['password']   = intval($server['s']['password']);

      $server['s']['players']    = intval($server['s']['players']);

      $server['s']['playersmax'] = intval($server['s']['playersmax']);

      if ($server['s']['players']    < 0) { $server['s']['players']    = 0; }

      if ($server['s']['playersmax'] < 0) { $server['s']['playersmax'] = 0; }

    }

//---------------------------------------------------------+

    return $server;

  }

//------------------------------------------------------------------------------------------------------------+

//------------------------------------------------------------------------------------------------------------+

  function lgsl_query_direct(&$server, $request, $lgsl_function)

  {

//---------------------------------------------------------+

    $lgsl_fp = @fsockopen("udp://{$server['b']['ip']}", $server['b']['q_port'], $errno, $errstr, 1);

    if (!$lgsl_fp) { return FALSE; }

//---------------------------------------------------------+

    global $lgsl_config;

    $lgsl_config['timeout'] = intval($lgsl_config['timeout']);

    stream_set_timeout($lgsl_fp, $lgsl_config['timeout'], $lgsl_config['timeout'] ? 0 : 500000);

    stream_set_blocking($lgsl_fp, TRUE);

//---------------------------------------------------------+

    $lgsl_need      = array();

    $lgsl_need['s'] = strpos($request, "s") !== FALSE ? TRUE : FALSE;

    $lgsl_need['e'] = strpos($request, "e") !== FALSE ? TRUE : FALSE;

    $lgsl_need['p'] = strpos($request, "p") !== FALSE ? TRUE : FALSE;

    // REQUEST OFTEN ALSO RETURNS SOME [e] SO CHANGE [e] ONLY REQUESTS TO [e]

    if ($lgsl_need['e'] && !$lgsl_need['s']) { $lgsl_need['s'] = TRUE; }

//---------------------------------------------------------+

    do // THIS AVOIDS DUPLICATING PACKET CODE

    {

      $lgsl_need_check = $lgsl_need;

      // CALL FUNCTION REQUIRES '&$variable' TO PASS 'BY REFERENCE'

      $status = call_user_func_array($lgsl_function, array(&$server, &$lgsl_need, &$lgsl_fp));

      // CHECK IF SERVER IS OFFLINE

      if (!$status) { break; }

      // CHECK IF NEED HAS NOT CHANGED - THIS SERVES TWO PURPOSES - TO PREVENT INFINITE LOOPS - AND TO

      // AVOID WRITING $lgsl_need = FALSE FALSE FALSE FOR GAMES THAT RETURN ALL DATA IN ONE RESPONSE

      if ($lgsl_need_check == $lgsl_need) { break; }

      // OPTIMIZATION THAT SKIPS REQUEST FOR PLAYER DETAILS WHEN THE SERVER IS KNOWN TO BE EMPTY

      if ($lgsl_need['p'] && $server['s']['players'] == "0") { $lgsl_need['p'] = FALSE; }

    }

    while ($lgsl_need['s'] == TRUE || $lgsl_need['e'] == TRUE || $lgsl_need['p'] == TRUE);

//---------------------------------------------------------+

    @fclose($lgsl_fp);

    return $status;

  }

//------------------------------------------------------------------------------------------------------------+

//------------------------------------------------------------------------------------------------------------+

  function lgsl_query_01(&$server, &$lgsl_need, &$lgsl_fp)

  {

//---------------------------------------------------------+

//  PROTOCOL FOR DEVELOPING WITHOUT USING LIVE SERVERS TO HELP ENSURE RETURNED

//  DATA IS SANITIZED AND THAT LONG SERVER AND PLAYER NAMES ARE HANDLED PROPERLY

    $server['s'] = array(

    "game"       => "test_game",

    "name"       => "test_ServerNameThatsOften'Really'LongAndCanHaveSymbols<hr />ThatWill\"Screw\"UpHtmlUnlessEntitied",

    "map"        => "test_map",

    "players"    => rand(0,  16),

    "playersmax" => rand(16, 32),

    "password"   => rand(0,  1));

//---------------------------------------------------------+

    $server['e'] = array(

    "testextra1" => "normal",

    "testextra2" => 123,

    "testextra3" => time(),

    "testextra4" => "",

    "testextra5" => "<b>Setting<hr />WithHtml</b>",

    "testextra6" => "ReallyLongSettingLikeSomeMapCyclesThatHaveNoSpacesAndCauseThePageToGoReallyWideIfNotBrokenUp");

//---------------------------------------------------------+

    $server['p']['0']['name']  = "Normal";

    $server['p']['0']['score'] = "12";

    $server['p']['0']['ping']  = "34";

    $server['p']['1']['name']  = "\xc3\xa9\x63\x68\x6f\x20\xd0\xb8-d0\xb3\xd1\x80\xd0\xbe\xd0\xba"; // UTF PLAYER NAME

    $server['p']['1']['score'] = "56";

    $server['p']['1']['ping']  = "78";

    $server['p']['2']['name']  = "One&<Two>&Three&\"Four\"&'Five'";

    $server['p']['2']['score'] = "90";

    $server['p']['2']['ping']  = "12";

    $server['p']['3']['name']  = "ReallyLongPlayerNameBecauseTheyAreUberCoolAndAreInFiveClans";

    $server['p']['3']['score'] = "90";

    $server['p']['3']['ping']  = "12";

//---------------------------------------------------------+

    if (rand(0, 10) == 5) { $server['p'] = array(); } // RANDOM NO PLAYERS

    if (rand(0, 10) == 5) { return FALSE; }           // RANDOM GOING OFFLINE

//---------------------------------------------------------+

    return TRUE;

  }

//------------------------------------------------------------------------------------------------------------+

//------------------------------------------------------------------------------------------------------------+

  function lgsl_query_02(&$server, &$lgsl_need, &$lgsl_fp)

  {

//---------------------------------------------------------+

    if     ($server['b']['type'] == "quake2")              { fwrite($lgsl_fp, "\xFF\xFF\xFF\xFFstatus");        }

    elseif ($server['b']['type'] == "warsowold")           { fwrite($lgsl_fp, "\xFF\xFF\xFF\xFFgetinfo");       }

    elseif (strpos($server['b']['type'], "moh") !== FALSE) { fwrite($lgsl_fp, "\xFF\xFF\xFF\xFF\x02getstatus"); } // mohaa_ mohaab_ mohaas_ mohpa_

    else                                                   { fwrite($lgsl_fp, "\xFF\xFF\xFF\xFFgetstatus");     }

    $buffer = fread($lgsl_fp, 4096);

    if (!$buffer) { return FALSE; }

//---------------------------------------------------------+

    $part = explode("\n", $buffer);  // SPLIT INTO PARTS: HEADER/SETTINGS/PLAYERS/FOOTER

    array_pop($part);                // REMOVE FOOTER WHICH IS EITHER NULL OR "\challenge\"

    $item = explode("\\", $part[1]); // SPLIT PART INTO ITEMS

    foreach ($item as $item_key => $data_key)

    {

      if (!($item_key % 2)) { continue; } // SKIP EVEN KEYS

      $data_key               = strtolower(lgsl_parse_color($data_key, "1"));

      $server['e'][$data_key] = lgsl_parse_color($item[$item_key+1], "1");

    }

//---------------------------------------------------------+

    $server['s']['game']       = $server['e']['gamename'];

    $server['s']['name']       = $server['e']['sv_hostname'];

    $server['s']['map']        = $server['e']['mapname'];

    $server['s']['players']    = $part['2'] ? count($part) - 2 : 0;

    $server['s']['playersmax'] = $server['e']['sv_maxclients'];

    $server['s']['password']   = $server['e']['g_needpass'];

    if (!$server['s']['name'])             { $server['s']['name']       = $server['e']['hostname'];   } // HOSTNAME ALTERNATIVE

    if (isset($server['e']['pswrd']))      { $server['s']['password']   = $server['e']['pswrd'];      } // CALL OF DUTY

    if (isset($server['e']['needpass']))   { $server['s']['password']   = $server['e']['needpass'];   } // QUAKE2

    if (isset($server['e']['maxclients'])) { $server['s']['playersmax'] = $server['e']['maxclients']; } // QUAKE2

    array_shift($part); // REMOVE HEADER

    array_shift($part); // REMOVE SETTING

//---------------------------------------------------------+

    if ($server['b']['type'] == "nexuiz") // (SCORE) (PING) (TEAM IF TEAM GAME) "(NAME)"

    {

      $pattern = "/(.*) (.*) (.*)\"(.*)\"/U"; $fields = array(1=>"score", 2=>"ping", 3=>"team", 4=>"name");

    }

    elseif ($server['b']['type'] == "warsow") // (SCORE) (PING) "(NAME)" (TEAM)

    {

      $pattern = "/(.*) (.*) \"(.*)\" (.*)/"; $fields = array(1=>"score", 2=>"ping", 3=>"name", 4=>"team");

    }

    elseif ($server['b']['type'] == "sof2") // (SCORE) (PING) (DEATHS) "(NAME)"

    {

      $pattern = "/(.*) (.*) (.*) \"(.*)\"/"; $fields = array(1=>"score", 2=>"ping", 3=>"deaths", 4=>"name");

    }

    elseif (strpos($server['b']['type'], "mohpa") !== FALSE) // (?) (SCORE) (?) (TIME) (?) "(RANK?)" "(NAME)"

    {

      $pattern = "/(.*) (.*) (.*) (.*) (.*) \"(.*)\" \"(.*)\"/"; $fields = array(2=>"score", 3=>"deaths", 4=>"time", 6=>"rank", 7=>"name");

    }

    elseif (strpos($server['b']['type'], "moh") !== FALSE) // (PING) "(NAME)"

    {

      $pattern = "/(.*) \"(.*)\"/"; $fields = array(1=>"ping", 2=>"name");

    }

    else // (SCORE) (PING) "(NAME)"

    {

      $pattern = "/(.*) (.*) \"(.*)\"/"; $fields = array(1=>"score", 2=>"ping", 3=>"name");

    }

//---------------------------------------------------------+

    foreach ($part as $player_key => $data)

    {

      if (!$data) { continue; }

      preg_match($pattern, $data, $match);

      foreach ($fields as $match_key => $field_name)

      {

        $server['p'][$player_key][$field_name] = trim($match[$match_key]);

      }

      $server['p'][$player_key]['name'] = lgsl_parse_color($server['p'][$player_key]['name'], "1");

      if (isset($server['p'][$player_key]['time']))

      {

        $server['p'][$player_key]['time'] = lgsl_time($server['p'][$player_key]['time']);

      }

    }

//---------------------------------------------------------+

    return TRUE;

  }

//------------------------------------------------------------------------------------------------------------+

//------------------------------------------------------------------------------------------------------------+

  function lgsl_query_03(&$server, &$lgsl_need, &$lgsl_fp)

  {

//---------------------------------------------------------+

    // BF1942 HAS A BUG WHERE IT RETURNS EXTRA NAMES - IN ORDER TO SKIP THESE 'GHOSTS' WE NEED AN REQUEST TO GET THE CURRENT NUMBER OF PLAYERS

    if ($server['b']['type'] == "bf1942" && $lgsl_need['p'] && !$lgsl_need['s'] && !$lgsl_need['sp']) { $lgsl_need['s'] = TRUE; $lgsl_need['sp'] = TRUE; }

    if     ($server['b']['type'] == "cncrenegade") { fwrite($lgsl_fp, "\\status\\");                 $lgsl_need['s'] = FALSE; $lgsl_need['e'] = FALSE; $lgsl_need['p'] = FALSE; }

    elseif ($lgsl_need['s'] || $lgsl_need['e'])    { fwrite($lgsl_fp, "\\basic\\\\info\\\\rules\\"); $lgsl_need['s'] = FALSE; $lgsl_need['e'] = FALSE; }

    elseif ($lgsl_need['p'])                       { fwrite($lgsl_fp, "\\players\\");                $lgsl_need['p'] = FALSE; }

//---------------------------------------------------------+

    $packet1 = fread($lgsl_fp, 4096);

    if (!$packet1) { return FALSE; }

    preg_match_all("/(queryid\\\(.*)\.1|final\\\)/Us", $packet1, $match);

    if (count(array_unique($match[1])) < 2)

    {

      $packet2 = fread($lgsl_fp, 4096);

      if (!$packet2) { return FALSE; }

      preg_match_all("/(queryid\\\(.*)\.1|queryid\\\(.*)\.2|final\\\)/Us", $packet1.$packet2, $match);

      if (count(array_unique($match[1])) < 3)

      {

        $packet3 = fread($lgsl_fp, 4096);

        if (!$packet3) { return FALSE; }

      }

    }

    $buffer = $packet1.$packet2.$packet3; // JOIN ORDER DOES NOT MATTER

    // FOR AVP2 REMOVE NAME ID PREFIX DIRECTLY FROM BUFFER

    if (!$lgsl_need['s'] && !$lgsl_need['e'] && $server['b']['type'] == "avp2") { $buffer = preg_replace("/\\\[0-9]+~/", "\\", $buffer); }

//---------------------------------------------------------+

    $item = explode("\\", $buffer);

    foreach ($item as $item_key => $data_key)

    {

      if (!($item_key % 2))       { continue; } // SKIP EVEN KEYS

      if ($data_key == "")        { continue; }

      if ($data_key == "final")   { continue; }

      if ($data_key == "queryid") { continue; }

      $data_key = strtolower($data_key);

      $tmp = explode("_", $data_key, 2); // SPLIT TO CHECK IF ITS A PLAYER OR SETTING

      if (!isset($tmp[1]) || !is_numeric($tmp[1]) || $tmp[0] == "teamname")

      {

        $server['e'][$data_key] = $item[$item_key+1];

      }

      else

      {

        if     ($tmp[0] == "player")     { $tmp[0] = "name";  } // LGSL STANDARD

        elseif ($tmp[0] == "playername") { $tmp[0] = "name";  }

        elseif ($tmp[0] == "frags")      { $tmp[0] = "score"; }

        elseif ($tmp[0] == "ngsecret")   { $tmp[0] = "stats"; }

        $server['p'][$tmp[1]][$tmp[0]] = $item[$item_key+1];

      }

    }

//---------------------------------------------------------+

    if ($server['e']['mapname'])

    {

      if     ($server['b']['type'] == "bf1942" || !$server['e']['gamename']) { $server['s']['game'] = $server['e']['gameid']; }

      elseif ($server['b']['type'] != "kingpin")                             { $server['s']['game'] = $server['e']['gamename']; }

      if (!$server['e']['sv_hostname']) { $server['s']['name'] = $server['e']['hostname']; }

      else                              { $server['s']['name'] = $server['e']['sv_hostname']; }

      $server['s']['name']       = lgsl_parse_color($server['s']['name'], $server['b']['type']);

      $server['s']['map']        = $server['e']['mapname'];

      $server['s']['players']    = $server['e']['numplayers'];

      $server['s']['playersmax'] = $server['e']['maxplayers'];

      $server['s']['password']   = $server['e']['password'];

    }

//---------------------------------------------------------+

    if ($server['p']) // RE-INDEX KEYS TO REMOVE ANY GAPS

    {

      $player_tmp = array();

      $player_key = 0;

      foreach ($server['p'] as $player)

      {

        if ($player_key >= $server['s']['players']) { continue; } // SKIP BF1942 GHOST PLAYERS

        $player_tmp[$player_key] = $player;

        $player_key++;

      }

      $server['p'] = $player_tmp;

    }

//---------------------------------------------------------+

    return TRUE;

  }

//------------------------------------------------------------------------------------------------------------+

//------------------------------------------------------------------------------------------------------------+

  function lgsl_query_04(&$server, &$lgsl_need, &$lgsl_fp)

  {

//---------------------------------------------------------+

    fwrite($lgsl_fp, "REPORT");

    $buffer = fread($lgsl_fp, 4096);

    if (!$buffer) { return FALSE; }

//---------------------------------------------------------+

    $lgsl_ravenshield_key = array(

    "A1" => "playersmax",

    "A2" => "tkpenalty",

    "B1" => "players",

    "B2" => "allowradar",

    "D2" => "version",

    "E1" => "mapname",

    "E2" => "lid",

    "F1" => "maptype",

    "F2" => "gid",

    "G1" => "password",

    "G2" => "hostport",

    "H1" => "dedicated",

    "H2" => "terroristcount",

    "I1" => "hostname",

    "I2" => "aibackup",

    "J1" => "mapcycletypes",

    "J2" => "rotatemaponsuccess",

    "K1" => "mapcycle",

    "K2" => "forcefirstpersonweapons",

    "L1" => "players_name",

    "L2" => "gamename",

    "L3" => "punkbuster",

    "M1" => "players_time",

    "N1" => "players_ping",

    "O1" => "players_score",

    "P1" => "queryport",

    "Q1" => "rounds",

    "R1" => "roundtime",

    "S1" => "bombtimer",

    "T1" => "bomb",

    "W1" => "allowteammatenames",

    "X1" => "iserver",

    "Y1" => "friendlyfire",

    "Z1" => "autobalance");

//---------------------------------------------------------+

    $item = explode("\xB6", $buffer);

    foreach ($item as $data_value)

    {

      $tmp = explode(" ", $data_value, 2);

      $data_key = $lgsl_ravenshield_key[$tmp[0]] ? $lgsl_ravenshield_key[$tmp[0]] : $tmp[0]; // CONVERT TO DESCRIPTIVE KEYS

      $server['e'][$data_key] = trim($tmp[1]); // ALL VALUES NEED TRIMMING

    }

    $server['e']['mapcycle']      = str_replace("/"," ", $server['e']['mapcycle']);      // CONVERT SLASH TO SPACE

    $server['e']['mapcycletypes'] = str_replace("/"," ", $server['e']['mapcycletypes']); // SO LONG LISTS WRAP

//---------------------------------------------------------+

    $server['s']['game']       = $server['e']['gamename'];

    $server['s']['name']       = $server['e']['hostname'];

    $server['s']['map']        = $server['e']['mapname'];

    $server['s']['players']    = $server['e']['players'];

    $server['s']['playersmax'] = $server['e']['playersmax'];

    $server['s']['password']   = $server['e']['password'];

//---------------------------------------------------------+

    $player_name  = $server['e']['players_name']  ? explode("/", substr($server['e']['players_name'],  1)) : array(); unset($server['e']['players_name']);

    $player_time  = $server['e']['players_time']  ? explode("/", substr($server['e']['players_time'],  1)) : array(); unset($server['e']['players_time']);

    $player_ping  = $server['e']['players_ping']  ? explode("/", substr($server['e']['players_ping'],  1)) : array(); unset($server['e']['players_ping']);

    $player_score = $server['e']['players_score'] ? explode("/", substr($server['e']['players_score'], 1)) : array(); unset($server['e']['players_score']);

    foreach ($player_name as $key => $name)

    {

      $server['p'][$key]['name']  = $player_name[$key];

      $server['p'][$key]['time']  = $player_time[$key];

      $server['p'][$key]['ping']  = $player_ping[$key];

      $server['p'][$key]['score'] = $player_score[$key];

    }

//---------------------------------------------------------+

    return TRUE;

  }

//------------------------------------------------------------------------------------------------------------+

//------------------------------------------------------------------------------------------------------------+

  function lgsl_query_05(&$server, &$lgsl_need, &$lgsl_fp)

  {

//---------------------------------------------------------+

//  REFERENCE: http://developer.valvesoftware.com/wiki/Server_Queries

    if ($server['b']['type'] == "halflifewon")

    {

      if     ($lgsl_need['s']) { fwrite($lgsl_fp, "\xFF\xFF\xFF\xFFdetails\x00"); }

      elseif ($lgsl_need['p']) { fwrite($lgsl_fp, "\xFF\xFF\xFF\xFFplayers\x00"); }

      elseif ($lgsl_need['e']) { fwrite($lgsl_fp, "\xFF\xFF\xFF\xFFrules\x00");   }

    }

    else

    {

      $challenge_code = isset($lgsl_need['challenge']) ? $lgsl_need['challenge'] : "\x00\x00\x00\x00";

      if     ($lgsl_need['s']) { fwrite($lgsl_fp, "\xFF\xFF\xFF\xFF\x54Source Engine Query\x00"); }

      elseif ($lgsl_need['p']) { fwrite($lgsl_fp, "\xFF\xFF\xFF\xFF\x55{$challenge_code}");       }

      elseif ($lgsl_need['e']) { fwrite($lgsl_fp, "\xFF\xFF\xFF\xFF\x56{$challenge_code}");       }

    }

//---------------------------------------------------------+

//  THE STANDARD HEADER POSITION REVEALS THE TYPE BUT IT MAY NOT ARRIVE FIRST

//  ONCE WE KNOW THE TYPE WE CAN FIND THE TOTAL NUMBER OF PACKETS EXPECTED

    $packet_temp  = array();

    $packet_type  = 0;

    $packet_count = 0;

    $packet_total = 4;

    do

    {

      $packet = fread($lgsl_fp, 4096);

      //---------------------------------------------------------------------------------------------------------------------------------+

      // NEWER HL1 SERVERS REPLY TO A2S_INFO WITH 3 PACKETS ( HL1 FORMAT INFO, SOURCE FORMAT INFO, PLAYERS )

      // THIS DISCARDS UN-EXPECTED PACKET FORMATS ON THE GO ( AS READING IN ADVANCE CAUSES TIMEOUT DELAYS FOR OTHER SERVER VERSIONS )

      // ITS NOT PERFECT AS CAN FLIP BETWEEN HL1 AND SOURCE FORMATS DEPENDING ON ARRIVAL ORDER ( MAYBE FIX WITH RETURN ON HL1 APPID )

      if     ($lgsl_need['s']) { if ($packet[4] == "D")                                           { continue; } }

      elseif ($lgsl_need['p']) { if ($packet[4] == "m" || $packet[4] == "I")                      { continue; } }

      elseif ($lgsl_need['e']) { if ($packet[4] == "m" || $packet[4] == "I" || $packet[4] == "D") { continue; } }

      //---------------------------------------------------------------------------------------------------------------------------------+

      if     (substr($packet, 0,  5) == "\xFF\xFF\xFF\xFF\x41") { $lgsl_need['challenge'] = substr($packet, 5,  4); return TRUE; } // REPEAT WITH GIVEN CHALLENGE CODE

      elseif (substr($packet, 0,  4) == "\xFF\xFF\xFF\xFF")     { $packet_total = 1;                     $packet_type = 1;       } // SINGLE PACKET - HL1 OR HL2

      elseif (substr($packet, 9,  4) == "\xFF\xFF\xFF\xFF")     { $packet_total = ord($packet[8]) & 0xF; $packet_type = 2;       } // MULTI PACKET  - HL1 ( TOTAL IS LOWER NIBBLE OF BYTE )

      elseif (substr($packet, 12, 4) == "\xFF\xFF\xFF\xFF")     { $packet_total = ord($packet[8]);       $packet_type = 3;       } // MULTI PACKET  - HL2

      elseif (substr($packet, 18, 2) == "BZ")                   { $packet_total = ord($packet[8]);       $packet_type = 4;       } // BZIP PACKET   - HL2

      $packet_count ++;

      $packet_temp[] = $packet;

    }

    while ($packet && $packet_count < $packet_total);

    if ($packet_type == 0) { return $server['s'] ? TRUE : FALSE; } // UNKNOWN RESPONSE ( SOME SERVERS ONLY SEND )


//---------------------------------------------------------+

//  WITH THE TYPE WE CAN NOW SORT AND JOIN THE PACKETS IN THE CORRECT ORDER

//  REMOVING ANY EXTRA HEADERS IN THE PROCESS

    $buffer = array();

    foreach ($packet_temp as $packet)

    {

      if     ($packet_type == 1) { $packet_order = 0; }

      elseif ($packet_type == 2) { $packet_order = ord($packet[8]) >> 4; $packet = substr($packet, 9);  } // ( INDEX IS UPPER NIBBLE OF BYTE )

      elseif ($packet_type == 3) { $packet_order = ord($packet[9]);      $packet = substr($packet, 12); }

      elseif ($packet_type == 4) { $packet_order = ord($packet[9]);      $packet = substr($packet, 18); }

      $buffer[$packet_order] = $packet;

    }

    ksort($buffer);

    $buffer = implode("", $buffer);

//---------------------------------------------------------+

//  WITH THE PACKETS JOINED WE CAN NOW DECOMPRESS BZIP PACKETS

//  THEN REMOVE THE STANDARD HEADER AND CHECK ITS CORRECT

    if ($packet_type == 4)

    {

      if (!function_exists("bzdecompress")) // REQUIRES http://php.net/bzip2

      {

        $server['e']['bzip2'] = "unavailable"; $lgsl_need['e'] = FALSE;

        return TRUE;

      }

      $buffer = bzdecompress($buffer);

    }

    $header = lgsl_cut_byte($buffer, 4);

    if ($header != "\xFF\xFF\xFF\xFF") { return FALSE; } // SOMETHING WENT WRONG

//---------------------------------------------------------+

    $response_type = lgsl_cut_byte($buffer, 1);

    if ($response_type == "I") // SOURCE INFO ( HALF-LIFE 2 )

    {

      $server['e']['netcode']     = ord(lgsl_cut_byte($buffer, 1));

      $server['s']['name']        = lgsl_cut_string($buffer);

      $server['s']['map']         = lgsl_cut_string($buffer);

      $server['s']['game']        = lgsl_cut_string($buffer);

      $server['e']['description'] = lgsl_cut_string($buffer);

      $server['e']['appid']       = lgsl_unpack(lgsl_cut_byte($buffer, 2), "S");

      $server['s']['players']     = ord(lgsl_cut_byte($buffer, 1));

      $server['s']['playersmax']  = ord(lgsl_cut_byte($buffer, 1));

      $server['e']['bots']        = ord(lgsl_cut_byte($buffer, 1));

      $server['e']['dedicated']   = lgsl_cut_byte($buffer, 1);

      $server['e']['os']          = lgsl_cut_byte($buffer, 1);

      $server['s']['password']    = ord(lgsl_cut_byte($buffer, 1));

      $server['e']['anticheat']   = ord(lgsl_cut_byte($buffer, 1));

      $server['e']['version']     = lgsl_cut_string($buffer);

    }

    elseif ($response_type == "m") // HALF-LIFE 1 INFO

    {

      $server_ip                  = lgsl_cut_string($buffer);

      $server['s']['name']        = lgsl_cut_string($buffer);

      $server['s']['map']         = lgsl_cut_string($buffer);

      $server['s']['game']        = lgsl_cut_string($buffer);

      $server['e']['description'] = lgsl_cut_string($buffer);

      $server['s']['players']     = ord(lgsl_cut_byte($buffer, 1));

      $server['s']['playersmax']  = ord(lgsl_cut_byte($buffer, 1));

      $server['e']['netcode']     = ord(lgsl_cut_byte($buffer, 1));

      $server['e']['dedicated']   = lgsl_cut_byte($buffer, 1);

      $server['e']['os']          = lgsl_cut_byte($buffer, 1);

      $server['s']['password']    = ord(lgsl_cut_byte($buffer, 1));

      if (ord(lgsl_cut_byte($buffer, 1))) // MOD FIELDS ( OFF FOR SOME HALFLIFEWON-VALVE SERVERS )

      {

        $server['e']['mod_url_info']     = lgsl_cut_string($buffer);

        $server['e']['mod_url_download'] = lgsl_cut_string($buffer);

        $buffer = substr($buffer, 1);

        $server['e']['mod_version']      = lgsl_unpack(lgsl_cut_byte($buffer, 4), "l");

        $server['e']['mod_size']         = lgsl_unpack(lgsl_cut_byte($buffer, 4), "l");

        $server['e']['mod_server_side']  = ord(lgsl_cut_byte($buffer, 1));

        $server['e']['mod_custom_dll']   = ord(lgsl_cut_byte($buffer, 1));

      }

      $server['e']['anticheat'] = ord(lgsl_cut_byte($buffer, 1));

      $server['e']['bots']      = ord(lgsl_cut_byte($buffer, 1));

    }

    elseif ($response_type == "D") // SOURCE AND HALF-LIFE 1 PLAYERS

    {

      $returned = ord(lgsl_cut_byte($buffer, 1));

      $player_key = 0;

      while ($buffer)

      {

        $server['p'][$player_key]['pid']   = ord(lgsl_cut_byte($buffer, 1));

        $server['p'][$player_key]['name']  = lgsl_cut_string($buffer);

        $server['p'][$player_key]['score'] = lgsl_unpack(lgsl_cut_byte($buffer, 4), "l");

        $server['p'][$player_key]['time']  = lgsl_time(lgsl_unpack(lgsl_cut_byte($buffer, 4), "f"));

        $player_key ++;

      }

    }

    elseif ($response_type == "E") // SOURCE AND HALF-LIFE 1 RULES

    {

      $returned = lgsl_unpack(lgsl_cut_byte($buffer, 2), "S");

      while ($buffer)

      {

        $item_key   = strtolower(lgsl_cut_string($buffer));

        $item_value = lgsl_cut_string($buffer);

        $server['e'][$item_key] = $item_value;

      }

    }

//---------------------------------------------------------+

    // IF ONLY WAS REQUESTED THEN REMOVE INCOMPLETE [e]

    if ($lgsl_need['s'] && !$lgsl_need['e']) { $server['e'] = array(); }

    if     ($lgsl_need['s']) { $lgsl_need['s'] = FALSE; }

    elseif ($lgsl_need['p']) { $lgsl_need['p'] = FALSE; }

    elseif ($lgsl_need['e']) { $lgsl_need['e'] = FALSE; }

//---------------------------------------------------------+

    return TRUE;

  }

//------------------------------------------------------------------------------------------------------------+

//------------------------------------------------------------------------------------------------------------+

  function lgsl_query_06(&$server, &$lgsl_need, &$lgsl_fp)

  {

//---------------------------------------------------------+

//  GET A CHALLENGE CODE IF NEEDED

    if ($server['b']['type'] == "bf2" && $server['b']['type'] == "graw")

    {

      $challenge_code = "";

    }

    else

    {

      fwrite($lgsl_fp, "\xFE\xFD\x09\x21\x21\x21\x21\xFF\xFF\xFF\x01");

      $challenge_packet = fread($lgsl_fp, 4096);

      if (!$challenge_packet) { return FALSE; }

      $challenge_code = substr($challenge_packet, 5, -1); // REMOVE HEADER AND TRAILING NULL

      // IF CODE IS RETURNED ( SOME STALKER SERVERS RETURN BLANK WHERE THE CODE IS NOT NEEDED )

      // CONVERT DECIMAL |TO| HEX AS 8 CHARACTER STRING |TO| 4 PAIRS OF HEX |TO| 4 PAIRS OF DECIMAL |TO| 4 PAIRS OF ASCII

      $challenge_code = $challenge_code ? chr($challenge_code >> 24).chr($challenge_code >> 16).chr($challenge_code >> 8).chr($challenge_code >> 0) : "";

    }

    fwrite($lgsl_fp, "\xFE\xFD\x00\x21\x21\x21\x21{$challenge_code}\xFF\xFF\xFF\x01");

//---------------------------------------------------------+

//  GET RAW PACKET DATA

    $buffer = array();

    $packet_count = 0;

    $packet_total = 4;

    do

    {

      $packet_count ++;

      $packet = fread($lgsl_fp, 4096);

      if (!$packet) { return FALSE; }

      $packet       = substr($packet, 14); // REMOVE SPLITNUM HEADER

      $packet_order = ord(lgsl_cut_byte($packet, 1));

      if ($packet_order >= 128) // LAST PACKET - SO ITS ORDER NUMBER IS ALSO THE TOTAL

      {

        $packet_order -= 128;

        $packet_total = $packet_order + 1;

      }

      $buffer[$packet_order] = $packet;

    }

    while ($packet_count < $packet_total);

//---------------------------------------------------------+

//  PROCESS AND SORT PACKETS

    foreach ($buffer as $key => $packet)

    {

      $packet_type = lgsl_cut_byte($packet, 1);

      if ($packet_type == "\x01") // CONTINUED DATA - REMOVE REPEATED DATA KEY AT THE FRONT

      {

        lgsl_cut_string($packet);

        $packet = substr($packet, 1);

      }

      if (substr($packet, -2) != "\x00\x00") // ENDS WITH CHOPPED DATA - REMOVE AS NEXT PACKET WILL HAVE THE COMPLETE VALUE

      {

        $temp = explode("\x00", $packet);

        array_pop($temp);

        array_pop($temp);

        $packet = implode("\x00", $temp)."\x00";

      }

      $buffer[$key] = $packet;

    }

    ksort($buffer);

    $buffer = implode("", $buffer);

//---------------------------------------------------------+

//  SERVER SETTINGS

    while ($key = lgsl_cut_string($buffer))

    {

      $value = lgsl_cut_string($buffer);

      $server['e'][$key] = $value;

    }

    $lgsl_conversion = array("gamename"=>"game", "hostname"=>"name", "mapname"=>"map", "numplayers"=>"players", "maxplayers"=>"playersmax", "password"=>"password");

    foreach ($lgsl_conversion as $e => $s) { $server['s'][$s] = $server['e'][$e]; unset($server['e'][$e]); } // LGSL STANDARD

    if ($server['b']['type'] == "bf2" || $server['b']['type'] == "bf2142") { $server['s']['map'] = ucwords(str_replace("_", " ", $server['s']['map'])); } // FOR CONSISTENCY

    if ($server['s']['players'] == "0") { return TRUE; } // SKIP THE REST IF SERVER EMPTY

//---------------------------------------------------------+

//  SEPERATE TEAM DATA FROM PLAYERS DATA

    $split  = explode("\x02", $buffer, 2);

    $buffer = $split[0];

    preg_match_all("/(.*)\\x00\\x00(.*)\\x00\\x00/Us", $split[1], $match);

    foreach ($match[1] as $match_key => $key_name)

    {

      if     ($key_name == "team_t")  { $key_name = "name";  }

      elseif ($key_name == "score_t") { $key_name = "score"; }

      $values = explode("\x00", $match[2][$match_key]);

      foreach ($values as $team_key => $team_value)

      {

        $server['t'][$team_key][$key_name] = $team_value;

      }

    }

//---------------------------------------------------------+

//  PLAYER DETAILS

    $buffer = substr($buffer, 1);

    $buffer = str_replace("\x00\x00\x00", "\x00\x00", $buffer); // FIXES SERVERS SOMETIMES RETURNING AN EXTRA NULL BEFORE A KEY NAME

    preg_match_all("/(.*)_\\x00.(.*)\\x00\\x00/Us", $buffer, $match);

    foreach ($match[1] as $key_index => $key_name)

    {

      $key_name = strtolower($key_name);

      if     ($key_name == "player") { $key_name = "name"; }

      elseif ($key_name == "aibot")  { $key_name = "bot";  }

      $values = explode("\x00", $match[2][$key_index]);

      foreach ($values as $player_id => $value)

      {

        $server['p'][$player_id][$key_name] = $value;

      }

    }

//---------------------------------------------------------+

//  CHANGE TEAM NUMBERS TO TEAM NAMES IF POSSIBLE

    if ($server['t'][0]['name'] && $server['t'][0]['name'] != "Team")

    {

      foreach ($server['p'] as $key => $value)

      {

        $team_key = $server['p'][$key]['team'] - 1;

        $server['p'][$key]['team'] = $server['t'][$team_key]['name'];

      }

    }

//---------------------------------------------------------+

    return TRUE;

  }

//------------------------------------------------------------------------------------------------------------+

//------------------------------------------------------------------------------------------------------------+

  function lgsl_query_07(&$server, &$lgsl_need, &$lgsl_fp)

  {

//---------------------------------------------------------+

    fwrite($lgsl_fp, "\xFF\xFF\xFF\xFFstatus\x00");

    $buffer = fread($lgsl_fp, 4096);

    if (!$buffer) { return FALSE; }

//---------------------------------------------------------+

    $buffer = substr($buffer, 6, -2); // REMOVE HEADER AND FOOTER

    $part   = explode("\n", $buffer); // SPLIT INTO SETTINGS/PLAYER/PLAYER/PLAYER

//---------------------------------------------------------+

    $item = explode("\\", $part[0]);

    foreach ($item as $item_key => $data_key)

    {

      if ($item_key % 2) { continue; } // SKIP ODD KEYS

      $data_key               = strtolower($data_key);

      $server['e'][$data_key] = $item[$item_key+1];

    }

//---------------------------------------------------------+

    array_shift($part); // REMOVE SETTINGS

    foreach ($part as $key => $data)

    {

      preg_match("/(.*) (.*) (.*) (.*) \"(.*)\" \"(.*)\" (.*) (.*)/s", $data, $match); // GREEDY MATCH FOR SKINS

      $server['p'][$key]['pid']         = $match[1];

      $server['p'][$key]['score']       = $match[2];

      $server['p'][$key]['time']        = $match[3];

      $server['p'][$key]['ping']        = $match[4];

      $server['p'][$key]['name']        = lgsl_parse_color($match[5], $server['b']['type']);

      $server['p'][$key]['skin']        = $match[6];

      $server['p'][$key]['skin_top']    = $match[7];

      $server['p'][$key]['skin_bottom'] = $match[8];

    }

//---------------------------------------------------------+

    $server['s']['game']       = $server['e']['*gamedir'];

    $server['s']['name']       = $server['e']['hostname'];

    $server['s']['map']        = $server['e']['map'];

    $server['s']['players']    = $server['p'] ? count($server['p']) : 0;

    $server['s']['playersmax'] = $server['e']['maxclients'];

    $server['s']['password']   = $server['e']['needpass'] > 0 && $server['e']['needpass'] < 4 ? 1 : 0;

//---------------------------------------------------------+

    return TRUE;

  }

//------------------------------------------------------------------------------------------------------------+

//------------------------------------------------------------------------------------------------------------+

  function lgsl_query_08(&$server, &$lgsl_need, &$lgsl_fp)

  {

//---------------------------------------------------------+

    fwrite($lgsl_fp, "s"); // ASE ( ALL SEEING EYE ) PROTOCOL

    $buffer = fread($lgsl_fp, 4096);

    if (!$buffer) { return FALSE; }

//---------------------------------------------------------+

    $buffer = substr($buffer, 4); // REMOVE HEADER

    $server['e']['gamename']   = lgsl_cut_pascal($buffer, 1, -1);

    $server['e']['hostport']   = lgsl_cut_pascal($buffer, 1, -1);

    $server['s']['name']       = lgsl_parse_color(lgsl_cut_pascal($buffer, 1, -1), $server['b']['type']);

    $server['e']['gamemode']   = lgsl_cut_pascal($buffer, 1, -1);

    $server['s']['map']        = lgsl_cut_pascal($buffer, 1, -1);

    $server['e']['version']    = lgsl_cut_pascal($buffer, 1, -1);

    $server['s']['password']   = lgsl_cut_pascal($buffer, 1, -1);

    $server['s']['players']    = lgsl_cut_pascal($buffer, 1, -1);

    $server['s']['playersmax'] = lgsl_cut_pascal($buffer, 1, -1);

    while ($buffer && $buffer[0] != "\x01")

    {

      $item_key   = strtolower(lgsl_cut_pascal($buffer, 1, -1));

      $item_value = lgsl_cut_pascal($buffer, 1, -1);

      $server['e'][$item_key] = $item_value;

    }

    $buffer = substr($buffer, 1); // REMOVE END MARKER

//---------------------------------------------------------+

    while ($buffer)

    {

      $field_character = lgsl_cut_byte($buffer, 1); // BITWISE OF FIELDS ( HARD CODED BELOW BECAUSE GAMES DO NOT USE IT PROPERLY )

      if     ($field_character == "\x3D")           { $field_list = array("name",                  "score", "",     "time"); } // FARCRY PLAYERS CONNECTING

      elseif ($server['b']['type'] == "farcry")     { $field_list = array("name", "team", "",      "score", "ping", "time"); } // FARCRY PLAYERS JOINED

      elseif ($server['b']['type'] == "mta")        { $field_list = array("name", "",      "",     "score", "ping", ""    ); }

      elseif ($server['b']['type'] == "painkiller") { $field_list = array("name", "",     "skin",  "score", "ping", ""    ); }

      elseif ($server['b']['type'] == "soldat")     { $field_list = array("name", "team", "",      "score", "ping", "time"); }

      foreach ($field_list as $item_key)

      {

        $item_value = lgsl_cut_pascal($buffer, 1, -1);

        if (!$item_key) { continue; }

        if ($item_key == "name") { lgsl_parse_color($item_value, $server['b']['type']); }

        $server['p'][$player_key][$item_key] = $item_value;

      }

      $player_key ++;

    }

//---------------------------------------------------------+

    return TRUE;

  }

//------------------------------------------------------------------------------------------------------------+

//------------------------------------------------------------------------------------------------------------+

  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']) { fwrite($lgsl_fp, "\xFE\xFD\x00\x21\x21\x21\x21\xFF\x00\x00\x00"); }

    elseif ($lgsl_need['p'])                    { fwrite($lgsl_fp, "\xFE\xFD\x00\x21\x21\x21\x21\x00\xFF\x00\x00"); }

    $buffer = fread($lgsl_fp, 4096);

    if (!$buffer) { return FALSE; }

//---------------------------------------------------------+

    if ($lgsl_need['s'] || $lgsl_need['e'])

    {

      $lgsl_need['s'] = FALSE; $lgsl_need['e'] = FALSE;

      $buffer = substr($buffer, 5, -2); // REMOVE HEADER AND FOOTER

      $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];

      }

      $server['s']['name']       = $server['e']['hostname'];

      $server['s']['map']        = $server['e']['mapname'];

      $server['s']['players']    = $server['e']['numplayers'];

      $server['s']['playersmax'] = $server['e']['maxplayers'];

      $server['s']['password']   = $server['e']['password'];

          if ($server['e']['game_id'])    { $server['s']['game'] = $server['e']['game_id'];    } // BFVIETNAM

      elseif ($server['e']['gsgamename']) { $server['s']['game'] = $server['e']['gsgamename']; } // FEAR

      elseif ($server['e']['gamename'])   { $server['s']['game'] = $server['e']['gamename'];   } // AARMY

      if ($server['b']['type'] == "arma")

      {

        $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;

      $buffer = substr($buffer, 7, -1); // REMOVE HEADER / PLAYER TOTAL / FOOTER

      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;

  }

//------------------------------------------------------------------------------------------------------------+

//------------------------------------------------------------------------------------------------------------+

  function lgsl_query_10(&$server, &$lgsl_need, &$lgsl_fp)

  {

//---------------------------------------------------------+

    if ($server['b']['type'] == "quakewars") { fwrite($lgsl_fp, "\xFF\xFFgetInfoEX\xFF"); }

    else                                     { fwrite($lgsl_fp, "\xFF\xFFgetInfo\xFF");   }

    $buffer = fread($lgsl_fp, 4096);

    if (!$buffer) { return FALSE; }

//---------------------------------------------------------+

    if     ($server['b']['type'] == "wolf2009")  { $buffer = substr($buffer, 31); }  // REMOVE HEADERS

    elseif ($server['b']['type'] == "quakewars") { $buffer = substr($buffer, 33); }

    else                                         { $buffer = substr($buffer, 23); }

    $buffer = lgsl_parse_color($buffer, "2");

//---------------------------------------------------------+

    while ($buffer && $buffer[0] != "\x00")

    {

      $item_key   = strtolower(lgsl_cut_string($buffer));

      $item_value = lgsl_cut_string($buffer);

      $server['e'][$item_key] = $item_value;

    }

//---------------------------------------------------------+

    $buffer = substr($buffer, 2);

    $player_key = 0;

//---------------------------------------------------------+

    if ($server['b']['type'] == "wolf2009") // WOLFENSTEIN: (PID)(PING)(NAME)(TAGPOSITION)(TAG)(BOT)

    {

      while ($buffer && $buffer[0] != "\x10") // STOPS AT PID 16

      {

        $server['p'][$player_key]['pid']     = ord(lgsl_cut_byte($buffer, 1));

        $server['p'][$player_key]['ping']    = lgsl_unpack(lgsl_cut_byte($buffer, 2), "S");

        $server['p'][$player_key]['rate']    = lgsl_unpack(lgsl_cut_byte($buffer, 2), "S");

        $server['p'][$player_key]['unknown'] = lgsl_unpack(lgsl_cut_byte($buffer, 2), "S");

        $player_name                         = lgsl_cut_string($buffer);

        $player_tag_position                 = ord(lgsl_cut_byte($buffer, 1));

        $player_tag                          = lgsl_cut_string($buffer);

        $server['p'][$player_key]['bot']     = ord(lgsl_cut_byte($buffer, 1));

        if     ($player_tag == "")           { $server['p'][$player_key]['name'] = $player_name; }

        elseif ($player_tag_position == "0") { $server['p'][$player_key]['name'] = $player_tag." ".$player_name; }

        else                                 { $server['p'][$player_key]['name'] = $player_name." ".$player_tag; }

        $player_key ++;

      }

    }

//---------------------------------------------------------+

    elseif ($server['b']['type'] == "quakewars") // QUAKEWARS: (PID)(PING)(NAME)(TAGPOSITION)(TAG)(BOT)

    {

      while ($buffer && $buffer[0] != "\x20") // STOPS AT PID 32

      {

        $server['p'][$player_key]['pid']  = ord(lgsl_cut_byte($buffer, 1));

        $server['p'][$player_key]['ping'] = lgsl_unpack(lgsl_cut_byte($buffer, 2), "S");

        $player_name                      = lgsl_cut_string($buffer);

        $player_tag_position              = ord(lgsl_cut_byte($buffer, 1));

        $player_tag                       = lgsl_cut_string($buffer);

        $server['p'][$player_key]['bot']  = ord(lgsl_cut_byte($buffer, 1));

            if ($player_tag_position == "")  { $server['p'][$player_key]['name'] = $player_name; }

        elseif ($player_tag_position == "1") { $server['p'][$player_key]['name'] = $player_name." ".$player_tag; }

        else                                 { $server['p'][$player_key]['name'] = $player_tag." ".$player_name; }

        $player_key ++;

      }

      $buffer                      = substr($buffer, 1);

      $server['e']['si_osmask']    = lgsl_unpack(lgsl_cut_byte($buffer, 4), "I");

      $server['e']['si_ranked']    = ord(lgsl_cut_byte($buffer, 1));

      $server['e']['si_timeleft']  = lgsl_time(lgsl_unpack(lgsl_cut_byte($buffer, 4), "I") / 1000);

      $server['e']['si_gamestate'] = ord(lgsl_cut_byte($buffer, 1));

      $buffer                      = substr($buffer, 2);

      $player_key = 0;

      while ($buffer && $buffer[0] != "\x20") // QUAKEWARS EXTENDED: (PID)(XP)(TEAM)(KILLS)(DEATHS)

      {

        $server['p'][$player_key]['pid']    = ord(lgsl_cut_byte($buffer, 1));

        $server['p'][$player_key]['xp']     = intval(lgsl_unpack(lgsl_cut_byte($buffer, 4), "f"));

        $server['p'][$player_key]['team']   = lgsl_cut_string($buffer);

        $server['p'][$player_key]['score']  = lgsl_unpack(lgsl_cut_byte($buffer, 4), "i");

        $server['p'][$player_key]['deaths'] = lgsl_unpack(lgsl_cut_byte($buffer, 4), "i");

        $player_key ++;

      }

    }

//---------------------------------------------------------+

    elseif ($server['b']['type'] == "quake4") // QUAKE4: (PID)(PING)(RATE)(NULLNULL)(NAME)(TAG)

    {

      while ($buffer && $buffer[0] != "\x20") // STOPS AT PID 32

      {

        $server['p'][$player_key]['pid']  = ord(lgsl_cut_byte($buffer, 1));

        $server['p'][$player_key]['ping'] = lgsl_unpack(lgsl_cut_byte($buffer, 2), "S");

        $server['p'][$player_key]['rate'] = lgsl_unpack(lgsl_cut_byte($buffer, 2), "S");

        $buffer                           = substr($buffer, 2);

        $player_name                      = lgsl_cut_string($buffer);

        $player_tag                       = lgsl_cut_string($buffer);

        $server['p'][$player_key]['name'] = $player_tag ? $player_tag." ".$player_name : $player_name;

        $player_key ++;

      }

    }

//---------------------------------------------------------+

    else // DOOM3 AND PREY: (PID)(PING)(RATE)(NULLNULL)(NAME)

    {

      while ($buffer && $buffer[0] != "\x20") // STOPS AT PID 32

      {

        $server['p'][$player_key]['pid']  = ord(lgsl_cut_byte($buffer, 1));

        $server['p'][$player_key]['ping'] = lgsl_unpack(lgsl_cut_byte($buffer, 2), "S");

        $server['p'][$player_key]['rate'] = lgsl_unpack(lgsl_cut_byte($buffer, 2), "S");

        $buffer                           = substr($buffer, 2);

        $server['p'][$player_key]['name'] = lgsl_cut_string($buffer);

        $player_key ++;

      }

    }

//---------------------------------------------------------+

    $server['s']['game']       = $server['e']['gamename'];

    $server['s']['name']       = $server['e']['si_name'];

    $server['s']['map']        = $server['e']['si_map'];

    $server['s']['players']    = $server['p'] ? count($server['p']) : 0;

    $server['s']['playersmax'] = $server['e']['si_maxplayers'];

    if ($server['b']['type'] == "wolf2009" || $server['b']['type'] == "quakewars")

    {

      $server['s']['map']      = str_replace(".entities", "", $server['s']['map']);

      $server['s']['password'] = $server['e']['si_needpass'];

    }

    else

    {

      $server['s']['password'] = $server['e']['si_usepass'];

    }

//---------------------------------------------------------+

    return TRUE;

  }

//------------------------------------------------------------------------------------------------------------+

//------------------------------------------------------------------------------------------------------------+

  function lgsl_query_11(&$server, &$lgsl_need, &$lgsl_fp)

  {

//---------------------------------------------------------+

//  REFERENCE: http://wiki.unrealadmin.org/UT3_query_protocol

//  UT3 RESPONSE IS REALLY MESSY SO THIS CLEANS IT UP

    $status = lgsl_query_06($server, $lgsl_need, $lgsl_fp);

    if (!$status) { return FALSE; }

//---------------------------------------------------------+

    $server['s']['map'] = $server['e']['p1073741825'];

                    unset($server['e']['p1073741825']);

//---------------------------------------------------------+

    $lgsl_ut3_key = array(

    "s0"          => "bots_skill",

    "s6"          => "pure",

    "s7"          => "password",

    "s8"          => "bots_vs",

    "s10"         => "forcerespawn",

    "p268435703"  => "bots",

    "p268435704"  => "goalscore",

    "p268435705"  => "timelimit",

    "p268435717"  => "mutators_default",

    "p1073741826" => "gamemode",

    "p1073741827" => "description",

    "p1073741828" => "mutators_custom");

    foreach ($lgsl_ut3_key as $old => $new)

    {

      if (!isset($server['e'][$old])) { continue; }

      $server['e'][$new] = $server['e'][$old];

      unset($server['e'][$old]);

    }

//---------------------------------------------------------+

    $temp = explode(".", $server['e']['gamemode']);

    if ($temp[0] && (stristr($temp[0], "UT") === FALSE))

    {

      $server['s']['game'] = $temp[0];

    }

//---------------------------------------------------------+

    $tmp = $server['e']['mutators_default'];

           $server['e']['mutators_default'] = "";

    if ($tmp & 1)     { $server['e']['mutators_default'] .= " BigHead";           }

    if ($tmp & 2)     { $server['e']['mutators_default'] .= " FriendlyFire";      }

    if ($tmp & 4)     { $server['e']['mutators_default'] .= " Handicap";          }

    if ($tmp & 8)     { $server['e']['mutators_default'] .= " Instagib";          }

    if ($tmp & 16)    { $server['e']['mutators_default'] .= " LowGrav";           }

    if ($tmp & 64)    { $server['e']['mutators_default'] .= " NoPowerups";        }

    if ($tmp & 128)   { $server['e']['mutators_default'] .= " NoTranslocator";    }

    if ($tmp & 256)   { $server['e']['mutators_default'] .= " Slomo";             }

    if ($tmp & 1024)  { $server['e']['mutators_default'] .= " SpeedFreak";        }

    if ($tmp & 2048)  { $server['e']['mutators_default'] .= " SuperBerserk";      }

    if ($tmp & 8192)  { $server['e']['mutators_default'] .= " WeaponReplacement"; }

    if ($tmp & 16384) { $server['e']['mutators_default'] .= " WeaponsRespawn";    }

    $server['e']['mutators_default'] = str_replace(" ",    " / ", trim($server['e']['mutators_default']));

    $server['e']['mutators_custom']  = str_replace("\x1c", " / ",      $server['e']['mutators_custom']);

//---------------------------------------------------------+

    return TRUE;

  }

//------------------------------------------------------------------------------------------------------------+

//------------------------------------------------------------------------------------------------------------+

  function lgsl_query_12(&$server, &$lgsl_need, &$lgsl_fp)

  {

//---------------------------------------------------------+

    if     ($lgsl_need['s']) { fwrite($lgsl_fp, "SAMP\x21\x21\x21\x21\x00\x00i"); } // THIS SIMPLIFIED QUERY WORKS BUT INCASE

    elseif ($lgsl_need['e']) { fwrite($lgsl_fp, "SAMP\x21\x21\x21\x21\x00\x00r"); } // IT BREAKS THE OFFICIAL EXAMPLE USES

    elseif ($lgsl_need['p']) { fwrite($lgsl_fp, "SAMP\x21\x21\x21\x21\x00\x00d"); } // THE SERVER IP IN HEX INSTEAD OF x21

    $buffer = fread($lgsl_fp, 4096);

    if (!substr($buffer, 0, 4) == "SAMP") { return FALSE; }

//---------------------------------------------------------+

    $buffer = substr($buffer, 11); // REMOVE HEADER

//---------------------------------------------------------+

    if ($lgsl_need['s'])

    {

      $lgsl_need['s'] = FALSE;

      $server['s']['password']   = ord(lgsl_cut_byte($buffer, 1));

      $server['s']['players']    = lgsl_unpack(lgsl_cut_byte($buffer, 2), "S");

      $server['s']['playersmax'] = lgsl_unpack(lgsl_cut_byte($buffer, 2), "S");

      $server['s']['name']       = lgsl_cut_pascal($buffer, 4);

      $server['e']['gamemode']   = lgsl_cut_pascal($buffer, 4);

      $server['s']['map']        = lgsl_cut_pascal($buffer, 4);

    }

//---------------------------------------------------------+

    elseif ($lgsl_need['e'])

    {

      $lgsl_need['e'] = FALSE;

      $item_total = lgsl_unpack(lgsl_cut_byte($buffer, 2), "S");

      for ($i=0; $i<$item_total; $i++)

      {

        if (!$buffer) { return FALSE; }

        $data_key   = strtolower(lgsl_cut_pascal($buffer, 1));

        $data_value = lgsl_cut_pascal($buffer, 1);

        $server['e'][$data_key] = $data_value;

      }

    }

//---------------------------------------------------------+

    elseif ($lgsl_need['p'])

    {

      $lgsl_need['p'] = FALSE;

      $player_total = lgsl_unpack(lgsl_cut_byte($buffer, 2), "S");

      for ($i=0; $i<$player_total; $i++)

      {

        if (!$buffer) { return FALSE; }

        $server['p'][$i]['pid']   = ord(lgsl_cut_byte($buffer, 1));

        $server['p'][$i]['name']  = lgsl_cut_pascal($buffer, 1);

        $server['p'][$i]['score'] = lgsl_unpack(lgsl_cut_byte($buffer, 4), "S");

        $server['p'][$i]['ping']  = lgsl_unpack(lgsl_cut_byte($buffer, 4), "S");

      }

    }

//---------------------------------------------------------+

    return TRUE;

  }

//------------------------------------------------------------------------------------------------------------+

//------------------------------------------------------------------------------------------------------------+

  function lgsl_query_13(&$server, &$lgsl_need, &$lgsl_fp)

  {

//---------------------------------------------------------+

    fwrite($lgsl_fp, "\x21\x21\x21\x21\x00"); // REQUEST

    fwrite($lgsl_fp, "\x21\x21\x21\x21\x01"); // REQUEST [e]

    fwrite($lgsl_fp, "\x21\x21\x21\x21\x02"); // REQUEST [p]

//---------------------------------------------------------+

    while ($packet = fread($lgsl_fp, 4096))

    {

      if     ($packet[4] == "\x00") { $buffer_s .= substr($packet, 5); }

      elseif ($packet[4] == "\x01") { $buffer_e .= substr($packet, 5); }

      elseif ($packet[4] == "\x02") { $buffer_p .= substr($packet, 5); }

    }

    if (!$buffer_s) { return FALSE; }

//---------------------------------------------------------+

//  SOME VALUES START WITH A PASCAL LENGTH AND END WITH A NULL BUT THERE IS AN ISSUE WHERE

//  CERTAIN CHARACTERS CAUSE A WRONG PASCAL LENGTH AND NULLS TO APPEAR WITHIN NAMES

    $buffer_s = str_replace("\xa0", "\x20", $buffer_s); // REPLACE SPECIAL SPACE WITH NORMAL SPACE

    $buffer_s = substr($buffer_s, 5);

    $server['e']['hostport']   = lgsl_unpack(lgsl_cut_byte($buffer_s, 4), "S");

    $buffer_s = substr($buffer_s, 4);

    $server['s']['name']       = lgsl_cut_string($buffer_s, 1);

    $server['s']['map']        = lgsl_cut_string($buffer_s, 1);

    $server['e']['gamemode']   = lgsl_cut_string($buffer_s, 1);

    $server['s']['players']    = lgsl_unpack(lgsl_cut_byte($buffer_s, 4), "S");

    $server['s']['playersmax'] = lgsl_unpack(lgsl_cut_byte($buffer_s, 4), "S");

//---------------------------------------------------------+

    while ($buffer_e && $buffer_e[0] != "\x00")

    {

      $item_key   = strtolower(lgsl_cut_string($buffer_e, 1));

      $item_value = lgsl_cut_string($buffer_e, 1);

      $item_key   = str_replace("\x1B\xFF\xFF\x01", "", $item_key);   // REMOVE MOD

      $item_value = str_replace("\x1B\xFF\xFF\x01", "", $item_value); // GARBAGE

      $server['e'][$item_key] = $item_value;

    }

//---------------------------------------------------------+

//  THIS PROTOCOL RETURNS MORE INFO THAN THE ALTERNATIVE BUT IT DOES NOT

//  RETURN THE GAME NAME ! SO WE HAVE MANUALLY DETECT IT USING THE GAME TYPE

    $tmp = strtolower(substr($server['e']['gamemode'], 0, 2));

        if ($tmp == "ro") { $server['s']['game'] = "Red Orchestra"; }

    elseif ($tmp == "kf") { $server['s']['game'] = "Killing Floor"; }

   $server['s']['password'] = ($server['e']['password'] || $server['e']['gamepassword']) ? "1" : "0";

//---------------------------------------------------------+

    $player_key = 0;

    while ($buffer_p && $buffer_p[0] != "\x00")

    {

      $server['p'][$player_key]['pid']   = lgsl_unpack(lgsl_cut_byte($buffer_p, 4), "S");

      $end_marker = ord($buffer_p[0]) > 64 ? "\x00\x00" : "\x00"; // DIRTY WORK-AROUND FOR NAMES WITH PROBLEM CHARACTERS

      $server['p'][$player_key]['name']  = lgsl_cut_string($buffer_p, 1, $end_marker);

      $server['p'][$player_key]['ping']  = lgsl_unpack(lgsl_cut_byte($buffer_p, 4), "S");

      $server['p'][$player_key]['score'] = lgsl_unpack(lgsl_cut_byte($buffer_p, 4), "s");

      $tmp                               = lgsl_cut_byte($buffer_p, 4);

          if ($tmp[3] == "\x20") { $server['p'][$player_key]['team'] = 1; }

      elseif ($tmp[3] == "\x40") { $server['p'][$player_key]['team'] = 2; }

      $player_key ++;

    }

//---------------------------------------------------------+

    return TRUE;

  }

//------------------------------------------------------------------------------------------------------------+

//------------------------------------------------------------------------------------------------------------+

  function lgsl_query_14(&$server, &$lgsl_need, &$lgsl_fp)

  {

//---------------------------------------------------------+

//  REFERENCE: http://flstat.cryosphere.co.uk/global-list.php

    fwrite($lgsl_fp, "\x00\x02\xf1\x26\x01\x26\xf0\x90\xa6\xf0\x26\x57\x4e\xac\xa0\xec\xf8\x68\xe4\x8d\x21");

    $buffer = fread($lgsl_fp, 4096);

    if (!$buffer) { return FALSE; }

//---------------------------------------------------------+

    $buffer = substr($buffer, 4); // HEADER   ( 00 03 F1 26 )

    $buffer = substr($buffer, 4); // NOT USED ( 87 + NAME LENGTH )

    $buffer = substr($buffer, 4); // NOT USED ( NAME END TO BUFFER END LENGTH )

    $buffer = substr($buffer, 4); // UNKNOWN  ( 80 )

    $server['s']['map']        = "freelancer";

    $server['s']['password']   = lgsl_unpack(lgsl_cut_byte($buffer, 4), "l") - 1 ? 1 : 0;

    $server['s']['playersmax'] = lgsl_unpack(lgsl_cut_byte($buffer, 4), "l") - 1;

    $server['s']['players']    = lgsl_unpack(lgsl_cut_byte($buffer, 4), "l") - 1;

    $buffer                    = substr($buffer, 4);  // UNKNOWN ( 88 )

    $name_length               = lgsl_unpack(lgsl_cut_byte($buffer, 4), "l");

    $buffer                    = substr($buffer, 56); // UNKNOWN

    $server['s']['name']       = lgsl_cut_byte($buffer, $name_length);

    lgsl_cut_string($buffer, 0, ":");

    lgsl_cut_string($buffer, 0, ":");

    lgsl_cut_string($buffer, 0, ":");

    lgsl_cut_string($buffer, 0, ":");

    lgsl_cut_string($buffer, 0, ":");

    // WHATS LEFT IS THE MOTD

    $server['e']['motd'] = substr($buffer, 0, -1);

    // REMOVE UTF-8 ENCODING NULLS

    $server['s']['name'] = str_replace("\x00", "", $server['s']['name']);

    $server['e']['motd'] = str_replace("\x00", "", $server['e']['motd']);

    // DOES NOT RETURN PLAYER INFORMATION

//---------------------------------------------------------+

    return TRUE;

  }

//------------------------------------------------------------------------------------------------------------+

//------------------------------------------------------------------------------------------------------------+

  function lgsl_query_15(&$server, &$lgsl_need, &$lgsl_fp)

  {

//---------------------------------------------------------+

    fwrite($lgsl_fp, "GTR2_Direct_IP_Search\x00");

    $buffer = fread($lgsl_fp, 4096);

    if (!$buffer) { return FALSE; }

//---------------------------------------------------------+

    $buffer = str_replace("\xFE", "\xFF", $buffer);

    $buffer = explode("\xFF", $buffer);

    $server['s']['name']       = $buffer[3];

    $server['s']['game']       = $buffer[7];

    $server['e']['version']    = $buffer[11];

    $server['e']['hostport']   = $buffer[15];

    $server['s']['map']        = $buffer[19];

    $server['s']['players']    = $buffer[25];

    $server['s']['playersmax'] = $buffer[27];

    $server['e']['gamemode']   = $buffer[31];

    // DOES NOT RETURN PLAYER INFORMATION

//---------------------------------------------------------+

    return TRUE;

  }

//------------------------------------------------------------------------------------------------------------+

//------------------------------------------------------------------------------------------------------------+

  function lgsl_query_16(&$server, &$lgsl_need, &$lgsl_fp)

  {

//---------------------------------------------------------+

//  REFERENCE:

// http://www.planetpointy.co.uk/software/rfactorsspy.shtml

// http://users.pandora.be/viperius/mUtil/

//  USES FIXED DATA POSITIONS WITH RANDOM CHARACTERS FILLING THE GAPS

    fwrite($lgsl_fp, "rF_S");

    $buffer = fread($lgsl_fp, 4096);

    if (!$buffer) { return FALSE; }

//---------------------------------------------------------+

//  $server['e']['gamename']         = lgsl_get_string($buffer);

    $buffer = substr($buffer, 8);

//  $server['e']['fullupdate']       = lgsl_unpack($buffer[0], "C");

    $server['e']['region']           = lgsl_unpack($buffer[1] .$buffer[2],  "S");

//  $server['e']['ip']               = ($buffer[3] .$buffer[4].$buffer[5].$buffer[6]); // UNSIGNED LONG

//  $server['e']['size']             = lgsl_unpack($buffer[7] .$buffer[8],  "S");

    $server['e']['version']          = lgsl_unpack($buffer[9] .$buffer[10], "S");

//  $server['e']['version_racecast'] = lgsl_unpack($buffer[11].$buffer[12], "S");

    $server['e']['hostport']         = lgsl_unpack($buffer[13].$buffer[14], "S");

//  $server['e']['queryport']        = lgsl_unpack($buffer[15].$buffer[16], "S");

    $buffer = substr($buffer, 17);

    $server['s']['game']             = lgsl_get_string($buffer);

    $buffer = substr($buffer, 20);

    $server['s']['name']             = lgsl_get_string($buffer);

    $buffer = substr($buffer, 28);

    $server['s']['map']              = lgsl_get_string($buffer);

    $buffer = substr($buffer, 32);

    $server['e']['motd']             = lgsl_get_string($buffer);

    $buffer = substr($buffer, 96);

    $server['e']['packed_aids']      = lgsl_unpack($buffer[0].$buffer[1], "S");

//  $server['e']['ping']             = lgsl_unpack($buffer[2].$buffer[3], "S");

    $server['e']['packed_flags']     = lgsl_unpack($buffer[4],  "C");

    $server['e']['rate']             = lgsl_unpack($buffer[5],  "C");

    $server['s']['players']          = lgsl_unpack($buffer[6],  "C");

    $server['s']['playersmax']       = lgsl_unpack($buffer[7],  "C");

    $server['e']['bots']             = lgsl_unpack($buffer[8],  "C");

    $server['e']['packed_special']   = lgsl_unpack($buffer[9],  "C");

    $server['e']['damage']           = lgsl_unpack($buffer[10], "C");

    $server['e']['packed_rules']     = lgsl_unpack($buffer[11].$buffer[12], "S");

    $server['e']['credits1']         = lgsl_unpack($buffer[13], "C");

    $server['e']['credits2']         = lgsl_unpack($buffer[14].$buffer[15], "S");

    $server['e']['time']   = lgsl_time(lgsl_unpack($buffer[16].$buffer[17], "S"));

    $server['e']['laps']             = lgsl_unpack($buffer[18].$buffer[19], "s") / 16;

    $buffer = substr($buffer, 23);

    $server['e']['vehicles']         = lgsl_get_string($buffer);

    // DOES NOT RETURN PLAYER INFORMATION

//---------------------------------------------------------+

    $server['s']['password']    = ($server['e']['packed_special'] & 2)  ? 1 : 0;

    $server['e']['racecast']    = ($server['e']['packed_special'] & 4)  ? 1 : 0;

    $server['e']['fixedsetups'] = ($server['e']['packed_special'] & 16) ? 1 : 0;

    $flag = $server['e']['packed_aids'];

    if ($flag & 1)    { $server['e']['aids'] .= " TractionControl"; }

    if ($flag & 2)    { $server['e']['aids'] .= " AntiLockBraking"; }

    if ($flag & 4)    { $server['e']['aids'] .= " StabilityControl"; }

    if ($flag & 8)    { $server['e']['aids'] .= " AutoShifting"; }

    if ($flag & 16)   { $server['e']['aids'] .= " AutoClutch"; }

    if ($flag & 32)   { $server['e']['aids'] .= " Invulnerability"; }

    if ($flag & 64)   { $server['e']['aids'] .= " OppositeLock"; }

    if ($flag & 128)  { $server['e']['aids'] .= " SteeringHelp"; }

    if ($flag & 256)  { $server['e']['aids'] .= " BrakingHelp"; }

    if ($flag & 512)  { $server['e']['aids'] .= " SpinRecovery"; }

    if ($flag & 1024) { $server['e']['aids'] .= " AutoPitstop"; }

    $server['e']['aids']     = str_replace(" ", " / ", trim($server['e']['aids']));

    $server['e']['vehicles'] = str_replace("|", " / ", $server['e']['vehicles']);

    unset($server['e']['packed_aids']);

    unset($server['e']['packed_flags']);

    unset($server['e']['packed_special']);

    unset($server['e']['packed_rules']);

//---------------------------------------------------------+

    return TRUE;

  }

//------------------------------------------------------------------------------------------------------------+

//------------------------------------------------------------------------------------------------------------+

  function lgsl_query_17(&$server, &$lgsl_need, &$lgsl_fp)

  {

//---------------------------------------------------------+

//  REFERENCE: http://masterserver.savage.s2games.com

    fwrite($lgsl_fp, "\x9e\x4c\x23\x00\x00\xce\x21\x21\x21\x21");

    $buffer = fread($lgsl_fp, 4096);

    if (!$buffer) { return FALSE; }

//---------------------------------------------------------+

    $buffer = substr($buffer, 12); // REMOVE HEADER

    while ($key = strtolower(lgsl_cut_string($buffer, 0, "\xFE")))

    {

      if ($key == "players") { break; }

      $value = lgsl_cut_string($buffer, 0, "\xFF");

      $value = str_replace("\x00", "", $value);

      $value = lgsl_parse_color($value, $server['b']['type']);

      $server['e'][$key] = $value;

    }

    $server['s']['name']       = $server['e']['name'];  unset($server['e']['name']);

    $server['s']['map']        = $server['e']['world']; unset($server['e']['world']);

    $server['s']['players']    = $server['e']['cnum'];  unset($server['e']['cnum']);

    $server['s']['playersmax'] = $server['e']['cmax'];  unset($server['e']['cnum']);

    $server['s']['password']   = $server['e']['pass'];  unset($server['e']['cnum']);

//---------------------------------------------------------+

    $server['t'][0]['name'] = $server['e']['race1'];

    $server['t'][1]['name'] = $server['e']['race2'];

    $server['t'][2]['name'] = "spectator";

    $team_key   = -1;

    $player_key = 0;

    while ($value = lgsl_cut_string($buffer, 0, "\x0a"))

    {

      if ($value[0] == "\x00") { break; }

      if ($value[0] != "\x20") { $team_key++; continue; }

      $server['p'][$player_key]['name'] = lgsl_parse_color(substr($value, 1), $server['b']['type']);

      $server['p'][$player_key]['team'] = $server['t'][$team_key]['name'];

      $player_key++;

    }

//---------------------------------------------------------+

    return TRUE;

  }

//------------------------------------------------------------------------------------------------------------+

//------------------------------------------------------------------------------------------------------------+

  function lgsl_query_18(&$server, &$lgsl_need, &$lgsl_fp)

  {

//---------------------------------------------------------+

//  REFERENCE: http://masterserver.savage2.s2games.com

    fwrite($lgsl_fp, "\x01");

    $buffer = fread($lgsl_fp, 4096);

    if (!$buffer) { return FALSE; }

//---------------------------------------------------------+

    $buffer = substr($buffer, 12); // REMOVE HEADER

    $server['s']['name']            = lgsl_cut_string($buffer);

    $server['s']['players']         = ord(lgsl_cut_byte($buffer, 1));

    $server['s']['playersmax']      = ord(lgsl_cut_byte($buffer, 1));

    $server['e']['time']            = lgsl_cut_string($buffer);

    $server['s']['map']             = lgsl_cut_string($buffer);

    $server['e']['nextmap']         = lgsl_cut_string($buffer);

    $server['e']['location']        = lgsl_cut_string($buffer);

    $server['e']['minimum_players'] = ord(lgsl_cut_string($buffer));

    $server['e']['gamemode']        = lgsl_cut_string($buffer);

    $server['e']['version']         = lgsl_cut_string($buffer);

    $server['e']['minimum_level']   = ord(lgsl_cut_byte($buffer, 1));

    // DOES NOT RETURN PLAYER INFORMATION

//---------------------------------------------------------+

    return TRUE;

  }

//------------------------------------------------------------------------------------------------------------+

//------------------------------------------------------------------------------------------------------------+

  function lgsl_query_19(&$server, &$lgsl_need, &$lgsl_fp)

  {

//---------------------------------------------------------+

    fwrite($lgsl_fp, "\xC0\xDE\xF1\x11\x42\x06\x00\xF5\x03\x21\x21\x21\x21");

    $buffer = fread($lgsl_fp, 4096);

    if (!$buffer) { return FALSE; }

//---------------------------------------------------------+

    $buffer = substr($buffer, 25); // REMOVE HEADER

    $server['s']['name']       = lgsl_get_string(lgsl_cut_pascal($buffer, 4, 3, -3));

    $server['s']['map']        = lgsl_get_string(lgsl_cut_pascal($buffer, 4, 3, -3));

    $server['e']['nextmap']    = lgsl_get_string(lgsl_cut_pascal($buffer, 4, 3, -3));

    $server['e']['gametype']   = lgsl_get_string(lgsl_cut_pascal($buffer, 4, 3, -3));

    $buffer = substr($buffer, 1);

    $server['s']['password']   = ord(lgsl_cut_byte($buffer, 1));

    $server['s']['playersmax'] = ord(lgsl_cut_byte($buffer, 4));

    $server['s']['players']    = ord(lgsl_cut_byte($buffer, 4));

//---------------------------------------------------------+

    for ($player_key=0; $player_key<$server['s']['players']; $player_key++)

    {

     $server['p'][$player_key]['name'] = lgsl_get_string(lgsl_cut_pascal($buffer, 4, 3, -3));

    }

//---------------------------------------------------------+

    $buffer = substr($buffer, 17);

    $server['e']['version']    = lgsl_get_string(lgsl_cut_pascal($buffer, 4, 3, -3));

    $server['e']['mods']       = lgsl_get_string(lgsl_cut_pascal($buffer, 4, 3, -3));

    $server['e']['dedicated']  = ord(lgsl_cut_byte($buffer, 1));

    $server['e']['time']       = lgsl_time(lgsl_unpack(lgsl_cut_byte($buffer, 4), "f"));

    $server['e']['status']     = ord(lgsl_cut_byte($buffer, 4));

    $server['e']['gamemode']   = ord(lgsl_cut_byte($buffer, 4));

    $server['e']['motd']       = lgsl_get_string(lgsl_cut_pascal($buffer, 4, 3, -3));

    $server['e']['respawns']   = ord(lgsl_cut_byte($buffer, 4));

    $server['e']['time_limit'] = lgsl_time(lgsl_unpack(lgsl_cut_byte($buffer, 4), "f"));

    $server['e']['voting']     = ord(lgsl_cut_byte($buffer, 4));

    $buffer = substr($buffer, 2);

//---------------------------------------------------------+

    for ($player_key=0; $player_key<$server['s']['players']; $player_key++)

    {

     $server['p'][$player_key]['team'] = ord(lgsl_cut_byte($buffer, 4));

     $unknown = ord(lgsl_cut_byte($buffer, 1));

    }

//---------------------------------------------------------+

    $buffer = substr($buffer, 7);

    $server['e']['platoon_1_color']   = ord(lgsl_cut_byte($buffer, 8));

    $server['e']['platoon_2_color']   = ord(lgsl_cut_byte($buffer, 8));

    $server['e']['platoon_3_color']   = ord(lgsl_cut_byte($buffer, 8));

    $server['e']['platoon_4_color']   = ord(lgsl_cut_byte($buffer, 8));

    $server['e']['timer_on']          = ord(lgsl_cut_byte($buffer, 1));

    $server['e']['timer_time']        = lgsl_time(lgsl_unpack(lgsl_cut_byte($buffer, 4), "f"));

    $server['e']['time_debriefing']   = lgsl_time(lgsl_unpack(lgsl_cut_byte($buffer, 4), "f"));

    $server['e']['time_respawn_min']  = lgsl_time(lgsl_unpack(lgsl_cut_byte($buffer, 4), "f"));

    $server['e']['time_respawn_max']  = lgsl_time(lgsl_unpack(lgsl_cut_byte($buffer, 4), "f"));

    $server['e']['time_respawn_safe'] = lgsl_time(lgsl_unpack(lgsl_cut_byte($buffer, 4), "f"));

    $server['e']['difficulty']        = ord(lgsl_cut_byte($buffer, 4));

    $server['e']['respawn_total']     = ord(lgsl_cut_byte($buffer, 4));

    $server['e']['random_insertions'] = ord(lgsl_cut_byte($buffer, 1));

    $server['e']['spectators']        = ord(lgsl_cut_byte($buffer, 1));

    $server['e']['arcademode']        = ord(lgsl_cut_byte($buffer, 1));

    $server['e']['ai_backup']         = ord(lgsl_cut_byte($buffer, 1));

    $server['e']['random_teams']      = ord(lgsl_cut_byte($buffer, 1));

    $server['e']['time_starting']     = lgsl_time(lgsl_unpack(lgsl_cut_byte($buffer, 4), "f"));

    $server['e']['identify_friends']  = ord(lgsl_cut_byte($buffer, 1));

    $server['e']['identify_threats']  = ord(lgsl_cut_byte($buffer, 1));