Provide and use universal way for get locale and locale index for chat/console command use.

This commit is contained in:
VladimirMangos 2009-05-19 00:45:48 +04:00
parent 695d83568a
commit fdbc22ac93
6 changed files with 56 additions and 30 deletions

View file

@ -1578,6 +1578,16 @@ bool ChatHandler::needReportToTarget(Player* chr) const
return pl != chr && pl->IsVisibleGloballyFor(chr);
}
LocaleConstant ChatHandler::GetSessionDbcLocale() const
{
return m_session->GetSessionDbcLocale();
}
int ChatHandler::GetSessionDbLocaleIndex() const
{
return m_session->GetSessionDbLocaleIndex();
}
const char *CliHandler::GetMangosString(int32 entry) const
{
return objmgr.GetMangosStringForDBCLocale(entry);
@ -1605,3 +1615,12 @@ bool CliHandler::needReportToTarget(Player* /*chr*/) const
return true;
}
LocaleConstant CliHandler::GetSessionDbcLocale() const
{
return sWorld.GetDefaultDbcLocale();
}
int CliHandler::GetSessionDbLocaleIndex() const
{
return objmgr.GetDBCLocaleIndex();
}

View file

@ -60,9 +60,10 @@ class ChatHandler
static char* LineFromMessage(char*& pos) { char* start = strtok(pos,"\n"); pos = NULL; return start; }
// function with different implementation for chat/console
virtual const char *GetMangosString(int32 entry) const;
virtual void SendSysMessage( const char *str);
void SendSysMessage( int32 entry);
void PSendSysMessage( const char *format, ...) ATTR_PRINTF(2,3);
void PSendSysMessage( int32 entry, ... );
@ -73,8 +74,13 @@ class ChatHandler
bool hasStringAbbr(const char* name, const char* part);
// function with different implementation for chat/console
virtual bool isAvailable(ChatCommand const& cmd) const;
virtual std::string GetNameLink() const { return GetNameLink(m_session->GetPlayer()); }
virtual bool needReportToTarget(Player* chr) const;
virtual LocaleConstant GetSessionDbcLocale() const;
virtual int GetSessionDbLocaleIndex() const;
bool HasLowerSecurity(Player* target, uint64 guid, bool strong = false);
bool HasLowerSecurityAccount(WorldSession* target, uint32 account, bool strong = false);
@ -115,8 +121,8 @@ class ChatHandler
bool HandleCharacterCustomizeCommand(const char * args);
bool HandleCharacterDeleteCommand(const char* args);
bool HandleCharacterRenameCommand(const char * args);
bool HandleCharacterLevelCommand(const char* args);
bool HandleCharacterRenameCommand(const char * args);
bool HandleDebugAnimCommand(const char* args);
bool HandleDebugArenaCommand(const char * args);
@ -499,7 +505,6 @@ class ChatHandler
bool extractPlayerTarget(char* args, Player** player, uint64* player_guid = NULL, std::string* player_name = NULL);
std::string playerLink(std::string const& name) const { return m_session ? "|cffffffff|Hplayer:"+name+"|h["+name+"]|h|r" : name; }
virtual std::string GetNameLink() const { return GetNameLink(m_session->GetPlayer()); }
std::string GetNameLink(Player* chr) const { return playerLink(chr->GetName()); }
GameObject* GetObjectGlobalyWithGuidOrNearWithDbGuid(uint32 lowguid,uint32 entry);
@ -534,6 +539,8 @@ class CliHandler : public ChatHandler
void SendSysMessage(const char *str);
std::string GetNameLink() const;
bool needReportToTarget(Player* chr) const;
LocaleConstant GetSessionDbcLocale() const;
int GetSessionDbLocaleIndex() const;
private:
Print* m_print;

View file

