tibia-client/src/protocollogin.cpp

148 lines
3.7 KiB
C++
Raw Normal View History

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>
#include <script/luainterface.h>
2011-07-13 23:12:36 +02:00
#include <boost/bind.hpp>
2011-04-20 08:40:31 +02:00
ProtocolLogin::ProtocolLogin()
{
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-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()) {
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
static const char hosts[][32] = {
"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-05-30 05:11:12 +02:00
std::string host = hosts[rand() % 10];
//std::string host = "tecserver.zapto.org";
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()
{
sendPacket();
}
void ProtocolLogin::sendPacket()
{
2011-05-30 05:11:12 +02:00
OutputMessage oMsg;
oMsg.addU8(0x01); // Protocol id
oMsg.addU16(0x02); // OS
2011-07-27 20:10:49 +02:00
oMsg.addU16(910); // 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
if(!Rsa::encrypt((char*)oMsg.getBuffer() + 6 + oMsg.getMessageSize() - 128, 128, CIPSOFT_PUBLIC_RSA))
return;
send(&oMsg);
m_xteaEncryptionEnabled = true;
2011-07-27 20:10:49 +02:00
recv();
2011-05-30 05:11:12 +02:00
}
void ProtocolLogin::onRecv(InputMessage *inputMessage)
{
while(!inputMessage->end()) {
uint8 opt = inputMessage->getU8();
logDebug("opt:",(uint)opt);
2011-05-30 05:11:12 +02:00
switch(opt) {
case 0x0A:
parseError(inputMessage);
break;
case 0x14:
parseMOTD(inputMessage);
break;
case 0x1e:
inputMessage->getU8();
inputMessage->getU8();
inputMessage->getU8();
inputMessage->getU8();
inputMessage->getU8();
callField("onError", "Client needs update.");
break;
2011-05-30 05:11:12 +02:00
case 0x64:
parseCharacterList(inputMessage);
break;
}
}
}
void ProtocolLogin::parseError(InputMessage *inputMessage)
{
std::string error = inputMessage->getString();
callField("onError", error);
2011-05-30 05:11:12 +02:00
}
void ProtocolLogin::parseMOTD(InputMessage *inputMessage)
{
std::string motd = inputMessage->getString();
callField("onMotd", motd);
2011-05-30 05:11:12 +02:00
}
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();
2011-04-20 08:40:31 +02:00
logDebug("character: ", name.c_str(), world.c_str(), ip, port);
2011-05-30 05:11:12 +02:00
}
uint16 premiumDays = inputMessage->getU16();
logDebug("prem days: ", premiumDays);
2011-04-20 08:40:31 +02:00
}