r5230 - in trunk/data: . qcsrc/server
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Tue Dec 16 02:28:01 EST 2008
Author: div0
Date: 2008-12-16 02:28:00 -0500 (Tue, 16 Dec 2008)
New Revision: 5230
Modified:
trunk/data/defaultNexuiz.cfg
trunk/data/qcsrc/server/ipban.qc
trunk/data/qcsrc/server/ipban.qh
trunk/data/qcsrc/server/miscfunctions.qc
Log:
ipban update
Modified: trunk/data/defaultNexuiz.cfg
===================================================================
--- trunk/data/defaultNexuiz.cfg 2008-12-15 17:46:47 UTC (rev 5229)
+++ trunk/data/defaultNexuiz.cfg 2008-12-16 07:28:00 UTC (rev 5230)
@@ -1232,6 +1232,7 @@
set g_ban_sync_uri "" // sync using this ban list provider (empty string to disable)
set g_ban_sync_interval 5 // sync every 5 minutes
set g_ban_sync_trusted_servers "" // request ban lists from these nexuiz servers (do not include your own server there, or unbanning may fail)
+set g_ban_sync_timeout 45 // time out in seconds for the ban sync requests
set g_ban_sync_trusted_servers_verify 0 // when set to 1, additional bans sent by the servers are ignored, and only bans for the requested IP are used
alias records "cmd records"
Modified: trunk/data/qcsrc/server/ipban.qc
===================================================================
--- trunk/data/qcsrc/server/ipban.qc 2008-12-15 17:46:47 UTC (rev 5229)
+++ trunk/data/qcsrc/server/ipban.qc 2008-12-16 07:28:00 UTC (rev 5230)
@@ -32,8 +32,10 @@
uri = strcat(uri, "&reason=", uri_escape(reason));
n = tokenize_sane(cvar_string("g_ban_sync_uri"));
+ if(n >= MAX_IPBAN_URIS)
+ n = MAX_IPBAN_URIS;
for(i = 0; i < n; ++i)
- uri_get(strcat(argv(i), uri), 0); // 0 = "discard" callback target
+ uri_get(strcat(argv(i), uri), URI_GET_DISCARD); // 0 = "discard" callback target
}
void OnlineBanList_SendUnban(string ip)
@@ -45,15 +47,17 @@
uri = strcat(uri, "&ip=", uri_escape(ip));
n = tokenize_sane(cvar_string("g_ban_sync_uri"));
+ if(n >= MAX_IPBAN_URIS)
+ n = MAX_IPBAN_URIS;
for(i = 0; i < n; ++i)
- uri_get(strcat(argv(i), uri), 0); // 0 = "discard" callback target
+ uri_get(strcat(argv(i), uri), URI_GET_DISCARD); // 0 = "discard" callback target
}
string OnlineBanList_Servers;
float OnlineBanList_Timeout;
-float OnlineBanList_Requests;
+float OnlineBanList_RequestWaiting[MAX_IPBAN_URIS];
-void OnlineBanList_URI_Get_Callback(float status, string data)
+void OnlineBanList_URI_Get_Callback(float id, float status, string data)
{
float n, i, j, l;
string ip;
@@ -61,46 +65,71 @@
string reason;
string serverip;
float syncinterval;
+ string uri;
- if(OnlineBanList_Requests <= 0)
+ id -= URI_GET_IPBAN;
+
+ if(id >= MAX_IPBAN_URIS)
+ {
+ print("Received ban list for invalid ID\n");
return;
+ }
- --OnlineBanList_Requests;
+ tokenize_sane(cvar_string("g_ban_sync_uri"));
+ uri = argv(id);
+ print("Received ban list from ", uri, ": ");
+
+ if(OnlineBanList_RequestWaiting[id] == 0)
+ {
+ print("rejected (unexpected)\n");
+ return;
+ }
+
+ OnlineBanList_RequestWaiting[id] = 0;
+
if(time > OnlineBanList_Timeout)
+ {
+ print("rejected (too late)\n");
return;
+ }
syncinterval = cvar("g_ban_sync_interval");
if(syncinterval == 0)
+ {
+ print("rejected (syncing disabled)\n");
return;
+ }
if(syncinterval > 0)
syncinterval *= 60;
-
+
if(status != 0)
{
- print("Error receiving the online ban list: Status is ", ftos(status), "\n");
+ print("error: status is ", ftos(status), "\n");
return;
}
if(substring(data, 0, 1) == "<")
{
- print("Error receiving the online ban list: Received HTML instead of a ban list: ");
+ print("error: received HTML instead of a ban list: ");
return;
}
if(strstrofs(data, "\r", 0) != -1)
{
- print("Error receiving the online ban list: Received carriage returns: ");
+ print("error: received carriage returns: ");
return;
}
n = tokenizebyseparator(data, "\n");
if(mod(n, 4) != 0)
{
- print("Error receiving the online ban list: Received invalid item count: ");
+ print("error: eceived invalid item count: ");
return;
}
+ print("OK\n");
+
for(i = 0; i < n; i += 4)
{
ip = argv(i);
@@ -108,7 +137,7 @@
reason = argv(i + 2);
serverip = argv(i + 3);
- timeleft -= 15;
+ timeleft -= 1.5 * cvar("g_ban_sync_timeout");
if(timeleft < 0)
continue;
@@ -125,11 +154,12 @@
goto skip;
if(syncinterval > 0)
- timeleft = min(syncinterval + 15, timeleft);
- // 15 seconds for safety
+ timeleft = min(syncinterval + (OnlineBanList_Timeout - time) + 5, timeleft);
// the ban will be prolonged on the next sync
- Ban_Insert(ip, timeleft, strcat("ban synced from ", serverip), 0);
- print("Ban list syncing: accepted ban of ", ip, " by ", serverip, ": ", reason, "\n");
+ // or expire 5 seconds after the next timeout
+ Ban_Insert(ip, timeleft, strcat("ban synced from ", serverip, " at ", uri), 0);
+ print("Ban list syncing: accepted ban of ", ip, " by ", serverip, " at ", uri, ": ");
+ print(reason, "\n");
continue;
:skip
@@ -150,26 +180,27 @@
if(argc == 0)
return;
- if(OnlineBanList_Requests == 0) // only if there is no ongoing request!
- {
- if(OnlineBanList_Servers)
- strunzone(OnlineBanList_Servers);
- OnlineBanList_Servers = argv(0);
- for(i = 1; i < argc; ++i)
- OnlineBanList_Servers = strcat(OnlineBanList_Servers, ";", argv(i));
- OnlineBanList_Servers = strzone(OnlineBanList_Servers);
-
- uri = strcat( "?action=list&hostname=", uri_escape(cvar_string("hostname")));
- uri = strcat(uri, "&servers=", uri_escape(OnlineBanList_Servers));
+ if(OnlineBanList_Servers)
+ strunzone(OnlineBanList_Servers);
+ OnlineBanList_Servers = argv(0);
+ for(i = 1; i < argc; ++i)
+ OnlineBanList_Servers = strcat(OnlineBanList_Servers, ";", argv(i));
+ OnlineBanList_Servers = strzone(OnlineBanList_Servers);
+
+ uri = strcat( "?action=list&hostname=", uri_escape(cvar_string("hostname")));
+ uri = strcat(uri, "&servers=", uri_escape(OnlineBanList_Servers));
- OnlineBanList_Timeout = time + 10;
+ OnlineBanList_Timeout = time + cvar("g_ban_sync_timeout");
- n = tokenize_sane(cvar_string("g_ban_sync_uri"));
- for(i = 0; i < n; ++i)
- {
- ++OnlineBanList_Requests;
- uri_get(strcat(argv(i), uri), 1); // 1 = "banlist" callback target
- }
+ n = tokenize_sane(cvar_string("g_ban_sync_uri"));
+ if(n >= MAX_IPBAN_URIS)
+ n = MAX_IPBAN_URIS;
+ for(i = 0; i < n; ++i)
+ {
+ if(OnlineBanList_RequestWaiting[i])
+ continue;
+ OnlineBanList_RequestWaiting[i] = 1;
+ uri_get(strcat(argv(i), uri), URI_GET_IPBAN + i); // 1000 = "banlist" callback target
}
if(cvar("g_ban_sync_interval") > 0)
Modified: trunk/data/qcsrc/server/ipban.qh
===================================================================
--- trunk/data/qcsrc/server/ipban.qh 2008-12-15 17:46:47 UTC (rev 5229)
+++ trunk/data/qcsrc/server/ipban.qh 2008-12-16 07:28:00 UTC (rev 5230)
@@ -3,4 +3,4 @@
float Ban_MaybeEnforceBan(entity client);
float GameCommand_Ban(string command);
-void OnlineBanList_URI_Get_Callback(float status, string data);
+void OnlineBanList_URI_Get_Callback(float id, float status, string data);
Modified: trunk/data/qcsrc/server/miscfunctions.qc
===================================================================
--- trunk/data/qcsrc/server/miscfunctions.qc 2008-12-15 17:46:47 UTC (rev 5229)
+++ trunk/data/qcsrc/server/miscfunctions.qc 2008-12-16 07:28:00 UTC (rev 5230)
@@ -1663,25 +1663,31 @@
const string STR_MISC_NULL_WAV = "misc/null.wav";
#define PROJECTILE_TOUCH_NOSOUND do { if(SUB_OwnerCheck()) return; if(SUB_NoImpactCheck()) { sound (self, CHAN_PROJECTILE, STR_MISC_NULL_WAV, VOL_BASE, ATTN_NORM); remove(self); return; } } while(0)
+float MAX_IPBAN_URIS = 16;
+
+float URI_GET_DISCARD = 0;
+float URI_GET_IPBAN = 1;
+float URI_GET_IPBAN_END = 16;
+
void URI_Get_Callback(float id, float status, string data)
{
dprint("Received HTTP request data for id ", ftos(id), "; status is ", ftos(status), "\nData is\n:");
dprint(data);
dprint("\nEnd of data.\n");
- switch(id)
+ if(id == URI_GET_DISCARD)
{
- case 0:
- // 0 is the ID for discarding
- break;
- case 1:
- // 1 is the ID for online ban list
- OnlineBanList_URI_Get_Callback(status, data);
- break;
- default:
- print("Received HTTP request data for an invalid id ", ftos(id), ".\n");
- break;
+ // discard
}
+ else if(id >= URI_GET_IPBAN && id <= URI_GET_IPBAN_END)
+ {
+ // online ban list
+ OnlineBanList_URI_Get_Callback(id, status, data);
+ }
+ else
+ {
+ print("Received HTTP request data for an invalid id ", ftos(id), ".\n");
+ }
}
void print_to(entity e, string s)
More information about the nexuiz-commits
mailing list