]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Display map author in Welcome message, add more author fallback paths
authorbones_was_here <bones_was_here@xonotic.au>
Tue, 26 Mar 2024 04:24:28 +0000 (14:24 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Sat, 30 Mar 2024 07:46:04 +0000 (17:46 +1000)
Fixes "<AUTHOR>" sometimes appearing in the Create menu.

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

index 10d18dc3e0515197bb64f1196eec52bd2972d9c2..06e7df4edc9e7af26ec0ef80a4113ffe54bfa5f8 100644 (file)
@@ -1440,6 +1440,7 @@ bool net_handle_ServerWelcome()
        bool version_mismatch = flags & 2;
        bool version_check = flags & 4;
        MapInfo_Map_titlestring = ReadString();
+       MapInfo_Map_author = flags & 8 ? ReadString() : "";
        srv_minplayers = ReadByte();
        srv_maxplayers = ReadByte();
        string modifications = translate_modifications(ReadString());
@@ -1452,6 +1453,8 @@ bool net_handle_ServerWelcome()
        msg = strcat(msg, "\n\n", _("Gametype:"), " ^1", MapInfo_Type_ToText(gametype), "\n");
 
        msg = strcat(msg, "\n", _("Map:"), " ", MapInfo_Map_titlestring, "\n");
+       if (flags & 8)
+               msg = strcat(msg, "^9", _("by:"), " ", MapInfo_Map_author, "\n");
 
        if (srv_minplayers || srv_maxplayers)
        {
index b8c7ec941d828e34cc18fa91bbd6882e72bf3e6b..c1cdd7a90cd0b22d4dd940931caf2f6f1d7c485e 100644 (file)
@@ -768,6 +768,18 @@ string MapInfo_title_sans_author(string title)
                        MapInfo_Map_author = substring(title, offset + 4, strlen(title) - (offset + 4));
                title = substring(title, 0, offset);
        }
+       else if ((offset = strstrofs(title, " (by ", 0)) >= 0 || (offset = strstrofs(title, " [by ", 0)) >= 0)
+       {
+               if (MapInfo_Map_author == "<AUTHOR>")
+                       MapInfo_Map_author = substring(title, offset + 5, strlen(title) - (offset + 5) - 1);
+               title = substring(title, 0, offset);
+       }
+       else if ((offset = strstrofs(title, "Made By ", 0)) >= 0) // often at the start of the string
+       {
+               if (MapInfo_Map_author == "<AUTHOR>")
+                       MapInfo_Map_author = substring(title, offset + 8, strlen(title) - (offset + 8));
+               title = substring(title, 0, offset);
+       }
 
        return title != "" ? title : "<TITLE>";
 }
@@ -843,7 +855,8 @@ bool _MapInfo_ParseArena(string arena_filename, int fh, string pFilename, Gamety
                                MapInfo_Map_description = stored_Map_description;
                                if(stored_Map_title != "")
                                        MapInfo_Map_title = stored_Map_title;
-                               MapInfo_Map_author = stored_Map_author;
+                               if(stored_Map_author != "") // write the usual "<AUTHOR>" if we have nothing better
+                                       MapInfo_Map_author = stored_Map_author;
                                // might have .arena AND .defi for the same map so these bitfields are OR'd
                                if(isgenerator)
                                        MapInfo_Map_supportedGametypes |= stored_supportedGametypes;
@@ -1325,6 +1338,9 @@ LABEL(mapinfo_handled)
                if (MapInfo_Map_title == "<TITLE>")
                        if (world.message != "")
                                MapInfo_Map_title = world.message;
+               if (MapInfo_Map_author == "<AUTHOR>")
+                       if ((s = GetField_fullspawndata(world, "author")) != "")
+                               MapInfo_Map_author = s;
        }
 #endif
        // Could skip removing author from title when it's source is .mapinfo
@@ -1339,6 +1355,9 @@ LABEL(mapinfo_handled)
        else
                MapInfo_Map_titlestring = sprintf("^2%s ^7// ^2%s", MapInfo_Map_bspname, MapInfo_Map_title);
 
+       if (MapInfo_Map_author == "<AUTHOR>")
+               MapInfo_Map_author = ""; // don't display "<AUTHOR>" in the UI (we do write it to .mapinfo files)
+
        MapInfo_Cache_Store();
        if(MapInfo_Map_supportedGametypes != 0)
                return r;
index 80a98b25fbef06ba6c0a395410740a1fe780ad6a..1d62feffa2858ea3bbc689fa8da8b1059f3a215a 100644 (file)
@@ -1054,12 +1054,16 @@ void SendWelcomeMessage(entity this, int msg_type)
        if (CS(this).version < autocvar_gameversion)
                flags |= 4;
        MapInfo_Get_ByName(mi_shortname, 0, NULL);
+       if (MapInfo_Map_author != "")
+               flags |= 8;
        WriteByte(msg_type, flags);
 
        WriteString(msg_type, autocvar_hostname);
        WriteString(msg_type, autocvar_g_xonoticversion);
 
        WriteString(msg_type, MapInfo_Map_titlestring);
+       if (flags & 8)
+               WriteString(msg_type, MapInfo_Map_author);
        MapInfo_ClearTemps();
 
        WriteByte(msg_type, autocvar_g_warmup > 1 ? autocvar_g_warmup : map_minplayers);