Skip to content

Commit

Permalink
feat(Core/Locale): rework game and module locale (#135)
Browse files Browse the repository at this point in the history
- Rename all `modules` to `module`
- Rename all `locales` to `locale`
- Move locale helpers to `LocaleCommon`
- Added a new function for check locale string module
  • Loading branch information
Winfidonarleyan authored Nov 10, 2020
1 parent 85139b7 commit f2ea49c
Show file tree
Hide file tree
Showing 21 changed files with 549 additions and 497 deletions.
24 changes: 10 additions & 14 deletions modules/mod-anti-ad/src/AntiAD_SC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "Player.h"
#include "AccountMgr.h"
#include "GameTime.h"
#include "ModulesLocale.h"
#include "ModuleLocale.h"
#include "MuteManager.h"
#include <vector>

Expand Down Expand Up @@ -57,11 +57,7 @@ class AntiAD

void Init()
{
if (sModulesLocale->GetStringsCount(MODULE_NAME) != StringLocales::ANTIAD_LOCALE_MAX - 1)
{
LOG_FATAL("modules.antiad", "> AntiAD: string locales (%u) for module != (%u)", sModulesLocale->GetStringsCount(MODULE_NAME), StringLocales::ANTIAD_LOCALE_MAX - 1);
return;
}
sModuleLocale->CheckStrings(MODULE_NAME, ANTIAD_LOCALE_MAX);

LoadDataFromDB();
}
Expand All @@ -72,13 +68,13 @@ class AntiAD

messages.clear();

LOG_INFO("modules.antiad", "Loading forbidden words...");
LOG_INFO("module.antiad", "Loading forbidden words...");

QueryResult result = WorldDatabase.PQuery("SELECT message FROM `anti_ad_messages`");
if (!result)
{
LOG_INFO("modules.antiad", ">> Loading 0 word. DB table `anti_ad_messages` is empty.");
LOG_INFO("modules.antiad", "");
LOG_INFO("module.antiad", ">> Loading 0 word. DB table `anti_ad_messages` is empty.");
LOG_INFO("module.antiad", "");
return;
}

Expand All @@ -89,8 +85,8 @@ class AntiAD

} while (result->NextRow());

LOG_INFO("modules.antiad", ">> Loaded forbidden words %u in %u ms", static_cast<uint32>(messages.size()), GetMSTimeDiffToNow(oldMSTime));
LOG_INFO("modules.antiad", "");
LOG_INFO("module.antiad", ">> Loaded forbidden words %u in %u ms", static_cast<uint32>(messages.size()), GetMSTimeDiffToNow(oldMSTime));
LOG_INFO("module.antiad", "");
}

bool IsNeedCheckChannel(uint8 channelType)
Expand Down Expand Up @@ -183,7 +179,7 @@ class AntiAD_Player : public PlayerScript
sMute->MutePlayer(player->GetName(), muteTime, "Console", "Advertisment");

if (CONF_GET_BOOL("AntiAD.SelfMessage.Enable"))
sModulesLocale->SendGlobalMessage(true, MODULE_NAME, StringLocales::ANTIAD_LOCALE_SEND_SELF, muteTime);
sModuleLocale->SendGlobalMessage(true, MODULE_NAME, StringLocales::ANTIAD_LOCALE_SEND_SELF, muteTime);
}

void SendGMTexts(Player* player, std::string ADMessage, std::string FullMessage)
Expand All @@ -192,10 +188,10 @@ class AntiAD_Player : public PlayerScript
std::string NameLink = ChatHandler(player->GetSession()).GetNameLink(player);

if (CONF_GET_BOOL("AntiAD.MessageGMsInWorld.Enable"))
sModulesLocale->SendGlobalMessage(true, MODULE_NAME, StringLocales::ANTIAD_LOCALE_SEND_GM_TEXT, NameLink.c_str(), ADMessage.c_str());
sModuleLocale->SendGlobalMessage(true, MODULE_NAME, StringLocales::ANTIAD_LOCALE_SEND_GM_TEXT, NameLink.c_str(), ADMessage.c_str());

if (CONF_GET_BOOL("AntiAD.FullMessageGMsInWorld.Enable"))
sModulesLocale->SendGlobalMessage(true, MODULE_NAME, StringLocales::ANTIAD_LOCALE_SEND_GM_TEXT_FULL, NameLink.c_str(), FullMessage.c_str());
sModuleLocale->SendGlobalMessage(true, MODULE_NAME, StringLocales::ANTIAD_LOCALE_SEND_GM_TEXT_FULL, NameLink.c_str(), FullMessage.c_str());
}

