Example #1
0
void ProtocolLogin::sendLoginPacket()
{
    OutputMessage oMsg;

    oMsg.addU8(Proto::ClientEnterAccount);
    oMsg.addU16(Proto::OsLinux);
    oMsg.addU16(Proto::ClientVersion);

    oMsg.addU32(g_thingsType.getSignature()); // data signature
    oMsg.addU32(g_sprites.getSignature()); // sprite signature
    oMsg.addU32(Proto::PicSignature); // pic signature

    oMsg.addU8(0); // first RSA byte must be 0

    // xtea key
    generateXteaKey();
    oMsg.addU32(m_xteaKey[0]);
    oMsg.addU32(m_xteaKey[1]);
    oMsg.addU32(m_xteaKey[2]);
    oMsg.addU32(m_xteaKey[3]);

    oMsg.addString(m_accountName);
    oMsg.addString(m_accountPassword);

    // complete the 128 bytes for rsa encryption with zeros
    oMsg.addPaddingBytes(128 - (21 + m_accountName.length() + m_accountPassword.length()));
    Rsa::encrypt((char*)oMsg.getBuffer() + InputMessage::DATA_POS + oMsg.getMessageSize() - 128, 128, Proto::RSA);

    send(oMsg);
    enableXteaEncryption();
    recv();
}
void ProtocolGame::sendLoginPacket(uint timestamp, uint8 unknown)
{
    OutputMessage oMsg;

    oMsg.addU8(Proto::ClientEnterGame);
    oMsg.addU16(Proto::OsLinux);
    oMsg.addU16(Proto::ClientVersion);

    oMsg.addU8(0); // first RSA byte must be 0

    // xtea key
    generateXteaKey();
    oMsg.addU32(m_xteaKey[0]);
    oMsg.addU32(m_xteaKey[1]);
    oMsg.addU32(m_xteaKey[2]);
    oMsg.addU32(m_xteaKey[3]);

    oMsg.addU8(0); // is gm set?
    oMsg.addString(m_accountName);
    oMsg.addString(m_characterName);
    oMsg.addString(m_accountPassword);

    oMsg.addU32(timestamp);
    oMsg.addU8(unknown);

    // complete the 128 bytes for rsa encryption with zeros
    oMsg.addPaddingBytes(128 - (29 + m_accountName.length() + m_characterName.length() + m_accountPassword.length()));

    // encrypt with RSA
    Rsa::encrypt((char*)oMsg.getBuffer() + 6 + oMsg.getMessageSize() - 128, 128, Proto::RSA);

    send(oMsg);

    enableXteaEncryption();
}
void ProtocolGame::sendLoginPacket(uint challengeTimestamp, uint8 challengeRandom)
{
    OutputMessagePtr msg(new OutputMessage);

    msg->addU8(Proto::ClientPendingGame);
    msg->addU16(g_game.getOs());
    msg->addU16(g_game.getProtocolVersion());

    if(g_game.getProtocolVersion() >= 971) {
        msg->addU32(g_game.getClientVersion());
        msg->addU8(0); // clientType
    }

    int offset = msg->getMessageSize();

    msg->addU8(0); // first RSA byte must be 0

    if(g_game.getProtocolVersion() >= 770)
    {
        // xtea key
        generateXteaKey();
        msg->addU32(m_xteaKey[0]);
        msg->addU32(m_xteaKey[1]);
        msg->addU32(m_xteaKey[2]);
        msg->addU32(m_xteaKey[3]);
        msg->addU8(0); // is gm set?
    }

    if(g_game.getFeature(Otc::GameAccountNames))
        msg->addString(m_accountName);
    else
        msg->addU32(stdext::from_string<uint32>(m_accountName));

    msg->addString(m_characterName);
    msg->addString(m_accountPassword);

    if(g_game.getFeature(Otc::GameChallengeOnLogin)) {
        msg->addU32(challengeTimestamp);
        msg->addU8(challengeRandom);
    }

    std::string extended = callLuaField<std::string>("getLoginExtendedData");
    if(!extended.empty())
        msg->addString(extended);

    // complete the bytes for rsa encryption with zeros
    int paddingBytes = g_crypt.rsaGetSize() - (msg->getMessageSize() - offset);
    assert(paddingBytes >= 0);
    msg->addPaddingBytes(paddingBytes);

    // encrypt with RSA
    if(g_game.getProtocolVersion() >= 770)
        msg->encryptRsa();

    if(g_game.getFeature(Otc::GameProtocolChecksum))
        enableChecksum();

    send(msg);

    if(g_game.getProtocolVersion() >= 770)
        enableXteaEncryption();
}