hosts.php

Go to the documentation of this file.
00001 <?php
00013 require_once(dirname(__FILE__).'/base.php'); 
00014  
00021 class LFSWorldHostsList extends LFSWorldDataProvider
00022 {
00027     var $m_sURL = 'http://www.lfsworld.net/pubstat/get_stat2.php?action=hosts';
00028     
00033     var $m_aSrcMetaData = array('lifeTime' => 90, 'actualTarpit' => 60);
00034     
00078     function parse($rawList, &$outputList)
00079     {
00080         //Offset var for position
00081         $offset = 0; $t=0;
00082 
00083         while(true)
00084         {
00085             $blob = substr($rawList, $offset, 53);
00086             //If chunk len is less than 53 then it can't be valid
00087             if(strlen($blob) == 53)
00088             {
00089                 $data = $racers = array();
00090 
00091                 //We could use L1cars & L1rules but that limits cars and rules to 31 bits(4 byte int, 1 sign bit)
00092                 $data = unpack('a32host_name/C1server_type/C1major_version/C1minor_version/C1test_version/C1track/C1config/C1reversed/C1max_players/C4cars/C4rules/C1laps/C1qualify_mins/x2/C1players', $blob);
00093                 $offset+= 53;
00094 
00095                 //Get racers
00096                 for($i=0; $i < $data['players']; $i++)
00097                 {
00098                     $racers[] = trim(substr($rawList, $offset, 24));
00099                     $offset += 24;
00100                 }
00101 
00102                 //Laps parsing.
00103                 $data['hours'] = 0;
00104                 if($data['laps'] > 100)
00105                 {
00106                     if($data['laps'] < 191)
00107                     {
00108                         //Laps are in 10 step increment range (101-191)
00109                         $data['laps'] = (($data['laps'] - 100) * 10) + 100;
00110                     }
00111                     else
00112                     {
00113                         //Laps are hours
00114                         $data['hours'] = $data['laps'] - 190;
00115                         $data['laps'] = 0;
00116                     }
00117                 }
00118 
00119                 //Formatting
00120                 //About as elegant as a wet fart but also very fast
00121                 //Turn car and rule bit encoding in to bit strings
00122                 $data['cars'] = strrev( str_pad(decbin($data['cars4']), 8, '0', STR_PAD_LEFT).
00123                                         str_pad(decbin($data['cars3']), 8, '0', STR_PAD_LEFT).
00124                                         str_pad(decbin($data['cars2']), 8, '0', STR_PAD_LEFT).
00125                                         str_pad(decbin($data['cars1']), 8, '0', STR_PAD_LEFT));
00126                                         
00127                 $data['rules'] = strrev(str_pad(decbin($data['rules4']), 8, '0', STR_PAD_LEFT).
00128                                         str_pad(decbin($data['rules3']), 8, '0', STR_PAD_LEFT).
00129                                         str_pad(decbin($data['rules2']), 8, '0', STR_PAD_LEFT).
00130                                         str_pad(decbin($data['rules1']), 8, '0', STR_PAD_LEFT));
00131                                         
00132                 //Compound the 3 integers that make up the track in to 1 var
00133                 $data['track'] = $data['track'].$data['config'].$data['reversed'];
00134                 
00135                 //Unset transformed data
00136                 unset($data['config'], $data['reversed'],
00137                         $data['cars1'], $data['cars2'], $data['cars3'], $data['cars4'],
00138                         $data['rules1'], $data['rules2'], $data['rules3'], $data['rules4']);
00139 
00140                 //Put the racers in the output
00141                 $data['racers'] = $racers;
00142 
00143                 //Version formatting
00144                 $data['major_version'] /= 10;
00145                 $data['minor_version'] = chr($data['minor_version']);
00146 
00147                 //Append to output list
00148                 $outputList[] = $data;
00149             }
00150             else
00151             {
00152                 break;
00153             }
00154         }
00155         return true;
00156     }
00157 }
00158 
00159 ?>

Generated on Wed Oct 25 03:13:32 2006 for LFSWorldParsingProviderFramework by  doxygen 1.4.6