]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
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 a50191775932476dc2963873b341845cdd4774a6..a763b97267b5a69dcec8883b66a4a8c71127bf70 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 8abf5e743f5c64ab4902481441316ef322fef69e..41331541bc68b24b9ed634857b0ad83bdd6173e4 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 fdba9aec08afba53e8a152122e09af9f7dcf6c27..db36db5b79cf2d952bf09addf7970f0dab2ea803 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"