
// shared over network
set kill after run 1

shared string $topString[10]
shared int $curTime
shared string $curName

if server
{
  // local
  string $topNames[10]
  int    $topTimes[10]

  int $c
  int $b
  int $a
  rcar $car
  int $tcarcount

  for $c < 10 do ++$c
  {
    $topString[10]=""
    $topTimes=99999999
  }

  while 1
  {
  //paint "server" at float[2]{500,10}
  
    $c=0
    for $c < get carcount do ++$c
    {
      $curTime=0
      $car = get car $c
      $curName=get $car drivername

      $tcarcount=get carcount
        
      wait 5000 

      if $tcarcount!=get carcount
      {
        // to make sure everything is loaded
        wait 10000
        $b=0
        for $b < 10 do $b++
        {
          $topString[$b]=$topString[$b] // force to resend everything
        }
      }

      //paint $name at float[2]{200,20*$c}
      //paint $time at float[2]{300,20*$c}
      
      if $curTime > 0
      {        
        $b=9
        for $b > -1 do $b--
        {   
          if $topTimes[$b]>$curTime
          {        
            if $curName!=$topNames[$b]
            {
              $a=0
              for $a < $b do ++$a
              {
                $topNames[$a]=$topNames[$a+1]    
                $topTimes[$a]=$topTimes[$a+1]
                $topString[$a]=$topString[$a+1]
              } 
            }          
            $topString[$b]=($topNames[$b]=$curName)
            $topString[$b]+=":\t "+laptime ($topTimes[$b]=$curTime) to string    
            $b=-1        
          }  
          else if $curName==$topNames[$b]
          {
            $b=-1 
          }
        }
      }
    }
  }
}

while 1
{
  //paint "noserver" at float[2]{500,10}
  interrupt
}