Advertisement
Guest User

fast

a guest
Oct 23rd, 2010
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.42 KB | None | 0 0
  1. <?php
  2. ////////////////////////////////////////////////////////////////
  3. //ร‚ยค
  4. // File:      FAST 3.2 (First Automatic Server for Trackmania)
  5. // Web:      
  6. // Date:      19.04.2009
  7. // Author:    Gilles Masson
  8. //
  9. ////////////////////////////////////////////////////////////////
  10. //
  11. //
  12. // dependences: need manialinks and ml_times plugins
  13. //
  14. registerPlugin('ml_records',18);
  15.  
  16.  
  17.  
  18. function ml_recordsInit($event){
  19.     global $_tm_db;
  20.     console("ml_records.Event[".$event."]");
  21.     ml_recordsAddTimesMod();
  22. }
  23.  
  24.  
  25. function ml_recordsStartRace($event,$tm_db_n,$chalinfo,$ChallengeInfo){
  26.     console("ml_records.Event[$event]");
  27.     ml_recordsAddTimesMod();
  28.     ml_timesRefresh();
  29.  
  30. }
  31.  
  32.  
  33. function ml_recordsPlayerConnect($event,$login){
  34.     global $_mldebug,$_tm_db,$_ml_times_mods;
  35.   if(!is_string($login))
  36.     $login = ''.$login;
  37.     //console("ml_records.Event[$event]('$login')");
  38. }
  39.  
  40.  
  41. function ml_recordsPlayerMenuBuild($event,$login){
  42.     global $_mldebug,$_tm_db,$_ml_times_mods,$_players;
  43.     //console("ml_records.Event[$event]('$login')");
  44.     if(!isset($_players[$login]['Relayed']) || $_players[$login]['Relayed'])
  45.         return;
  46.  
  47.     if(isset($_tm_db[1]['XmlrpcDB']))
  48.         ml_menusAddItem($login, 'menu.hud.times.menu', 'menu.hud.times.records.1',
  49.                                         array('Name'=>stripColors($_tm_db[1]['Name']),'Type'=>'bool'));
  50.     if(isset($_tm_db[0]['XmlrpcDB']))
  51.         ml_menusAddItem($login, 'menu.hud.times.menu', 'menu.hud.times.records.0',
  52.                                         array('Name'=>stripColors($_tm_db[0]['Name']),'Type'=>'bool'));
  53. }
  54.  
  55.  
  56. function ml_recordsPlayerMenuAction($event,$login,$action,$state){
  57.     global $_mldebug;
  58.     //if($_mldebug>6) console("ml_records.Event[$event]('$login',$action,$state)");
  59.  
  60. }
  61.  
  62.    
  63. function ml_recordsPlayerRecord($event,$tm_db_n,$login,$time,$rank,$old_time,$old_rank,$ChallengeInfo){
  64.     ml_timesRefresh();
  65. }
  66.  
  67.  
  68. function ml_recordsAddTimesMod(){
  69.     global $_mldebug,$_tm_db,$_ml_times_mods;
  70.     if(isset($_tm_db[1]['XmlrpcDB']) && !isset($_ml_times_mods['db1']))
  71.         ml_timesAddTimesMod('db1','ml_recordsGetTimesArray',1,-1);
  72.     if(isset($_tm_db[0]['XmlrpcDB']) && !isset($_ml_times_mods['db0']))
  73.         ml_timesAddTimesMod('db0','ml_recordsGetTimesArray',0,0);
  74.     //ml_timesAddTimesMod('dbp','ml_recordsGetTimesArray',0,-p);
  75. }
  76.  
  77.  
  78. function ml_recordsGetTimesArray($login,$data,$num,$min){
  79.     global $_mldebug,$_Game,$_players,$_tm_db,$_ChallengeInfo,$_players_positions,$_StatusCode;
  80.   if(!is_string($login))
  81.     $login = ''.$login;
  82.  
  83.     $times = array();
  84.     $tmdb =& $_tm_db[$data];
  85.  
  86.     if(!isset($tmdb['Challenge']['Uid']) || $tmdb['Challenge']['Uid']!=$_ChallengeInfo['UId'] || !isset($tmdb['Challenge']['ServerMaxRecords'])){
  87.         //if($_mldebug>2) console("ml_recordsGetTimesArray - unsure: return false");
  88.         return false;
  89.     }
  90.  
  91.     $uid = $_ChallengeInfo['UId'];
  92.     if(isset($tmdb['Results']['Uid']) && $tmdb['Results']['Uid']==$uid && count($tmdb['Results']['Records'])>0)
  93.         $records = &$tmdb['Results']['Records'];
  94.     elseif(count($tmdb['Challenge']['Records'])>0)
  95.         $records = &$tmdb['Challenge']['Records'];
  96.     else{
  97.         $times['Name'] = htmlspecialchars(sprintf($tmdb['NameForTrack'],$_Game,$uid));
  98.         return $times;
  99.     }
  100.  
  101.     //if($_mldebug>2) debugPrint("ml_recordsGetTimesArray - $num - $min - records",$records);
  102.  
  103.     if($min > 0){
  104.         $max = count($records);
  105.         if($max > $tmdb['Challenge']['ServerMaxRecords'])
  106.         $max = $tmdb['Challenge']['ServerMaxRecords'];
  107.         if($min > $num)
  108.             $min = $num;
  109.    
  110.         //if($_mldebug>1) debugPrint("ml_recordsGetTimesArray - state=$_StatusCode - max=$max - min=$min - num=$num - _tm_db[$data]['Results']",$tmdb['Results']);
  111.         //if($_mldebug>1) debugPrint("ml_recordsGetTimesArray - state=$_StatusCode - max=$max - min=$min - num=$num - _tm_db[$data]['Challenge']",$tmdb['Challenge']);
  112.  
  113.         // fill table with first times
  114.         $own = -1;
  115.         for($i = 0; $i < $num && $i < $max; $i++){
  116.             if($records[$i]['Login']==$login)
  117.                 $own = $i;
  118.             $times[$i] = ml_recordsGetPlayerTime($records[$i],$login);
  119.         }
  120.  
  121.         //if($_mldebug>2) debugPrint("ml_recordsGetTimesArray A - times",$times);
  122.  
  123.         if($i<$min){
  124.             // complete list with empty entries...
  125.             for( ;$i<$min;$i++)
  126.                 $times[$i] = array('Pos'=>'','Name'=>'','Time'=>'');
  127.            
  128.         }elseif($i>1){
  129.             // list is full
  130.  
  131.             // search login
  132.             for($j = $i; $own < 0 && $j < $max; $j++){
  133.                 if($records[$j]['Login']==$login)
  134.                     $own = $j;
  135.             }
  136.  
  137.             if($own>=0){
  138.                 if($i<=2){
  139.                     // small list : put login in 2nd pos, else put max
  140.                     if($own>=$i)
  141.                         $times[$i-1] = ml_recordsGetPlayerTime($records[$own],$login);
  142.                     elseif($own< 1 && $max>$i)
  143.                         $times[$i-1] = ml_recordsGetPlayerTime($records[$max-1],$login);
  144.                    
  145.                 }elseif($i<4){
  146.                     // medium list should not happen, just put login in last pos
  147.                     if($own>=$i)
  148.                         $times[$i-1] = ml_recordsGetPlayerTime($records[$own],$login);
  149.  
  150.                 }else{
  151.                     // classic sized list
  152.  
  153.                     if($own<$i-1){
  154.                         // login is before last pos, just put max in last pos
  155.                         if($max>$i)
  156.                             $times[$i-1] = ml_recordsGetPlayerTime($records[$max-1],$login);
  157.  
  158.                     }else{
  159.                         if($own>=$max-1){
  160.                             // login is max, just put it last
  161.                             $times[$i-1] = ml_recordsGetPlayerTime($records[$own],$login);
  162.  
  163.                         }else{
  164.                             $times[$i-3] = ml_recordsGetPlayerTime($records[$own-1],$login);
  165.                             $times[$i-2] = ml_recordsGetPlayerTime($records[$own],$login);
  166.                             $times[$i-1] = ml_recordsGetPlayerTime($records[$max-1],$login);
  167.                         }
  168.                     }
  169.                 }
  170.  
  171.             }elseif($i>1 && $max>$i){
  172.                 // no login, put max in last pos
  173.                 $times[$i-1] = ml_recordsGetPlayerTime($records[$max-1],$login);
  174.             }
  175.         }
  176.     }
  177.     $times['Name'] = htmlspecialchars(sprintf($tmdb['NameForTrack'],$_Game,$uid));
  178.  
  179.     //if($_mldebug>2) debugPrint("ml_recordsGetTimesArray - times",$times);
  180.     //if($_mldebug>1) debugPrint("ml_recordsGetTimesArray - _tm_db[$data]['Challenge']",$tmdb['Challenge']);
  181.     return $times;
  182. }
  183.  
  184.  
  185. function ml_recordsGetPlayerTime(&$rec,$login){
  186.     global $_players;
  187.   if(!is_string($login))
  188.     $login = ''.$login;
  189.     $color = '';
  190.     if($rec['Login']==$login){
  191.         $own = true;
  192.         if(isset($rec['NewBest']) && $rec['NewBest'])
  193.             $color = '$f33';
  194.         else
  195.             $color = '$f88';
  196.     }elseif(isset($rec['NewBest']) && $rec['NewBest'])
  197.          $color = '$07f';
  198.     elseif(isset($_players[$rec['Login']]))
  199.         $color = '$7cf';
  200.     $topcol = (count($rec['Checks'])<=0 || $rec['Best']!=end($rec['Checks'])) ? '$aaa' : '';
  201.     return array('Pos'=>($topcol.'Top$ff0'.$rec['Rank']),
  202.                              'Name'=>'$s'.$color.$rec['NickDraw'],
  203.                              'Time'=>$color.MwTimeToString($rec['Best']));
  204. }
  205.  
  206.  
  207. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement