bool BanIPMgr_Impl::WriteBans( ) { // If not initialized, we can't write out the bans yet. if( !m_bInitialized ) return false; CButeMgr banBute; char szBanKey[128] = ""; char szClientIP[16] = ""; int nBanIndex = 0; // Look through list of banned ip's. for( BanList::iterator iter = m_BanList.begin( ); iter != m_BanList.end( ); iter++ ) { ClientIP const& bannedIP = *iter; // Convert it to a string. if( !ConvertClientIPToString( bannedIP, szClientIP, ARRAY_LEN( szClientIP ))) return false; // Write the banned IP. sprintf( szBanKey, "Ban%d", nBanIndex ); banBute.SetString( "Bans", szBanKey, szClientIP ); nBanIndex++; } // Save the list. banBute.Save( "BanList.txt" ); return true; }
bool BanIPMgr_Impl::IsClientBanned( HCLIENT hClient ) { // Get the clients IP. uint8 aClientIP[4]; uint16 nPort; g_pLTServer->GetClientAddr( hClient, aClientIP, &nPort ); // Look through list of banned ip's. for( BanList::iterator iter = m_BanList.begin( ); iter != m_BanList.end( ); iter++ ) { ClientIP const& bannedIP = *iter; bool bBanned = false; int i; for( i = 0; i < 4; i++ ) { // Check if no IP's allowed with this part. if( bannedIP.m_nPart[i] == ( uint8 )-1 ) { bBanned = true; break; } // Check if this part doesn't match. if( bannedIP.m_nPart[i] != aClientIP[i] ) break; } // Check if they matched the ban. if( bBanned || i == 4 ) return true; } // Client not banned. return false; }
bool BanIPMgr_Impl::WriteBans( ) { // If not initialized, we can't write out the bans yet. if( !m_bInitialized ) return false; // build the file name by prepending the user directory char szFilename[MAX_PATH]; LTFileOperations::GetUserDirectory(szFilename, LTARRAYSIZE(szFilename)); LTStrCat(szFilename, szBanFile, LTARRAYSIZE(szFilename)); // remove the existing file LTFileOperations::DeleteFile(szFilename); // open the new file CLTFileWrite cBanFile; if (!cBanFile.Open(szFilename, false)) { return false; } // Look through list of banned ip's. for( BanList::iterator iter = m_BanList.begin( ); iter != m_BanList.end( ); iter++ ) { ClientIP const& bannedIP = *iter; // Convert it to a string. char szClientIP[16] = ""; if( !ConvertClientIPToString( bannedIP, szClientIP, ARRAY_LEN( szClientIP ))) return false; // Write the banned IP. if (!cBanFile.Write(szClientIP, LTStrLen(szClientIP))) { return false; } } return true; }
void ModeChannelBan::RemoveMode(Channel* channel, irc::modestacker* stack) { BanList copy; for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++) { copy.push_back(*i); } for (BanList::iterator i = copy.begin(); i != copy.end(); i++) { if (stack) { stack->Push(this->GetModeChar(), i->data); } else { std::vector<std::string> parameters; parameters.push_back(channel->name); parameters.push_back("-b"); parameters.push_back(i->data); ServerInstance->SendMode(parameters, ServerInstance->FakeClient); } } }