Example #1
0
});
$client->on("receive", function (swoole_client $cli, $message) {
    //echo 'receive: ',$message,"\n";
    if (($data = substr($message, 4)) && ($result = ConvertUtil::unpack($data)) && isset($result['from']) && isset($result['to']) && isset($result['type']) && isset($result['content'])) {
        G::$sessionId = isset($result['session_id']) ? $result['session_id'] : null;
        /* @var Packet $packet */
        $packet = Packet::getPacketFromArray($result);
        if (!G::$auth) {
            $authPacket = new AuthPacket();
            $authPacket->setFrom(G::$account);
            $authPacket->setTo('system');
            if ($packet->getType() == $authPacket->getType()) {
                $authPacket->setContent($packet->getContent());
                switch ($authPacket->getStatus()) {
                    case AuthPacket::STATUS_NEED_AUTH:
                        $authPacket->setAccount(G::$account);
                        $authPacket->setPassword(G::$password);
                        $cli->send(serializePacket($authPacket));
                        break;
                    case AuthPacket::STATUS_AUTH_FAILED:
                        echo "error: auth failed\n";
                        break;
                    case AuthPacket::STATUS_AUTH_SUCCESS:
                        echo "auth success\n";
                        G::$auth = true;
                        G::$uid = $authPacket->getUid();
                        sendChatPacket();
                        sendGroupMessage();
                        sendChatroomMessage();
                        break;
                    default:
Example #2
0
 public function sendAuthPacket()
 {
     $packet = new AuthPacket();
     $packet->setFrom(0);
     $packet->setTo('system');
     $packet->setAccount($this->account);
     $packet->setPassword($this->password);
     $this->send($this->serializePacket($packet));
 }