From 74b49d6e5412af206448119963e0a4b3617e8ca4 Mon Sep 17 00:00:00 2001 From: bones_was_here Date: Thu, 28 Sep 2023 19:03:28 +1000 Subject: [PATCH] Make `name` be a command or virtual cvar on a game-specific basis This allows matching the client console behaviour of div0-stable in games that want it. Closes https://gitlab.com/xonotic/darkplaces/-/issues/337 Signed-off-by: bones_was_here --- cl_cmd.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/cl_cmd.c b/cl_cmd.c index 9277ad50..4bbd8ea9 100644 --- a/cl_cmd.c +++ b/cl_cmd.c @@ -28,7 +28,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "cl_collision.h" -cvar_t cl_name = {CF_CLIENT | CF_ARCHIVE | CF_USERINFO, "name", "player", "player name"}; +cvar_t cl_name = {CF_CLIENT | CF_ARCHIVE | CF_USERINFO, "_cl_name", "player", "player name"}; cvar_t cl_rate = {CF_CLIENT | CF_ARCHIVE | CF_USERINFO, "rate", "20000", "connection speed"}; cvar_t cl_rate_burstsize = {CF_CLIENT | CF_ARCHIVE | CF_USERINFO, "rate_burstsize", "1024", "rate control burst size"}; cvar_t cl_topcolor = {CF_CLIENT | CF_ARCHIVE | CF_USERINFO, "topcolor", "0", "color of your shirt"}; @@ -216,6 +216,32 @@ static void CL_SendCvar_f(cmd_state_t *cmd) } } +/* +================== +CL_Name_f + +The logic from div0-stable's Host_Name_f() is now in SV_Name_f(). +================== +*/ +static void CL_Name_f(cmd_state_t *cmd) +{ + char *newNameSource; + + if (Cmd_Argc(cmd) == 1) + { + Con_Printf("name: \"%s^7\"\n", cl_name.string); + return; + } + + // in the single-arg case any enclosing quotes shall be stripped + newNameSource = (char *)(Cmd_Argc(cmd) == 2 ? Cmd_Argv(cmd, 1) : Cmd_Args(cmd)); + + if (strlen(newNameSource) >= MAX_SCOREBOARDNAME) // may as well truncate before networking + newNameSource[MAX_SCOREBOARDNAME - 1] = '\0'; // this is fine (cbuf stores length) + + Cvar_SetQuick(&cl_name, newNameSource); +} + /* ================== CL_Color_f @@ -715,8 +741,16 @@ void CL_InitCommands(void) { dpsnprintf(cls.userinfo, sizeof(cls.userinfo), "\\name\\player\\team\\none\\topcolor\\0\\bottomcolor\\0\\rate\\10000\\msg\\1\\noaim\\1\\*ver\\dp"); + /* In Quake `name` is a command that concatenates its arguments (quotes unnecessary) + * which is expected in most DP-based games. + * In QuakeWorld it's a cvar which requires quotes if spaces are used. + */ Cvar_RegisterVariable(&cl_name); - Cvar_RegisterVirtual(&cl_name, "_cl_name"); + if ((0)) // TODO: if (gamemode == GAME_QUAKEWORLD) + Cvar_RegisterVirtual(&cl_name, "name"); + else + Cmd_AddCommand(CF_CLIENT, "name", CL_Name_f, "change your player name"); + Cvar_RegisterVariable(&cl_rate); Cvar_RegisterVirtual(&cl_rate, "_cl_rate"); Cvar_RegisterVariable(&cl_rate_burstsize); -- 2.39.2