コード例 #1
0
 /**
  * What's a parser without a parse method? Exactly, nothing much. So...
  * here it is. This method will happily parse our LVP echo channel
  * message and extract the needed informations. These will then be put 
  * to use in other methods.
  * 
  * @var Bot $pBot The bot which received the message.
  * @var string $sMessage The actual message we're going to parse.
  */
 public function parse(Bot $pBot, $sMessage)
 {
     $aChunks = preg_split('/\\s+/', $sMessage);
     switch ($aChunks[0]) {
         case '05***':
             $this->handleAdminMessage($pBot, substr($sMessage, 7), $aChunks);
             break;
         case '2***':
             if ($aChunks[1] == '7Admin' || $aChunks[1] == '7Report') {
                 $this->handleCrewChat($pBot, $aChunks[2], implode(' ', array_slice($aChunks, 4)), $aChunks);
             }
             break;
         case '4***':
             if ($aChunks[1] == 'Global' && $aChunks[2] == 'Gamemode' && $aChunks[3] == 'Initialization') {
                 $this->handleGamemodeInit();
             }
             break;
         case '4IP':
             $nId = substr($aChunks[3], 4, -2);
             $this->handleIpMessage($pBot, $nId, $aChunks[2], $aChunks[4], $aChunks);
             break;
     }
     if (!isset($aChunks[1])) {
         return;
     }
     switch ($aChunks[1]) {
         case '03***':
         case '3***':
             $nId = substr(Func::stripFormat($aChunks[0]), 1, -1);
             if ($aChunks[3] == 'joined') {
                 $this->handleJoinGame($pBot, $nId, $aChunks[2], $aChunks);
             } else {
                 if ($aChunks[3] == 'left') {
                     $this->handleLeaveGame($pBot, $nId, $aChunks[2], substr($aChunks[6], 1, -3), $aChunks);
                 } else {
                     if ($aChunks[4] == 'logged') {
                         $this->handleLoggedIn($pBot, $nId, $aChunks[2], $aChunks);
                     }
                 }
             }
             break;
         default:
             if (substr($aChunks[1], 0, 3) == '07' && substr($aChunks[1], -2) == ':') {
                 $nId = substr(Util::stripFormat($aChunks[0]), 1, -1);
                 $sNickname = substr(Util::stripFormat($aChunks[1]), 0, -1);
                 $this->handleMainChatMessage($pBot, $nId, $sNickname, implode(' ', array_slice($aChunks, 2)), $aChunks);
             }
             break;
     }
     /* Enable this when going to save the echo logs.
        if (in_array ($aChunks [0], $this -> m_aIgnoreTriggers))
        {
                return ;
        }
        
        if (count ($aChunks) == count (explode (', ', implode (' ', $aChunks))))
        {
                // Filter out the !players command.
                return ;
        }
        
        if (Func :: getPieces ($aChunks, ' ', 0, 3) == 'has been online for' ||
            Func :: getPieces ($aChunks, ' ', 0, 2) == 'is a player' ||
            Func :: getPieces ($aChunks, ' ', 0, 4) == 'requested player is not registered')
        {
                return ;
        }
        */
 }