From 73895b06e50af4ae170fd03a578a3639650db6f4 Mon Sep 17 00:00:00 2001 From: bones_was_here Date: Tue, 26 Mar 2024 14:24:28 +1000 Subject: [PATCH] Display map author in Welcome message, add more author fallback paths Fixes "" sometimes appearing in the Create menu. --- qcsrc/client/main.qc | 3 +++ qcsrc/common/mapinfo.qc | 21 ++++++++++++++++++++- qcsrc/server/client.qc | 4 ++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index 10d18dc3e..06e7df4ed 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -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) { diff --git a/qcsrc/common/mapinfo.qc b/qcsrc/common/mapinfo.qc index b8c7ec941..c1cdd7a90 100644 --- a/qcsrc/common/mapinfo.qc +++ b/qcsrc/common/mapinfo.qc @@ -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 == "") + 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 == "") + MapInfo_Map_author = substring(title, offset + 8, strlen(title) - (offset + 8)); + title = substring(title, 0, offset); + } return 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; diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc index 80a98b25f..1d62feffa 100644 --- a/qcsrc/server/client.qc +++ b/qcsrc/server/client.qc @@ -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); -- 2.39.2