From 222b94d2d796e4282af54ed199b6605c73b690f3 Mon Sep 17 00:00:00 2001 From: terencehill Date: Sun, 17 Apr 2022 04:01:22 +0200 Subject: [PATCH] On client connection, send client cvars only after client has been initialized on the server It fixes issue https://gitlab.com/xonotic/xonstat-go/-/issues/44 that was due to .playerstats_id getting wrongly set to "Player#0" because .playerid was not initialized yet (0) --- qcsrc/client/main.qc | 5 +++-- qcsrc/common/playerstats.qh | 2 +- qcsrc/lib/replicate.qh | 7 ++++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index 5beca00be..e5b38b768 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -58,8 +58,6 @@ void CSQC_Init() maxclients = i; } - ReplicateVars(REPLICATEVARS_SEND_ALL); - // needs to be done so early because of the constants they create static_init(); static_init_late(); @@ -667,6 +665,9 @@ NET_HANDLE(ENT_CLIENT_CLIENTDATA, bool isnew) spectatee_status = newspectatee_status; // we could get rid of spectatee_status, and derive it from player_localentnum and player_localnum + + // this can't be called in CSQC_Init as it'd send cvars too early + ReplicateVars_Start(); } NET_HANDLE(ENT_CLIENT_NAGGER, bool isnew) diff --git a/qcsrc/common/playerstats.qh b/qcsrc/common/playerstats.qh index 06feced27..9fff940f2 100644 --- a/qcsrc/common/playerstats.qh +++ b/qcsrc/common/playerstats.qh @@ -81,7 +81,7 @@ void PlayerStats_GameReport_Accuracy(entity p); void PlayerStats_GameReport_FinalizePlayer(entity p); // call this at the end of the match -void PlayerStats_GameReport(float finished); +void PlayerStats_GameReport(bool finished); void PlayerStats_GameReport_Handler(entity fh, entity pass, float status); diff --git a/qcsrc/lib/replicate.qh b/qcsrc/lib/replicate.qh index a7a8d10df..470d56aa0 100644 --- a/qcsrc/lib/replicate.qh +++ b/qcsrc/lib/replicate.qh @@ -45,10 +45,15 @@ const int REPLICATEVARS_DESTROY = 1; // destroy data associated with cvars (shut noref float ReplicateVars_time; ACCUMULATE void ReplicateVars(int mode) { - if (time < ReplicateVars_time) + if (!ReplicateVars_time || time < ReplicateVars_time) return; ReplicateVars_time = time + 0.8 + random() * 0.4; // check cvars periodically } + void ReplicateVars_Start() + { + ReplicateVars_time = time; + ReplicateVars(REPLICATEVARS_SEND_ALL); + } #endif #define REPLICATE_3(fld, type, var) REPLICATE_4(fld, type, var, ) -- 2.39.2