From: havoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Date: Thu, 9 Nov 2006 10:16:16 +0000 (+0000)
Subject: patch from div0 that removes connect flood ban when a player disconnects (this preven... 
X-Git-Tag: xonotic-v0.1.0preview~3778
X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=33d5e5ada3c068d54ba5ca9bdcd2eb4e0125912a;p=xonotic%2Fdarkplaces.git

patch from div0 that removes connect flood ban when a player disconnects (this prevents people from getting connect-flood-banned for simply reconnecting after a pk3 autodownload in Nexuiz)


git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@6617 d7cf8633-e32d-0410-b094-e92efae38249
---

diff --git a/netconn.c b/netconn.c
index d848411d..d876b929 100755
--- a/netconn.c
+++ b/netconn.c
@@ -787,10 +787,15 @@ netconn_t *NetConn_Open(lhnetsocket_t *mysocket, lhnetaddress_t *peeraddress)
 	return conn;
 }
 
+void NetConn_ClearConnectFlood(lhnetaddress_t *peeraddress);
 void NetConn_Close(netconn_t *conn)
 {
 	netconn_t *c;
 	// remove connection from list
+
+	// allow the client to reconnect immediately
+	NetConn_ClearConnectFlood(&(conn->peeraddress));
+
 	if (conn == netconn_list)
 		netconn_list = conn->next;
 	else
@@ -1753,6 +1758,7 @@ static qboolean NetConn_PreventConnectFlood(lhnetaddress_t *peeraddress)
 				// renew the ban on this address so it does not expire
 				// until the flood has subsided
 				sv.connectfloodaddresses[floodslotnum].lasttime = realtime;
+				//Con_Printf("Flood detected!\n");
 				return true;
 			}
 			// the flood appears to have subsided, so allow this
@@ -1763,9 +1769,30 @@ static qboolean NetConn_PreventConnectFlood(lhnetaddress_t *peeraddress)
 	// begin a new timeout on this address
 	sv.connectfloodaddresses[bestfloodslotnum].address = noportpeeraddress;
 	sv.connectfloodaddresses[bestfloodslotnum].lasttime = realtime;
+	//Con_Printf("Flood detection initiated!\n");
 	return false;
 }
 
+void NetConn_ClearConnectFlood(lhnetaddress_t *peeraddress)
+{
+	int floodslotnum;
+	lhnetaddress_t noportpeeraddress;
+	// see if this is a connect flood
+	noportpeeraddress = *peeraddress;
+	LHNETADDRESS_SetPort(&noportpeeraddress, 0);
+	for (floodslotnum = 0;floodslotnum < MAX_CONNECTFLOODADDRESSES;floodslotnum++)
+	{
+		if (sv.connectfloodaddresses[floodslotnum].lasttime && LHNETADDRESS_Compare(&noportpeeraddress, &sv.connectfloodaddresses[floodslotnum].address) == 0)
+		{
+			// this address matches an ongoing flood address
+			// remove the ban
+			sv.connectfloodaddresses[floodslotnum].address.addresstype = LHNETADDRESSTYPE_NONE;
+			sv.connectfloodaddresses[floodslotnum].lasttime = 0;
+			//Con_Printf("Flood cleared!\n");
+		}
+	}
+}
+
 extern void SV_SendServerinfo (client_t *client);
 static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *data, int length, lhnetaddress_t *peeraddress)
 {