From: terencehill Date: Thu, 31 Mar 2022 09:56:53 +0000 (+0200) Subject: Send the welcome message together with the gametype on connection in order to avoid... X-Git-Tag: xonotic-v0.8.5~122 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=765eed8d356d25d15047202838dc58db8cb80b89;p=xonotic%2Fxonotic-data.pk3dir.git Send the welcome message together with the gametype on connection in order to avoid printing it when gametype hasn't received yet --- diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index 16227a0cb..238ce891a 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -1037,6 +1037,7 @@ void Fog_Force() localcmd(sprintf("\nfog %s\nr_fog_exp2 0\nr_drawfog 1\n", forcefog)); } +bool net_handle_ServerWelcome(); NET_HANDLE(ENT_CLIENT_SCORES_INFO, bool isnew) { make_pure(this); @@ -1052,6 +1053,8 @@ NET_HANDLE(ENT_CLIENT_SCORES_INFO, bool isnew) strcpy(teamscores_label(i), ReadString()); teamscores_flags(i) = ReadByte(); } + if (ReadByte()) + net_handle_ServerWelcome(); return = true; Scoreboard_InitScores(); Gamemode_Init(); @@ -1312,7 +1315,7 @@ NET_HANDLE(TE_CSQC_WEAPONCOMPLAIN, bool isNew) } } -NET_HANDLE(TE_CSQC_SERVERWELCOME, bool isNew) +bool net_handle_ServerWelcome() { bool campaign = ReadByte(); if (campaign) @@ -1365,6 +1368,11 @@ NET_HANDLE(TE_CSQC_SERVERWELCOME, bool isNew) return true; } +NET_HANDLE(TE_CSQC_SERVERWELCOME, bool isNew) +{ + return net_handle_ServerWelcome(); +} + string _getcommandkey(string cmd_name, string command, bool forcename) { string keys; diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc index 68c19f638..a5f508851 100644 --- a/qcsrc/server/client.qc +++ b/qcsrc/server/client.qc @@ -1037,17 +1037,22 @@ void SendWelcomemessage(entity this, bool force_centerprint) { msg_entity = this; WriteHeader(MSG_ONE, TE_CSQC_SERVERWELCOME); - WriteByte(MSG_ONE, boolean(autocvar_g_campaign)); + SendWelcomemessage_msg_type(this, force_centerprint, MSG_ONE); +} + +void SendWelcomemessage_msg_type(entity this, bool force_centerprint, int msg_type) +{ + WriteByte(msg_type, boolean(autocvar_g_campaign)); if (boolean(autocvar_g_campaign)) { - WriteString(MSG_ONE, Campaign_GetTitle()); - WriteByte(MSG_ONE, Campaign_GetLevelNum()); - WriteString(MSG_ONE, Campaign_GetMessage()); + WriteString(msg_type, Campaign_GetTitle()); + WriteByte(msg_type, Campaign_GetLevelNum()); + WriteString(msg_type, Campaign_GetMessage()); return; } - WriteByte(MSG_ONE, force_centerprint); - WriteString(MSG_ONE, autocvar_hostname); - WriteString(MSG_ONE, GetClientVersionMessage(this)); + WriteByte(msg_type, force_centerprint); + WriteString(msg_type, autocvar_hostname); + WriteString(msg_type, GetClientVersionMessage(this)); MUTATOR_CALLHOOK(BuildMutatorsPrettyString, ""); string modifications = M_ARGV(0, string); @@ -1069,7 +1074,7 @@ void SendWelcomemessage(entity this, bool force_centerprint) modifications = strcat(modifications, ", Jet pack"); modifications = substring(modifications, 2, strlen(modifications) - 2); - WriteString(MSG_ONE, modifications); + WriteString(msg_type, modifications); if(cache_lastmutatormsg != autocvar_g_mutatormsg) { @@ -1077,25 +1082,14 @@ void SendWelcomemessage(entity this, bool force_centerprint) strcpy(cache_mutatormsg, cache_lastmutatormsg); } - WriteString(MSG_ONE, cache_mutatormsg); + WriteString(msg_type, cache_mutatormsg); string mutator_msg = ""; MUTATOR_CALLHOOK(BuildGameplayTipsString, mutator_msg); mutator_msg = M_ARGV(0, string); - WriteString(MSG_ONE, mutator_msg); // trust that the mutator will do proper formatting - WriteString(MSG_ONE, strreplace("\\n", "\n", autocvar_sv_motd)); -} - -void SendWelcomemessage_onConnection_think(entity this) -{ - SendWelcomemessage(this, false); -} - -void SendWelcomemessage_onConnection(entity this) -{ - // give the client time to sent its version - defer(this, 0.5, SendWelcomemessage_onConnection_think); + WriteString(msg_type, mutator_msg); // trust that the mutator will do proper formatting + WriteString(msg_type, strreplace("\\n", "\n", autocvar_sv_motd)); } /** @@ -1185,11 +1179,7 @@ void ClientConnect(entity this) CS(this).model_randomizer = random(); if (IS_REAL_CLIENT(this)) - { - if (!autocvar_g_campaign) - SendWelcomemessage_onConnection(this); sv_notice_join(this); - } this.move_qcphysics = autocvar_sv_qcphysics; diff --git a/qcsrc/server/client.qh b/qcsrc/server/client.qh index cca687aeb..5fc5422c6 100644 --- a/qcsrc/server/client.qh +++ b/qcsrc/server/client.qh @@ -320,6 +320,8 @@ bool independent_players; .float nickspamtime; // time of last nick change .float nickspamcount; +void SendWelcomemessage_msg_type(entity this, bool force_centerprint, int msg_type); + // respawning .int respawn_flags; .float respawn_time; diff --git a/qcsrc/server/scores.qc b/qcsrc/server/scores.qc index 07c400f5d..ac3f52c72 100644 --- a/qcsrc/server/scores.qc +++ b/qcsrc/server/scores.qc @@ -194,6 +194,7 @@ void ScoreInfo_SetLabel_TeamScore(float i, string label, float scoreflags) } } +int Welcomemessage_too = 1; bool ScoreInfo_SendEntity(entity this, entity to, int sf) { float i; @@ -208,6 +209,15 @@ bool ScoreInfo_SendEntity(entity this, entity to, int sf) WriteString(MSG_ENTITY, teamscores_label(i)); WriteByte(MSG_ENTITY, teamscores_flags(i)); } + WriteByte(MSG_ENTITY, Welcomemessage_too); + // for some reason ScoreInfo_SendEntity is called twice on client connection + // send the welcome message only once + if (Welcomemessage_too) + { + // welcome message is sent here because it needs to know the gametype + SendWelcomemessage_msg_type(this, false, MSG_ENTITY); + Welcomemessage_too = 0; + } return true; }