From f7c89557b0a6009fe620005358ce04adaa0493b4 Mon Sep 17 00:00:00 2001 From: sogla Date: Tue, 31 Mar 2026 15:47:54 +0200 Subject: [PATCH] fix: Replace welcome text to use fmt-style placeholders MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit May fix runtime issues when using special characters like `Lok’tar ogar` Replaces angle bracket placeholders in guild welcome messages with curly braces and updates substitution logic to use fmt for safer, clearer formatting. Improves flexibility and reduces risks from manual string replacement. --- conf/mod_starterguild.conf.dist | 10 +++++----- src/mod_starterguild.cpp | 15 +++++++++------ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/conf/mod_starterguild.conf.dist b/conf/mod_starterguild.conf.dist index ea15fb7..b6887d8 100644 --- a/conf/mod_starterguild.conf.dist +++ b/conf/mod_starterguild.conf.dist @@ -45,9 +45,9 @@ StarterGuild.Level = 0 # StarterGuild.HordeWelcomeText # StarterGuild.AllianceWelcomeText # Description: Welcome text sent to the player in chat when he is added to the guild. Can be set to not notify, by setting this config to an empty string. -# Default HordeWelcomeText: "Lok’tar ogar! Welcome to the horde starter guild ." -# Default AllianceWelcomeText: "Welcome to the alliance starter guild . For the Alliance!" -# Value: Any String, using either or in your string will cause them to be replaced with the starter guilds name or characters name respectivly. +# Default HordeWelcomeText: "Lok’tar ogar! Welcome to the horde starter guild {GUILD} {PLAYER}." +# Default AllianceWelcomeText: "Welcome to the alliance starter guild {GUILD} {PLAYER}. For the Alliance!" +# Value: Any String, using either {GUILD} or {PLAYER} in your string will cause them to be replaced with the starter guilds name or characters name respectivly. # -StarterGuild.HordeWelcomeText = "Lok’tar ogar! Welcome to the horde starter guild ." -StarterGuild.AllianceWelcomeText = "Welcome to the alliance starter guild . For the Alliance!" \ No newline at end of file +StarterGuild.HordeWelcomeText = "Lok’tar ogar! Welcome to the horde starter guild {GUILD} {PLAYER}." +StarterGuild.AllianceWelcomeText = "Welcome to the alliance starter guild {GUILD} {PLAYER}. For the Alliance!" diff --git a/src/mod_starterguild.cpp b/src/mod_starterguild.cpp index c01a89c..10f8895 100644 --- a/src/mod_starterguild.cpp +++ b/src/mod_starterguild.cpp @@ -1,5 +1,5 @@ #include "mod_starterguild.h" -#include +#include void StarterGuild::OnPlayerLogin(Player* player) { @@ -30,8 +30,8 @@ void StarterGuild::addPlayerToGuild(Player* player) const uint32 GUILD_ID_HORDE = sConfigMgr->GetOption("StarterGuild.Horde", 1); const uint32 GUILD_ID_ALLIANCE = sConfigMgr->GetOption("StarterGuild.Alliance", 2); - const std::string GUILD_WELCOME_TEXT_HORDE = sConfigMgr->GetOption("StarterGuild.HordeWelcomeText", "Lok’tar ogar! Welcome to the horde starter guild ."); - const std::string GUILD_WELCOME_TEXT_ALLIANCE = sConfigMgr->GetOption("StarterGuild.AllianceWelcomeText", "Welcome to the alliance starter guild . For the Alliance!"); + const std::string GUILD_WELCOME_TEXT_HORDE = sConfigMgr->GetOption("StarterGuild.HordeWelcomeText", "Lok’tar ogar! Welcome to the horde starter guild {GUILD} {PLAYER}."); + const std::string GUILD_WELCOME_TEXT_ALLIANCE = sConfigMgr->GetOption("StarterGuild.AllianceWelcomeText", "Welcome to the alliance starter guild {GUILD} {PLAYER}. For the Alliance!"); Guild* guild = sGuildMgr->GetGuildById(player->GetTeamId() == TEAM_ALLIANCE ? GUILD_ID_ALLIANCE : GUILD_ID_HORDE); @@ -45,10 +45,13 @@ void StarterGuild::addPlayerToGuild(Player* player) // Inform the player they have joined the guild std::string welcome_text = player->GetTeamId() == TEAM_ALLIANCE ? GUILD_WELCOME_TEXT_ALLIANCE : GUILD_WELCOME_TEXT_HORDE; - welcome_text = std::regex_replace(welcome_text, std::regex(""), player->GetGuildName()); - welcome_text = std::regex_replace(welcome_text, std::regex(""), player->GetName()); + welcome_text = fmt::format( + fmt::runtime(welcome_text), + fmt::arg("GUILD", player->GetGuildName()), + fmt::arg("PLAYER", player->GetPlayerName()) + ); - ChatHandler(player->GetSession()).SendSysMessage(welcome_text.c_str()); + ChatHandler(player->GetSession()).SendSysMessage(welcome_text); } else ChatHandler(player->GetSession()).SendSysMessage("The brotherhood has exceeded its membership limit.");