From: terencehill Date: Tue, 12 Apr 2022 17:11:20 +0000 (+0200) Subject: Merge branch 'master' into terencehill/welcome_dialog_translatable X-Git-Tag: xonotic-v0.8.5~81^2 X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=commitdiff_plain;h=d2b0f12cb08fe3d1e59d3c9514546c4858cf9012;hp=-c Merge branch 'master' into terencehill/welcome_dialog_translatable --- d2b0f12cb08fe3d1e59d3c9514546c4858cf9012 diff --combined qcsrc/client/main.qc index 1c7013a834,0892bb6bf2..5beca00bef --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@@ -1316,55 -1316,6 +1316,55 @@@ NET_HANDLE(TE_CSQC_WEAPONCOMPLAIN, boo } } +string translate_modifications(string s) +{ + return build_mutator_list(s); +} + +string translate_weaponarena(string s) +{ + if (s == "") return s; + if (s == "All Weapons Arena") return _("All Weapons Arena"); + if (s == "All Available Weapons Arena") return _("All Available Weapons Arena"); + if (s == "Most Weapons Arena") return _("Most Weapons Arena"); + if (s == "Most Available Weapons Arena") return _("Most Available Weapons Arena"); + if (s == "Dev All Weapons Arena") return s; // development option, do not translate + if (s == "Dev All Available Weapons Arena") return s; // development option, do not translate + if (s == "No Weapons Arena") return _("No Weapons Arena"); + + int n = tokenizebyseparator(s, " & "); + string wpn_list = ""; + for (int i = 0; i < n; i++) + { + Weapon wep = Weapon_from_name(argv(i)); + if (wep == WEP_Null) + LOG_INFO("^3Warning: ^7server sent an invalid weapon name\n"); + wpn_list = cons_mid(wpn_list, " & ", wep.m_name); + } + if (wpn_list != "") + return sprintf(_("%s Arena"), wpn_list); + else + return _("No Weapons Arena"); +} + +string GetVersionMessage(string hostversion, bool version_mismatch, bool version_check) +{ + string xonotic_hostversion = strcat("Xonotic ", hostversion); + if (version_mismatch) + { + if(!version_check) + return strcat(sprintf(_("This is %s"), xonotic_hostversion), "\n^3", + _("Your client version is outdated."), "\n\n\n", + _("### YOU WON'T BE ABLE TO PLAY ON THIS SERVER ###"), "\n\n\n", + _("Please update!")); + else + return strcat(sprintf(_("This is %s"), xonotic_hostversion), "\n^3", + _("This server is using an outdated Xonotic version."), "\n\n\n", + _("### THIS SERVER IS INCOMPATIBLE AND THUS YOU CANNOT JOIN ###")); + } + return sprintf(_("Welcome to %s"), xonotic_hostversion); +} + bool net_handle_ServerWelcome() { bool campaign = ReadByte(); @@@ -1386,48 -1337,52 +1386,64 @@@ return true; } - bool force_centerprint = ReadByte(); - string hostname = ReadString(); + welcome_msg_force_centerprint = ReadByte(); + strcpy(hostname, ReadString()); - string ver = ReadString(); - string modifications = ReadString(); + + string hostversion = ReadString(); + bool version_mismatch = ReadByte(); + bool version_check = ReadByte(); + string ver = GetVersionMessage(hostversion, version_mismatch, version_check); + + string modifications = translate_modifications(ReadString()); + string weaponarena_list = translate_weaponarena(ReadString()); string cache_mutatormsg = ReadString(); - string mutator_msg = ReadString(); string motd = ReadString(); string msg = ""; msg = strcat(msg, ver); msg = strcat(msg, "^8\n\n", strcat(_("Gametype:"), " ^1", MapInfo_Type_ToText(gametype)), "^8\n"); + + modifications = cons_mid(modifications, ", ", weaponarena_list); if(modifications != "") msg = strcat(msg, "^8\n", _("Active modifications:"), " ^3", modifications, "^8\n"); + if (cache_mutatormsg != "") msg = strcat(msg, "\n\n^8", _("Special gameplay tips:"), " ^7", cache_mutatormsg); + string mutator_msg = ""; + MUTATOR_CALLHOOK(BuildGameplayTipsString, mutator_msg); + mutator_msg = M_ARGV(0, string); msg = strcat(msg, mutator_msg); // trust that the mutator will do proper formatting + if (motd != "") msg = strcat(msg, "\n\n^8", _("MOTD:"), " ^7", motd); - if (!force_centerprint && !isdemo() && cvar("_menu_welcome_dialog_available") && autocvar_cl_welcome_in_menu_dialog) + strcpy(welcome_msg, msg); + welcome_msg_menu_check_maxtime = time + 1; // wait for menu to load before showing the welcome dialog + return true; + } + + void Welcome_Message_Show_Try() + { + if (!welcome_msg_menu_check_maxtime) + return; + + bool want_dialog = (!welcome_msg_force_centerprint && !isdemo() && autocvar_cl_welcome_in_menu_dialog); + // if want dialog check if menu is initialized but for a short time + if (!want_dialog || cvar("_menu_initialized") == 2 || time > welcome_msg_menu_check_maxtime) { - string welcomedialog_args; - welcomedialog_args = strcat("HOSTNAME \"", hostname, "\""); - msg = MakeConsoleSafe(strreplace("\n", "\\n", msg)); - welcomedialog_args = strcat(welcomedialog_args, " WELCOME \"", msg, "\""); - localcmd("\nmenu_cmd directmenu Welcome ", welcomedialog_args, "\n"); + if (want_dialog && cvar("_menu_welcome_dialog_available")) + { + string welcomedialog_args = strcat("HOSTNAME \"", hostname, "\""); + string msg = MakeConsoleSafe(strreplace("\n", "\\n", welcome_msg)); + welcomedialog_args = strcat(welcomedialog_args, " WELCOME \"", msg, "\""); + localcmd("\nmenu_cmd directmenu Welcome ", welcomedialog_args, "\n"); + } + else + centerprint_Add(ORDINAL(CPID_MOTD), strcat(hostname, "\n\n\n", welcome_msg), -1, 0); + + strfree(welcome_msg); + welcome_msg_menu_check_maxtime = 0; } - else - centerprint_Add(ORDINAL(CPID_MOTD), strcat(hostname, "\n\n\n", msg), -1, 0); - return true; } NET_HANDLE(TE_CSQC_SERVERWELCOME, bool isNew) diff --combined qcsrc/server/client.qc index 097cafda03,2c3bdc25cc..bacb82e071 --- a/qcsrc/server/client.qc +++ b/qcsrc/server/client.qc @@@ -1018,6 -1018,21 +1018,6 @@@ void ClientPreConnect(entity this } #endif -string GetClientVersionMessage(entity this) -{ - if (CS(this).version_mismatch) { - if(CS(this).version < autocvar_gameversion) { - return strcat("This is Xonotic ", autocvar_g_xonoticversion, - "\n^3Your client version is outdated.\n\n\n### YOU WON'T BE ABLE TO PLAY ON THIS SERVER ###\n\n\nPlease update!!!^8"); - } else { - return strcat("This is Xonotic ", autocvar_g_xonoticversion, - "\n^3This server is using an outdated Xonotic version.\n\n\n ### THIS SERVER IS INCOMPATIBLE AND THUS YOU CANNOT JOIN ###.^8"); - } - } else { - return strcat("Welcome to Xonotic ", autocvar_g_xonoticversion); - } -} - void SendWelcomemessage(entity this, bool force_centerprint) { msg_entity = this; @@@ -1025,9 -1040,6 +1025,9 @@@ SendWelcomemessage_msg_type(this, force_centerprint, MSG_ONE); } +// NOTE csqc uses the active mutators list sent by this function +// to understand which mutators are enabled +// also note that they aren't all registered mutators, e.g. jetpack, low gravity void SendWelcomemessage_msg_type(entity this, bool force_centerprint, int msg_type) { WriteByte(msg_type, boolean(autocvar_g_campaign)); @@@ -1040,27 -1052,30 +1040,27 @@@ } WriteByte(msg_type, force_centerprint); WriteString(msg_type, autocvar_hostname); - WriteString(msg_type, GetClientVersionMessage(this)); + WriteString(msg_type, autocvar_g_xonoticversion); + WriteByte(msg_type, CS(this).version_mismatch); + WriteByte(msg_type, (CS(this).version < autocvar_gameversion)); MUTATOR_CALLHOOK(BuildMutatorsPrettyString, ""); string modifications = M_ARGV(0, string); - if(g_weaponarena) - { - if(g_weaponarena_random) - modifications = strcat(modifications, ", ", ftos(g_weaponarena_random), " of ", g_weaponarena_list, " Arena"); - else - modifications = strcat(modifications, ", ", g_weaponarena_list, " Arena"); - } - else if(cvar("g_balance_blaster_weaponstartoverride") == 0) + if (!g_weaponarena && cvar("g_balance_blaster_weaponstartoverride") == 0) modifications = strcat(modifications, ", No start weapons"); if(cvar("sv_gravity") < stof(cvar_defstring("sv_gravity"))) modifications = strcat(modifications, ", Low gravity"); if(g_weapon_stay && !g_cts) modifications = strcat(modifications, ", Weapons stay"); if(autocvar_g_jetpack) - modifications = strcat(modifications, ", Jet pack"); + modifications = strcat(modifications, ", Jetpack"); modifications = substring(modifications, 2, strlen(modifications) - 2); WriteString(msg_type, modifications); + WriteString(msg_type, g_weaponarena_list); + if(cache_lastmutatormsg != autocvar_g_mutatormsg) { strcpy(cache_lastmutatormsg, autocvar_g_mutatormsg); @@@ -1069,6 -1084,11 +1069,6 @@@ WriteString(msg_type, cache_mutatormsg); - string mutator_msg = ""; - MUTATOR_CALLHOOK(BuildGameplayTipsString, mutator_msg); - mutator_msg = M_ARGV(0, string); - - WriteString(msg_type, mutator_msg); // trust that the mutator will do proper formatting WriteString(msg_type, strreplace("\\n", "\n", autocvar_sv_motd)); } @@@ -1174,6 -1194,9 +1174,9 @@@ void ClientConnect(entity this MUTATOR_CALLHOOK(ClientConnect, this); + if (player_count == 1) + localcmd("\nsv_hook_firstjoin\n"); + if (IS_REAL_CLIENT(this) && !IS_PLAYER(this) && !autocvar_g_campaign) CS(this).motd_actived_time = -1; // the welcome message is shown by the client } @@@ -1242,6 -1265,9 +1245,9 @@@ void ClientDisconnect(entity this player_powerups_remove_all(this); // stop powerup sound ONREMOVE(this); + + if (player_count == 0) + localcmd("\nsv_hook_lastleave\n"); } void ChatBubbleThink(entity this)