Skip to content

Commit

Permalink
refactor(Core/ObjectMgr): Change GetAcoreString from char const* to s… (
Browse files Browse the repository at this point in the history
#21213)

...ring
  • Loading branch information
Kitzunu authored Feb 1, 2025
1 parent 1373376 commit 9e9a2fe
Show file tree
Hide file tree
Showing 25 changed files with 71 additions and 95 deletions.
20 changes: 11 additions & 9 deletions apps/codestyle/codestyle-sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def parsing_file(files: list) -> None:
multiple_blank_lines_check(file, file_path)
trailing_whitespace_check(file, file_path)
sql_check(file, file_path)
insert_safety_check(file, file_path)
insert_delete_safety_check(file, file_path)
semicolon_check(file, file_path)
except UnicodeDecodeError:
print(f"\nCould not decode file {file_path}")
Expand Down Expand Up @@ -102,16 +102,10 @@ def trailing_whitespace_check(file: io, file_path: str) -> None:
def sql_check(file: io, file_path: str) -> None:
global error_handler, results
file.seek(0) # Reset file pointer to the beginning
not_delete = ["creature_template", "gameobject_template", "item_template", "quest_template"]
check_failed = False

# Parse all the file
for line_number, line in enumerate(file, start = 1):
for table in not_delete:
if f"DELETE FROM `{table}`" in line:
print(
f"Entries from this {table} should not be deleted! {file_path} at line {line_number}")
check_failed = True
if [match for match in ['broadcast_text'] if match in line]:
print(
f"DON'T EDIT broadcast_text TABLE UNLESS YOU KNOW WHAT YOU ARE DOING!\nThis error can safely be ignored if the changes are approved to be sniffed: {file_path} at line {line_number}")
Expand Down Expand Up @@ -140,9 +134,10 @@ def sql_check(file: io, file_path: str) -> None:
error_handler = True
results["SQL codestyle check"] = "Failed"

def insert_safety_check(file: io, file_path: str) -> None:
def insert_delete_safety_check(file: io, file_path: str) -> None:
global error_handler, results
file.seek(0) # Reset file pointer to the beginning
not_delete = ["creature_template", "gameobject_template", "item_template", "quest_template"]
check_failed = False
previous_line = ""

Expand All @@ -154,11 +149,18 @@ def insert_safety_check(file: io, file_path: str) -> None:
print(f"No DELETE keyword found after the INSERT in {file_path} at line {line_number}\nIf this error is intended, please advert a maintainer")
check_failed = True
previous_line = line
match = re.match(r"DELETE FROM\s+`([^`]+)`", line, re.IGNORECASE)
if match:
table_name = match.group(1)
if table_name in not_delete:
print(
f"Entries from {table} should not be deleted! {file_path} at line {line_number}")
check_failed = True

# Handle the script error and update the result output
if check_failed:
error_handler = True
results["INSERT safety usage check"] = "Failed"
results["INSERT & DELETE safety usage check"] = "Failed"

def semicolon_check(file: io, file_path: str) -> None:
global error_handler, results
Expand Down
2 changes: 2 additions & 0 deletions data/sql/updates/pending_db_world/rev_1737290143156167600.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--
DELETE FROM `acore_string` WHERE `entry` = 6617;
2 changes: 1 addition & 1 deletion src/server/game/AI/SmartScripts/SmartScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2696,7 +2696,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
}
case SMART_ACTION_PLAYER_TALK:
{
char const* text = sObjectMgr->GetAcoreString(e.action.playerTalk.textId, DEFAULT_LOCALE);
std::string text = sObjectMgr->GetAcoreString(e.action.playerTalk.textId, DEFAULT_LOCALE);

if (!targets.empty())
for (WorldObject* target : targets)
Expand Down
19 changes: 8 additions & 11 deletions src/server/game/Battlegrounds/Battleground.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ namespace Acore

void operator()(WorldPacket& data, LocaleConstant loc_idx)
{
char const* text = sObjectMgr->GetAcoreString(_textId, loc_idx);
std::string strtext = sObjectMgr->GetAcoreString(_textId, loc_idx);
char const* text = strtext.c_str();
if (_args)
{
// we need copy va_list before use or original va_list will corrupted
Expand Down Expand Up @@ -95,9 +96,12 @@ namespace Acore

void operator()(WorldPacket& data, LocaleConstant loc_idx)
{
char const* text = sObjectMgr->GetAcoreString(_textId, loc_idx);
char const* arg1str = _arg1 ? sObjectMgr->GetAcoreString(_arg1, loc_idx) : "";
char const* arg2str = _arg2 ? sObjectMgr->GetAcoreString(_arg2, loc_idx) : "";
std::string strtext = sObjectMgr->GetAcoreString(_textId, loc_idx);
char const* text = strtext.c_str();
std::string stragr1str = sObjectMgr->GetAcoreString(_arg1, loc_idx);
char const* arg1str = _arg1 ? stragr1str.c_str() : "";
std::string strarg2str = sObjectMgr->GetAcoreString(_arg2, loc_idx);
char const* arg2str = _arg2 ? strarg2str.c_str() : "";

char str[2048];
snprintf(str, 2048, text, arg1str, arg2str);
Expand Down Expand Up @@ -1659,13 +1663,6 @@ void Battleground::EndNow()
SetEndTime(0);
}

// To be removed
char const* Battleground::GetAcoreString(int32 entry)
{
// FIXME: now we have different DBC locales and need localized message for each target client
return sObjectMgr->GetAcoreStringForDBCLocale(entry);
}

void Battleground::HandleTriggerBuff(GameObject* gameObject)
{
// Xinef: crash fix?
Expand Down
2 changes: 0 additions & 2 deletions src/server/game/Battlegrounds/Battleground.h
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,6 @@ class Battleground

void DoorOpen(uint32 type);
void DoorClose(uint32 type);
//to be removed
const char* GetAcoreString(int32 entry);

virtual bool HandlePlayerUnderMap(Player* /*player*/) { return false; }

Expand Down
4 changes: 2 additions & 2 deletions src/server/game/Chat/Chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Player* ChatHandler::GetPlayer() const
return m_session ? m_session->GetPlayer() : nullptr;
}

char const* ChatHandler::GetAcoreString(uint32 entry) const
std::string ChatHandler::GetAcoreString(uint32 entry) const
{
return m_session->GetAcoreString(entry);
}
Expand Down Expand Up @@ -881,7 +881,7 @@ std::string ChatHandler::GetNameLink(Player* chr) const
return playerLink(chr->GetName());
}

char const* CliHandler::GetAcoreString(uint32 entry) const
std::string CliHandler::GetAcoreString(uint32 entry) const
{
return sObjectMgr->GetAcoreStringForDBCLocale(entry);
}
Expand Down
4 changes: 2 additions & 2 deletions src/server/game/Chat/Chat.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class AC_GAME_API ChatHandler
}

// function with different implementation for chat/console
virtual char const* GetAcoreString(uint32 entry) const;
virtual std::string GetAcoreString(uint32 entry) const;
virtual void SendSysMessage(std::string_view str, bool escapeCharacters = false);

void SendSysMessage(uint32 entry);
Expand Down Expand Up @@ -258,7 +258,7 @@ class AC_GAME_API CliHandler : public ChatHandler
explicit CliHandler(void* callbackArg, Print* zprint) : m_callbackArg(callbackArg), m_print(zprint) { }

// overwrite functions
char const* GetAcoreString(uint32 entry) const override;
std::string GetAcoreString(uint32 entry) const override;
void SendSysMessage(std::string_view, bool escapeCharacters) override;
bool ParseCommands(std::string_view str) override;
std::string GetNameLink() const override;
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Chat/ChatCommands/ChatCommandHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void Acore::Impl::ChatCommands::SendErrorMessageToHandler(ChatHandler* handler,
handler->SetSentErrorMessage(true);
}

char const* Acore::Impl::ChatCommands::GetAcoreString(ChatHandler const* handler, AcoreStrings which)
std::string Acore::Impl::ChatCommands::GetAcoreString(ChatHandler const* handler, AcoreStrings which)
{
return handler->GetAcoreString(which);
}
2 changes: 1 addition & 1 deletion src/server/game/Chat/ChatCommands/ChatCommandHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ namespace Acore::Impl::ChatCommands
};

