Changeset - r17591:c2a7b2b05a8a
[Not reviewed]
master
0 4 0
rubidium - 13 years ago 2011-04-22 15:59:32
rubidium@openttd.org
(svn r22365) -Codechange: add overload of NetworkServerKickOrBanIP using the ClientID, which later resolves the IP address to ban. This to consolidate the knowledge about resolving IP addresses
4 files changed with 11 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/console_cmds.cpp
Show inline comments
 
@@ -487,13 +487,13 @@ DEF_CONSOLE_CMD(ConClearBuffer)
 
 * Network Core Console Commands
 
 **********************************/
 
#ifdef ENABLE_NETWORK
 

	
 
static bool ConKickOrBan(const char *argv, bool ban)
 
{
 
	const char *ip = argv;
 
	uint n;
 

	
 
	if (strchr(argv, '.') == NULL && strchr(argv, ':') == NULL) { // banning with ID
 
		ClientID client_id = (ClientID)atoi(argv);
 

	
 
		if (client_id == CLIENT_ID_SERVER) {
 
			IConsolePrintF(CC_ERROR, "ERROR: Silly boy, you can not %s yourself!", ban ? "ban" : "kick");
 
@@ -510,16 +510,17 @@ static bool ConKickOrBan(const char *arg
 
			/* Kick only this client, not all clients with that IP */
 
			NetworkServerKickClient(client_id);
 
			return true;
 
		}
 

	
 
		/* When banning, kick+ban all clients with that IP */
 
		ip = GetClientIP(ci);
 
		n = NetworkServerKickOrBanIP(client_id, ban);
 
	} else {
 
		n = NetworkServerKickOrBanIP(argv, ban);
 
	}
 

	
 
	uint n = NetworkServerKickOrBanIP(ip, ban);
 
	if (n == 0) {
 
		IConsolePrint(CC_DEFAULT, ban ? "Client not online, address added to banlist" : "Client not found");
 
	} else {
 
		IConsolePrintF(CC_DEFAULT, "%sed %u client(s)", ban ? "Bann" : "Kick", n);
 
	}
 

	
src/network/network_func.h
Show inline comments
 
@@ -72,12 +72,13 @@ const char *GetClientIP(NetworkClientInf
 

	
 
void NetworkServerDoMove(ClientID client_id, CompanyID company_id);
 
void NetworkServerSendRcon(ClientID client_id, TextColour colour_code, const char *string);
 
void NetworkServerSendChat(NetworkAction action, DestType type, int dest, const char *msg, ClientID from_id, int64 data = 0, bool from_admin = false);
 

	
 
void NetworkServerKickClient(ClientID client_id);
 
uint NetworkServerKickOrBanIP(ClientID client_id, bool ban);
 
uint NetworkServerKickOrBanIP(const char *ip, bool ban);
 

	
 
void NetworkInitChatMessage();
 
void CDECL NetworkAddChatMessage(TextColour colour, uint duration, const char *message, ...) WARN_FORMAT(3, 4);
 
void NetworkUndrawChatMessage();
 
void NetworkChatMessageLoop();
src/network/network_gui.cpp
Show inline comments
 
@@ -1714,13 +1714,13 @@ static void ClientList_Kick(const Networ
 
{
 
	NetworkServerKickClient(ci->client_id);
 
}
 

	
 
static void ClientList_Ban(const NetworkClientInfo *ci)
 
{
 
	NetworkServerKickOrBanIP(GetClientIP(const_cast<NetworkClientInfo *>(ci)), true);
 
	NetworkServerKickOrBanIP(ci->client_id, true);
 
}
 

	
 
static void ClientList_GiveMoney(const NetworkClientInfo *ci)
 
{
 
	ShowNetworkGiveMoneyWindow(ci->client_playas);
 
}
src/network/network_server.cpp
Show inline comments
 
@@ -1916,12 +1916,17 @@ static void NetworkServerSendError(Clien
 
void NetworkServerKickClient(ClientID client_id)
 
{
 
	if (client_id == CLIENT_ID_SERVER) return;
 
	NetworkServerSendError(client_id, NETWORK_ERROR_KICKED);
 
}
 

	
 
uint NetworkServerKickOrBanIP(ClientID client_id, bool ban)
 
{
 
	return NetworkServerKickOrBanIP(GetClientIP(NetworkClientInfo::GetByClientID(client_id)), ban);
 
}
 

	
 
uint NetworkServerKickOrBanIP(const char *ip, bool ban)
 
{
 
	/* Add address to ban-list */
 
	if (ban) *_network_ban_list.Append() = strdup(ip);
 

	
 
	uint n = 0;
0 comments (0 inline, 0 general)