//***************************************************************************** // 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(); */ }
//***************************************************************************** // 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 ); }