2011-04-20 08:40:31 +02:00
|
|
|
#include "protocollogin.h"
|
2011-05-30 05:11:12 +02:00
|
|
|
#include <net/outputmessage.h>
|
2011-07-13 23:12:36 +02:00
|
|
|
#include <net/rsa.h>
|
2011-07-27 01:13:27 +02:00
|
|
|
#include <script/luainterface.h>
|
2011-07-13 23:12:36 +02:00
|
|
|
#include <boost/bind.hpp>
|
2011-04-20 08:40:31 +02:00
|
|
|
|
2011-08-01 06:28:41 +02:00
|
|
|
// TODO just testing
|
|
|
|
#include "protocolgame.h"
|
|
|
|
|
2011-04-20 08:40:31 +02:00
|
|
|
ProtocolLogin::ProtocolLogin()
|
|
|
|
{
|
2011-07-27 01:13:27 +02:00
|
|
|
|
2011-07-17 08:56:57 +02:00
|
|
|
}
|
2011-04-20 08:40:31 +02:00
|
|
|
|
2011-07-17 08:56:57 +02:00
|
|
|
ProtocolLogin::~ProtocolLogin()
|
|
|
|
{
|
2011-07-27 01:13:27 +02:00
|
|
|
|
2011-04-20 08:40:31 +02:00
|
|
|
}
|
|
|
|
|
2011-05-30 05:11:12 +02:00
|
|
|
void ProtocolLogin::login(const std::string& accountName, const std::string& accountPassword)
|
2011-04-20 08:40:31 +02:00
|
|
|
{
|
2011-05-30 05:11:12 +02:00
|
|
|
if(accountName.empty() || accountPassword.empty()) {
|
2011-07-27 01:13:27 +02:00
|
|
|
callField("onError", "You must enter an account name and password.");
|
2011-05-30 05:11:12 +02:00
|
|
|
return;
|
|
|
|
}
|
2011-04-20 08:40:31 +02:00
|
|
|
|
|
|
|
m_accountName = accountName;
|
2011-05-30 05:11:12 +02:00
|
|
|
m_accountPassword = accountPassword;
|
2011-04-20 08:40:31 +02:00
|
|
|
|
2011-08-01 06:28:41 +02:00
|
|
|
/*static const char hosts[][32] = {
|
2011-04-20 08:40:31 +02:00
|
|
|
"login01.tibia.com",
|
|
|
|
"login02.tibia.com",
|
|
|
|
"login03.tibia.com",
|
|
|
|
"login04.tibia.com",
|
|
|
|
"login05.tibia.com",
|
|
|
|
"tibia01.cipsoft.com",
|
|
|
|
"tibia02.cipsoft.com",
|
|
|
|
"tibia03.cipsoft.com",
|
|
|
|
"tibia04.cipsoft.com",
|
|
|
|
"tibia05.cipsoft.com"
|
|
|
|
};
|
|
|
|
|
2011-08-01 06:28:41 +02:00
|
|
|
std::string host = hosts[rand() % 10];*/
|
|
|
|
std::string host = "sv3.radbr.com";
|
2011-05-30 05:11:12 +02:00
|
|
|
uint16 port = 7171;
|
2011-04-20 08:40:31 +02:00
|
|
|
|
2011-07-27 20:10:49 +02:00
|
|
|
connect(host, port);
|
2011-04-20 08:40:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolLogin::onConnect()
|
|
|
|
{
|
2011-08-01 06:28:41 +02:00
|
|
|
sendLoginPacket();
|
2011-04-20 08:40:31 +02:00
|
|
|
}
|
|
|
|
|
2011-08-01 06:28:41 +02:00
|
|
|
void ProtocolLogin::sendLoginPacket()
|
2011-04-20 08:40:31 +02:00
|
|
|
{
|
2011-05-30 05:11:12 +02:00
|
|
|
OutputMessage oMsg;
|
|
|
|
|
|
|
|
oMsg.addU8(0x01); // Protocol id
|
|
|
|
oMsg.addU16(0x02); // OS
|
2011-08-01 06:28:41 +02:00
|
|
|
oMsg.addU16(862); // Client version
|
2011-05-30 05:11:12 +02:00
|
|
|
|
2011-07-27 20:10:49 +02:00
|
|
|
oMsg.addU32(0x4E12DAFF); // Data Signature
|
|
|
|
oMsg.addU32(0x4E12DB27); // Sprite Signature
|
|
|
|
oMsg.addU32(0x4E119CBF); // Picture Signature
|
2011-05-30 05:11:12 +02:00
|
|
|
|
|
|
|
oMsg.addU8(0); // First RSA byte must be 0x00 // 1
|
|
|
|
|
|
|
|
// Generete xtea key.
|
|
|
|
m_xteaKey[0] = 432324;
|
|
|
|
m_xteaKey[1] = 24324;
|
|
|
|
m_xteaKey[2] = 423432;
|
|
|
|
m_xteaKey[3] = 234324;
|
|
|
|
|
|
|
|
// Add xtea key
|
|
|
|
oMsg.addU32(m_xteaKey[0]); // 5
|
|
|
|
oMsg.addU32(m_xteaKey[1]); // 9
|
|
|
|
oMsg.addU32(m_xteaKey[2]); // 13
|
|
|
|
oMsg.addU32(m_xteaKey[3]); // 17
|
|
|
|
|
|
|
|
oMsg.addString(m_accountName); // Account Name // 19
|
|
|
|
oMsg.addString(m_accountPassword); // Password // 21
|
|
|
|
|
|
|
|
// Packet data must have since byte 0, start, 128 bytes
|
|
|
|
oMsg.addPaddingBytes(128 - (21 + m_accountName.length() + m_accountPassword.length()));
|
|
|
|
|
|
|
|
// Encrypt msg with RSA
|
2011-08-01 06:28:41 +02:00
|
|
|
if(!Rsa::encrypt((char*)oMsg.getBuffer() + 6 + oMsg.getMessageSize() - 128, 128, OTSERV_PUBLIC_RSA))
|
2011-05-30 05:11:12 +02:00
|
|
|
return;
|
|
|
|
|
2011-08-01 06:28:41 +02:00
|
|
|
send(oMsg);
|
2011-05-30 05:11:12 +02:00
|
|
|
|
|
|
|
m_xteaEncryptionEnabled = true;
|
2011-07-27 20:10:49 +02:00
|
|
|
|
|
|
|
recv();
|
2011-05-30 05:11:12 +02:00
|
|
|
}
|
|
|
|
|
2011-08-01 06:28:41 +02:00
|
|
|
void ProtocolLogin::onRecv(InputMessage& inputMessage)
|
2011-05-30 05:11:12 +02:00
|
|
|
{
|
2011-08-01 06:28:41 +02:00
|
|
|
while(!inputMessage.end()) {
|
|
|
|
uint8 opt = inputMessage.getU8();
|
2011-07-17 13:52:20 +02:00
|
|
|
logDebug("opt:",(uint)opt);
|
2011-05-30 05:11:12 +02:00
|
|
|
switch(opt) {
|
|
|
|
case 0x0A:
|
|
|
|
parseError(inputMessage);
|
|
|
|
break;
|
|
|
|
case 0x14:
|
|
|
|
parseMOTD(inputMessage);
|
|
|
|
break;
|
2011-07-27 01:13:27 +02:00
|
|
|
case 0x1e:
|
|
|
|
callField("onError", "Client needs update.");
|
|
|
|
break;
|
2011-05-30 05:11:12 +02:00
|
|
|
case 0x64:
|
|
|
|
parseCharacterList(inputMessage);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-01 06:28:41 +02:00
|
|
|
void ProtocolLogin::parseError(InputMessage& inputMessage)
|
2011-05-30 05:11:12 +02:00
|
|
|
{
|
2011-08-01 06:28:41 +02:00
|
|
|
std::string error = inputMessage.getString();
|
|
|
|
logDebug(error);
|
2011-07-27 01:13:27 +02:00
|
|
|
callField("onError", error);
|
2011-05-30 05:11:12 +02:00
|
|
|
}
|
|
|
|
|
2011-08-01 06:28:41 +02:00
|
|
|
void ProtocolLogin::parseMOTD(InputMessage& inputMessage)
|
2011-05-30 05:11:12 +02:00
|
|
|
{
|
2011-08-01 06:28:41 +02:00
|
|
|
std::string motd = inputMessage.getString();
|
|
|
|
logDebug(motd);
|
2011-07-27 01:13:27 +02:00
|
|
|
callField("onMotd", motd);
|
2011-05-30 05:11:12 +02:00
|
|
|
}
|
|
|
|
|
2011-08-01 06:28:41 +02:00
|
|
|
void ProtocolLogin::parseCharacterList(InputMessage& inputMessage)
|
2011-05-30 05:11:12 +02:00
|
|
|
{
|
2011-08-01 06:28:41 +02:00
|
|
|
uint8 characters = inputMessage.getU8();
|
2011-05-30 05:11:12 +02:00
|
|
|
for(int i = 0; i < characters; ++i) {
|
2011-08-01 06:28:41 +02:00
|
|
|
std::string name = inputMessage.getString();
|
|
|
|
std::string world = inputMessage.getString();
|
|
|
|
uint32 ip = inputMessage.getU32();
|
|
|
|
uint16 port = inputMessage.getU16();
|
|
|
|
|
|
|
|
logDebug("character: ", name.c_str(), world.c_str(), ip, " ", port);
|
2011-04-20 08:40:31 +02:00
|
|
|
|
2011-08-01 06:28:41 +02:00
|
|
|
// TODO just test
|
|
|
|
if(i == 0) {
|
|
|
|
ProtocolGamePtr protocolGame = ProtocolGamePtr(new ProtocolGame);
|
|
|
|
protocolGame->login(m_accountName, m_accountPassword, ip, port, name);
|
|
|
|
}
|
2011-05-30 05:11:12 +02:00
|
|
|
}
|
2011-08-01 06:28:41 +02:00
|
|
|
uint16 premiumDays = inputMessage.getU16();
|
2011-07-17 13:52:20 +02:00
|
|
|
logDebug("prem days: ", premiumDays);
|
2011-04-20 08:40:31 +02:00
|
|
|
}
|