tibia-client/src/otclient/net/protocolgame.cpp

57 lines
1.4 KiB
C++
Raw Normal View History

2011-08-15 16:11:24 +02:00
#include <otclient/net/protocolgame.h>
#include <otclient/core/game.h>
ProtocolGame::ProtocolGame()
{
m_checksumEnabled = false;
2011-08-16 02:30:31 +02:00
m_waitingLoginPacket = false;
2011-08-15 16:11:24 +02:00
}
void ProtocolGame::login(const std::string& accountName, const std::string& accountPassword, uint32 ip, uint16 port, const std::string& characterName)
{
if(accountName.empty() || accountPassword.empty()) {
callLuaField("onError", "You must enter an account name and password.");
return;
}
2011-08-16 02:30:31 +02:00
m_waitingLoginPacket = true;
2011-08-15 16:11:24 +02:00
m_accountName = accountName;
m_accountPassword = accountPassword;
m_characterName = characterName;
char host[16];
sprintf(host, "%d.%d.%d.%d", (uint8)ip, (uint8)(ip >> 8), (uint8)(ip >> 16), (uint8)(ip >> 24));
connect(host, port);
}
void ProtocolGame::onConnect()
{
recv();
}
void ProtocolGame::onRecv(InputMessage& inputMessage)
{
2011-08-16 02:30:31 +02:00
if(m_waitingLoginPacket) {
2011-08-15 16:11:24 +02:00
inputMessage.skipBytes(3);
uint32 timestamp = inputMessage.getU32();
uint8 unknown = inputMessage.getU8();
2011-08-16 02:30:31 +02:00
m_waitingLoginPacket = false;
2011-08-15 16:11:24 +02:00
m_checksumEnabled = true;
sendLoginPacket(timestamp, unknown);
2011-08-16 02:30:31 +02:00
recv();
2011-08-15 16:11:24 +02:00
}
else {
parseMessage(inputMessage);
2011-08-16 02:30:31 +02:00
recv();
2011-08-15 16:11:24 +02:00
}
}
2011-08-16 02:30:31 +02:00
void ProtocolGame::onError(const boost::system::error_code& error)
{
// already disconnected, just send onLogout
g_game.onLogout();
}