From: cloudwalk Date: Tue, 27 Oct 2020 14:50:19 +0000 (+0000) Subject: Merge the sendcvar command into one. Call the old functions using hooks. X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=1c1c1d842e8930e8c09eea8e877f07a829858d5a;p=xonotic%2Fdarkplaces.git Merge the sendcvar command into one. Call the old functions using hooks. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@13034 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/cl_cmd.c b/cl_cmd.c index 37ecbaa4..4f844a82 100644 --- a/cl_cmd.c +++ b/cl_cmd.c @@ -744,8 +744,8 @@ void CL_InitCommands(void) Cmd_AddCommand(CF_CLIENT, "packet", CL_Packet_f, "send a packet to the specified address:port containing a text string"); Cmd_AddCommand(CF_CLIENT, "fullinfo", CL_FullInfo_f, "allows client to modify their userinfo"); Cmd_AddCommand(CF_CLIENT, "setinfo", CL_SetInfo_f, "modifies your userinfo"); - Cmd_AddCommand(CF_CLIENT, "sendcvar", CL_SendCvar_f, "sends the value of a cvar to the server as a sentcvar command, for use by QuakeC"); Cmd_AddCommand(CF_CLIENT, "fixtrans", Image_FixTransparentPixels_f, "change alpha-zero pixels in an image file to sensible values, and write out a new TGA (warning: SLOW)"); + host.hook.CL_SendCvar = CL_SendCvar_f; // commands that are only sent by server to client for execution Cmd_AddCommand(CF_CLIENT_FROM_SERVER, "pingplreport", CL_PingPLReport_f, "command sent by server containing client ping and packet loss values for scoreboard, triggered by pings command from client (not used by QW servers)"); diff --git a/host.c b/host.c index 8cf8593d..268c1467 100644 --- a/host.c +++ b/host.c @@ -167,6 +167,21 @@ static void Host_Framerate_c(cvar_t *var) Cvar_SetValueQuick(var, 0); } +// TODO: Find a better home for this. +static void SendCvar_f(cmd_state_t *cmd) +{ + if(cmd->source == src_local && host.hook.SV_SendCvar) + { + host.hook.SV_SendCvar(cmd); + return; + } + if(cmd->source == src_client && host.hook.CL_SendCvar) + { + host.hook.CL_SendCvar(cmd); + return; + } +} + /* ======================= Host_InitLocal @@ -182,6 +197,7 @@ static void Host_InitLocal (void) Cmd_AddCommand(CF_SHARED, "version", Host_Version_f, "print engine version"); Cmd_AddCommand(CF_SHARED, "saveconfig", Host_SaveConfig_f, "save settings to config.cfg (or a specified filename) immediately (also automatic when quitting)"); Cmd_AddCommand(CF_SHARED, "loadconfig", Host_LoadConfig_f, "reset everything and reload configs"); + Cmd_AddCommand(CF_SHARED, "sendcvar", SendCvar_f, "sends the value of a cvar to the server as a sentcvar command, for use by QuakeC"); Cvar_RegisterVariable (&cl_maxphysicsframesperserverframe); Cvar_RegisterVariable (&host_framerate); Cvar_RegisterCallback (&host_framerate, Host_Framerate_c); diff --git a/host.h b/host.h index 9def0939..0fcbb714 100644 --- a/host.h +++ b/host.h @@ -6,6 +6,8 @@ #include "qdefs.h" #include "cmd.h" +struct cmd_state_s; + typedef enum host_state_e { host_shutdown, @@ -33,6 +35,8 @@ typedef struct host_s void (*ToggleMenu)(void); qbool (*CL_Intermission)(void); // Quake compatibility qbool (*SV_CanSave)(void); // Quake compatibility + void (*CL_SendCvar)(struct cmd_state_s *); + void (*SV_SendCvar)(struct cmd_state_s *); } hook; } host_t; diff --git a/sv_ccmds.c b/sv_ccmds.c index 78954aa8..d9e08c04 100644 --- a/sv_ccmds.c +++ b/sv_ccmds.c @@ -1633,7 +1633,7 @@ void SV_InitOperatorCommands(void) Cmd_AddCommand(CF_SHARED, "viewnext", SV_Viewnext_f, "change to next animation frame of viewthing entity in current level"); Cmd_AddCommand(CF_SHARED, "viewprev", SV_Viewprev_f, "change to previous animation frame of viewthing entity in current level"); Cmd_AddCommand(CF_SHARED, "maxplayers", SV_MaxPlayers_f, "sets limit on how many players (or bots) may be connected to the server at once"); - Cmd_AddCommand(CF_SERVER, "sendcvar", SV_SendCvar_f, "sends the value of a cvar to the server as a sentcvar command, for use by QuakeC"); + host.hook.SV_SendCvar = SV_SendCvar_f; // commands that do not have automatic forwarding from cmd_client, these are internal details of the network protocol and not of interest to users (if they know what they are doing they can still use a generic "cmd prespawn" or similar) Cmd_AddCommand(CF_SERVER_FROM_CLIENT, "prespawn", SV_PreSpawn_f, "internal use - signon 1 (client acknowledges that server information has been received)");