Пример #1
0
void Client::processMessage(ENetEvent& event)
{
    std::string packetContents = std::string(reinterpret_cast<char*>(event.packet->data), event.packet->dataLength);

    uint32_t packetType = Packet::deserializePacketType(packetContents);

    switch (packetType) {
    case Packet::FromServerPacketContents::ChatMessageFromServerPacket:
        receiveChatMessage(packetContents);
        break;

    case Packet::FromServerPacketContents::InitialPlayerDataFromServerPacket:
        receiveInitialPlayerData(packetContents);
        break;

    case Packet::FromServerPacketContents::PlayerDisconnectedFromServerPacket:
        receivePlayerDisconnected(packetContents);
        break;

    case Packet::FromServerPacketContents::PlayerMoveFromServerPacket:
        receivePlayerMove(packetContents);
        break;

    case Packet::FromServerPacketContents::InitialPlayerDataFinishedFromServerPacket:
        m_initialPlayersReceivedFinished = true;
        break;

    case Packet::FromServerPacketContents::ChunkFromServerPacket:
        receiveChunk(packetContents);
        break;

    case Packet::QuickBarInventoryItemFromServerPacket:
        receiveQuickBarInventoryItem(packetContents);
        break;

    case Packet::QuickBarInventoryItemCountChangedFromServerPacket:
        receiveQuickBarInventoryItemCountChanged(packetContents);
        break;

    case Packet::ItemSpawnedFromServerPacket:
        receiveItemSpawned(packetContents);
        break;

    case Packet::WorldTimeChangedFromServerPacket:
        receiveWorldTimeChanged(packetContents);
        break;

    case Packet::InitialVegetationSpawningFromServerPacket:
        receiveInitialVegetationSpawning(packetContents);
        break;

    default:
        Debug::assertf(false, "Client failure, unhandled packet type received from server, it needs implemented apparently.");
    }

    enet_packet_destroy(event.packet);
}
Пример #2
0
void KeyhoteeMainWindow::received_text( const bts::bitchat::decrypted_message& msg)
{
   auto opt_contact = _addressbook->get_contact_by_public_key( *(msg.from_key) );
   if( !opt_contact )
   {
      elog( "Received text from unknown contact!" );
   }
   else
   {
      wlog( "Received text from known contact!" );
      auto contact_gui = createContactGuiIfNecessary( opt_contact->wallet_index );
      auto text = msg.as<bts::bitchat::private_text_message>();
      QDateTime dateTime;
      dateTime.setTime_t(msg.sig_time.sec_since_epoch());
      bts::get_profile()->get_chat_db()->store(msg);
      contact_gui->receiveChatMessage( opt_contact->dac_id_string.c_str(), text.msg.c_str(), dateTime );
   }
}
Пример #3
0
void ChessProtocol::receiveMessage(const QString &msg)
{
    QHash<QString, QString> hash = analyse(msg);
    qDebug() << hash;
    if(!hash.contains("TYPE"))
    {
        Chess_Error("has no message type: "+msg);
        return;
    }
    QString type = hash.value("TYPE");
    QString body = hash.value("BODY");
    if(type == "CHAT")
    {
        emit receiveChatMessage(body);
    }
    else if(type == "CHESS")
    {
        int fid = -1;
        int fx = -1;
        int fy = -1;
        int tid = -1;
        int tx = -1;
        int ty = -1;
        if(body.size() == 8)
        {
        fid = body.mid(0, 2).toInt();
        fx = body.mid(2, 1).toInt();
        fy = body.mid(3, 1).toInt();
        tid = body.mid(4, 2).toInt();
        tx = body.mid(6, 1).toInt();
        ty = body.mid(7, 1).toInt();

        }
        else if(body.size() == 4)
        {
            body = body.toLower();

//            fx = body.at(0).toAscii() - 'a';
//            fy = 9 - (body.at(1).toAscii() - '0');
//            fid = ChessData::instance()->isWho(QPoint(fx, fy));
//            tx = body.at(2).toAscii() - 'a';
//            ty = 9 - (body.at(3).toAscii() - '0');

            fx = body.at(0).toLatin1() - 'a';
            fy = 9 - (body.at(1).toLatin1() - '0');
            fid = ChessData::instance()->isWho(QPoint(fx, fy));
            tx = body.at(2).toLatin1() - 'a';
            ty = 9 - (body.at(3).toLatin1() - '0');

            tid = ChessData::instance()->isWho(QPoint(tx, ty));
        }
        emit receiveChessMessage(fid, tid, QPoint(fx, fy), QPoint(tx, ty));
    }
    else if(type == "START")
    {
        emit receiveStartMessage();
    }
    else
    {
        Chess_Error("unknown message type: "+type);
    }
}