2011-08-15 16:11:24 +02:00
|
|
|
#include <otclient/net/protocolgame.h>
|
|
|
|
#include <otclient/core/game.h>
|
|
|
|
|
|
|
|
ProtocolGame::ProtocolGame()
|
|
|
|
{
|
2011-08-16 02:30:31 +02:00
|
|
|
m_waitingLoginPacket = false;
|
2011-08-15 16:11:24 +02:00
|
|
|
}
|
|
|
|
|
2011-08-26 20:00:22 +02:00
|
|
|
void ProtocolGame::login(const std::string& accountName, const std::string& accountPassword, const std::string& host, uint16 port, const std::string& characterName)
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
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-16 05:27:46 +02:00
|
|
|
enableChecksum();
|
2011-08-15 16:11:24 +02:00
|
|
|
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)
|
|
|
|
{
|
2011-08-16 05:27:46 +02:00
|
|
|
// already disconnected, just fire onLogout
|
2011-08-16 02:30:31 +02:00
|
|
|
g_game.onLogout();
|
|
|
|
}
|
|
|
|
|