bool ProtocolLogin::parseFirstPacket(NetworkMessage& msg)
{
if(
#if defined(WINDOWS) && !defined(__CONSOLE__)
!GUI::getInstance()->m_connections ||
#endif
g_game.getGameState() == GAME_STATE_SHUTDOWN)
{
getConnection()->close();
return false;
}
uint32_t clientIp = getConnection()->getIP();
/*uint16_t operatingSystem = msg.GetU16();*/msg.SkipBytes(2);
uint16_t version = msg.GetU16();
std::cout << "Client version: " << version << std::endl;
msg.SkipBytes(12);
if(!RSA_decrypt(msg))
{
getConnection()->close();
return false;
}
uint32_t key[4] = {msg.GetU32(), msg.GetU32(), msg.GetU32(), msg.GetU32()};
enableXTEAEncryption();
setXTEAKey(key);
std::string name = msg.GetString(), password = msg.GetString();
if(name.empty())
{
if(!g_config.getBool(ConfigManager::ACCOUNT_MANAGER))
{
disconnectClient(0x0A, "Invalid account name.");
return false;
}
name = "1";
password = "1";
}
if(version < CLIENT_VERSION_MIN || version > CLIENT_VERSION_MAX)
{
disconnectClient(0x0A, CLIENT_VERSION_STRING);
return false;
}
if(g_game.getGameState() < GAME_STATE_NORMAL)
{
disconnectClient(0x0A, "Server is just starting up, please wait.");
return false;
}
if(g_game.getGameState() == GAME_STATE_MAINTAIN)
{
disconnectClient(0x0A, "Server is under maintenance, please re-connect in a while.");
return false;
}
if(ConnectionManager::getInstance()->isDisabled(clientIp, protocolId))
{
disconnectClient(0x0A, "Too many connections attempts from your IP address, please try again later.");
return false;
}
if(IOBan::getInstance()->isIpBanished(clientIp))
{
disconnectClient(0x0A, "Your IP is banished!");
return false;
}
uint32_t id = 1;
if(!IOLoginData::getInstance()->getAccountId(name, id))
{
ConnectionManager::getInstance()->addAttempt(clientIp, protocolId, false);
disconnectClient(0x0A, "Invalid account name.");
return false;
}
Account account = IOLoginData::getInstance()->loadAccount(id);
if(!encryptTest(password, account.password))
{
ConnectionManager::getInstance()->addAttempt(clientIp, protocolId, false);
disconnectClient(0x0A, "Invalid password.");
return false;
}