2011-08-15 16:11:24 +02:00
|
|
|
#include "protocollogin.h"
|
|
|
|
#include <framework/net/outputmessage.h>
|
|
|
|
#include <framework/net/rsa.h>
|
|
|
|
#include <framework/luascript/luainterface.h>
|
|
|
|
#include <boost/bind.hpp>
|
|
|
|
|
|
|
|
// TODO just testing
|
|
|
|
#include "protocolgame.h"
|
2011-08-16 02:30:31 +02:00
|
|
|
#include <otclient/core/game.h>
|
2011-08-15 16:11:24 +02:00
|
|
|
|
|
|
|
ProtocolLogin::ProtocolLogin()
|
|
|
|
{
|
2011-08-16 05:27:46 +02:00
|
|
|
enableChecksum();
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolLogin::login(const std::string& accountName, const std::string& accountPassword)
|
|
|
|
{
|
|
|
|
if(accountName.empty() || accountPassword.empty()) {
|
|
|
|
callLuaField("onError", "You must enter an account name and password.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_accountName = accountName;
|
|
|
|
m_accountPassword = accountPassword;
|
|
|
|
|
|
|
|
std::string host = "sv3.radbr.com";
|
|
|
|
uint16 port = 7171;
|
|
|
|
|
|
|
|
connect(host, port);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolLogin::onConnect()
|
|
|
|
{
|
|
|
|
sendLoginPacket();
|
|
|
|
}
|
|
|
|
|
2011-08-16 05:27:46 +02:00
|
|
|
void ProtocolLogin::onRecv(InputMessage& inputMessage)
|
|
|
|
{
|
2011-08-16 06:24:20 +02:00
|
|
|
while(!inputMessage.eof()) {
|
2011-08-16 05:27:46 +02:00
|
|
|
uint8 opt = inputMessage.getU8();
|
|
|
|
switch(opt) {
|
|
|
|
case 0x0A:
|
|
|
|
parseError(inputMessage);
|
|
|
|
break;
|
|
|
|
case 0x14:
|
|
|
|
parseMOTD(inputMessage);
|
|
|
|
break;
|
|
|
|
case 0x1e:
|
|
|
|
callLuaField("onError", "Client needs update.");
|
|
|
|
break;
|
|
|
|
case 0x64:
|
|
|
|
parseCharacterList(inputMessage);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
disconnect();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolLogin::onError(const boost::system::error_code& error)
|
|
|
|
{
|
|
|
|
callLuaField("onError", error.message());
|
|
|
|
}
|
|
|
|
|
2011-08-15 16:11:24 +02:00
|
|
|
void ProtocolLogin::sendLoginPacket()
|
|
|
|
{
|
|
|
|
OutputMessage oMsg;
|
|
|
|
|
2011-08-16 06:24:20 +02:00
|
|
|
oMsg.addU8(0x01); // protocol id
|
|
|
|
oMsg.addU16(0x02); // os
|
|
|
|
oMsg.addU16(862); // client version
|
2011-08-15 16:11:24 +02:00
|
|
|
|
2011-08-16 06:24:20 +02:00
|
|
|
oMsg.addU32(0x4E12DAFF); // data signature
|
|
|
|
oMsg.addU32(0x4E12DB27); // sprite signature
|
|
|
|
oMsg.addU32(0x4E119CBF); // pic signature
|
2011-08-15 16:11:24 +02:00
|
|
|
|
2011-08-16 06:24:20 +02:00
|
|
|
oMsg.addU8(0); // first RSA byte must be 0
|
2011-08-15 16:11:24 +02:00
|
|
|
|
2011-08-16 06:24:20 +02:00
|
|
|
// xtea key
|
2011-08-16 05:27:46 +02:00
|
|
|
generateXteaKey();
|
2011-08-16 06:24:20 +02:00
|
|
|
oMsg.addU32(m_xteaKey[0]);
|
|
|
|
oMsg.addU32(m_xteaKey[1]);
|
|
|
|
oMsg.addU32(m_xteaKey[2]);
|
|
|
|
oMsg.addU32(m_xteaKey[3]);
|
2011-08-15 16:11:24 +02:00
|
|
|
|
2011-08-16 06:24:20 +02:00
|
|
|
oMsg.addString(m_accountName);
|
|
|
|
oMsg.addString(m_accountPassword);
|
2011-08-15 16:11:24 +02:00
|
|
|
|
2011-08-16 06:24:20 +02:00
|
|
|
// complete the 128 bytes for rsa encryption with zeros
|
2011-08-15 16:11:24 +02:00
|
|
|
oMsg.addPaddingBytes(128 - (21 + m_accountName.length() + m_accountPassword.length()));
|
|
|
|
|
|
|
|
if(!Rsa::encrypt((char*)oMsg.getBuffer() + 6 + oMsg.getMessageSize() - 128, 128, OTSERV_PUBLIC_RSA))
|
|
|
|
return;
|
|
|
|
|
|
|
|
send(oMsg);
|
|
|
|
|
2011-08-16 05:27:46 +02:00
|
|
|
enableXteaEncryption();
|
2011-08-15 16:11:24 +02:00
|
|
|
|
|
|
|
recv();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolLogin::parseError(InputMessage& inputMessage)
|
|
|
|
{
|
|
|
|
std::string error = inputMessage.getString();
|
|
|
|
callLuaField("onError", error);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolLogin::parseMOTD(InputMessage& inputMessage)
|
|
|
|
{
|
|
|
|
std::string motd = inputMessage.getString();
|
|
|
|
callLuaField("onMotd", motd);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolLogin::parseCharacterList(InputMessage& inputMessage)
|
|
|
|
{
|
|
|
|
uint8 characters = inputMessage.getU8();
|
|
|
|
for(int i = 0; i < characters; ++i) {
|
|
|
|
std::string name = inputMessage.getString();
|
|
|
|
std::string world = inputMessage.getString();
|
|
|
|
uint32 ip = inputMessage.getU32();
|
|
|
|
uint16 port = inputMessage.getU16();
|
|
|
|
|
|
|
|
// TODO just test
|
|
|
|
if(i == 0) {
|
2011-08-16 02:30:31 +02:00
|
|
|
g_game.loginWorld(m_accountName, m_accountPassword, ip, port, name);
|
|
|
|
break;
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
}
|
2011-08-16 02:30:31 +02:00
|
|
|
/*uint16 premiumDays =*/ inputMessage.getU16();
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|