+#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
+
/*
* Protocol of online ban list:
*
* 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):
}
if(syncinterval > 0)
syncinterval *= 60;
-
+
if(status != 0)
{
print("error: status is ", ftos(status), "\n");
else
n = tokenizebyseparator(data, "\n");
- if(mod(n, 4) != 0)
+ if((n % 4) != 0)
{
print("error: received invalid item count: ", ftos(n), "\n");
return;
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"
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));
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
remove(self);
}
-#define BAN_MAX 256
+const float BAN_MAX = 256;
float ban_loaded;
string ban_ip[BAN_MAX];
float ban_expire[BAN_MAX];
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]);
ban_expire[i] = 0;
ban_ip[i] = "";
Ban_SaveBans();
- return TRUE;
+ return true;
}
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)
{
{
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");
}
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
else
ban_ip3 = strcat(substring(s, 0, i2), ":0::/56");
- return TRUE;
+ return true;
}
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;
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 || !ban_idfp)
- return TRUE;
- return FALSE;
+ {
+ if(!autocvar_g_banned_list_idmode)
+ return true;
+ if (!ban_idfp)
+ return true;
+ }
+ return false;
}
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 Ban_MaybeEnforceBan(self);
}
string Ban_Enforce(float i, string reason)
reason = strcat(reason, ", ");
reason = strcat(reason, e.netname);
}
- s = strcat(s, "^1NOTE:^7 banned client ", e.netname, "^7 has to go\n");
+ s = strcat(s, "^1NOTE:^7 banned client ", e.netaddress, "^7 has to go\n");
dropclient(e);
}
bprint(s);
if(substring(reason, 0, 1) != "~") // like IRC: unauthenticated banner
OnlineBanList_SendBan(ip, bantime, reason);
- return FALSE;
+ return false;
}
// do we have a free slot?
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);
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)