From 5eeab7fcfe4c0da2b2514b6cd34fdc4bcdf372b5 Mon Sep 17 00:00:00 2001 From: truelight Date: Sun, 2 Jan 2005 12:03:43 +0000 Subject: (svn r1322) -Add: banning system (mostly tnx to guru3) A server can ban people via ClientList Both server and dedicated can do it via console: 'ban', 'unban', 'banlist'. --- network.c | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) (limited to 'network.c') diff --git a/network.c b/network.c index 5f4b82815..c26969860 100644 --- a/network.c +++ b/network.c @@ -219,7 +219,8 @@ static void NetworkClientError(byte res, NetworkClientState *cs) { default: errorno = NETWORK_ERROR_GENERAL; } // This means we fucked up and the server closed the connection - if (res != NETWORK_RECV_STATUS_SERVER_ERROR && res != NETWORK_RECV_STATUS_SERVER_FULL) { + if (res != NETWORK_RECV_STATUS_SERVER_ERROR && res != NETWORK_RECV_STATUS_SERVER_FULL && + res != NETWORK_RECV_STATUS_SERVER_BANNED) { SEND_COMMAND(PACKET_CLIENT_ERROR)(errorno); // Dequeue all commands before closing the socket @@ -615,6 +616,8 @@ static void NetworkAcceptClients(void) #else LONG sin_len; // for some reason we need a 'LONG' under MorphOS #endif + int i; + bool banned; // Should never ever happen.. is it possible?? assert(_listensocket != INVALID_SOCKET); @@ -639,6 +642,33 @@ static void NetworkAcceptClients(void) {int b = 1; setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (const char*)&b, sizeof(b));} #endif + /* Check if the client is banned */ + banned = false; + for (i = 0; i < lengthof(_network_ban_list); i++) { + if (_network_ban_list[i] == NULL) + continue; + + if (sin.sin_addr.s_addr == inet_addr(_network_ban_list[i])) { + Packet *p = NetworkSend_Init(PACKET_SERVER_BANNED); + + DEBUG(net, 1)("[NET] Banned ip tried to join (%s), refused", _network_ban_list[i]); + + p->buffer[0] = p->size & 0xFF; + p->buffer[1] = p->size >> 8; + + send(s, p->buffer, p->size, 0); + closesocket(s); + + free(p); + + banned = true; + break; + } + } + /* If this client is banned, continue with next client */ + if (banned) + continue; + cs = NetworkAllocClient(s); if (cs == NULL) { // no more clients allowed? @@ -844,15 +874,15 @@ void NetworkAddServer(const byte *b) * by the function that generates the config file. */ void NetworkRebuildHostList() { - int i=0; + int i = 0; NetworkGameList *item = _network_game_list; - while (item != NULL && i!=lengthof(_network_host_list)) { + while (item != NULL && i != lengthof(_network_host_list)) { if (item->manually) _network_host_list[i++] = strdup(item->info.hostname); item = item->next; } - for (; i