Send the welcome message together with the gametype on connection in order to avoid...
authorterencehill <piuntn@gmail.com>
Thu, 31 Mar 2022 09:56:53 +0000 (11:56 +0200)
committerterencehill <piuntn@gmail.com>
Thu, 31 Mar 2022 09:56:53 +0000 (11:56 +0200)
qcsrc/client/main.qc
qcsrc/server/client.qc
qcsrc/server/client.qh
qcsrc/server/scores.qc

index 16227a0cba9071dfb31632f5376b21df07dd43eb..238ce891a2bada7c0fa4b65451a311cca23aa6c3 100644 (file)
@@ -1037,6 +1037,7 @@ void Fog_Force()
                localcmd(sprintf("\nfog %s\nr_fog_exp2 0\nr_drawfog 1\n", forcefog));
 }
 
                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);
 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();
        }
                strcpy(teamscores_label(i), ReadString());
                teamscores_flags(i) = ReadByte();
        }
+       if (ReadByte())
+               net_handle_ServerWelcome();
        return = true;
        Scoreboard_InitScores();
        Gamemode_Init();
        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)
 {
        bool campaign = ReadByte();
        if (campaign)
@@ -1365,6 +1368,11 @@ NET_HANDLE(TE_CSQC_SERVERWELCOME, bool isNew)
        return true;
 }
 
        return true;
 }
 
+NET_HANDLE(TE_CSQC_SERVERWELCOME, bool isNew)
+{
+       return net_handle_ServerWelcome();
+}
+
 string _getcommandkey(string cmd_name, string command, bool forcename)
 {
        string keys;
 string _getcommandkey(string cmd_name, string command, bool forcename)
 {
        string keys;
index 68c19f638a0bfbaa4f578b7f41fde53bab809ad2..a5f508851b00876304e486f92f9fcb9634d6f438 100644 (file)
@@ -1037,17 +1037,22 @@ void SendWelcomemessage(entity this, bool force_centerprint)
 {
        msg_entity = this;
        WriteHeader(MSG_ONE, TE_CSQC_SERVERWELCOME);
 {
        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))
        {
        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;
        }
                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);
 
        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);
 
                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)
        {
 
        if(cache_lastmutatormsg != autocvar_g_mutatormsg)
        {
@@ -1077,25 +1082,14 @@ void SendWelcomemessage(entity this, bool force_centerprint)
                strcpy(cache_mutatormsg, cache_lastmutatormsg);
        }
 
                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);
 
 
        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))
        CS(this).model_randomizer = random();
 
        if (IS_REAL_CLIENT(this))
-       {
-               if (!autocvar_g_campaign)
-                       SendWelcomemessage_onConnection(this);
                sv_notice_join(this);
                sv_notice_join(this);
-       }
 
        this.move_qcphysics = autocvar_sv_qcphysics;
 
 
        this.move_qcphysics = autocvar_sv_qcphysics;
 
index cca687aeb6d2447293171adebd68dc49ca180353..5fc5422c63f7e55e5d4316f1a91fad7f3b0bdce5 100644 (file)
@@ -320,6 +320,8 @@ bool independent_players;
 .float nickspamtime; // time of last nick change
 .float nickspamcount;
 
 .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;
 // respawning
 .int respawn_flags;
 .float respawn_time;
index 07c400f5d3bf31337449629435cfe5f1dc5949c7..ac3f52c72f446fb29ec0074d9eb43dfe6d2bbe9f 100644 (file)
@@ -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;
 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));
        }
                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;
 }
 
        return true;
 }