From: terencehill Date: Wed, 5 Jan 2022 21:48:13 +0000 (+0100) Subject: Make cvar_cl_allow_uidtracking an int thanks to a patch to ReplicateVars: replicated... X-Git-Tag: xonotic-v0.8.5~243 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=8840adadb43cd96ccd530ddf127f8b9bf6c685cc;p=xonotic%2Fxonotic-data.pk3dir.git Make cvar_cl_allow_uidtracking an int thanks to a patch to ReplicateVars: replicated cvars are now sent to the server on connection even if not changed so that server can process them properly cvar_cl_allow_uidtracking as string was networked on connection because code immediately detects a change (null value "" != default value "0"), not possible as int (null value 0 == default value 0) --- diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index ca49edd03..5dbfb7209 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -57,6 +57,8 @@ void CSQC_Init() maxclients = i; } + ReplicateVars_Send_All(); + // needs to be done so early because of the constants they create static_init(); static_init_late(); @@ -187,7 +189,7 @@ void Shutdown() deactivate_minigame(); HUD_MinigameMenu_Close(NULL, NULL, NULL); - ReplicateVars(true); // destroy + ReplicateVars_Destroy(); } void AuditLists() diff --git a/qcsrc/client/view.qc b/qcsrc/client/view.qc index d423337df..4086e1b19 100644 --- a/qcsrc/client/view.qc +++ b/qcsrc/client/view.qc @@ -1540,9 +1540,7 @@ void CSQC_UpdateView(entity this, float w, float h) stats_get(); hud = STAT(HUD); - ReplicateVars(false); - if (ReplicateVars_NOT_SENDING()) - ReplicateVars_DELAY(0.8 + random() * 0.4); // no need to check cvars every frame + ReplicateVars_Check(); HUD_Scale_Disable(); diff --git a/qcsrc/common/replicate.qh b/qcsrc/common/replicate.qh index 478181029..127ee3082 100644 --- a/qcsrc/common/replicate.qh +++ b/qcsrc/common/replicate.qh @@ -4,7 +4,7 @@ #if defined(CSQC) float autoswitch; bool cvar_cl_allow_uid2name; - string cvar_cl_allow_uidtracking; + float cvar_cl_allow_uidtracking; bool cvar_cl_allow_uidranking; float cvar_cl_autoscreenshot; float cvar_cl_autotaunt; @@ -83,10 +83,9 @@ REPLICATE(cvar_cl_weapon_switch_fallback_to_impulse, bool, "cl_weapon_switch_fal float cvar_cl_newusekeysupported; REPLICATE(cvar_cl_newusekeysupported, bool, "cl_newusekeysupported"); */ +// cvar_cl_allow_uidtracking is handled specially on the server #ifdef CSQC -// handled specially on the server -// FIXME change cvar_cl_allow_uidtracking type from string to float without breaking playerstats -REPLICATE(cvar_cl_allow_uidtracking, string, "cl_allow_uidtracking"); +REPLICATE(cvar_cl_allow_uidtracking, int, "cl_allow_uidtracking"); #endif REPLICATE(cvar_cl_weaponpriority, string, "cl_weaponpriority"); diff --git a/qcsrc/lib/replicate.qh b/qcsrc/lib/replicate.qh index 019194a6d..64d893a10 100644 --- a/qcsrc/lib/replicate.qh +++ b/qcsrc/lib/replicate.qh @@ -15,7 +15,7 @@ #if defined(SVQC) ACCUMULATE void ReplicateVars(entity this, entity store, string thisname, int i) {} #elif defined(CSQC) - ACCUMULATE void ReplicateVars(bool would_destroy) {} + ACCUMULATE void ReplicateVars(int mode) {} #endif #define REPLICATE_3(fld, type, var) REPLICATE_4(fld, type, var, ) @@ -68,13 +68,25 @@ #define REPLICATE_bool(fld, var, func) REPLICATE_7(fld, bool, var, func, (fld != cvar(var)), { fld = cvar(var); }, ) #define REPLICATE_int(fld, var, func) REPLICATE_7(fld, int, var, func, (fld != cvar(var)), { fld = cvar(var); }, ) + void ReplicateVars_Destroy() { ReplicateVars(1); } + void ReplicateVars_Send_All() { ReplicateVars(-1); } + void ReplicateVars_Check() + { + // if a cvar has changed send it and check cvars again next frame + ReplicateVars(0); + if (ReplicateVars_NOT_SENDING()) // if no cvar has changed + ReplicateVars_DELAY(0.8 + random() * 0.4); // check cvars after a while + } + void ReplicateVars_Send(string cvarname) { localcmd(strcat("cl_cmd sendcvar ", cvarname, "\n")); } + #define REPLICATE_7(fld, type, var, func, check, update, destroy) \ - void ReplicateVars(bool would_destroy) \ + void ReplicateVars(int mode) \ { \ - if (would_destroy) { destroy } \ + if (mode == 1) { destroy } \ + else if (mode == -1) { ReplicateVars_Send(var); update } \ else if (ReplicateVars_NOT_SENDING() && check) \ { \ - localcmd(strcat("cl_cmd sendcvar ", var, "\n")); \ + ReplicateVars_Send(var); \ ReplicateVars_DELAY_1FRAME(); \ update \ return; \ @@ -87,7 +99,7 @@ float thecvar = cvar(cvarname); \ if(field != thecvar) \ { \ - localcmd(strcat("cl_cmd sendcvar ", cvarname, "\n")); \ + ReplicateVars_Send(cvarname); \ ReplicateVars_DELAY_1FRAME(); \ field = thecvar; \ return; \