From: terencehill Date: Sun, 7 Apr 2019 17:16:25 +0000 (+0200) Subject: Reduce player names longer than 30 chars (name_maxlength cvar) X-Git-Tag: xonotic-v0.8.5~1560 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=a5201422b62c733dca00e4dbfcdac64acd19b2ce;p=xonotic%2Fxonotic-data.pk3dir.git Reduce player names longer than 30 chars (name_maxlength cvar) --- diff --git a/qcsrc/server/autocvars.qh b/qcsrc/server/autocvars.qh index a50191775..a763b9726 100644 --- a/qcsrc/server/autocvars.qh +++ b/qcsrc/server/autocvars.qh @@ -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; diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc index 8abf5e743..41331541b 100644 --- a/qcsrc/server/client.qc +++ b/qcsrc/server/client.qc @@ -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? } diff --git a/xonotic-server.cfg b/xonotic-server.cfg index fdba9aec0..db36db5b7 100644 --- a/xonotic-server.cfg +++ b/xonotic-server.cfg @@ -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"