void CheckMessage(Player* player, std::string& msg)
Expand Down
12 changes: 6 additions & 6 deletions modules/mod-anticheat/src/Anticheat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void Anticheat::JumpHackDetection(Player* player, MovementInfo /* movementInfo *

if (m_Players[key].GetLastOpcode() == MSG_MOVE_JUMP && opcode == MSG_MOVE_JUMP)
{
LOG_INFO("modules", "> Anticheat: Jump-Hack detected player %s (%u)", player->GetName().c_str(), player->GetGUIDLow());
LOG_INFO("module", "> Anticheat: Jump-Hack detected player %s (%u)", player->GetName().c_str(), player->GetGUIDLow());
BuildReport(player);
}
}
Expand All @@ -96,7 +96,7 @@ void Anticheat::WalkOnWaterHackDetection(Player* player, MovementInfo movementI
player->HasAuraType(SPELL_AURA_WATER_WALK))
return;

LOG_INFO("modules", "> Anticheat: Walk on Water - Hack detected player %s (%u)", player->GetName().c_str(), player->GetGUIDLow());
LOG_INFO("module", "> Anticheat: Walk on Water - Hack detected player %s (%u)", player->GetName().c_str(), player->GetGUIDLow());

BuildReport(player);
}
Expand All @@ -120,7 +120,7 @@ void Anticheat::FlyHackDetection(Player* player, MovementInfo movementInfo)
if (!movementInfo.HasMovementFlag(MOVEMENTFLAG_CAN_FLY) && !movementInfo.HasMovementFlag(MOVEMENTFLAG_FLYING) && stricterChecks)
return;

LOG_INFO("modules", "> Anticheat: Fly-Hack detected player %s (%u)", player->GetName().c_str(), player->GetGUIDLow());
LOG_INFO("module", "> Anticheat: Fly-Hack detected player %s (%u)", player->GetName().c_str(), player->GetGUIDLow());

BuildReport(player);
}
Expand All @@ -147,7 +147,7 @@ void Anticheat::TeleportPlaneHackDetection(Player* player, MovementInfo movement
// we are not really walking there
if (z_diff > 1.0f)
{
LOG_INFO("modules", "AnticheatMgr:: Teleport To Plane - Hack detected player %s (%u)", player->GetName().c_str(), player->GetGUIDLow());
LOG_INFO("module", "AnticheatMgr:: Teleport To Plane - Hack detected player %s (%u)", player->GetName().c_str(), player->GetGUIDLow());
BuildReport(player);
}
}
Expand Down Expand Up @@ -203,7 +203,7 @@ void Anticheat::ClimbHackDetection(Player* player, MovementInfo movementInfo, ui

if (angle > CLIMB_ANGLE)
{
LOG_INFO("modules", "> Anticheat: Climb-Hack detected player %s (%u)", player->GetName().c_str(), player->GetGUIDLow());
LOG_INFO("module", "> Anticheat: Climb-Hack detected player %s (%u)", player->GetName().c_str(), player->GetGUIDLow());
BuildReport(player);
}
}
Expand Down Expand Up @@ -251,7 +251,7 @@ void Anticheat::SpeedHackDetection(Player* player, MovementInfo movementInfo)
if (clientSpeedRate > speedRate)
{
BuildReport(player);
LOG_INFO("modules", "> Anticheat: Speed-Hack detected player %s (%u)", player->GetName().c_str(), player->GetGUIDLow());
LOG_INFO("module", "> Anticheat: Speed-Hack detected player %s (%u)", player->GetName().c_str(), player->GetGUIDLow());
}
}

Expand Down
15 changes: 7 additions & 8 deletions modules/mod-boss-announcer/src/BossAnnouncer_SC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "StringFormat.h"
#include "GameConfig.h"
#include "GameLocale.h"
#include "ModulesLocale.h"
#include "ModuleLocale.h"

enum StringLocales : uint8
{
Expand Down Expand Up @@ -49,7 +49,7 @@ class Boss_Announcer_Player : public PlayerScript
if (!creature->isWorldBoss())
return;

sModulesLocale->SendGlobalMessage(false, MODULE_NAME, BOSS_AN_LOCALE_SEND_TEXT, player->GetName().c_str(), GetCreatureName(player, creature).c_str(), GetDiffString(player).c_str());
sModuleLocale->SendGlobalMessage(false, MODULE_NAME, BOSS_AN_LOCALE_SEND_TEXT, player->GetName().c_str(), GetCreatureName(player, creature).c_str(), GetDiffString(player).c_str());
};

private:
Expand All @@ -67,13 +67,13 @@ class Boss_Announcer_Player : public PlayerScript
switch (map->GetDifficulty())
{
case RAID_DIFFICULTY_10MAN_NORMAL:
return *sModulesLocale->GetModuleString(MODULE_NAME, BOSS_AN_LOCALE_10_MAN_NORMAL, localeIndex);
return *sModuleLocale->GetModuleString(MODULE_NAME, BOSS_AN_LOCALE_10_MAN_NORMAL, localeIndex);
case RAID_DIFFICULTY_10MAN_HEROIC:
return *sModulesLocale->GetModuleString(MODULE_NAME, BOSS_AN_LOCALE_10_MAN_HEROIC, localeIndex);
return *sModuleLocale->GetModuleString(MODULE_NAME, BOSS_AN_LOCALE_10_MAN_HEROIC, localeIndex);
case RAID_DIFFICULTY_25MAN_NORMAL:
return *sModulesLocale->GetModuleString(MODULE_NAME, BOSS_AN_LOCALE_25_MAN_NORMAL, localeIndex);
return *sModuleLocale->GetModuleString(MODULE_NAME, BOSS_AN_LOCALE_25_MAN_NORMAL, localeIndex);
case RAID_DIFFICULTY_25MAN_HEROIC:
return *sModulesLocale->GetModuleString(MODULE_NAME, BOSS_AN_LOCALE_25_MAN_HEROIC, localeIndex);
return *sModuleLocale->GetModuleString(MODULE_NAME, BOSS_AN_LOCALE_25_MAN_HEROIC, localeIndex);
default:
return "";
}
Expand Down Expand Up @@ -110,8 +110,7 @@ class Boss_Announcer_World : public WorldScript

void OnStartup() override
{
if (sModulesLocale->GetStringsCount(MODULE_NAME) != StringLocales::BOSS_AN_LOCALE_MAX - 1)
LOG_FATAL("modules.bossan", "> String locales (%u) for module != (%u)", sModulesLocale->GetStringsCount(MODULE_NAME), StringLocales::BOSS_AN_LOCALE_MAX - 1);
sModuleLocale->CheckStrings(MODULE_NAME, BOSS_AN_LOCALE_MAX);
}
};

Expand Down
23 changes: 11 additions & 12 deletions modules/mod-buff-command/src/BuffCommand_SC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "Log.h"
#include "ScriptMgr.h"
#include "GameConfig.h"
#include "ModulesLocale.h"
#include "ModuleLocale.h"
#include "Chat.h"
#include "Player.h"
#include "AccountMgr.h"
Expand Down Expand Up @@ -49,13 +49,13 @@ class BuffCommand

buffs.clear();

LOG_INFO("modules", "Loading buff for command .buff...");
LOG_INFO("module", "Loading buff for command .buff...");

QueryResult result = WorldDatabase.PQuery("SELECT SpellID FROM `player_buff`");
if (!result)
{
LOG_INFO("modules", ">> Loaded 0 buffs. DB table `player_buff` is empty.");
LOG_INFO("modules", "");
LOG_INFO("module", ">> Loaded 0 buffs. DB table `player_buff` is empty.");
LOG_INFO("module", "");
return;
}

Expand All @@ -66,16 +66,16 @@ class BuffCommand
auto spell = sSpellStore.LookupEntry(spellID);
if (!spell)
{
LOG_ERROR("modules", "-> Spell with number (%u) not found. Skip.", spellID);
LOG_ERROR("module", "-> Spell with number (%u) not found. Skip.", spellID);
continue;
}

buffs.push_back(spellID);

} while (result->NextRow());

LOG_INFO("modules", ">> Loaded %u buffs in %u ms", static_cast<uint32>(buffs.size()), GetMSTimeDiffToNow(oldMSTime));
LOG_INFO("modules", "");
LOG_INFO("module", ">> Loaded %u buffs in %u ms", static_cast<uint32>(buffs.size()), GetMSTimeDiffToNow(oldMSTime));
LOG_INFO("module", "");
}

void ApplyBuffs(Player* player)
Expand Down Expand Up @@ -113,7 +113,7 @@ class BuffCommand_Command : public CommandScript

if (!CONF_GET_BOOL("BuffCommand.Enable"))
{
sModulesLocale->SendPlayerMessage(player, MODULE_NAME, BC_LOCALE_COMMAND_DISABLE);
sModuleLocale->SendPlayerMessage(player, MODULE_NAME, BC_LOCALE_COMMAND_DISABLE);
handler->SetSentErrorMessage(true);
return false;
}
Expand All @@ -122,7 +122,7 @@ class BuffCommand_Command : public CommandScript

if (stringArg == "reload" && AccountMgr::IsAdminAccount(player->GetSession()->GetSecurity()))
{
LOG_INFO("modules", "Re-Loading player buff data...");
LOG_INFO("module", "Re-Loading player buff data...");
sBC->LoadDataFromDB();
handler->SendGlobalGMSysMessage("|cff6C8CD5#|cFFFF0000 DB Table|r `player_buff` |cFFFF0000reloaded.|r");
return true;
Expand All @@ -131,7 +131,7 @@ class BuffCommand_Command : public CommandScript
{
if (player->duel || player->GetMap()->IsBattleArena() || player->HasFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FEIGN_DEATH) || player->isDead(), player->IsInCombat() || player->IsInFlight())
{
sModulesLocale->SendPlayerMessage(player, MODULE_NAME, BC_LOCALE_COMMAND_CANT);
sModuleLocale->SendPlayerMessage(player, MODULE_NAME, BC_LOCALE_COMMAND_CANT);
handler->SetSentErrorMessage(true);
return false;
}
Expand Down Expand Up @@ -160,8 +160,7 @@ class BuffCommand_World : public WorldScript
if (!CONF_GET_BOOL("BuffCommand.Enable"))
return;

if (sModulesLocale->GetStringsCount(MODULE_NAME) != StringLocales::BC_LOCALE_MAX - 1)
LOG_FATAL("modules.bc", "> BC: String locales (%u) for module != (%u)", sModulesLocale->GetStringsCount(MODULE_NAME), StringLocales::BC_LOCALE_MAX - 1);
sModuleLocale->CheckStrings(MODULE_NAME, BC_LOCALE_MAX);

sBC->LoadDataFromDB();
}
Expand Down
18 changes: 9 additions & 9 deletions modules/mod-external-mail/src/ExternalMail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ bool ExMail::AddItems(uint32 itemID, uint32 itemCount)
ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(itemID);
if (!itemTemplate)
{
LOG_ERROR("modules", "> External Mail: Предмета под номером %u не существует. ID (%u)", itemID, ID);
LOG_ERROR("module", "> External Mail: Предмета под номером %u не существует. ID (%u)", itemID, ID);
return false;
}

if (itemCount < 1 || (itemTemplate->MaxCount > 0 && itemCount > static_cast<uint32>(itemTemplate->MaxCount)))
{
LOG_ERROR("modules", "> External Mail: Некорректное количество (%u) для предмета (%u). ID (%u)", itemCount, itemID, ID);
LOG_ERROR("module", "> External Mail: Некорректное количество (%u) для предмета (%u). ID (%u)", itemCount, itemID, ID);
return false;
}

Expand Down Expand Up @@ -69,7 +69,7 @@ void ExternalMail::GetMailsFromDB()
if (!result)
return;

LOG_TRACE("modules.em", "> External Mail: GetMailsFromDB");
LOG_TRACE("module.em", "> External Mail: GetMailsFromDB");

do
{
Expand All @@ -86,7 +86,7 @@ void ExternalMail::GetMailsFromDB()

if (!normalizePlayerName(PlayerName))
{
LOG_ERROR("modules", "> External Mail: Неверное имя персонажа (%s)", PlayerName.c_str());
LOG_ERROR("module", "> External Mail: Неверное имя персонажа (%s)", PlayerName.c_str());
continue;
}

Expand All @@ -100,14 +100,14 @@ void ExternalMail::GetMailsFromDB()
ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(ItemID);
if (!itemTemplate)
{
LOG_ERROR("modules", "> External Mail: Предмета под номером %u не существует. Пропуск", ItemID);
LOG_ERROR("module", "> External Mail: Предмета под номером %u не существует. Пропуск", ItemID);
_error = true;
}

auto const* creature = sObjectMgr->GetCreatureTemplate(CreatureEntry);
if (!creature)
{
LOG_ERROR("modules", "> External Mail: НПС под номером %u не существует. Пропуск", CreatureEntry);
LOG_ERROR("module", "> External Mail: НПС под номером %u не существует. Пропуск", CreatureEntry);
_error = true;
}

Expand Down Expand Up @@ -139,7 +139,7 @@ void ExternalMail::SendMails()
if (_store.empty())
return;

LOG_TRACE("modules.em", "> External Mail: SendMails");
LOG_TRACE("module.em", "> External Mail: SendMails");

SQLTransaction trans = CharacterDatabase.BeginTransaction();

Expand Down Expand Up @@ -173,8 +173,8 @@ void ExternalMail::SendMails()

CharacterDatabase.CommitTransaction(trans);

LOG_DEBUG("modules", "> External Mail: Отправлено (%u) писем", static_cast<uint32>(_store.size()));
LOG_DEBUG("modules", "");
LOG_DEBUG("module", "> External Mail: Отправлено (%u) писем", static_cast<uint32>(_store.size()));
LOG_DEBUG("module", "");

// Clear for next time
_store.clear();
Expand Down
Loading

0 comments on commit f2ea49c

Please sign in to comment.