Guest User

Untitled

a guest
Jun 5th, 2018
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.34 KB | None | 0 0
  1. public function step()
  2.     {
  3.         $data = $this->readLog();
  4.         if($data)
  5.         {
  6.             $data = explode("\n", trim($data, "\n"));
  7.             foreach($data as $line)
  8.             {
  9.                 //Parsing line for event and arguments
  10.                 $line =substr($line, 7); //Remove the time (todo : see if elapsed time for the map is useful (more than when we count it ourselves))
  11.                 Leelabot::printText('['.$this->_name.'] '.$line);
  12.                 $line = explode(':',$line, 2);
  13.                
  14.                 if(isset($line[1]))
  15.                     $line[1] = trim($line[1]);
  16.                
  17.                 switch($line[0])
  18.                 {
  19.                     //A client connects
  20.                     case 'ClientConnect':
  21.                         $id = intval($line[1]);
  22.                         $this->players[$id] = new Storage(array('id' => $id, 'begin' => FALSE, 'team' => Server::TEAM_SPEC, 'level' => $this->_defaultLevel, 'time' => time()));
  23.                         Leelabot::message('Client connected: $0', array($id), E_DEBUG);
  24.                         $this->_leelabot->plugins->callServerEvent('ClientConnect', $id);
  25.                         break;
  26.                     //A client has disconnected
  27.                     case 'ClientDisconnect':
  28.                         $id = intval($line[1]);
  29.                         $this->_leelabot->plugins->callServerEvent('ClientDisconnect', $id);
  30.                         Leelabot::message('Client disconnected: $0', array($id), E_DEBUG);
  31.                         unset($this->players[$id]);
  32.                         break;
  33.                     //The client has re-sent his personal info (like credit name, weapons, weapmodes, card number)
  34.                     case 'ClientUserinfo':
  35.                         list($id, $infostr) = explode(' ', $line[1], 2);
  36.                         $userinfo = Server::parseInfo($infostr);
  37.                        
  38.                         Leelabot::message('Client send user info: $0', array($id), E_DEBUG);
  39.                         Leelabot::message(' Name: $0', array($userinfo['name']), E_DEBUG);
  40.                        
  41.                         //Basically it's a copypasta of the code user above for initial data storage
  42.                         if(isset($userinfo['characterfile']))
  43.                         {
  44.                             $playerData['isBot'] = TRUE;
  45.                             Leelabot::message(' Is a bot.', array(), E_DEBUG);
  46.                         }
  47.                         else
  48.                         {
  49.                             $playerData['isBot'] = FALSE;
  50.                             $address = explode(':', $userinfo['ip']);
  51.                             $playerData['addr'] = $address[0];
  52.                             $playerData['port'] = $address[1];
  53.                             $playerData['guid'] = $userinfo['cl_guid'];
  54.                            
  55.                             Leelabot::message(' GUID: $0', array($playerData['guid']));
  56.                             Leelabot::message(' IP: $0', array($playerData['addr']));
  57.                         }
  58.                         $playerData['name'] = preg_replace('#^[0-9]#', '', $userinfo['name']);
  59.                         $playerData['id'] = $id;
  60.                         $this->_leelabot->plugins->callServerEvent('ClientUserinfo', array($id, $userinfo));
  61.                        
  62.                         $this->players[$id]->merge($playerData);
  63.                        
  64.                         //Binding IP pointer
  65.                         if(!isset($this->players[$id]->ip))
  66.                             $this->players[$id]->ip = &$this->players[$id]->addr;
  67.                        
  68.                         if(!isset($this->players[$id]->other))
  69.                             $this->players[$id]->other = $userinfo;
  70.                         else
  71.                             $this->players[$id]->other = array_merge($this->players[$id]->other, $userinfo);
  72.                         break;
  73.                     //Change in client userinfo, useful for gathering teams
  74.                     case 'ClientUserinfoChanged':
  75.                         list($id, $infostr) = explode(' ', $line[1], 2);
  76.                         $userinfo = Server::parseInfo($infostr);
  77.                         Leelabot::message('Client has send changed user info: $0', array($id), E_DEBUG);
  78.                         Leelabot::message(' Name: $0', array($userinfo['n']), E_DEBUG);
  79.                         Leelabot::message(' Team: $0', array(Server::getTeamName($userinfo['t'])), E_DEBUG);
  80.                        
  81.                         $this->_leelabot->plugins->callServerEvent('ClientUserinfoChanged', array($id, $userinfo));
  82.                         $this->players[$id]->team = $userinfo['t'];
  83.                         $this->players[$id]->other['cg_rgb'] = $userinfo['a0'].' '.$userinfo['a1'].' '.$userinfo['a2'];
  84.                         $this->players[$id]->name = preg_replace('#^[0-9]#', '', $userinfo['n']);
  85.                         break;
  86.                     //Player start to play
  87.                     case 'ClientBegin':
  88.                         $id = intval($line[1]);
  89.                         Leelabot::message('Client has begun: $0', array($id), E_DEBUG);
  90.                        
  91.                         $this->_leelabot->plugins->callServerEvent('ClientBegin', $id);
  92.                         $this->players[$id]->begin = TRUE;
  93.                         break;
  94.                     //New round, map info is re-sended
  95.                     case 'InitRound':
  96.                         $serverinfo = Server::parseInfo($line[1]);
  97.                         Leelabot::message('New round started', array(), E_DEBUG);
  98.                        
  99.                         $this->_leelabot->plugins->callServerEvent('InitRound', $serverinfo);
  100.                     //New map, with new info
  101.                     case 'InitGame':
  102.                         if($line[0] == 'InitGame')
  103.                         {
  104.                             $serverinfo = Server::parseInfo($line[1]);
  105.                             Leelabot::message('New map started: $0', array($serverinfo['mapname']), E_DEBUG);
  106.                            
  107.                             $this->_leelabot->plugins->callServerEvent('InitGame', $serverinfo);
  108.                             $this->scores = array(1 => 0, 2 => 0);
  109.                         }
  110.                        
  111.                         if(!empty($this->serverInfo))
  112.                             $this->serverInfo = array_merge($this->serverInfo, $serverinfo);
  113.                         else
  114.                             $this->serverInfo = $serverinfo;
  115.                         break;
  116.                     //The game has ended. Usually, next to that line are written the scores, but we just don't care about them
  117.                     case 'Exit':
  118.                         Leelabot::message('Map ended', array(), E_DEBUG);
  119.                         $this->_leelabot->plugins->callServerEvent('Exit', $line[1]);
  120.                         break;
  121.                     //Survivor round has ended, with the winner
  122.                     case 'SurvivorWinner':
  123.                         Leelabot::message('Round ended, winner: $0', array($line[1]), E_DEBUG);
  124.                         $winner = Server::getTeamNumber($line[1]);
  125.                         $this->_leelabot->plugins->callServerEvent('SurvivorWinner', $winner);
  126.                         if($winner)
  127.                             $this->scores[$winner]++;
  128.                         break;
  129.                     //The server goes down (it occurs also with a map change)
  130.                     case 'ShutdownGame':
  131.                         Leelabot::message('The server is going down', array(), E_DEBUG);
  132.                         $this->_leelabot->plugins->callServerEvent('ShutdownGame');
  133.                         break;
  134.                     //One player kills another, probably the most common action that will occur ?
  135.                     case 'Kill':
  136.                         $kill = explode(':', $line[1]);
  137.                         $kill = explode(' ', $kill[0]);
  138.                         $this->_leelabot->plugins->callServerEvent('Kill', $kill);
  139.                         break;
  140.                     //One player hit another, OMG FLOOD OF GAME LOG !
  141.                     case 'Hit':
  142.                         $hit = explode(':', $line[1]);
  143.                         $hit = explode(' ', $hit[0]);
  144.                         $this->_leelabot->plugins->callServerEvent('Hit', $hit);
  145.                         break;
  146.                     //Item of player, example : take kevlar. (utility ?)
  147.                     case 'Item':
  148.                         $item = explode(' ', $line[1]);
  149.                         $this->_leelabot->plugins->callServerEvent('Item', $item);
  150.                         break;
  151.                     //Actions on flag
  152.                     case 'Flag':
  153.                         $flag = explode(':', $line[1]);
  154.                         $flag = explode(' ', $flag[0]);
  155.                         $this->_leelabot->plugins->callServerEvent('Flag', $flag);
  156.                         break;
  157.                     //Player message
  158.                     case 'say':
  159.                     case 'sayteam':
  160.                         $message = explode(' ', $line[1], 2);
  161.                         $id = intval($message[0]);
  162.                         $contents = explode(':', $message[1], 2);
  163.                         $contents = substr($contents[1], 1);
  164.                         Leelabot::message('$0 sended a message: $1',array($this->players[$id]->name, $contents), E_DEBUG);
  165.                         $this->_leelabot->plugins->callServerEvent('Say',array($id, $contents));
  166.                        
  167.                         //We check if it's a command
  168.                         if($contents[0] == '!')
  169.                         {
  170.                             $contents = substr($contents, 1);
  171.                             $args = explode(' ', $contents);
  172.                             $command = array_shift($args);
  173.                             Leelabot::message('Command catched: !$0', array($command), E_DEBUG);
  174.                             $this->_leelabot->plugins->callCommand($command, $id, $args);
  175.                         }
  176.                         break;
  177.                 }
  178.                
  179.             }
  180.         }
  181.        
  182.         //Before returning, we execute all routines
  183.         $this->_leelabot->plugins->callAllRoutines();
  184.        
  185.         return TRUE;
  186.     }
Add Comment
Please, Sign In to add comment