]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Display mapinfo titlestring in Welcome message, handle title the same in all code...
authorbones_was_here <bones_was_here@xonotic.au>
Mon, 25 Mar 2024 18:28:50 +0000 (04:28 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Sat, 30 Mar 2024 07:40:25 +0000 (17:40 +1000)
Moves the world.message fallback into the mapinfo system.

qcsrc/client/main.qc
qcsrc/common/mapinfo.qc
qcsrc/server/client.qc

index 9d45c455412380f3bdc26ef1a6c751766feef8ed..10d18dc3e0515197bb64f1196eec52bd2972d9c2 100644 (file)
@@ -1439,6 +1439,7 @@ bool net_handle_ServerWelcome()
        string hostversion = ReadString();
        bool version_mismatch = flags & 2;
        bool version_check = flags & 4;
+       MapInfo_Map_titlestring = ReadString();
        srv_minplayers = ReadByte();
        srv_maxplayers = ReadByte();
        string modifications = translate_modifications(ReadString());
@@ -1450,15 +1451,7 @@ bool net_handle_ServerWelcome()
 
        msg = strcat(msg, "\n\n", _("Gametype:"), " ^1", MapInfo_Type_ToText(gametype), "\n");
 
-       msg = strcat(msg, "\n", _("Map:"), " ^2");
-       if (world.message == "")
-               msg = strcat(msg, mi_shortname, "\n");
-       else
-       {
-               int i = strstrofs(world.message, " by ", 0); // matches _MapInfo_Generate()
-               string longname = i >= 0 ? substring(world.message, 0, i) : world.message;
-               msg = strcat(msg, (strcasecmp(longname, mi_shortname) ? strcat(mi_shortname, " ^7// ^2") : ""), longname, "\n");
-       }
+       msg = strcat(msg, "\n", _("Map:"), " ", MapInfo_Map_titlestring, "\n");
 
        if (srv_minplayers || srv_maxplayers)
        {
index 92d275af443576178b443790d87bbb7ab1380e71..b8c7ec941d828e34cc18fa91bbd6882e72bf3e6b 100644 (file)
@@ -339,17 +339,8 @@ float _MapInfo_Generate(string pFilename) // 0: failure, 1: ok ent, 2: ok bsp
                                _MapInfo_Map_worldspawn_music = v;
                        else if(k == "noise")
                                _MapInfo_Map_worldspawn_music = v;
-                       else if(k == "message" && (!MapInfo_Map_title || MapInfo_Map_title == "<TITLE>"))
-                       {
-                               i = strstrofs(v, " by ", 0);
-                               if(MapInfo_Map_author == "<AUTHOR>" && i >= 0)
-                               {
-                                       MapInfo_Map_title = substring(v, 0, i);
-                                       MapInfo_Map_author = substring(v, i + 4, strlen(v) - (i + 4));
-                               }
-                               else
-                                       MapInfo_Map_title = v;
-                       }
+                       else if(k == "message" && (!MapInfo_Map_title || MapInfo_Map_title == "<TITLE>") && v != "")
+                               MapInfo_Map_title = v;
                }
                else
                {
@@ -765,7 +756,23 @@ void _MapInfo_Parse_Settemp(string pFilename, string acl, float type, string s,
        }
 }
 
-float MapInfo_isRedundant(string fn, string t)
+/// Removes author string from title (if found)
+/// and copies it to MapInfo_Map_author if that wasn't set.
+string MapInfo_title_sans_author(string title)
+{
+       int offset;
+
+       if ((offset = strstrofs(title, " by ", 0)) >= 0)
+       {
+               if (MapInfo_Map_author == "<AUTHOR>")
+                       MapInfo_Map_author = substring(title, offset + 4, strlen(title) - (offset + 4));
+               title = substring(title, 0, offset);
+       }
+
+       return title != "" ? title : "<TITLE>";
+}
+
+bool MapInfo_isRedundant(string fn, string t)
 {
        // normalize file name
        fn = strreplace("_", "", fn);
@@ -1059,6 +1066,7 @@ float MapInfo_Get_ByName_NoFallbacks(string pFilename, int pAllowGenerate, Gamet
                        r = _MapInfo_Generate(pFilename);
                        if(!r)
                                return 0;
+                       MapInfo_Map_title = MapInfo_title_sans_author(MapInfo_Map_title);
                        fh = fopen(fn, FILE_WRITE);
                        fputs(fh, strcat("title ", MapInfo_Map_title, "\n"));
                        fputs(fh, strcat("description ", MapInfo_Map_description, "\n"));
@@ -1310,12 +1318,26 @@ float MapInfo_Get_ByName_NoFallbacks(string pFilename, int pAllowGenerate, Gamet
        fclose(fh);
 
 LABEL(mapinfo_handled)
+#ifdef SVQC
+       // if the map is currently loaded we can read worldspawn fields directly
+       if (pFilename == mi_shortname)
+       {
+               if (MapInfo_Map_title == "<TITLE>")
+                       if (world.message != "")
+                               MapInfo_Map_title = world.message;
+       }
+#endif
+       // Could skip removing author from title when it's source is .mapinfo
+       // but must always do it for world.message and .arena/.defi as VQ3 didn't support author
+       // so mappers tended to put it in world.message and/or longname.
+       MapInfo_Map_title = MapInfo_title_sans_author(MapInfo_Map_title); // may set author if not set
+
        if(MapInfo_Map_title == "<TITLE>")
-               MapInfo_Map_titlestring = MapInfo_Map_bspname;
+               MapInfo_Map_titlestring = strcat("^2", MapInfo_Map_bspname);
        else if(MapInfo_isRedundant(MapInfo_Map_bspname, MapInfo_Map_title))
-               MapInfo_Map_titlestring = MapInfo_Map_title;
+               MapInfo_Map_titlestring = strcat("^2", MapInfo_Map_title);
        else
-               MapInfo_Map_titlestring = sprintf("%s: %s", MapInfo_Map_bspname, MapInfo_Map_title);
+               MapInfo_Map_titlestring = sprintf("^2%s ^7// ^2%s", MapInfo_Map_bspname, MapInfo_Map_title);
 
        MapInfo_Cache_Store();
        if(MapInfo_Map_supportedGametypes != 0)
index 4085736233417411c9b64464d29c1ecdbd9ee576..80a98b25fbef06ba6c0a395410740a1fe780ad6a 100644 (file)
@@ -1053,11 +1053,15 @@ void SendWelcomeMessage(entity this, int msg_type)
                flags |= 2;
        if (CS(this).version < autocvar_gameversion)
                flags |= 4;
+       MapInfo_Get_ByName(mi_shortname, 0, NULL);
        WriteByte(msg_type, flags);
 
        WriteString(msg_type, autocvar_hostname);
        WriteString(msg_type, autocvar_g_xonoticversion);
 
+       WriteString(msg_type, MapInfo_Map_titlestring);
+       MapInfo_ClearTemps();
+
        WriteByte(msg_type, autocvar_g_warmup > 1 ? autocvar_g_warmup : map_minplayers);
        WriteByte(msg_type, GetPlayerLimit());