#include "ipban.qh"
-#include "_all.qh"
+#include <server/defs.qh>
+#include <server/miscfunctions.qh>
#include "autocvars.qh"
#include "command/banning.qh"
#include "defs.qh"
#include "../common/constants.qh"
#include "../common/util.qh"
-#include "../dpdefs/dpextensions.qh"
-#include "../dpdefs/progsdefs.qh"
/*
* Protocol of online ban list:
if(id >= MAX_IPBAN_URIS)
{
- LOG_INFO("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);
- LOG_INFO("Received ban list from ", uri, ": ");
+ string prelude = strcat("Received ban list from ", uri, ": ");
if(OnlineBanList_RequestWaiting[id] == 0)
{
- LOG_INFO("rejected (unexpected)\n");
+ LOG_INFO(prelude, "rejected (unexpected)");
return;
}
if(time > OnlineBanList_Timeout)
{
- LOG_INFO("rejected (too late)\n");
+ LOG_INFO(prelude, "rejected (too late)");
return;
}
syncinterval = autocvar_g_ban_sync_interval;
if(syncinterval == 0)
{
- LOG_INFO("rejected (syncing disabled)\n");
+ LOG_INFO(prelude, "rejected (syncing disabled)");
return;
}
if(syncinterval > 0)
if(status != 0)
{
- LOG_INFO("error: status is ", ftos(status), "\n");
+ LOG_INFO(prelude, "error: status is ", ftos(status));
return;
}
if(substring(data, 0, 1) == "<")
{
- LOG_INFO("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)
{
- LOG_INFO("error: received carriage returns\n");
+ LOG_INFO(prelude, "error: received carriage returns");
return;
}
if((n % 4) != 0)
{
- LOG_INFO("error: received invalid item count: ", ftos(n), "\n");
+ LOG_INFO(prelude, "error: received invalid item count: ", ftos(n));
return;
}
- LOG_INFO("OK, ", ftos(n / 4), " items\n");
+ LOG_INFO(prelude, "OK, ", ftos(n / 4), " items");
for(i = 0; i < n; i += 4)
{
LOG_TRACE("received ban list item ", ftos(i / 4), ": ip=", ip);
LOG_TRACE(" timeleft=", ftos(timeleft), " reason=", reason);
- LOG_TRACE(" serverip=", serverip, "\n");
+ LOG_TRACE(" serverip=", serverip);
timeleft -= 1.5 * autocvar_g_ban_sync_timeout;
if(timeleft < 0)
for(j = 0; j < l; ++j)
if(strstrofs("0123456789.", substring(ip, j, 1), 0) == -1)
{
- LOG_INFO("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;
}
}
// 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);
- LOG_INFO("Ban list syncing: accepted ban of ", ip, " by ", serverip, " at ", uri, ": ");
- LOG_INFO(reason, "\n");
+ LOG_INFO("Ban list syncing: accepted ban of ", ip, " by ", serverip, " at ", uri, ": ", reason);
-:skip
+LABEL(skip)
}
}
-void OnlineBanList_Think()
-{SELFPARAM();
+void OnlineBanList_Think(entity this)
+{
float argc;
string uri;
float i, n;
if(argc == 0)
goto killme;
- 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);
+ string s = argv(0); for(i = 1; i < argc; ++i) s = strcat(s, ";", argv(i));
+ strcpy(OnlineBanList_Servers, s);
uri = strcat( "action=list&hostname=", uri_escape(autocvar_hostname));
uri = strcat(uri, "&servers=", uri_escape(OnlineBanList_Servers));
}
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;
}
}
- entity e;
- e = spawn();
- e.classname = "bansyncer";
- e.think = OnlineBanList_Think;
+ entity e = new(bansyncer);
+ setthink(e, OnlineBanList_Think);
e.nextthink = time + 1;
}
float i, n;
string msg;
- LOG_INFO("^2Listing all existing active bans:\n");
+ LOG_INFO("^2Listing all existing active bans:");
n = 0;
for(i = 0; i < ban_count; ++i)
msg = strcat(msg, ban_ip[i], " is still banned for ");
msg = strcat(msg, ftos(ban_expire[i] - time), " seconds");
- LOG_INFO(" ", msg, "\n");
+ LOG_INFO(" ", msg);
}
- LOG_INFO("^2Done listing all active (", ftos(n), ") bans.\n");
+ LOG_INFO("^2Done listing all active (", ftos(n), ") bans.");
}
float Ban_GetClientIP(entity client)
ban_ip4 = strcat1(s); // 32
return true;
-:ipv6
+LABEL(ipv6)
i1 = strstrofs(s, ":", 0);
if(i1 < 0)
return false;
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;
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 != "")
{
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;
if(time + bantime > ban_expire[i])
{
ban_expire[i] = time + bantime;
- LOG_TRACE(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
- LOG_TRACE(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);
if(i < ban_count)
if(ban_expire[i] > time + bantime)
{
- LOG_INFO(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);
- LOG_TRACE(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);