Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function step()
- {
- $data = $this->readLog();
- if($data)
- {
- $data = explode("\n", trim($data, "\n"));
- foreach($data as $line)
- {
- //Parsing line for event and arguments
- $line =substr($line, 7); //Remove the time (todo : see if elapsed time for the map is useful (more than when we count it ourselves))
- Leelabot::printText('['.$this->_name.'] '.$line);
- $line = explode(':',$line, 2);
- if(isset($line[1]))
- $line[1] = trim($line[1]);
- switch($line[0])
- {
- //A client connects
- case 'ClientConnect':
- $id = intval($line[1]);
- $this->players[$id] = new Storage(array('id' => $id, 'begin' => FALSE, 'team' => Server::TEAM_SPEC, 'level' => $this->_defaultLevel, 'time' => time()));
- Leelabot::message('Client connected: $0', array($id), E_DEBUG);
- $this->_leelabot->plugins->callServerEvent('ClientConnect', $id);
- break;
- //A client has disconnected
- case 'ClientDisconnect':
- $id = intval($line[1]);
- $this->_leelabot->plugins->callServerEvent('ClientDisconnect', $id);
- Leelabot::message('Client disconnected: $0', array($id), E_DEBUG);
- unset($this->players[$id]);
- break;
- //The client has re-sent his personal info (like credit name, weapons, weapmodes, card number)
- case 'ClientUserinfo':
- list($id, $infostr) = explode(' ', $line[1], 2);
- $userinfo = Server::parseInfo($infostr);
- Leelabot::message('Client send user info: $0', array($id), E_DEBUG);
- Leelabot::message(' Name: $0', array($userinfo['name']), E_DEBUG);
- //Basically it's a copypasta of the code user above for initial data storage
- if(isset($userinfo['characterfile']))
- {
- $playerData['isBot'] = TRUE;
- Leelabot::message(' Is a bot.', array(), E_DEBUG);
- }
- else
- {
- $playerData['isBot'] = FALSE;
- $address = explode(':', $userinfo['ip']);
- $playerData['addr'] = $address[0];
- $playerData['port'] = $address[1];
- $playerData['guid'] = $userinfo['cl_guid'];
- Leelabot::message(' GUID: $0', array($playerData['guid']));
- Leelabot::message(' IP: $0', array($playerData['addr']));
- }
- $playerData['name'] = preg_replace('#^[0-9]#', '', $userinfo['name']);
- $playerData['id'] = $id;
- $this->_leelabot->plugins->callServerEvent('ClientUserinfo', array($id, $userinfo));
- $this->players[$id]->merge($playerData);
- //Binding IP pointer
- if(!isset($this->players[$id]->ip))
- $this->players[$id]->ip = &$this->players[$id]->addr;
- if(!isset($this->players[$id]->other))
- $this->players[$id]->other = $userinfo;
- else
- $this->players[$id]->other = array_merge($this->players[$id]->other, $userinfo);
- break;
- //Change in client userinfo, useful for gathering teams
- case 'ClientUserinfoChanged':
- list($id, $infostr) = explode(' ', $line[1], 2);
- $userinfo = Server::parseInfo($infostr);
- Leelabot::message('Client has send changed user info: $0', array($id), E_DEBUG);
- Leelabot::message(' Name: $0', array($userinfo['n']), E_DEBUG);
- Leelabot::message(' Team: $0', array(Server::getTeamName($userinfo['t'])), E_DEBUG);
- $this->_leelabot->plugins->callServerEvent('ClientUserinfoChanged', array($id, $userinfo));
- $this->players[$id]->team = $userinfo['t'];
- $this->players[$id]->other['cg_rgb'] = $userinfo['a0'].' '.$userinfo['a1'].' '.$userinfo['a2'];
- $this->players[$id]->name = preg_replace('#^[0-9]#', '', $userinfo['n']);
- break;
- //Player start to play
- case 'ClientBegin':
- $id = intval($line[1]);
- Leelabot::message('Client has begun: $0', array($id), E_DEBUG);
- $this->_leelabot->plugins->callServerEvent('ClientBegin', $id);
- $this->players[$id]->begin = TRUE;
- break;
- //New round, map info is re-sended
- case 'InitRound':
- $serverinfo = Server::parseInfo($line[1]);
- Leelabot::message('New round started', array(), E_DEBUG);
- $this->_leelabot->plugins->callServerEvent('InitRound', $serverinfo);
- //New map, with new info
- case 'InitGame':
- if($line[0] == 'InitGame')
- {
- $serverinfo = Server::parseInfo($line[1]);
- Leelabot::message('New map started: $0', array($serverinfo['mapname']), E_DEBUG);
- $this->_leelabot->plugins->callServerEvent('InitGame', $serverinfo);
- $this->scores = array(1 => 0, 2 => 0);
- }
- if(!empty($this->serverInfo))
- $this->serverInfo = array_merge($this->serverInfo, $serverinfo);
- else
- $this->serverInfo = $serverinfo;
- break;
- //The game has ended. Usually, next to that line are written the scores, but we just don't care about them
- case 'Exit':
- Leelabot::message('Map ended', array(), E_DEBUG);
- $this->_leelabot->plugins->callServerEvent('Exit', $line[1]);
- break;
- //Survivor round has ended, with the winner
- case 'SurvivorWinner':
- Leelabot::message('Round ended, winner: $0', array($line[1]), E_DEBUG);
- $winner = Server::getTeamNumber($line[1]);
- $this->_leelabot->plugins->callServerEvent('SurvivorWinner', $winner);
- if($winner)
- $this->scores[$winner]++;
- break;
- //The server goes down (it occurs also with a map change)
- case 'ShutdownGame':
- Leelabot::message('The server is going down', array(), E_DEBUG);
- $this->_leelabot->plugins->callServerEvent('ShutdownGame');
- break;
- //One player kills another, probably the most common action that will occur ?
- case 'Kill':
- $kill = explode(':', $line[1]);
- $kill = explode(' ', $kill[0]);
- $this->_leelabot->plugins->callServerEvent('Kill', $kill);
- break;
- //One player hit another, OMG FLOOD OF GAME LOG !
- case 'Hit':
- $hit = explode(':', $line[1]);
- $hit = explode(' ', $hit[0]);
- $this->_leelabot->plugins->callServerEvent('Hit', $hit);
- break;
- //Item of player, example : take kevlar. (utility ?)
- case 'Item':
- $item = explode(' ', $line[1]);
- $this->_leelabot->plugins->callServerEvent('Item', $item);
- break;
- //Actions on flag
- case 'Flag':
- $flag = explode(':', $line[1]);
- $flag = explode(' ', $flag[0]);
- $this->_leelabot->plugins->callServerEvent('Flag', $flag);
- break;
- //Player message
- case 'say':
- case 'sayteam':
- $message = explode(' ', $line[1], 2);
- $id = intval($message[0]);
- $contents = explode(':', $message[1], 2);
- $contents = substr($contents[1], 1);
- Leelabot::message('$0 sended a message: $1',array($this->players[$id]->name, $contents), E_DEBUG);
- $this->_leelabot->plugins->callServerEvent('Say',array($id, $contents));
- //We check if it's a command
- if($contents[0] == '!')
- {
- $contents = substr($contents, 1);
- $args = explode(' ', $contents);
- $command = array_shift($args);
- Leelabot::message('Command catched: !$0', array($command), E_DEBUG);
- $this->_leelabot->plugins->callCommand($command, $id, $args);
- }
- break;
- }
- }
- }
- //Before returning, we execute all routines
- $this->_leelabot->plugins->callAllRoutines();
- return TRUE;
- }
Add Comment
Please, Sign In to add comment