]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Merge branch 'master' into terencehill/welcome_dialog_translatable 1000/head
authorterencehill <piuntn@gmail.com>
Tue, 12 Apr 2022 17:11:20 +0000 (19:11 +0200)
committerterencehill <piuntn@gmail.com>
Tue, 12 Apr 2022 17:11:20 +0000 (19:11 +0200)
1  2 
qcsrc/client/main.qc
qcsrc/server/client.qc

diff --combined qcsrc/client/main.qc
index 1c7013a83406f4da3f2e093baba2178a654004b2,0892bb6bf2bf0bd67a21ce4fa727a3c22ff988f5..5beca00bef44dd88d0d05ef17464ba8a7510e455
@@@ -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();
                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 097cafda03813137afac5c0c28f57fe0c6841c8d,2c3bdc25ccf07e90931e1c0704cd09c44a0ffc71..bacb82e071429c219127ce07e5cc15888d39ff57
@@@ -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;
        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));
        }
        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);
  
        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)