AC_GAME_API void SendErrorMessageToHandler(ChatHandler* handler, std::string_view str);
AC_GAME_API char const* GetAcoreString(ChatHandler const* handler, AcoreStrings which);
AC_GAME_API std::string GetAcoreString(ChatHandler const* handler, AcoreStrings which);
template <typename... Ts>
std::string FormatAcoreString(ChatHandler const* handler, AcoreStrings which, Ts&&... args)
{
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Entities/Player/PlayerUpdates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ void Player::UpdateLocalChannels(uint32 newZone)

if (channel->flags & CHANNEL_DBC_FLAG_CITY_ONLY)
currentNameExt = sObjectMgr->GetAcoreStringForDBCLocale(
LANG_CHANNEL_CITY);
LANG_CHANNEL_CITY).c_str();
else
currentNameExt = current_zone_name.c_str();

Expand Down
17 changes: 9 additions & 8 deletions src/server/game/Globals/ObjectMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8770,19 +8770,20 @@ bool ObjectMgr::LoadAcoreStrings()
return true;
}

char const* ObjectMgr::GetAcoreString(uint32 entry, LocaleConstant locale) const
std::string ObjectMgr::GetAcoreString(uint32 entry, LocaleConstant locale) const
{
if (AcoreString const* ts = GetAcoreString(entry))
AcoreString const* as = GetAcoreString(entry);
if (as && !as->Content.empty())
{
if (ts->Content.size() > std::size_t(locale) && !ts->Content[locale].empty())
return ts->Content[locale].c_str();
if (as->Content.size() > std::size_t(locale) && !as->Content[locale].empty())
return as->Content[locale];

return ts->Content[DEFAULT_LOCALE].c_str();
return as->Content[DEFAULT_LOCALE];
}

LOG_ERROR("sql.sql", "Acore string entry {} not found in DB.", entry);

return "<error>";
std::string msg = Acore::StringFormat("No entry for acore_string ({}) in DB.", entry);
LOG_ERROR("sql.sql", msg);
return msg;
}

