コード例 #1
0
ファイル: com_wiz.cpp プロジェクト: sorressean/Aspen
BOOL CMDBan::Execute(const std::string &verb, Player* mobile,std::vector<std::string> &args,int subcmd)
{
    World*world = World::GetPtr();
    BanList* blist = world->GetServer()->GetBanList();

    if (args.size() != 1)
    {
        std::vector<std::string> header;
        std::vector<std::string> addresses;
        int i = 0;

        for (i = 0; i < 5; i++)
        {
            header.push_back("address");
        }

        blist->ListAddresses(&addresses);
        mobile->Message(MSG_LIST, Columnize(&addresses, 5, &header));
        return true;
    }

    if (blist->AddressExists(args[0]))
    {
        mobile->Message(MSG_ERROR, "That address is already in the ban list.");
        return false;
    }
    if (!blist->AddAddress(args[0]))
    {
        mobile->Message(MSG_ERROR, "Malformed address.");
        return false;
    }

    mobile->Message(MSG_INFO, "Added.");
    return true;
}
コード例 #2
0
ファイル: BanIPMgr.cpp プロジェクト: Arc0re/lithtech
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;
}
コード例 #3
0
ファイル: BanIPMgr.cpp プロジェクト: Arc0re/lithtech
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;
}
コード例 #4
0
ファイル: BanIPMgr.cpp プロジェクト: Arc0re/lithtech
bool BanIPMgr_Impl::AddBan( ClientIP const& bannedIP )
{
	// Don't allow banning of everyone.
	if( bannedIP.m_nPart[0] == 255 )
	{
		return false;
	}

	// Don't allow banning of local host, which has a special IP.
	if( bannedIP.m_nPart[0] == 0 && bannedIP.m_nPart[1] == 0 && 
		bannedIP.m_nPart[2] == 0 && bannedIP.m_nPart[3] == 0 )
	{
		return false;
	}

	// Add it to the list.
	m_BanList.insert( bannedIP );

	// Iterate over all the clients and see if any match the new banned IP.
    HCLIENT hIterClient = g_pLTServer->GetNextClient( NULL );
    while( hIterClient )
	{
		HCLIENT hNextIterClient = g_pLTServer->GetNextClient( hIterClient );

		if( IsClientBanned( hIterClient ))
		{
			g_pLTServer->KickClient( hIterClient );
		}

	    hIterClient = hNextIterClient;
	}
	
	return true;
}
コード例 #5
0
ファイル: BanIPMgr.cpp プロジェクト: Arc0re/lithtech
void BanIPMgr_Impl::Term( )
{
	// Write the current set of bans.
	WriteBans( );

	m_bInitialized = false;

	m_BanList.clear( );
}
コード例 #6
0
ファイル: BanIPMgr.cpp プロジェクト: Arc0re/lithtech
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;
}
コード例 #7
0
ファイル: cmode_b.cpp プロジェクト: Shawn-Smith/InspIRCd
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);
		}
	}
}
コード例 #8
0
ファイル: BanIPMgr.cpp プロジェクト: Arc0re/lithtech
bool BanIPMgr_Impl::RemoveBan( ClientIP const& bannedIP )
{
	m_BanList.erase( bannedIP );

	return true;
}