示例#1
0
 function read($msg)
 {
     if (empty($msg) || substr($msg, 0, 2) != "~&" || substr($msg, -1) != "~") {
         return false;
     }
     $msg = substr($msg, 2, -1);
     $this->category = $this->b85g($msg);
     $this->instance = $this->b85g($msg);
     $this->args = AOExtMsg::parse_params($msg);
     if ($this->args === null) {
         echo "Error parsing parameters for category: '{$this->category}' instance: '{$this->instance}' string: '{$msg}'\n";
     } else {
         $this->message_string = MMDBParser::get_message_string($this->category, $this->instance);
         if ($this->message_string !== null) {
             $this->message = vsprintf($this->message_string, $this->args);
         }
     }
 }
示例#2
0
 function get_packet()
 {
     $head = $this->read_data(4);
     if (strlen($head) != 4) {
         return false;
     }
     list(, $type, $len) = unpack("n2", $head);
     $data = $this->read_data($len);
     if (is_resource($this->debug)) {
         fwrite($this->debug, "<<<<<\n");
         fwrite($this->debug, $head);
         fwrite($this->debug, $data);
         fwrite($this->debug, "\n=====\n");
     }
     $packet = new AOChatPacket("in", $type, $data);
     switch ($type) {
         case AOCP_LOGIN_SEED:
             $this->serverseed = $packet->args[0];
             break;
         case AOCP_CLIENT_NAME:
         case AOCP_CLIENT_LOOKUP:
             list($id, $name) = $packet->args;
             $id = "" . $id;
             $name = ucfirst(strtolower($name));
             $this->id[$id] = $name;
             $this->id[$name] = $id;
             break;
         case AOCP_GROUP_ANNOUNCE:
             list($gid, $name, $status) = $packet->args;
             $this->grp[$gid] = $status;
             $this->gid[$gid] = $name;
             $this->gid[strtolower($name)] = $gid;
             break;
         case AOCP_GROUP_MESSAGE:
             /* Hack to support extended messages */
             if ($packet->args[1] === 0 && substr($packet->args[2], 0, 2) == "~&") {
                 $em = new AOExtMsg($packet->args[2]);
                 $packet->args[2] = $em->message;
                 $packet->args['extended_message'] = $em;
             }
             break;
         case AOCP_CHAT_NOTICE:
             $category_id = 20000;
             $packet->args[4] = MMDBParser::get_message_string($category_id, $packet->args[2]);
             if ($packet->args[4] !== null) {
                 $packet->args[5] = AOExtMsg::parse_params($packet->args[3]);
                 if ($packet->args[5] !== null) {
                     $packet->args[6] = vsprintf($packet->args[4], $packet->args[5]);
                 } else {
                     print_r($packet);
                 }
             }
             break;
     }
     $this->last_packet = time();
     return $packet;
 }