コード例 #1
0
 public static function parse_params($msg)
 {
     $args = array();
     while ($msg != '') {
         $data_type = $msg[0];
         $msg = substr($msg, 1);
         // skip the data type id
         switch ($data_type) {
             case "S":
                 $len = ord($msg[0]) * 256 + ord($msg[1]);
                 $str = substr($msg, 2, $len);
                 $msg = substr($msg, $len + 2);
                 $args[] = $str;
                 break;
             case "s":
                 $len = ord($msg[0]) - 1;
                 $str = substr($msg, 1, $len);
                 $msg = substr($msg, $len + 1);
                 $args[] = $str;
                 break;
             case "I":
                 $array = unpack("N", $msg);
                 $args[] = $array[1];
                 $msg = substr($msg, 4);
                 break;
             case "i":
             case "u":
                 $num = AOExtMsg::b85g($msg);
                 $args[] = $num;
                 break;
             case "R":
                 $cat = AOExtMsg::b85g($msg);
                 $ins = AOExtMsg::b85g($msg);
                 $str = MMDBParser::get_message_string($cat, $ins);
                 if ($str === null) {
                     $str = "Unknown ({$cat}, {$ins})";
                 }
                 $args[] = $str;
                 break;
             case "l":
                 $array = unpack("N", $msg);
                 $msg = substr($msg, 4);
                 $cat = 20000;
                 $ins = $array[1];
                 $str = MMDBParser::get_message_string($cat, $ins);
                 if ($str === null) {
                     $str = "Unknown ({$cat}, {$ins})";
                 }
                 $args[] = $str;
                 break;
             default:
                 echo "Error! could not parse argument: '{$data_type}'\n";
                 return null;
                 break;
         }
     }
     return $args;
 }
コード例 #2
0
ファイル: AOChat.class.php プロジェクト: jibinam/budabot2
 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;
 }