@ -309,9 +309,9 @@ bool ChatHandler::HandleGPSCommand(const char* args)
uint32 have_vmap = Map::ExistVMap(obj->GetMapId(),gx,gy) ? 1 : 0;
PSendSysMessage(LANG_MAP_POSITION,
obj->GetMapId(), (mapEntry ? mapEntry->name[m_session->GetSessionDbcLocale()] : "<unknown>" ),
zone_id, (zoneEntry ? zoneEntry->area_name[m_session->GetSessionDbcLocale()] : "<unknown>" ),
area_id, (areaEntry ? areaEntry->area_name[m_session->GetSessionDbcLocale()] : "<unknown>" ),
obj->GetMapId(), (mapEntry ? mapEntry->name[GetSessionDbcLocale()] : "<unknown>" ),
zone_id, (zoneEntry ? zoneEntry->area_name[GetSessionDbcLocale()] : "<unknown>" ),
area_id, (areaEntry ? areaEntry->area_name[GetSessionDbcLocale()] : "<unknown>" ),
obj->GetPhaseMask(),
obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ(), obj->GetOrientation(),
cell.GridX(), cell.GridY(), cell.CellX(), cell.CellY(), obj->GetInstanceId(),
@ -1818,7 +1818,7 @@ bool ChatHandler::HandleLookupAreaCommand(const char* args)
AreaTableEntry const *areaEntry = sAreaStore.LookupEntry (areaflag);
if (areaEntry)
{
int loc = m_session ? m_session->GetSessionDbcLocale () : sWorld.GetDefaultDbcLocale();
int loc = GetSessionDbcLocale ();
std::string name = areaEntry->area_name[loc];
if (name.empty())
continue;
@ -1828,7 +1828,7 @@ bool ChatHandler::HandleLookupAreaCommand(const char* args)
loc = 0;
for(; loc < MAX_LOCALE; ++loc)
{
if (m_session && loc==m_session->GetSessionDbcLocale ())
if (loc==GetSessionDbcLocale ())
continue;
name = areaEntry->area_name[loc];
@ -2432,7 +2432,7 @@ bool ChatHandler::HandleGoZoneXYCommand(const char* args)
if(map->Instanceable())
{
PSendSysMessage(LANG_INVALID_ZONE_MAP,areaEntry->ID,areaEntry->area_name[m_session->GetSessionDbcLocale()],map->GetId(),map->GetMapName());
PSendSysMessage(LANG_INVALID_ZONE_MAP,areaEntry->ID,areaEntry->area_name[GetSessionDbcLocale()],map->GetId(),map->GetMapName());
SetSentErrorMessage(true);
return false;
}

View file

@ -880,7 +880,7 @@ bool ChatHandler::HandleLookupFactionCommand(const char* args)
{
FactionState const* repState = target ? target->GetReputationMgr().GetState(factionEntry) : NULL;
int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
int loc = GetSessionDbcLocale();
std::string name = factionEntry->name[loc];
if(name.empty())
continue;
@ -890,7 +890,7 @@ bool ChatHandler::HandleLookupFactionCommand(const char* args)
loc = 0;
for(; loc < MAX_LOCALE; ++loc)
{
if(m_session && loc==m_session->GetSessionDbcLocale())
if(loc==GetSessionDbcLocale())
continue;
name = factionEntry->name[loc];
@ -1035,13 +1035,13 @@ bool ChatHandler::HandleModifyRepCommand(const char * args)
if (factionEntry->reputationListID < 0)
{
PSendSysMessage(LANG_COMMAND_FACTION_NOREP_ERROR, factionEntry->name[m_session->GetSessionDbcLocale()], factionId);
PSendSysMessage(LANG_COMMAND_FACTION_NOREP_ERROR, factionEntry->name[GetSessionDbcLocale()], factionId);
SetSentErrorMessage(true);
return false;
}
target->GetReputationMgr().SetReputation(factionEntry,amount);
PSendSysMessage(LANG_COMMAND_MODIFY_REP, factionEntry->name[m_session->GetSessionDbcLocale()], factionId,
PSendSysMessage(LANG_COMMAND_MODIFY_REP, factionEntry->name[GetSessionDbcLocale()], factionId,
GetNameLink(target).c_str(), target->GetReputationMgr().GetReputation(factionEntry));
return true;
}
@ -2211,7 +2211,7 @@ bool ChatHandler::HandlePInfoCommand(const char* args)
for(FactionStateList::const_iterator itr = targetFSL.begin(); itr != targetFSL.end(); ++itr)
{
FactionEntry const *factionEntry = sFactionStore.LookupEntry(itr->second.ID);
char const* factionName = factionEntry ? factionEntry->name[m_session->GetSessionDbcLocale()] : "#Not found#";
char const* factionName = factionEntry ? factionEntry->name[GetSessionDbcLocale()] : "#Not found#";
ReputationRank rank = target->GetReputationMgr().GetRank(factionEntry);
std::string rankName = GetMangosString(ReputationRankStrIndex[rank]);
std::ostringstream ss;
@ -3976,7 +3976,7 @@ bool ChatHandler::HandleLearnAllRecipesCommand(const char* args)
skillInfo->categoryId != SKILL_CATEGORY_SECONDARY )
continue;
int loc = m_session->GetSessionDbcLocale();
int loc = GetSessionDbcLocale();
std::string name = skillInfo->name[loc];
if(Utf8FitTo(name, wnamepart))

View file

@ -2584,7 +2584,7 @@ bool ChatHandler::HandleLookupItemCommand(const char* args)
if(!pProto)
continue;
int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
int loc_idx = GetSessionDbLocaleIndex();
if ( loc_idx >= 0 )
{
ItemLocale const *il = objmgr.GetItemLocale(pProto->ItemId);
@ -2649,7 +2649,7 @@ bool ChatHandler::HandleLookupItemSetCommand(const char* args)
ItemSetEntry const *set = sItemSetStore.LookupEntry(id);
if(set)
{
int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
int loc = GetSessionDbcLocale();
std::string name = set->name[loc];
if(name.empty())
continue;
@ -2659,7 +2659,7 @@ bool ChatHandler::HandleLookupItemSetCommand(const char* args)
loc = 0;
for(; loc < MAX_LOCALE; ++loc)
{
if(m_session && loc==m_session->GetSessionDbcLocale())
if(loc==GetSessionDbcLocale())
continue;
name = set->name[loc];
@ -2712,7 +2712,7 @@ bool ChatHandler::HandleLookupSkillCommand(const char* args)
SkillLineEntry const *skillInfo = sSkillLineStore.LookupEntry(id);
if(skillInfo)
{
int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
int loc = GetSessionDbcLocale();
std::string name = skillInfo->name[loc];
if(name.empty())
continue;
@ -2722,7 +2722,7 @@ bool ChatHandler::HandleLookupSkillCommand(const char* args)
loc = 0;
for(; loc < MAX_LOCALE; ++loc)
{
if(m_session && loc==m_session->GetSessionDbcLocale())
if(loc==GetSessionDbcLocale())
continue;
name = skillInfo->name[loc];
@ -2790,7 +2790,7 @@ bool ChatHandler::HandleLookupSpellCommand(const char* args)
SpellEntry const *spellInfo = sSpellStore.LookupEntry(id);
if(spellInfo)
{
int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
int loc = GetSessionDbcLocale();
std::string name = spellInfo->SpellName[loc];
if(name.empty())
continue;
@ -2800,7 +2800,7 @@ bool ChatHandler::HandleLookupSpellCommand(const char* args)
loc = 0;
for(; loc < MAX_LOCALE; ++loc)
{
if(m_session && loc==m_session->GetSessionDbcLocale())
if(loc==GetSessionDbcLocale())
continue;
name = spellInfo->SpellName[loc];
@ -2889,7 +2889,7 @@ bool ChatHandler::HandleLookupQuestCommand(const char* args)
{
Quest * qinfo = iter->second;
int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
int loc_idx = GetSessionDbLocaleIndex();
if ( loc_idx >= 0 )
{
QuestLocale const *il = objmgr.GetQuestLocale(qinfo->GetQuestId());
@ -2989,7 +2989,7 @@ bool ChatHandler::HandleLookupCreatureCommand(const char* args)
if(!cInfo)
continue;
int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
int loc_idx = GetSessionDbLocaleIndex();
if (loc_idx >= 0)
{
CreatureLocale const *cl = objmgr.GetCreatureLocale (id);
@ -3054,7 +3054,7 @@ bool ChatHandler::HandleLookupObjectCommand(const char* args)
if(!gInfo)
continue;
int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
int loc_idx = GetSessionDbLocaleIndex();
if ( loc_idx >= 0 )
{
GameObjectLocale const *gl = objmgr.GetGameObjectLocale(id);
@ -3119,7 +3119,7 @@ bool ChatHandler::HandleLookupTaxiNodeCommand(const char * args)
TaxiNodesEntry const *nodeEntry = sTaxiNodesStore.LookupEntry(id);
if(nodeEntry)
{
int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
int loc = GetSessionDbcLocale();
std::string name = nodeEntry->name[loc];
if(name.empty())
continue;
@ -3129,7 +3129,7 @@ bool ChatHandler::HandleLookupTaxiNodeCommand(const char * args)
loc = 0;
for(; loc < MAX_LOCALE; ++loc)
{
if(m_session && loc==m_session->GetSessionDbcLocale())
if(loc==GetSessionDbcLocale())
continue;
name = nodeEntry->name[loc];
@ -4394,7 +4394,7 @@ bool ChatHandler::HandleListAurasCommand (const char * /*args*/)
{
bool talent = GetTalentSpellCost(itr->second->GetId()) > 0;
char const* name = itr->second->GetSpellProto()->SpellName[m_session->GetSessionDbcLocale()];
char const* name = itr->second->GetSpellProto()->SpellName[GetSessionDbcLocale()];
if (m_session)
{
@ -4425,7 +4425,7 @@ bool ChatHandler::HandleListAurasCommand (const char * /*args*/)
{
bool talent = GetTalentSpellCost((*itr)->GetId()) > 0;
char const* name = (*itr)->GetSpellProto()->SpellName[m_session->GetSessionDbcLocale()];
char const* name = (*itr)->GetSpellProto()->SpellName[GetSessionDbcLocale()];
if (m_session)
{

View file

@ -406,7 +406,7 @@ class World
/// Get the current Message of the Day
const char* GetMotd() const { return m_motd.c_str(); }
uint32 GetDefaultDbcLocale() const { return m_defaultDbcLocale; }
LocaleConstant GetDefaultDbcLocale() const { return m_defaultDbcLocale; }
/// Get the path where data (dbc, maps) are stored on disk
std::string GetDataPath() const { return m_dataPath; }