void ObjectMgr::LoadFishingBaseSkillLevel()
Expand Down
4 changes: 2 additions & 2 deletions src/server/game/Globals/ObjectMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -1314,8 +1314,8 @@ class ObjectMgr

return &itr->second;
}
[[nodiscard]] char const* GetAcoreString(uint32 entry, LocaleConstant locale) const;
[[nodiscard]] char const* GetAcoreStringForDBCLocale(uint32 entry) const { return GetAcoreString(entry, DBCLocaleIndex); }
[[nodiscard]] std::string GetAcoreString(uint32 entry, LocaleConstant locale) const;
[[nodiscard]] std::string GetAcoreStringForDBCLocale(uint32 entry) const { return GetAcoreString(entry, DBCLocaleIndex); }
[[nodiscard]] LocaleConstant GetDBCLocaleIndex() const { return DBCLocaleIndex; }
void SetDBCLocaleIndex(LocaleConstant locale) { DBCLocaleIndex = locale; }

Expand Down
3 changes: 1 addition & 2 deletions src/server/game/Miscellaneous/Language.h
Original file line number Diff line number Diff line change
Expand Up @@ -1169,8 +1169,7 @@ enum AcoreStrings

LANG_GM_SILENCE = 6616, // "Silence is ON for %s" - Spell 1852

// Used for .string command
LANG_NO_ACORE_STRING_FOUND = 6617,
// Free strings 6617-7522

LANG_WORLD_CLOSED = 7523,
LANG_WORLD_OPENED = 7524,
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Server/WorldSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ bool WorldSession::DisallowHyperlinksAndMaybeKick(std::string_view str)
return false;
}

