X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fipban.qc;h=98dbf5c55b748d5a4d106f8dadec8fc3e29b412f;hb=723fe3aa08556fdde679753c0afde734853f34e5;hp=bd9880839d69f33ab220fd54a40eed7f87281460;hpb=6dc9591eba337374f2b4348a6a6deaa1cb6887d0;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/ipban.qc b/qcsrc/server/ipban.qc index bd9880839..98dbf5c55 100644 --- a/qcsrc/server/ipban.qc +++ b/qcsrc/server/ipban.qc @@ -1,15 +1,12 @@ -#if defined(CSQC) -#elif defined(MENUQC) -#elif defined(SVQC) - #include "../dpdefs/progsdefs.qh" - #include "../dpdefs/dpextensions.qh" - #include "../common/constants.qh" - #include "../common/util.qh" - #include "autocvars.qh" - #include "defs.qh" - #include "command/banning.qh" - #include "ipban.qh" -#endif +#include "ipban.qh" + +#include +#include +#include "autocvars.qh" +#include "command/banning.qh" +#include "defs.qh" +#include "../common/constants.qh" +#include "../common/util.qh" /* * Protocol of online ban list: @@ -96,18 +93,18 @@ void OnlineBanList_URI_Get_Callback(float id, float status, string data) if(id >= MAX_IPBAN_URIS) { - print("Received ban list for invalid ID\n"); + LOG_INFO("Received ban list for invalid ID"); return; } tokenize_console(autocvar_g_ban_sync_uri); uri = argv(id); - print("Received ban list from ", uri, ": "); + string prelude = strcat("Received ban list from ", uri, ": "); if(OnlineBanList_RequestWaiting[id] == 0) { - print("rejected (unexpected)\n"); + LOG_INFO(prelude, "rejected (unexpected)"); return; } @@ -115,14 +112,14 @@ void OnlineBanList_URI_Get_Callback(float id, float status, string data) if(time > OnlineBanList_Timeout) { - print("rejected (too late)\n"); + LOG_INFO(prelude, "rejected (too late)"); return; } syncinterval = autocvar_g_ban_sync_interval; if(syncinterval == 0) { - print("rejected (syncing disabled)\n"); + LOG_INFO(prelude, "rejected (syncing disabled)"); return; } if(syncinterval > 0) @@ -130,19 +127,19 @@ void OnlineBanList_URI_Get_Callback(float id, float status, string data) if(status != 0) { - print("error: status is ", ftos(status), "\n"); + LOG_INFO(prelude, "error: status is ", ftos(status)); return; } if(substring(data, 0, 1) == "<") { - print("error: received HTML instead of a ban list\n"); + LOG_INFO(prelude, "error: received HTML instead of a ban list"); return; } if(strstrofs(data, "\r", 0) != -1) { - print("error: received carriage returns\n"); + LOG_INFO(prelude, "error: received carriage returns"); return; } @@ -153,11 +150,11 @@ void OnlineBanList_URI_Get_Callback(float id, float status, string data) if((n % 4) != 0) { - print("error: received invalid item count: ", ftos(n), "\n"); + LOG_INFO(prelude, "error: received invalid item count: ", ftos(n)); return; } - print("OK, ", ftos(n / 4), " items\n"); + LOG_INFO(prelude, "OK, ", ftos(n / 4), " items"); for(i = 0; i < n; i += 4) { @@ -166,9 +163,9 @@ void OnlineBanList_URI_Get_Callback(float id, float status, string data) reason = argv(i + 2); serverip = argv(i + 3); - dprint("received ban list item ", ftos(i / 4), ": ip=", ip); - dprint(" timeleft=", ftos(timeleft), " reason=", reason); - dprint(" serverip=", serverip, "\n"); + LOG_TRACE("received ban list item ", ftos(i / 4), ": ip=", ip); + LOG_TRACE(" timeleft=", ftos(timeleft), " reason=", reason); + LOG_TRACE(" serverip=", serverip); timeleft -= 1.5 * autocvar_g_ban_sync_timeout; if(timeleft < 0) @@ -180,7 +177,7 @@ void OnlineBanList_URI_Get_Callback(float id, float status, string data) for(j = 0; j < l; ++j) if(strstrofs("0123456789.", substring(ip, j, 1), 0) == -1) { - print("Invalid character ", substring(ip, j, 1), " in IP address ", ip, ". Skipping this ban.\n"); + LOG_INFO("Invalid character ", substring(ip, j, 1), " in IP address ", ip, ". Skipping this ban."); goto skip; } } @@ -194,14 +191,13 @@ void OnlineBanList_URI_Get_Callback(float id, float status, string data) // the ban will be prolonged on the next sync // 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"); + LOG_INFO("Ban list syncing: accepted ban of ", ip, " by ", serverip, " at ", uri, ": ", reason); -:skip +LABEL(skip) } } -void OnlineBanList_Think() +void OnlineBanList_Think(entity this) { float argc; string uri; @@ -242,13 +238,13 @@ void OnlineBanList_Think() } if(autocvar_g_ban_sync_interval > 0) - self.nextthink = time + max(60, autocvar_g_ban_sync_interval * 60); + this.nextthink = time + max(60, autocvar_g_ban_sync_interval * 60); else goto killme; return; -:killme - remove(self); +LABEL(killme) + delete(this); } const float BAN_MAX = 256; @@ -323,10 +319,8 @@ void Ban_LoadBans() } } - entity e; - e = spawn(); - e.classname = "bansyncer"; - e.think = OnlineBanList_Think; + entity e = new(bansyncer); + setthink(e, OnlineBanList_Think); e.nextthink = time + 1; } @@ -335,7 +329,7 @@ void Ban_View() float i, n; string msg; - print("^2Listing all existing active bans:\n"); + LOG_INFO("^2Listing all existing active bans:"); n = 0; for(i = 0; i < ban_count; ++i) @@ -349,10 +343,10 @@ void Ban_View() msg = strcat(msg, ban_ip[i], " is still banned for "); msg = strcat(msg, ftos(ban_expire[i] - time), " seconds"); - print(" ", msg, "\n"); + LOG_INFO(" ", msg); } - print("^2Done listing all active (", ftos(n), ") bans.\n"); + LOG_INFO("^2Done listing all active (", ftos(n), ") bans."); } float Ban_GetClientIP(entity client) @@ -361,7 +355,7 @@ float Ban_GetClientIP(entity client) float i1, i2, i3, i4; string s; - if(client.crypto_keyfp) + if(client.crypto_idfp_signed) ban_idfp = client.crypto_idfp; else ban_idfp = string_null; @@ -387,7 +381,7 @@ float Ban_GetClientIP(entity client) ban_ip4 = strcat1(s); // 32 return true; -:ipv6 +LABEL(ipv6) i1 = strstrofs(s, ":", 0); if(i1 < 0) return false; @@ -453,12 +447,11 @@ float Ban_IsClientBanned(entity client, float idx) return false; } -float Ban_MaybeEnforceBan(entity client) +bool Ban_MaybeEnforceBan(entity client) { - if(Ban_IsClientBanned(client, -1)) + if (Ban_IsClientBanned(client, -1)) { - string s; - s = strcat("^1NOTE:^7 banned client ", client.netaddress, " just tried to enter\n"); + string s = sprintf("^1NOTE:^7 banned client %s just tried to enter\n", client.netaddress); dropclient(client); bprint(s); return true; @@ -466,25 +459,23 @@ float Ban_MaybeEnforceBan(entity client) return false; } -.float ban_checked; -float Ban_MaybeEnforceBanOnce(entity client) +.bool ban_checked; +bool Ban_MaybeEnforceBanOnce(entity client) { - if(client.ban_checked) - return false; + if (client.ban_checked) return false; client.ban_checked = true; return Ban_MaybeEnforceBan(client); } -string Ban_Enforce(float i, string reason) +string Ban_Enforce(float j, string reason) { string s; - entity e; // Enforce our new ban s = ""; - FOR_EACH_CLIENTSLOT(e) - if (IS_REAL_CLIENT(e)) - if(Ban_IsClientBanned(e, i)) + FOREACH_CLIENTSLOT(IS_REAL_CLIENT(it), + { + if(Ban_IsClientBanned(it, j)) { if(reason != "") { @@ -492,11 +483,12 @@ string Ban_Enforce(float i, string reason) reason = strcat(reason, ": affects "); else reason = strcat(reason, ", "); - reason = strcat(reason, e.netname); + reason = strcat(reason, it.netname); } - s = strcat(s, "^1NOTE:^7 banned client ", e.netaddress, "^7 has to go\n"); - dropclient(e); + s = strcat(s, "^1NOTE:^7 banned client ", it.netaddress, "^7 has to go\n"); + dropclient(it); } + }); bprint(s); return reason; @@ -516,10 +508,10 @@ float Ban_Insert(string ip, float bantime, string reason, float dosync) if(time + bantime > ban_expire[i]) { ban_expire[i] = time + bantime; - dprint(ip, "'s ban has been prolonged to ", ftos(bantime), " seconds from now\n"); + LOG_TRACE(ip, "'s ban has been prolonged to ", ftos(bantime), " seconds from now"); } else - dprint(ip, "'s ban is still active until ", ftos(ban_expire[i] - time), " seconds from now\n"); + LOG_TRACE(ip, "'s ban is still active until ", ftos(ban_expire[i] - time), " seconds from now"); // and enforce reason = Ban_Enforce(i, reason); @@ -556,12 +548,12 @@ float Ban_Insert(string ip, float bantime, string reason, float dosync) if(i < ban_count) if(ban_expire[i] > time + bantime) { - print(ip, " could not get banned due to no free ban slot\n"); + LOG_INFO(ip, " could not get banned due to no free ban slot"); return false; } // okay, insert our new victim as i Ban_Delete(i); - dprint(ip, " has been banned for ", ftos(bantime), " seconds\n"); + LOG_TRACE(ip, " has been banned for ", ftos(bantime), " seconds"); ban_expire[i] = time + bantime; ban_ip[i] = strzone(ip); ban_count = max(ban_count, i + 1);