X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fipban.qc;h=1a7d1ff4506e92f6cd6ae58f47a7f280c89c5608;hb=ba0988ca930f50286f8cf3b6c114ebc6584964af;hp=08fd83fe3fab99c12c6a448e5f6198328281523c;hpb=2be39968eee26eaafc1099e9d72ccb2066b8414e;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/ipban.qc b/qcsrc/server/ipban.qc index 08fd83fe3..1a7d1ff45 100644 --- a/qcsrc/server/ipban.qc +++ b/qcsrc/server/ipban.qc @@ -1,3 +1,17 @@ +#if defined(CSQC) +#elif defined(MENUQC) +#elif defined(SVQC) + #include "../dpdefs/progsdefs.qc" + #include "../dpdefs/dpextensions.qc" + #include "sys-post.qh" + #include "../common/constants.qh" + #include "../common/util.qh" + #include "autocvars.qh" + #include "defs.qh" + #include "command/banning.qh" + #include "ipban.qh" +#endif + /* * Protocol of online ban list: * @@ -8,7 +22,7 @@ * GET g_ban_sync_uri?action=unban&hostname=...&ip=xxx.xxx.xxx * - Querying the ban list * GET g_ban_sync_uri?action=list&hostname=...&servers=xxx.xxx.xxx.xxx;xxx.xxx.xxx.xxx;... - * + * * shows the bans from the listed servers, and possibly others. * Format of a ban is ASCII plain text, four lines per ban, delimited by * newline ONLY (no carriage return): @@ -114,7 +128,7 @@ void OnlineBanList_URI_Get_Callback(float id, float status, string data) } if(syncinterval > 0) syncinterval *= 60; - + if(status != 0) { print("error: status is ", ftos(status), "\n"); @@ -138,7 +152,7 @@ void OnlineBanList_URI_Get_Callback(float id, float status, string data) else n = tokenizebyseparator(data, "\n"); - if(mod(n, 4) != 0) + if((n % 4) != 0) { print("error: received invalid item count: ", ftos(n), "\n"); return; @@ -193,7 +207,7 @@ void OnlineBanList_Think() float argc; string uri; float i, n; - + if(autocvar_g_ban_sync_uri == "") goto killme; if(autocvar_g_ban_sync_interval == 0) // < 0 is okay, it means "sync on level start only" @@ -208,7 +222,7 @@ void OnlineBanList_Think() 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(autocvar_hostname)); uri = strcat(uri, "&servers=", uri_escape(OnlineBanList_Servers)); @@ -227,7 +241,7 @@ void OnlineBanList_Think() else uri_get(strcat(argv(i), "?", uri), URI_GET_IPBAN + i); // 1000 = "banlist" callback target } - + if(autocvar_g_ban_sync_interval > 0) self.nextthink = time + max(60, autocvar_g_ban_sync_interval * 60); else @@ -238,7 +252,7 @@ void OnlineBanList_Think() remove(self); } -#define BAN_MAX 256 +const float BAN_MAX = 256; float ban_loaded; string ban_ip[BAN_MAX]; float ban_expire[BAN_MAX]; @@ -276,11 +290,11 @@ void Ban_SaveBans() float Ban_Delete(float i) { if(i < 0) - return FALSE; + return false; if(i >= ban_count) - return FALSE; + return false; if(ban_expire[i] == 0) - return FALSE; + return false; if(ban_expire[i] > 0) { OnlineBanList_SendUnban(ban_ip[i]); @@ -289,7 +303,7 @@ float Ban_Delete(float i) ban_expire[i] = 0; ban_ip[i] = ""; Ban_SaveBans(); - return TRUE; + return true; } void Ban_LoadBans() @@ -298,7 +312,7 @@ void Ban_LoadBans() for(i = 0; i < ban_count; ++i) Ban_Delete(i); ban_count = 0; - ban_loaded = TRUE; + ban_loaded = true; n = tokenize_console(autocvar_g_banned_list); if(stof(argv(0)) == 1) { @@ -321,24 +335,24 @@ void Ban_View() { float i, n; string msg; - + print("^2Listing all existing active bans:\n"); - + n = 0; for(i = 0; i < ban_count; ++i) { if(time > ban_expire[i]) continue; - + ++n; // total number of existing bans - + msg = strcat("#", ftos(i), ": "); msg = strcat(msg, ban_ip[i], " is still banned for "); msg = strcat(msg, ftos(ban_expire[i] - time), " seconds"); - + print(" ", msg, "\n"); } - + print("^2Done listing all active (", ftos(n), ") bans.\n"); } @@ -360,33 +374,33 @@ float Ban_GetClientIP(entity client) goto ipv6; i2 = strstrofs(s, ".", i1 + 1); if(i2 < 0) - return FALSE; + return false; i3 = strstrofs(s, ".", i2 + 1); if(i3 < 0) - return FALSE; + return false; i4 = strstrofs(s, ".", i3 + 1); if(i4 >= 0) s = substring(s, 0, i4); - + ban_ip1 = substring(s, 0, i1); // 8 ban_ip2 = substring(s, 0, i2); // 16 ban_ip3 = substring(s, 0, i3); // 24 ban_ip4 = strcat1(s); // 32 - return TRUE; + return true; :ipv6 i1 = strstrofs(s, ":", 0); if(i1 < 0) - return FALSE; + return false; i1 = strstrofs(s, ":", i1 + 1); if(i1 < 0) - return FALSE; + return false; i2 = strstrofs(s, ":", i1 + 1); if(i2 < 0) - return FALSE; + return false; i3 = strstrofs(s, ":", i2 + 1); if(i3 < 0) - return FALSE; + return false; ban_ip1 = strcat(substring(s, 0, i1), "::/32"); // 32 ban_ip2 = strcat(substring(s, 0, i2), "::/48"); // 48 @@ -397,7 +411,7 @@ float Ban_GetClientIP(entity client) else ban_ip3 = strcat(substring(s, 0, i2), ":0::/56"); - return TRUE; + return true; } float Ban_IsClientBanned(entity client, float idx) @@ -406,7 +420,7 @@ float Ban_IsClientBanned(entity client, float idx) if(!ban_loaded) Ban_LoadBans(); if(!Ban_GetClientIP(client)) - return FALSE; + return false; if(idx < 0) { b = 0; @@ -417,27 +431,27 @@ float Ban_IsClientBanned(entity client, float idx) b = idx; e = idx + 1; } - ipbanned = FALSE; + ipbanned = false; for(i = b; i < e; ++i) { string s; if(time > ban_expire[i]) continue; s = ban_ip[i]; - if(ban_ip1 == s) ipbanned = TRUE; - if(ban_ip2 == s) ipbanned = TRUE; - if(ban_ip3 == s) ipbanned = TRUE; - if(ban_ip4 == s) ipbanned = TRUE; - if(ban_idfp == s) return TRUE; + if(ban_ip1 == s) ipbanned = true; + if(ban_ip2 == s) ipbanned = true; + if(ban_ip3 == s) ipbanned = true; + if(ban_ip4 == s) ipbanned = true; + if(ban_idfp == s) return true; } if(ipbanned) { if(!autocvar_g_banned_list_idmode) - return TRUE; - if not(ban_idfp) - return TRUE; + return true; + if (!ban_idfp) + return true; } - return FALSE; + return false; } float Ban_MaybeEnforceBan(entity client) @@ -448,17 +462,17 @@ float Ban_MaybeEnforceBan(entity client) s = strcat("^1NOTE:^7 banned client ", client.netaddress, " just tried to enter\n"); dropclient(client); bprint(s); - return TRUE; + return true; } - return FALSE; + return false; } .float ban_checked; float Ban_MaybeEnforceBanOnce(entity client) { if(client.ban_checked) - return FALSE; - client.ban_checked = TRUE; + return false; + client.ban_checked = true; return Ban_MaybeEnforceBan(self); } @@ -516,7 +530,7 @@ float Ban_Insert(string ip, float bantime, string reason, float dosync) if(substring(reason, 0, 1) != "~") // like IRC: unauthenticated banner OnlineBanList_SendBan(ip, bantime, reason); - return FALSE; + return false; } // do we have a free slot? @@ -543,7 +557,7 @@ float Ban_Insert(string ip, float bantime, string reason, float dosync) if(ban_expire[i] > time + bantime) { print(ip, " could not get banned due to no free ban slot\n"); - return FALSE; + return false; } // okay, insert our new victim as i Ban_Delete(i); @@ -562,7 +576,7 @@ float Ban_Insert(string ip, float bantime, string reason, float dosync) if(substring(reason, 0, 1) != "~") // like IRC: unauthenticated banner OnlineBanList_SendBan(ip, bantime, reason); - return TRUE; + return true; } void Ban_KickBanClient(entity client, float bantime, float masksize, string reason)