Core: Cleanup locale handling.

It also fixes the recent problem of strange strings.

--HG--
branch : trunk
This commit is contained in:
linencloth
2010-09-17 07:04:29 +02:00
parent 5de48a67c6
commit d8a854d6e0
19 changed files with 39 additions and 45 deletions
@@ -48,7 +48,7 @@ namespace Trinity
public: public:
AchievementChatBuilder(Player const& pl, ChatMsg msgtype, int32 textId, uint32 ach_id) AchievementChatBuilder(Player const& pl, ChatMsg msgtype, int32 textId, uint32 ach_id)
: i_player(pl), i_msgtype(msgtype), i_textId(textId), i_achievementId(ach_id) {} : i_player(pl), i_msgtype(msgtype), i_textId(textId), i_achievementId(ach_id) {}
void operator()(WorldPacket& data, int32 loc_idx) void operator()(WorldPacket& data, LocaleConstant loc_idx)
{ {
char const* text = sObjectMgr.GetTrinityString(i_textId,loc_idx); char const* text = sObjectMgr.GetTrinityString(i_textId,loc_idx);
@@ -44,7 +44,7 @@ namespace Trinity
public: public:
BattlegroundChatBuilder(ChatMsg msgtype, int32 textId, Player const* source, va_list* args = NULL) BattlegroundChatBuilder(ChatMsg msgtype, int32 textId, Player const* source, va_list* args = NULL)
: i_msgtype(msgtype), i_textId(textId), i_source(source), i_args(args) {} : i_msgtype(msgtype), i_textId(textId), i_source(source), i_args(args) {}
void operator()(WorldPacket& data, int32 loc_idx) void operator()(WorldPacket& data, LocaleConstant loc_idx)
{ {
char const* text = sObjectMgr.GetTrinityString(i_textId,loc_idx); char const* text = sObjectMgr.GetTrinityString(i_textId,loc_idx);
@@ -89,7 +89,7 @@ namespace Trinity
public: public:
Battleground2ChatBuilder(ChatMsg msgtype, int32 textId, Player const* source, int32 arg1, int32 arg2) Battleground2ChatBuilder(ChatMsg msgtype, int32 textId, Player const* source, int32 arg1, int32 arg2)
: i_msgtype(msgtype), i_textId(textId), i_source(source), i_arg1(arg1), i_arg2(arg2) {} : i_msgtype(msgtype), i_textId(textId), i_source(source), i_arg1(arg1), i_arg2(arg2) {}
void operator()(WorldPacket& data, int32 loc_idx) void operator()(WorldPacket& data, LocaleConstant loc_idx)
{ {
char const* text = sObjectMgr.GetTrinityString(i_textId,loc_idx); char const* text = sObjectMgr.GetTrinityString(i_textId,loc_idx);
char const* arg1str = i_arg1 ? sObjectMgr.GetTrinityString(i_arg1,loc_idx) : ""; char const* arg1str = i_arg1 ? sObjectMgr.GetTrinityString(i_arg1,loc_idx) : "";
@@ -2385,9 +2385,9 @@ TrainerSpellData const* Creature::GetTrainerSpells() const
} }
// overwrite WorldObject function for proper name localization // overwrite WorldObject function for proper name localization
const char* Creature::GetNameForLocaleIdx(int32 loc_idx) const const char* Creature::GetNameForLocaleIdx(LocaleConstant loc_idx) const
{ {
if (loc_idx >= 0) if (loc_idx != DEFAULT_LOCALE)
{ {
uint8 uloc_idx = uint8(loc_idx); uint8 uloc_idx = uint8(loc_idx);
CreatureLocale const *cl = sObjectMgr.GetCreatureLocale(GetEntry()); CreatureLocale const *cl = sObjectMgr.GetCreatureLocale(GetEntry());
+1 -1
View File
@@ -526,7 +526,7 @@ class Creature : public Unit, public GridObject<Creature>
void YellToZone(int32 textId, uint32 language, uint64 TargetGuid) { MonsterYellToZone(textId,language,TargetGuid); } void YellToZone(int32 textId, uint32 language, uint64 TargetGuid) { MonsterYellToZone(textId,language,TargetGuid); }
// overwrite WorldObject function for proper name localization // overwrite WorldObject function for proper name localization
const char* GetNameForLocaleIdx(int32 locale_idx) const; const char* GetNameForLocaleIdx(LocaleConstant locale_idx) const;
void setDeathState(DeathState s); // overwrite virtual Unit::setDeathState void setDeathState(DeathState s); // overwrite virtual Unit::setDeathState
bool FallGround(); bool FallGround();
@@ -1710,9 +1710,9 @@ void GameObject::EventInform(uint32 eventId)
} }
// overwrite WorldObject function for proper name localization // overwrite WorldObject function for proper name localization
const char* GameObject::GetNameForLocaleIdx(int32 loc_idx) const const char* GameObject::GetNameForLocaleIdx(LocaleConstant loc_idx) const
{ {
if (loc_idx >= 0) if (loc_idx != DEFAULT_LOCALE)
{ {
uint8 uloc_idx = uint8(loc_idx); uint8 uloc_idx = uint8(loc_idx);
if (GameObjectLocale const *cl = sObjectMgr.GetGameObjectLocale(GetEntry())) if (GameObjectLocale const *cl = sObjectMgr.GetGameObjectLocale(GetEntry()))
@@ -622,7 +622,7 @@ class GameObject : public WorldObject, public GridObject<GameObject>
void YellToZone(int32 textId, uint32 language, uint64 TargetGuid) { MonsterYellToZone(textId,language,TargetGuid); } void YellToZone(int32 textId, uint32 language, uint64 TargetGuid) { MonsterYellToZone(textId,language,TargetGuid); }
// overwrite WorldObject function for proper name localization // overwrite WorldObject function for proper name localization
const char* GetNameForLocaleIdx(int32 locale_idx) const; const char* GetNameForLocaleIdx(LocaleConstant locale_idx) const;
void SaveToDB(); void SaveToDB();
void SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask); void SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask);
+2 -2
View File
@@ -1634,7 +1634,7 @@ namespace Trinity
public: public:
MonsterChatBuilder(WorldObject const& obj, ChatMsg msgtype, int32 textId, uint32 language, uint64 targetGUID) MonsterChatBuilder(WorldObject const& obj, ChatMsg msgtype, int32 textId, uint32 language, uint64 targetGUID)
: i_object(obj), i_msgtype(msgtype), i_textId(textId), i_language(language), i_targetGUID(targetGUID) {} : i_object(obj), i_msgtype(msgtype), i_textId(textId), i_language(language), i_targetGUID(targetGUID) {}
void operator()(WorldPacket& data, int32 loc_idx) void operator()(WorldPacket& data, LocaleConstant loc_idx)
{ {
char const* text = sObjectMgr.GetTrinityString(i_textId,loc_idx); char const* text = sObjectMgr.GetTrinityString(i_textId,loc_idx);
@@ -1715,7 +1715,7 @@ void WorldObject::MonsterWhisper(int32 textId, uint64 receiver, bool IsBossWhisp
if (!player || !player->GetSession()) if (!player || !player->GetSession())
return; return;
uint32 loc_idx = player->GetSession()->GetSessionDbLocaleIndex(); LocaleConstant loc_idx = player->GetSession()->GetSessionDbLocaleIndex();
char const* text = sObjectMgr.GetTrinityString(textId, loc_idx); char const* text = sObjectMgr.GetTrinityString(textId, loc_idx);
WorldPacket data(SMSG_MESSAGECHAT, 200); WorldPacket data(SMSG_MESSAGECHAT, 200);
+1 -1
View File
@@ -612,7 +612,7 @@ class WorldObject : public Object, public WorldLocation
const char* GetName() const { return m_name.c_str(); } const char* GetName() const { return m_name.c_str(); }
void SetName(const std::string& newname) { m_name=newname; } void SetName(const std::string& newname) { m_name=newname; }
virtual const char* GetNameForLocaleIdx(int32 /*locale_idx*/) const { return GetName(); } virtual const char* GetNameForLocaleIdx(LocaleConstant /*locale_idx*/) const { return GetName(); }
float GetDistance(const WorldObject *obj) const float GetDistance(const WorldObject *obj) const
{ {
+10 -16
View File
@@ -7640,31 +7640,25 @@ PetNameInvalidReason ObjectMgr::CheckPetName(const std::string& name)
return PET_NAME_SUCCESS; return PET_NAME_SUCCESS;
} }
int ObjectMgr::GetIndexForLocale(LocaleConstant loc) LocaleConstant ObjectMgr::GetIndexForLocale(LocaleConstant loc)
{ {
if (loc == LOCALE_enUS)
return -1;
for (size_t i=0; i < m_LocalForIndex.size(); ++i) for (size_t i=0; i < m_LocalForIndex.size(); ++i)
if (m_LocalForIndex[i] == loc) if (m_LocalForIndex[i] == loc)
return i; return loc;
return -1; return DEFAULT_LOCALE;
} }
LocaleConstant ObjectMgr::GetLocaleForIndex(int i) LocaleConstant ObjectMgr::GetLocaleForIndex(int i)
{ {
if (i < 0 || i >= int(m_LocalForIndex.size())) if (i < 0 || i >= int(m_LocalForIndex.size()))
return LOCALE_enUS; return DEFAULT_LOCALE;
return m_LocalForIndex[i]; return m_LocalForIndex[i];
} }
int ObjectMgr::GetOrNewIndexForLocale(LocaleConstant loc) int ObjectMgr::GetOrNewIndexForLocale(LocaleConstant loc)
{ {
if (loc == LOCALE_enUS)
return -1;
for (size_t i = 0; i < m_LocalForIndex.size(); ++i) for (size_t i = 0; i < m_LocalForIndex.size(); ++i)
if (m_LocalForIndex[i] == loc) if (m_LocalForIndex[i] == loc)
return i; return i;
@@ -7815,8 +7809,7 @@ bool ObjectMgr::LoadTrinityStrings(char const* table, int32 min_value, int32 max
data.Content.resize(1); data.Content.resize(1);
++count; ++count;
data.Default = fields[1].GetCppString(); for (uint8 i = 0; i < MAX_LOCALE; ++i)
for (uint8 i = 1; i < MAX_LOCALE; ++i)
{ {
std::string str = fields[i + 1].GetCppString(); std::string str = fields[i + 1].GetCppString();
AddLocaleString(str, LocaleConstant(i), data.Content); AddLocaleString(str, LocaleConstant(i), data.Content);
@@ -7832,13 +7825,14 @@ bool ObjectMgr::LoadTrinityStrings(char const* table, int32 min_value, int32 max
return true; return true;
} }
const char *ObjectMgr::GetTrinityString(int32 entry, int locale_idx) const const char *ObjectMgr::GetTrinityString(int32 entry, LocaleConstant locale_idx) const
{ {
if (TrinityStringLocale const *msl = GetTrinityStringLocale(entry)) if (TrinityStringLocale const *msl = GetTrinityStringLocale(entry))
{ {
std::string s = msl->Default; if (msl->Content.size() > size_t(locale_idx) && !msl->Content[locale_idx].empty())
GetLocaleString(msl->Content, locale_idx, s); return msl->Content[locale_idx].c_str();
return s.c_str();
return msl->Content[DEFAULT_LOCALE].c_str();
} }
if (entry > 0) if (entry > 0)
+4 -5
View File
@@ -174,7 +174,6 @@ typedef UNORDERED_MAP<uint64/*(instance,guid) pair*/,time_t> RespawnTimes;
struct TrinityStringLocale struct TrinityStringLocale
{ {
std::string Default;
StringVector Content; StringVector Content;
}; };
@@ -864,9 +863,9 @@ class ObjectMgr
if (itr == mTrinityStringLocaleMap.end()) return NULL; if (itr == mTrinityStringLocaleMap.end()) return NULL;
return &itr->second; return &itr->second;
} }
const char *GetTrinityString(int32 entry, int locale_idx) const; const char *GetTrinityString(int32 entry, LocaleConstant locale_idx) const;
const char *GetTrinityStringForDBCLocale(int32 entry) const { return GetTrinityString(entry,DBCLocaleIndex); } const char *GetTrinityStringForDBCLocale(int32 entry) const { return GetTrinityString(entry,DBCLocaleIndex); }
int32 GetDBCLocaleIndex() const { return DBCLocaleIndex; } LocaleConstant GetDBCLocaleIndex() const { return DBCLocaleIndex; }
void SetDBCLocaleIndex(uint32 lang) { DBCLocaleIndex = GetIndexForLocale(LocaleConstant(lang)); } void SetDBCLocaleIndex(uint32 lang) { DBCLocaleIndex = GetIndexForLocale(LocaleConstant(lang)); }
void AddCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid, uint32 instance); void AddCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid, uint32 instance);
@@ -906,7 +905,7 @@ class ObjectMgr
static bool CheckDeclinedNames(std::wstring mainpart, DeclinedName const& names); static bool CheckDeclinedNames(std::wstring mainpart, DeclinedName const& names);
int GetIndexForLocale(LocaleConstant loc); LocaleConstant GetIndexForLocale(LocaleConstant loc);
LocaleConstant GetLocaleForIndex(int i); LocaleConstant GetLocaleForIndex(int i);
GameTele const* GetGameTele(uint32 id) const GameTele const* GetGameTele(uint32 id) const
@@ -1080,7 +1079,7 @@ class ObjectMgr
typedef std::vector<LocaleConstant> LocalForIndex; typedef std::vector<LocaleConstant> LocalForIndex;
LocalForIndex m_LocalForIndex; LocalForIndex m_LocalForIndex;
int DBCLocaleIndex; LocaleConstant DBCLocaleIndex;
private: private:
void LoadScripts(ScriptsType type); void LoadScripts(ScriptsType type);
@@ -404,7 +404,7 @@ void Trinity::PlayerSearcher<Check>::Visit(PlayerMapType &m)
template<class Builder> template<class Builder>
void Trinity::LocalizedPacketDo<Builder>::operator()(Player* p) void Trinity::LocalizedPacketDo<Builder>::operator()(Player* p)
{ {
int32 loc_idx = p->GetSession()->GetSessionDbLocaleIndex(); LocaleConstant loc_idx = p->GetSession()->GetSessionDbLocaleIndex();
uint32 cache_idx = loc_idx+1; uint32 cache_idx = loc_idx+1;
WorldPacket* data; WorldPacket* data;
@@ -429,7 +429,7 @@ void Trinity::LocalizedPacketDo<Builder>::operator()(Player* p)
template<class Builder> template<class Builder>
void Trinity::LocalizedPacketListDo<Builder>::operator()(Player* p) void Trinity::LocalizedPacketListDo<Builder>::operator()(Player* p)
{ {
int32 loc_idx = p->GetSession()->GetSessionDbLocaleIndex(); LocaleConstant loc_idx = p->GetSession()->GetSessionDbLocaleIndex();
uint32 cache_idx = loc_idx+1; uint32 cache_idx = loc_idx+1;
WorldPacketList* data_list; WorldPacketList* data_list;
+3 -3
View File
@@ -102,7 +102,7 @@ bool Guild::Create(Player* leader, std::string gname)
return AddMember(m_LeaderGuid, (uint32)GR_GUILDMASTER); return AddMember(m_LeaderGuid, (uint32)GR_GUILDMASTER);
} }
void Guild::CreateDefaultGuildRanks(int locale_idx) void Guild::CreateDefaultGuildRanks(LocaleConstant locale_idx)
{ {
CharacterDatabase.PExecute("DELETE FROM guild_rank WHERE guildid='%u'", m_Id); CharacterDatabase.PExecute("DELETE FROM guild_rank WHERE guildid='%u'", m_Id);
CharacterDatabase.PExecute("DELETE FROM guild_bank_right WHERE guildid = '%u'", m_Id); CharacterDatabase.PExecute("DELETE FROM guild_bank_right WHERE guildid = '%u'", m_Id);
@@ -279,7 +279,7 @@ bool Guild::LoadRanksFromDB(QueryResult guildRanksResult)
if (!guildRanksResult) if (!guildRanksResult)
{ {
sLog.outError("Guild %u has broken `guild_rank` data, creating new...",m_Id); sLog.outError("Guild %u has broken `guild_rank` data, creating new...",m_Id);
CreateDefaultGuildRanks(0); CreateDefaultGuildRanks(DEFAULT_LOCALE);
return true; return true;
} }
@@ -329,7 +329,7 @@ bool Guild::LoadRanksFromDB(QueryResult guildRanksResult)
{ {
m_Ranks.clear(); m_Ranks.clear();
sLog.outError("Guild %u has broken `guild_rank` data, creating new...", m_Id); sLog.outError("Guild %u has broken `guild_rank` data, creating new...", m_Id);
CreateDefaultGuildRanks(0); // 0 is default locale_idx CreateDefaultGuildRanks(DEFAULT_LOCALE);
broken_ranks = false; broken_ranks = false;
} }
// guild_rank have wrong numbered ranks, repair // guild_rank have wrong numbered ranks, repair
+1 -1
View File
@@ -291,7 +291,7 @@ class Guild
~Guild(); ~Guild();
bool Create(Player* leader, std::string gname); bool Create(Player* leader, std::string gname);
void CreateDefaultGuildRanks(int locale_idx); void CreateDefaultGuildRanks(LocaleConstant locale_idx);
void Disband(); void Disband();
void DeleteGuildBankItems(SQLTransaction& trans, bool alsoInDB = false); void DeleteGuildBankItems(SQLTransaction& trans, bool alsoInDB = false);
+1 -1
View File
@@ -3040,7 +3040,7 @@ void Map::ScriptsProcess()
if (Player *pSource = _GetScriptPlayerSourceOrTarget(source, target, step.script)) if (Player *pSource = _GetScriptPlayerSourceOrTarget(source, target, step.script))
{ {
uint64 targetGUID = target ? target->GetGUID() : 0; uint64 targetGUID = target ? target->GetGUID() : 0;
int loc_idx = pSource->GetSession()->GetSessionDbLocaleIndex(); LocaleConstant loc_idx = pSource->GetSession()->GetSessionDbLocaleIndex();
const std::string text(sObjectMgr.GetTrinityString(step.script->dataint, loc_idx)); const std::string text(sObjectMgr.GetTrinityString(step.script->dataint, loc_idx));
switch (step.script->datalong) switch (step.script->datalong)
@@ -598,7 +598,7 @@ namespace Trinity
EmoteChatBuilder(Player const& pl, uint32 text_emote, uint32 emote_num, Unit const* target) EmoteChatBuilder(Player const& pl, uint32 text_emote, uint32 emote_num, Unit const* target)
: i_player(pl), i_text_emote(text_emote), i_emote_num(emote_num), i_target(target) {} : i_player(pl), i_text_emote(text_emote), i_emote_num(emote_num), i_target(target) {}
void operator()(WorldPacket& data, int32 loc_idx) void operator()(WorldPacket& data, LocaleConstant loc_idx)
{ {
char const* nam = i_target ? i_target->GetNameForLocaleIdx(loc_idx) : NULL; char const* nam = i_target ? i_target->GetNameForLocaleIdx(loc_idx) : NULL;
uint32 namlen = (nam ? strlen(nam) : 0) + 1; uint32 namlen = (nam ? strlen(nam) : 0) + 1;
+2 -2
View File
@@ -286,7 +286,7 @@ class WorldSession
// Locales // Locales
LocaleConstant GetSessionDbcLocale() const { return m_sessionDbcLocale; } LocaleConstant GetSessionDbcLocale() const { return m_sessionDbcLocale; }
int GetSessionDbLocaleIndex() const { return m_sessionDbLocaleIndex; } LocaleConstant GetSessionDbLocaleIndex() const { return m_sessionDbLocaleIndex; }
const char *GetTrinityString(int32 entry) const; const char *GetTrinityString(int32 entry) const;
uint32 GetLatency() const { return m_latency; } uint32 GetLatency() const { return m_latency; }
@@ -853,7 +853,7 @@ class WorldSession
bool m_playerRecentlyLogout; bool m_playerRecentlyLogout;
bool m_playerSave; bool m_playerSave;
LocaleConstant m_sessionDbcLocale; LocaleConstant m_sessionDbcLocale;
int m_sessionDbLocaleIndex; LocaleConstant m_sessionDbLocaleIndex;
uint32 m_latency; uint32 m_latency;
AccountData m_accountData[NUM_ACCOUNT_DATA_TYPES]; AccountData m_accountData[NUM_ACCOUNT_DATA_TYPES];
uint32 m_Tutorials[8]; uint32 m_Tutorials[8];
+1 -1
View File
@@ -2061,7 +2061,7 @@ namespace Trinity
public: public:
typedef std::vector<WorldPacket*> WorldPacketList; typedef std::vector<WorldPacket*> WorldPacketList;
explicit WorldWorldTextBuilder(int32 textId, va_list* args = NULL) : i_textId(textId), i_args(args) {} explicit WorldWorldTextBuilder(int32 textId, va_list* args = NULL) : i_textId(textId), i_args(args) {}
void operator()(WorldPacketList& data_list, int32 loc_idx) void operator()(WorldPacketList& data_list, LocaleConstant loc_idx)
{ {
char const* text = sObjectMgr.GetTrinityString(i_textId,loc_idx); char const* text = sObjectMgr.GetTrinityString(i_textId,loc_idx);
+1 -1
View File
@@ -417,7 +417,7 @@ public:
void SendText(int32 iTextEntry, Player* pPlayer) void SendText(int32 iTextEntry, Player* pPlayer)
{ {
int loc_idx = pPlayer->GetSession()->GetSessionDbLocaleIndex(); LocaleConstant loc_idx = pPlayer->GetSession()->GetSessionDbLocaleIndex();
const char* text = sObjectMgr.GetTrinityString(iTextEntry, loc_idx); const char* text = sObjectMgr.GetTrinityString(iTextEntry, loc_idx);
sWorld.SendServerMessage(SERVER_MSG_STRING, text, pPlayer); sWorld.SendServerMessage(SERVER_MSG_STRING, text, pPlayer);
} }
+1
View File
@@ -179,6 +179,7 @@ enum LocaleConstant
}; };
const uint8 MAX_LOCALE = 9; const uint8 MAX_LOCALE = 9;
const LocaleConstant DEFAULT_LOCALE = LOCALE_enUS;
extern char const* localeNames[MAX_LOCALE]; extern char const* localeNames[MAX_LOCALE];