From: bones_was_here Date: Mon, 25 Mar 2024 18:28:50 +0000 (+1000) Subject: Display mapinfo titlestring in Welcome message, handle title the same in all code... X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=bf072cdd6407201428cf6486e2ebe68a17ba03fe;p=xonotic%2Fxonotic-data.pk3dir.git Display mapinfo titlestring in Welcome message, handle title the same in all code paths Moves the world.message fallback into the mapinfo system. --- diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index 9d45c4554..10d18dc3e 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -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) { diff --git a/qcsrc/common/mapinfo.qc b/qcsrc/common/mapinfo.qc index 92d275af4..b8c7ec941 100644 --- a/qcsrc/common/mapinfo.qc +++ b/qcsrc/common/mapinfo.qc @@ -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 == "")) - { - 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) diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc index 408573623..80a98b25f 100644 --- a/qcsrc/server/client.qc +++ b/qcsrc/server/client.qc @@ -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());