char const* WorldSession::GetAcoreString(uint32 entry) const
std::string WorldSession::GetAcoreString(uint32 entry) const
{
return sObjectMgr->GetAcoreString(entry, GetSessionDbLocaleIndex());
}
Expand Down
4 changes: 2 additions & 2 deletions src/server/game/Server/WorldSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ class WorldSession
void SendAreaTriggerMessage(std::string_view str);

template<typename... Args>
void SendAreaTriggerMessage(char const* fmt, Args&&... args)
void SendAreaTriggerMessage(std::string fmt, Args&&... args)
{
if (!m_playerLoading)
SendAreaTriggerMessage(Acore::StringFormat(fmt, std::forward<Args>(args)...));
Expand Down Expand Up @@ -510,7 +510,7 @@ class WorldSession
// Locales
LocaleConstant GetSessionDbcLocale() const { return m_sessionDbcLocale; }
LocaleConstant GetSessionDbLocaleIndex() const { return m_sessionDbLocaleIndex; }
char const* GetAcoreString(uint32 entry) const;
std::string GetAcoreString(uint32 entry) const;
std::string const* GetModuleString(std::string module, uint32 id) const;

uint32 GetLatency() const { return m_latency; }
Expand Down
3 changes: 2 additions & 1 deletion src/server/game/Texts/ChatTextBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ void Acore::CustomChatTextBuilder::operator()(WorldPacket& data, LocaleConstant

void Acore::AcoreStringChatBuilder::operator()(WorldPacket& data, LocaleConstant locale) const
{
char const* text = sObjectMgr->GetAcoreString(_textId, locale);
std::string strtext = sObjectMgr->GetAcoreString(_textId, locale);
char const* text = strtext.c_str();

if (_args)
{
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/World/IWorld.h
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ class IWorld
virtual void SendGlobalMessage(WorldPacket const* packet, WorldSession* self = nullptr, TeamId teamId = TEAM_NEUTRAL) = 0;
virtual void SendGlobalGMMessage(WorldPacket const* packet, WorldSession* self = nullptr, TeamId teamId = TEAM_NEUTRAL) = 0;
virtual bool SendZoneMessage(uint32 zone, WorldPacket const* packet, WorldSession* self = nullptr, TeamId teamId = TEAM_NEUTRAL) = 0;
virtual void SendZoneText(uint32 zone, const char* text, WorldSession* self = nullptr, TeamId teamId = TEAM_NEUTRAL) = 0;
virtual void SendZoneText(uint32 zone, std::string text, WorldSession* self = nullptr, TeamId teamId = TEAM_NEUTRAL) = 0;
virtual void SendServerMessage(ServerMessageType messageID, std::string stringParam = "", Player* player = nullptr) = 0;
[[nodiscard]] virtual bool IsShuttingDown() const = 0;
[[nodiscard]] virtual uint32 GetShutDownTimeLeft() const = 0;
Expand Down
7 changes: 4 additions & 3 deletions src/server/game/World/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2572,7 +2572,8 @@ namespace Acore
explicit WorldWorldTextBuilder(uint32 textId, va_list* args = nullptr) : i_textId(textId), i_args(args) {}
void operator()(WorldPacketList& data_list, LocaleConstant loc_idx)
{
char const* text = sObjectMgr->GetAcoreString(i_textId, loc_idx);
std::string strtext = sObjectMgr->GetAcoreString(i_textId, loc_idx);
char const* text = strtext.c_str();

if (i_args)
{
Expand Down Expand Up @@ -2631,10 +2632,10 @@ bool World::SendZoneMessage(uint32 zone, WorldPacket const* packet, WorldSession
}

/// Send a System Message to all players in the zone (except self if mentioned)
void World::SendZoneText(uint32 zone, const char* text, WorldSession* self, TeamId teamId)
void World::SendZoneText(uint32 zone, std::string text, WorldSession* self, TeamId teamId)
{
WorldPacket data;
ChatHandler::BuildChatPacket(data, CHAT_MSG_SYSTEM, LANG_UNIVERSAL, nullptr, nullptr, text);
ChatHandler::BuildChatPacket(data, CHAT_MSG_SYSTEM, LANG_UNIVERSAL, nullptr, nullptr, text.c_str());
SendZoneMessage(zone, &data, self, teamId);
}

Expand Down
2 changes: 1 addition & 1 deletion src/server/game/World/World.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class World: public IWorld
void SendGlobalMessage(WorldPacket const* packet, WorldSession* self = nullptr, TeamId teamId = TEAM_NEUTRAL) override;
void SendGlobalGMMessage(WorldPacket const* packet, WorldSession* self = nullptr, TeamId teamId = TEAM_NEUTRAL) override;
bool SendZoneMessage(uint32 zone, WorldPacket const* packet, WorldSession* self = nullptr, TeamId teamId = TEAM_NEUTRAL) override;
void SendZoneText(uint32 zone, const char* text, WorldSession* self = nullptr, TeamId teamId = TEAM_NEUTRAL) override;
void SendZoneText(uint32 zone, std::string text, WorldSession* self = nullptr, TeamId teamId = TEAM_NEUTRAL) override;
void SendServerMessage(ServerMessageType messageID, std::string stringParam = "", Player* player = nullptr) override;

/// Are we in the middle of a shutdown?
Expand Down
4 changes: 2 additions & 2 deletions src/server/scripts/Commands/cs_character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ class character_commandscript : public CommandScript
Player const* target = player->GetConnectedPlayer();

LocaleConstant loc = handler->GetSessionDbcLocale();
char const* knownStr = handler->GetAcoreString(LANG_KNOWN);
std::string knownStr = handler->GetAcoreString(LANG_KNOWN);

// Search in CharTitles.dbc
for (uint32 id = 0; id < sCharTitlesStore.GetNumRows(); id++)
Expand All @@ -308,7 +308,7 @@ class character_commandscript : public CommandScript
if (!*name)
continue;

char const* activeStr = "";
std::string activeStr = "";
if (target->GetUInt32Value(PLAYER_CHOSEN_TITLE) == titleInfo->bit_index)
activeStr = handler->GetAcoreString(LANG_ACTIVE);

Expand Down
10 changes: 2 additions & 8 deletions src/server/scripts/Commands/cs_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,22 @@ class event_commandscript : public CommandScript
GameEventMgr::GameEventDataMap const& events = sGameEventMgr->GetEventMap();
GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();

char const* active = handler->GetAcoreString(LANG_ACTIVE);
std::string active = handler->GetAcoreString(LANG_ACTIVE);

for (uint16 eventId : activeEvents)
{
GameEventData const& eventData = events[eventId];

if (handler->GetSession())
{
handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CHAT, eventId, eventId, eventData.description, active);
}
else
{
handler->PSendSysMessage(LANG_EVENT_ENTRY_LIST_CONSOLE, eventId, eventData.description, active);
}

++counter;
}

if (counter == 0)
{
handler->SendSysMessage(LANG_NOEVENTFOUND);
}

handler->SetSentErrorMessage(true);

Expand All @@ -108,7 +102,7 @@ class event_commandscript : public CommandScript

GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr->GetActiveEventList();
bool active = activeEvents.find(eventId) != activeEvents.end();
char const* activeStr = active ? handler->GetAcoreString(LANG_ACTIVE) : "";
std::string activeStr = active ? handler->GetAcoreString(LANG_ACTIVE) : "";

std::string startTimeStr = Acore::Time::TimeToTimestampStr(Seconds(eventData.start));
std::string endTimeStr = Acore::Time::TimeToTimestampStr(Seconds(eventData.end));
Expand Down
4 changes: 2 additions & 2 deletions src/server/scripts/Commands/cs_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,8 @@ class list_commandscript : public CommandScript

wstrToLower(namePart);

char const* talentStr = handler->GetAcoreString(LANG_TALENT);
char const* passiveStr = handler->GetAcoreString(LANG_PASSIVE);
std::string talentStr = handler->GetAcoreString(LANG_TALENT);
std::string passiveStr = handler->GetAcoreString(LANG_PASSIVE);

Unit::AuraApplicationMap const& auras = unit->GetAppliedAuras();
handler->PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS, auras.size());
Expand Down
Loading

0 comments on commit 9e9a2fe

Please sign in to comment.