Reduce player names longer than 30 chars (name_maxlength cvar)
authorterencehill <piuntn@gmail.com>
Sun, 7 Apr 2019 17:16:25 +0000 (19:16 +0200)
committerterencehill <piuntn@gmail.com>
Sun, 7 Apr 2019 17:16:25 +0000 (19:16 +0200)
qcsrc/server/autocvars.qh
qcsrc/server/client.qc
xonotic-server.cfg

index a501917..a763b97 100644 (file)
@@ -252,6 +252,7 @@ int autocvar_leadlimit_and_fraglimit;
 int autocvar_leadlimit_override;
 int autocvar_minplayers;
 int autocvar_minplayers_per_team;
+int autocvar_name_maxlength;
 string autocvar_nextmap;
 string autocvar_quit_and_redirect;
 float autocvar_quit_and_redirect_timer;
index 8abf5e7..4133154 100644 (file)
@@ -2396,9 +2396,18 @@ void PlayerPreThink (entity this)
        if (this.netname == "" || this.netname != CS(this).netname_previous)
        {
                bool assume_unchanged = (CS(this).netname_previous == "");
+               if (strlennocol(this.netname) > autocvar_name_maxlength)
+               {
+                       int new_length = textLengthUpToLength(this.netname, autocvar_name_maxlength, strlennocol);
+                       this.netname = strzone(strcat(substring(this.netname, 0, new_length), "^7"));
+                       sprint(this, sprintf("Warning: your name is longer than %d characters, it has been truncated.\n", autocvar_name_maxlength));
+                       assume_unchanged = false;
+                       // stuffcmd(this, strcat("name ", this.netname, "\n")); // maybe?
+               }
                if (isInvisibleString(this.netname))
                {
                        this.netname = strzone(sprintf("Player#%d", this.playerid));
+                       sprint(this, "Warning: invisible names are not allowed.\n");
                        assume_unchanged = false;
                        // stuffcmd(this, strcat("name ", this.netname, "\n")); // maybe?
                }
index fdba9ae..db36db5 100644 (file)
@@ -2,6 +2,7 @@
 // note that it doesn't reset all server cvars,
 // some are shared with the client and so are left in xonotic-common.cfg
 
+set name_maxlength 30 "max player name length (not counting color codes) allowed by the server"
 
 // taunts and voices
 set sv_taunt 1 "allow taunts on the server"