//***************************************************************************** // bool MASTERSERVER_RefreshIPList( IPList &List, const char *FileName ) { std::stringstream oldIPs; for ( ULONG ulIdx = 0; ulIdx < List.size(); ulIdx++ ) oldIPs << List.getEntryAsString ( ulIdx, false ).c_str() << "-"; if ( !(List.clearAndLoadFromFile( FileName )) ) std::cerr << List.getErrorMessage(); std::stringstream newIPs; for ( ULONG ulIdx = 0; ulIdx < List.size(); ulIdx++ ) newIPs << List.getEntryAsString ( ulIdx, false ).c_str() << "-"; return ( strcmp ( newIPs.str().c_str(), oldIPs.str().c_str() ) != 0 ); }
void ProtocolLogin::getCharacterList(uint32_t accountName, const std::string& password) { uint32_t serverIp = serverIPs[0].first; for (uint32_t i = 0; i < serverIPs.size(); i++) { if ((serverIPs[i].first & serverIPs[i].second) == (getConnection()->getIP() & serverIPs[i].second)) { serverIp = serverIPs[i].first; break; } } Account account; if (!IOLoginData::loginserverAuthentication(accountName, password, account)) { disconnectClient("Account name or password is not correct."); return; } auto output = OutputMessagePool::getOutputMessage(); //Update premium days Game::updatePremium(account); const std::string& motd = g_config.getString(ConfigManager::MOTD); if (!motd.empty()) { //Add MOTD output->addByte(0x14); std::ostringstream ss; ss << g_game.getMotdNum() << "\n" << motd; output->addString(ss.str()); } //Add char list output->addByte(0x64); uint8_t size = std::min<size_t>(std::numeric_limits<uint8_t>::max(), account.characters.size()); output->addByte(size); for (uint8_t i = 0; i < size; i++) { output->addString(account.characters[i]); output->addString(g_config.getString(ConfigManager::SERVER_NAME)); output->add<uint32_t>(serverIp); output->add<uint16_t>(g_config.getNumber(ConfigManager::GAME_PORT)); } //Add premium days if (g_config.getBoolean(ConfigManager::FREE_PREMIUM)) { output->add<uint16_t>(0xFFFF); //client displays free premium } else { output->add<uint16_t>(account.premiumDays); } send(output); disconnect(); }
//***************************************************************************** // void MASTERSERVER_InitializeBans( void ) { const bool BannedIPsChanged = MASTERSERVER_RefreshIPList ( g_BannedIPs, "banlist.txt" ); const bool BannedIPExemptionsChanged = MASTERSERVER_RefreshIPList ( g_BannedIPExemptions, "whitelist.txt" ); if ( !(g_MultiServerExceptions.clearAndLoadFromFile( "multiserver_whitelist.txt" )) ) std::cerr << g_MultiServerExceptions.getErrorMessage(); if ( !(g_BlockedIPs.clearAndLoadFromFile( "blocklist.txt" )) ) std::cerr << g_BlockedIPs.getErrorMessage(); std::cerr << "\nBan list: " << g_BannedIPs.size() << " banned IPs, " << g_BlockedIPs.size( ) << " blocked IPs, " << g_BannedIPExemptions.size() << " exemptions." << std::endl; std::cerr << "Multi-server exceptions: " << g_MultiServerExceptions.size() << "." << std::endl; if ( BannedIPsChanged || BannedIPExemptionsChanged ) { // [BB] The ban list was changed, so no server has the latest list anymore. for( std::set<SERVER_s, SERVERCompFunc>::iterator it = g_Servers.begin(); it != g_Servers.end(); ++it ) { it->bHasLatestBanList = false; it->bVerifiedLatestBanList = false; } std::cerr << "Ban lists were changed since last refresh\n"; } /* // [BB] Print all banned IPs, to make sure the IP list has been parsed successfully. std::cerr << "Entries in blacklist:\n"; for ( ULONG ulIdx = 0; ulIdx < g_BannedIPs.size(); ulIdx++ ) std::cerr << g_BannedIPs.getEntryAsString(ulIdx).c_str(); // [BB] Print all exemption-IPs, to make sure the IP list has been parsed successfully. std::cerr << "Entries in whitelist:\n"; for ( ULONG ulIdx = 0; ulIdx < g_BannedIPExemptions.size(); ulIdx++ ) std::cerr << g_BannedIPExemptions.getEntryAsString(ulIdx).c_str(); */ }
//***************************************************************************** // void MASTERSERVER_SendBanlistToServer( const SERVER_s &Server ) { // [BB] If the server supports it, potentially split the ban list over multiple packets. if ( Server.iServerRevision >= 2907 ) { BanlistPacketSender sender ( Server ); sender.start(); // Write all the bans. for ( unsigned int i = 0; i < g_BannedIPs.size( ); ++i ) sender.writeBanEntry ( g_BannedIPs.getEntryAsString( i, false, false, false ).c_str( ), MSB_BAN ); // Write all the exceptions. for ( unsigned int i = 0; i < g_BannedIPExemptions.size( ); ++i ) sender.writeBanEntry ( g_BannedIPExemptions.getEntryAsString( i, false, false, false ).c_str( ), MSB_BANEXEMPTION ); sender.end(); } else { NETWORK_ClearBuffer( &g_MessageBuffer ); NETWORK_WriteByte( &g_MessageBuffer.ByteStream, MASTER_SERVER_BANLIST ); // [BB] If the server sent us a verification string, send it along with the ban list. // This allows the server to verify that the list actually was sent from our master // (and is not just a packet with forged source IP). if ( Server.MasterBanlistVerificationString.size() ) NETWORK_WriteString( &g_MessageBuffer.ByteStream, Server.MasterBanlistVerificationString.c_str() ); // Write all the bans. NETWORK_WriteLong( &g_MessageBuffer.ByteStream, g_BannedIPs.size( )); for ( ULONG i = 0; i < g_BannedIPs.size( ); i++ ) NETWORK_WriteString( &g_MessageBuffer.ByteStream, g_BannedIPs.getEntryAsString( i, false, false, false ).c_str( )); // Write all the exceptions. NETWORK_WriteLong( &g_MessageBuffer.ByteStream, g_BannedIPExemptions.size( )); for ( ULONG i = 0; i < g_BannedIPExemptions.size( ); i++ ) NETWORK_WriteString( &g_MessageBuffer.ByteStream, g_BannedIPExemptions.getEntryAsString( i, false, false, false ).c_str( )); NETWORK_LaunchPacket( &g_MessageBuffer, Server.Address ); } Server.bHasLatestBanList = true; Server.bVerifiedLatestBanList = false; printf( "-> Banlist sent to %s.\n", NETWORK_AddressToString( Server.Address )); }
bool ProtocolLogin::parseFirstPacket(NetworkMessage& msg) { if( #ifndef _CONSOLE !GUI::getInstance()->m_connections || #endif g_game.getGameState() == GAME_STATE_SHUTDOWN) { getConnection()->closeConnection(); return false; } uint32_t clientip = getConnection()->getIP(); /*uint16_t clientos = */msg.GetU16(); uint16_t version = msg.GetU16(); msg.SkipBytes(12); if(version <= 760) { disconnectClient(0x0A, "Only clients with protocol " CLIENT_VERSION_STR " allowed!"); return false; } if(!RSA_decrypt(msg)) { getConnection()->closeConnection(); return false; } uint32_t key[4]; key[0] = msg.GetU32(); key[1] = msg.GetU32(); key[2] = msg.GetU32(); key[3] = msg.GetU32(); enableXTEAEncryption(); setXTEAKey(key); std::string accountName = msg.GetString(); std::string password = msg.GetString(); if(accountName.empty()) { if(g_config.getBoolean(ConfigManager::ACCOUNT_MANAGER)) { accountName = "1"; password = "******"; } else { disconnectClient(0x0A, "Invalid Account Name."); return false; } } if(version < CLIENT_VERSION_MIN || version > CLIENT_VERSION_MAX) { disconnectClient(0x0A, "Only clients with protocol " CLIENT_VERSION_STR " allowed!"); return false; } if(g_game.getGameState() == GAME_STATE_STARTUP) { disconnectClient(0x0A, "Gameworld is starting up. Please wait."); return false; } if(g_game.getGameState() == GAME_STATE_MAINTAIN) { disconnectClient(0x0A, "Gameworld is under maintenance. Please re-connect in a while."); return false; } if(g_bans.isIpDisabled(clientip)) { disconnectClient(0x0A, "Too many connections attempts from this IP. Try again later."); return false; } if(IOBan::getInstance()->isIpBanished(clientip)) { disconnectClient(0x0A, "Your IP is banished!"); return false; } uint32_t serverip = serverIPs[0].first; for(uint32_t i = 0; i < serverIPs.size(); i++) { if((serverIPs[i].first & serverIPs[i].second) == (clientip & serverIPs[i].second)) { serverip = serverIPs[i].first; break; } } Account account = IOLoginData::getInstance()->loadAccount(accountName); if(account.id == 0 || !passwordTest(password, account.password)) { g_bans.addLoginAttempt(clientip, false); disconnectClient(0x0A, "Account name or password is not correct."); return false; } g_bans.addLoginAttempt(clientip, true); OutputMessage_ptr output = OutputMessagePool::getInstance()->getOutputMessage(this, false); if(output) { TRACK_MESSAGE(output); //Update premium days g_game.updatePremium(account); //Add MOTD output->AddByte(0x14); std::ostringstream ss; ss << g_game.getMotdNum() << "\n" << g_config.getString(ConfigManager::MOTD); output->AddString(ss.str()); //Add char list output->AddByte(0x64); if(g_config.getBoolean(ConfigManager::ACCOUNT_MANAGER) && account.id != 1) { output->AddByte((uint8_t)account.charList.size() + 1); output->AddString("Account Manager"); output->AddString(g_config.getString(ConfigManager::SERVER_NAME)); output->AddU32(serverip); output->AddU16(g_config.getNumber(ConfigManager::GAME_PORT)); } else output->AddByte((uint8_t)account.charList.size()); std::list<std::string>::iterator it, end; for(it = account.charList.begin(), end = account.charList.end(); it != end; ++it) { output->AddString(*it); if(g_config.getBoolean(ConfigManager::ON_OR_OFF_CHARLIST)) { if(g_game.getPlayerByName((*it))) output->AddString("Online"); else output->AddString("Offline"); } else output->AddString(g_config.getString(ConfigManager::SERVER_NAME)); output->AddU32(serverip); output->AddU16(g_config.getNumber(ConfigManager::GAME_PORT)); } //Add premium days if(g_config.getBoolean(ConfigManager::FREE_PREMIUM)) output->AddU16(0xFFFF); //client displays free premium else output->AddU16(account.premiumDays); OutputMessagePool::getInstance()->send(output); } getConnection()->closeConnection(); return true; }
bool ProtocolLogin::parseFirstPacket(NetworkMessage& msg) { if(g_game.getGameState() == GAME_STATE_SHUTDOWN){ getConnection()->closeConnection(); return false; } uint32_t clientip = getConnection()->getIP(); /*uint16_t clientos =*/ msg.GetU16(); uint16_t version = msg.GetU16(); msg.SkipBytes(12); if(version <= 760){ disconnectClient(0x0A, STRING_CLIENT_VERSION); } if(!RSA_decrypt(g_otservRSA, msg)){ getConnection()->closeConnection(); return false; } uint32_t key[4]; key[0] = msg.GetU32(); key[1] = msg.GetU32(); key[2] = msg.GetU32(); key[3] = msg.GetU32(); enableXTEAEncryption(); setXTEAKey(key); uint32_t accnumber = msg.GetU32(); std::string password = msg.GetString(); if(!accnumber){ disconnectClient(0x0A, "You must enter your account number."); return false; } if(version < CLIENT_VERSION_MIN || version > CLIENT_VERSION_MAX){ disconnectClient(0x0A, STRING_CLIENT_VERSION); return false; } if(g_game.getGameState() == GAME_STATE_STARTUP){ disconnectClient(0x0A, "Gameworld is starting up. Please wait."); return false; } if(g_bans.isIpDisabled(clientip)){ disconnectClient(0x0A, "Too many connections attempts from this IP. Try again later."); return false; } if(g_bans.isIpBanished(clientip)){ disconnectClient(0x0A, "Your IP is banished!"); return false; } uint32_t serverip = serverIPs[0].first; for(uint32_t i = 0; i < serverIPs.size(); i++){ if((serverIPs[i].first & serverIPs[i].second) == (clientip & serverIPs[i].second)){ serverip = serverIPs[i].first; break; } } Account account = IOAccount::instance()->loadAccount(accnumber); if(!(accnumber != 0 && account.accnumber == accnumber && passwordTest(password, account.password))){ g_bans.addLoginAttempt(clientip, false); disconnectClient(0x0A, "Please enter a valid account number and password."); return false; } g_bans.addLoginAttempt(clientip, true); OutputMessage* output = OutputMessagePool::getInstance()->getOutputMessage(this, false); //Add MOTD std::stringstream motd; output->AddByte(0x14); motd << g_config.getNumber(ConfigManager::MOTD_NUM) << "\n"; motd << g_config.getString(ConfigManager::MOTD); output->AddString(motd.str()); //Add char list output->AddByte(0x64); output->AddByte((uint8_t)account.charList.size()); std::list<std::string>::iterator it; for(it = account.charList.begin(); it != account.charList.end(); it++){ output->AddString((*it)); output->AddString(g_config.getString(ConfigManager::WORLD_NAME)); output->AddU32(serverip); output->AddU16(g_config.getNumber(ConfigManager::PORT)); } //Add premium days output->AddU16(account.premiumDays);//output->AddU16(0); OutputMessagePool::getInstance()->send(output); getConnection()->closeConnection(); return true; }
bool ProtocolLogin::parseFirstPacket(NetworkMessage& msg) { if (g_game.getGameState() == GAME_STATE_SHUTDOWN) { getConnection()->closeConnection(); return false; } uint32_t clientip = getConnection()->getIP(); /*uint16_t clientos = */ msg.GetU16(); uint16_t version = msg.GetU16(); msg.SkipBytes(12); /* * Skipped bytes: * 12 bytes: dat, spr, pic signatures (4 bytes each) */ #ifdef __PROTOCOL_77__ if (!RSA_decrypt(msg)) { getConnection()->closeConnection(); return false; } uint32_t key[4]; key[0] = msg.GetU32(); key[1] = msg.GetU32(); key[2] = msg.GetU32(); key[3] = msg.GetU32(); enableXTEAEncryption(); setXTEAKey(key); #endif uint32_t accountName = msg.GetU32(); std::string password = msg.GetString(); if (version < CLIENT_VERSION_MIN || version > CLIENT_VERSION_MAX) { disconnectClient(0x0A, "Only clients with protocol " CLIENT_VERSION_STR " allowed!"); return false; } if (g_game.getGameState() == GAME_STATE_STARTUP) { disconnectClient(0x0A, "Gameworld is starting up. Please wait."); return false; } if (g_game.getGameState() == GAME_STATE_MAINTAIN) { disconnectClient(0x0A, "Gameworld is under maintenance. Please re-connect in a while."); return false; } BanInfo banInfo; if (IOBan::getInstance()->isIpBanned(clientip, banInfo)) { if (banInfo.reason.empty()) { banInfo.reason = "(none)"; } std::ostringstream ss; ss << "Your IP has been banned until " << formatDateShort(banInfo.expiresAt) << " by " << banInfo.bannedBy << ".\n\nReason specified:\n" << banInfo.reason; disconnectClient(0x0A, ss.str().c_str()); return false; } uint32_t serverip = serverIPs[0].first; for (uint32_t i = 0; i < serverIPs.size(); i++) { if ((serverIPs[i].first & serverIPs[i].second) == (clientip & serverIPs[i].second)) { serverip = serverIPs[i].first; break; } } if (!accountName) { disconnectClient(0x0A, "Invalid account id."); return false; } Account account; if (!IOLoginData::getInstance()->loginserverAuthentication(accountName, password, account)) { disconnectClient(0x0A, "Account id or password is not correct."); return false; } OutputMessage_ptr output = OutputMessagePool::getInstance()->getOutputMessage(this, false); if (output) { //Update premium days g_game.updatePremium(account); //Add MOTD output->AddByte(0x14); std::ostringstream ss; ss << g_game.getMotdNum() << "\n" << g_config.getString(ConfigManager::MOTD); output->AddString(ss.str()); //Add char list output->AddByte(0x64); output->AddByte((uint8_t)account.charList.size()); for (const std::string& characterName : account.charList) { output->AddString(characterName); if (g_config.getBoolean(ConfigManager::ON_OR_OFF_CHARLIST)) { if (g_game.getPlayerByName(characterName)) { output->AddString("Online"); } else { output->AddString("Offline"); } } else { output->AddString(g_config.getString(ConfigManager::SERVER_NAME)); } output->AddU32(serverip); output->AddU16(g_config.getNumber(ConfigManager::GAME_PORT)); } //Add premium days if (g_config.getBoolean(ConfigManager::FREE_PREMIUM)) { output->AddU16(0xFFFF); //client displays free premium } else { output->AddU16(account.premiumDays); } OutputMessagePool::getInstance()->send(output); } getConnection()->closeConnection(); return true; }