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
 
@@ -481,51 +481,52 @@ DEF_CONSOLE_CMD(ConClearBuffer)
 
	SetWindowDirty(WC_CONSOLE, 0);
 
	return true;
 
}
 

	
 

	
 
/**********************************
 
 * 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");
 
			return true;
 
		}
 

	
 
		NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
 
		if (ci == NULL) {
 
			IConsoleError("Invalid client");
 
			return true;
 
		}
 

	
 
		if (!ban) {
 
			/* 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);
 
	}
 

	
 
	return true;
 
}
 

	
 
DEF_CONSOLE_CMD(ConKick)
 
{
 
	if (argc == 0) {
src/network/network_func.h
Show inline comments
 
@@ -66,23 +66,24 @@ void NetworkServerSendConfigUpdate();
 
void NetworkServerShowStatusToConsole();
 
bool NetworkServerStart();
 
void NetworkServerUpdateCompanyPassworded(CompanyID company_id, bool passworded);
 
bool NetworkServerChangeClientName(ClientID client_id, const char *new_name);
 

	
 
const char *GetClientIP(NetworkClientInfo *ci);
 

	
 
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();
 

	
 
void NetworkAfterNewGRFScan();
 

	
 
#endif /* ENABLE_NETWORK */
 
#endif /* NETWORK_FUNC_H */
src/network/network_gui.cpp
Show inline comments
 
@@ -1708,25 +1708,25 @@ static const WindowDesc _client_list_pop
 
	0,
 
	_nested_client_list_popup_widgets, lengthof(_nested_client_list_popup_widgets)
 
);
 

	
 
/* Here we start to define the options out of the menu */
 
static void ClientList_Kick(const NetworkClientInfo *ci)
 
{
 
	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);
 
}
 

	
 
static void ClientList_SpeakToClient(const NetworkClientInfo *ci)
 
{
 
	ShowNetworkChatQueryWindow(DESTTYPE_CLIENT,ci->client_id);
 
}
 

	
src/network/network_server.cpp
Show inline comments
 
@@ -1910,24 +1910,29 @@ void NetworkServerSendRcon(ClientID clie
 

	
 
static void NetworkServerSendError(ClientID client_id, NetworkErrorCode error)
 
{
 
	NetworkClientSocket::GetByClientID(client_id)->SendError(error);
 
}
 

	
 
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;
 

	
 
	/* There can be multiple clients with the same IP, kick them all */
 
	NetworkClientInfo *ci;
 
	FOR_ALL_CLIENT_INFOS(ci) {
 
		if (ci->client_id == CLIENT_ID_SERVER) continue;
 
		if (ci->client_address.IsInNetmask(const_cast<char *>(ip))) {
0 comments (0 inline, 0 general)