]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/ipban.qc
Merge branch 'master' of ssh://gitlab.com/xonotic/xonotic-data.pk3dir into kickban...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / ipban.qc
index 9965113f67474bee4e6cc878cc9f11c04b34fef5..d8a70fe658a238fe1d4e414cfd3164d472ee7a9e 100644 (file)
@@ -8,7 +8,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 +114,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 +138,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 +193,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 +208,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 +227,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
@@ -321,23 +321,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");
 }
 
@@ -366,7 +367,7 @@ float Ban_GetClientIP(entity client)
        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
@@ -430,8 +431,12 @@ float Ban_IsClientBanned(entity client, float idx)
                if(ban_idfp == s) return TRUE;
        }
        if(ipbanned)
-               if(!autocvar_g_banned_list_idmode || !ban_idfp)
+       {
+               if(!autocvar_g_banned_list_idmode)
                        return TRUE;
+               if (!ban_idfp)
+                       return TRUE;
+       }
        return FALSE;
 }
 
@@ -448,6 +453,15 @@ float Ban_MaybeEnforceBan(entity client)
        return FALSE;
 }
 
+.float ban_checked;
+float Ban_MaybeEnforceBanOnce(entity client)
+{
+       if(client.ban_checked)
+               return FALSE;
+       client.ban_checked = TRUE;
+       return Ban_MaybeEnforceBan(client);
+}
+
 string Ban_Enforce(float i, string reason)
 {
        string s;
@@ -455,7 +469,8 @@ string Ban_Enforce(float i, string reason)
 
        // Enforce our new ban
        s = "";
-       FOR_EACH_REALCLIENT(e)
+       FOR_EACH_CLIENTSLOT(e)
+               if (IS_REAL_CLIENT(e))
                if(Ban_IsClientBanned(e, i))
                {
                        if(reason != "")
@@ -466,7 +481,7 @@ 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);
@@ -565,21 +580,21 @@ void Ban_KickBanClient(entity client, float bantime, float masksize, string reas
        switch(masksize)
        {
                case 1:
-                       ip = ban_ip1;
+                       ip = strcat1(ban_ip1);
                        break;
                case 2:
-                       ip = ban_ip2;
+                       ip = strcat1(ban_ip2);
                        break;
                case 3:
-                       ip = ban_ip3;
+                       ip = strcat1(ban_ip3);
                        break;
                case 4:
                default:
-                       ip = ban_ip4;
+                       ip = strcat1(ban_ip4);
                        break;
        }
        if(ban_idfp)
-               id = ban_idfp;
+               id = strcat1(ban_idfp);
        else
                id = string_null;