Core/Misc: changed trinity string id to unsigned and removed obsolete code

This commit is contained in:
joschiwald
2014-09-18 02:36:28 +02:00
parent 55ecd1c913
commit 72ed5bfc93
11 changed files with 63 additions and 140 deletions

View File

@@ -41,7 +41,7 @@ namespace Trinity
class BattlegroundChatBuilder
{
public:
BattlegroundChatBuilder(ChatMsg msgtype, int32 textId, Player const* source, va_list* args = NULL)
BattlegroundChatBuilder(ChatMsg msgtype, uint32 textId, Player const* source, va_list* args = NULL)
: _msgtype(msgtype), _textId(textId), _source(source), _args(args) { }
void operator()(WorldPacket& data, LocaleConstant loc_idx)
@@ -70,7 +70,7 @@ namespace Trinity
}
ChatMsg _msgtype;
int32 _textId;
uint32 _textId;
Player const* _source;
va_list* _args;
};
@@ -78,7 +78,7 @@ namespace Trinity
class Battleground2ChatBuilder
{
public:
Battleground2ChatBuilder(ChatMsg msgtype, int32 textId, Player const* source, int32 arg1, int32 arg2)
Battleground2ChatBuilder(ChatMsg msgtype, uint32 textId, Player const* source, uint32 arg1, uint32 arg2)
: _msgtype(msgtype), _textId(textId), _source(source), _arg1(arg1), _arg2(arg2) { }
void operator()(WorldPacket& data, LocaleConstant loc_idx)
@@ -95,10 +95,10 @@ namespace Trinity
private:
ChatMsg _msgtype;
int32 _textId;
uint32 _textId;
Player const* _source;
int32 _arg1;
int32 _arg2;
uint32 _arg1;
uint32 _arg2;
};
} // namespace Trinity
@@ -1561,7 +1561,7 @@ bool Battleground::AddSpiritGuide(uint32 type, Position const& pos, TeamId teamI
return AddSpiritGuide(type, pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), pos.GetOrientation(), teamId);
}
void Battleground::SendMessageToAll(int32 entry, ChatMsg type, Player const* source)
void Battleground::SendMessageToAll(uint32 entry, ChatMsg type, Player const* source)
{
if (!entry)
return;
@@ -1571,7 +1571,7 @@ void Battleground::SendMessageToAll(int32 entry, ChatMsg type, Player const* sou
BroadcastWorker(bg_do);
}
void Battleground::PSendMessageToAll(int32 entry, ChatMsg type, Player const* source, ...)
void Battleground::PSendMessageToAll(uint32 entry, ChatMsg type, Player const* source, ...)
{
if (!entry)
return;
@@ -1586,7 +1586,7 @@ void Battleground::PSendMessageToAll(int32 entry, ChatMsg type, Player const* so
va_end(ap);
}
void Battleground::SendWarningToAll(int32 entry, ...)
void Battleground::SendWarningToAll(uint32 entry, ...)
{
if (!entry)
return;
@@ -1612,7 +1612,7 @@ void Battleground::SendWarningToAll(int32 entry, ...)
}
}
void Battleground::SendMessage2ToAll(int32 entry, ChatMsg type, Player const* source, int32 arg1, int32 arg2)
void Battleground::SendMessage2ToAll(uint32 entry, ChatMsg type, Player const* source, uint32 arg1, uint32 arg2)
{
Trinity::Battleground2ChatBuilder bg_builder(type, entry, source, arg1, arg2);
Trinity::LocalizedPacketDo<Trinity::Battleground2ChatBuilder> bg_do(bg_builder);
@@ -1626,13 +1626,6 @@ void Battleground::EndNow()
SetEndTime(0);
}
// To be removed
char const* Battleground::GetTrinityString(int32 entry)
{
// FIXME: now we have different DBC locales and need localized message for each target client
return sObjectMgr->GetTrinityStringForDBCLocale(entry);
}
// IMPORTANT NOTICE:
// buffs aren't spawned/despawned when players captures anything
// buffs are in their positions when battleground starts

View File

@@ -360,12 +360,12 @@ class Battleground
virtual void EndBattleground(uint32 winner);
void BlockMovement(Player* player);
void SendWarningToAll(int32 entry, ...);
void SendMessageToAll(int32 entry, ChatMsg type, Player const* source = NULL);
void PSendMessageToAll(int32 entry, ChatMsg type, Player const* source, ...);
void SendWarningToAll(uint32 entry, ...);
void SendMessageToAll(uint32 entry, ChatMsg type, Player const* source = NULL);
void PSendMessageToAll(uint32 entry, ChatMsg type, Player const* source, ...);
// specialized version with 2 string id args
void SendMessage2ToAll(int32 entry, ChatMsg type, Player const* source, int32 strId1 = 0, int32 strId2 = 0);
void SendMessage2ToAll(uint32 entry, ChatMsg type, Player const* source, uint32 strId1 = 0, uint32 strId2 = 0);
// Raid Group
Group* GetBgRaid(uint32 TeamID) const { return TeamID == ALLIANCE ? m_BgRaids[TEAM_ALLIANCE] : m_BgRaids[TEAM_HORDE]; }
@@ -442,8 +442,6 @@ class Battleground
void DoorOpen(uint32 type);
void DoorClose(uint32 type);
//to be removed
const char* GetTrinityString(int32 entry);
virtual bool HandlePlayerUnderMap(Player* /*player*/) { return false; }

View File

@@ -104,7 +104,7 @@ ChatCommand* ChatHandler::getCommandTable()
return commandTableCache;
}
std::string ChatHandler::PGetParseString(int32 entry, ...) const
std::string ChatHandler::PGetParseString(uint32 entry, ...) const
{
const char *format = GetTrinityString(entry);
char str[1024];
@@ -115,7 +115,7 @@ std::string ChatHandler::PGetParseString(int32 entry, ...) const
return std::string(str);
}
const char *ChatHandler::GetTrinityString(int32 entry) const
char const* ChatHandler::GetTrinityString(uint32 entry) const
{
return m_session->GetTrinityString(entry);
}
@@ -253,12 +253,12 @@ void ChatHandler::SendGlobalGMSysMessage(const char *str)
free(buf);
}
void ChatHandler::SendSysMessage(int32 entry)
void ChatHandler::SendSysMessage(uint32 entry)
{
SendSysMessage(GetTrinityString(entry));
}
void ChatHandler::PSendSysMessage(int32 entry, ...)
void ChatHandler::PSendSysMessage(uint32 entry, ...)
{
const char *format = GetTrinityString(entry);
va_list ap;
@@ -1250,7 +1250,7 @@ std::string ChatHandler::GetNameLink(Player* chr) const
return playerLink(chr->GetName());
}
const char *CliHandler::GetTrinityString(int32 entry) const
char const* CliHandler::GetTrinityString(uint32 entry) const
{
return sObjectMgr->GetTrinityStringForDBCLocale(entry);
}

View File

@@ -64,13 +64,13 @@ 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 *GetTrinityString(int32 entry) const;
virtual void SendSysMessage(const char *str);
virtual char const* GetTrinityString(uint32 entry) const;
virtual void SendSysMessage(char const* str);
void SendSysMessage(int32 entry);
void PSendSysMessage(const char *format, ...) ATTR_PRINTF(2, 3);
void PSendSysMessage(int32 entry, ...);
std::string PGetParseString(int32 entry, ...) const;
void SendSysMessage(uint32 entry);
void PSendSysMessage(char const* format, ...) ATTR_PRINTF(2, 3);
void PSendSysMessage(uint32 entry, ...);
std::string PGetParseString(uint32 entry, ...) const;
bool ParseCommands(const char* text);
@@ -147,7 +147,7 @@ class CliHandler : public ChatHandler
explicit CliHandler(void* callbackArg, Print* zprint) : m_callbackArg(callbackArg), m_print(zprint) { }
// overwrite functions
const char *GetTrinityString(int32 entry) const override;
char const* GetTrinityString(uint32 entry) const override;
bool isAvailable(ChatCommand const& cmd) const override;
bool HasPermission(uint32 /*permission*/) const override { return true; }
void SendSysMessage(const char *str) override;

View File

@@ -7673,112 +7673,48 @@ void ObjectMgr::LoadGameObjectForQuests()
TC_LOG_INFO("server.loading", ">> Loaded %u GameObjects for quests in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
}
bool ObjectMgr::LoadTrinityStrings(const char* table, int32 min_value, int32 max_value)
bool ObjectMgr::LoadTrinityStrings()
{
uint32 oldMSTime = getMSTime();
int32 start_value = min_value;
int32 end_value = max_value;
// some string can have negative indexes range
if (start_value < 0)
{
if (end_value >= start_value)
{
TC_LOG_ERROR("sql.sql", "Table '%s' attempt loaded with invalid range (%d - %d), strings not loaded.", table, min_value, max_value);
return false;
}
// real range (max+1, min+1) exaple: (-10, -1000) -> -999...-10+1
std::swap(start_value, end_value);
++start_value;
++end_value;
}
else
{
if (start_value >= end_value)
{
TC_LOG_ERROR("sql.sql", "Table '%s' attempt loaded with invalid range (%d - %d), strings not loaded.", table, min_value, max_value);
return false;
}
}
// cleanup affected map part for reloading case
for (TrinityStringLocaleContainer::iterator itr = _trinityStringLocaleStore.begin(); itr != _trinityStringLocaleStore.end();)
{
if (itr->first >= start_value && itr->first < end_value)
_trinityStringLocaleStore.erase(itr++);
else
++itr;
}
QueryResult result = WorldDatabase.PQuery("SELECT entry, content_default, content_loc1, content_loc2, content_loc3, content_loc4, content_loc5, content_loc6, content_loc7, content_loc8 FROM %s", table);
_trinityStringStore.clear(); // for reload case
QueryResult result = WorldDatabase.Query("SELECT entry, content_default, content_loc1, content_loc2, content_loc3, content_loc4, content_loc5, content_loc6, content_loc7, content_loc8 FROM trinity_string");
if (!result)
{
if (min_value == MIN_TRINITY_STRING_ID) // error only in case internal strings
TC_LOG_ERROR("server.loading", ">> Loaded 0 trinity strings. DB table `%s` is empty. Cannot continue.", table);
else
TC_LOG_INFO("server.loading", ">> Loaded 0 string templates. DB table `%s` is empty.", table);
TC_LOG_ERROR("server.loading", ">> Loaded 0 trinity strings. DB table `trinity_string` is empty.");
return false;
}
uint32 count = 0;
do
{
Field* fields = result->Fetch();
int32 entry = fields[0].GetInt32();
uint32 entry = fields[0].GetUInt32();
if (entry == 0)
{
TC_LOG_ERROR("sql.sql", "Table `%s` contain reserved entry 0, ignored.", table);
continue;
}
else if (entry < start_value || entry >= end_value)
{
TC_LOG_ERROR("sql.sql", "Table `%s` contain entry %i out of allowed range (%d - %d), ignored.", table, entry, min_value, max_value);
continue;
}
TrinityString& data = _trinityStringStore[entry];
TrinityStringLocale& data = _trinityStringLocaleStore[entry];
if (!data.Content.empty())
{
TC_LOG_ERROR("sql.sql", "Table `%s` contain data for already loaded entry %i (from another table?), ignored.", table, entry);
continue;
}
data.Content.resize(1);
++count;
data.Content.resize(DEFAULT_LOCALE + 1);
for (int8 i = TOTAL_LOCALES - 1; i >= 0; --i)
AddLocaleString(fields[i + 1].GetString(), LocaleConstant(i), data.Content);
} while (result->NextRow());
if (min_value == MIN_TRINITY_STRING_ID)
TC_LOG_INFO("server.loading", ">> Loaded %u Trinity strings from table %s in %u ms", count, table, GetMSTimeDiffToNow(oldMSTime));
else
TC_LOG_INFO("server.loading", ">> Loaded %u string templates from %s in %u ms", count, table, GetMSTimeDiffToNow(oldMSTime));
}
while (result->NextRow());
TC_LOG_INFO("server.loading", ">> Loaded " SZFMTD " trinity strings in %u ms", _trinityStringStore.size(), GetMSTimeDiffToNow(oldMSTime));
return true;
}
const char *ObjectMgr::GetTrinityString(int32 entry, LocaleConstant locale_idx) const
char const* ObjectMgr::GetTrinityString(uint32 entry, LocaleConstant locale) const
{
if (TrinityStringLocale const* msl = GetTrinityStringLocale(entry))
if (TrinityString const* ts = GetTrinityString(entry))
{
if (msl->Content.size() > size_t(locale_idx) && !msl->Content[locale_idx].empty())
return msl->Content[locale_idx].c_str();
return msl->Content[DEFAULT_LOCALE].c_str();
if (ts->Content.size() > size_t(locale) && !ts->Content[locale].empty())
return ts->Content[locale].c_str();
return ts->Content[DEFAULT_LOCALE].c_str();
}
if (entry > 0)
TC_LOG_ERROR("sql.sql", "Entry %i not found in `trinity_string` table.", entry);
else
TC_LOG_ERROR("sql.sql", "Trinity string entry %i not found in DB.", entry);
TC_LOG_ERROR("sql.sql", "Trinity string entry %u not found in DB.", entry);
return "<error>";
}

View File

@@ -463,14 +463,10 @@ struct CellObjectGuids
typedef std::unordered_map<uint32/*cell_id*/, CellObjectGuids> CellObjectGuidsMap;
typedef std::unordered_map<uint32/*(mapid, spawnMode) pair*/, CellObjectGuidsMap> MapObjectGuids;
// Trinity string ranges
#define MIN_TRINITY_STRING_ID 1 // 'trinity_string'
#define MAX_TRINITY_STRING_ID 2000000000
// Trinity Trainer Reference start range
#define TRINITY_TRAINER_START_REF 200000
struct TrinityStringLocale
struct TrinityString
{
StringVector Content;
};
@@ -486,10 +482,11 @@ typedef std::unordered_map<uint32, ItemSetNameLocale> ItemSetNameLocaleContainer
typedef std::unordered_map<uint32, QuestLocale> QuestLocaleContainer;
typedef std::unordered_map<uint32, NpcTextLocale> NpcTextLocaleContainer;
typedef std::unordered_map<uint32, PageTextLocale> PageTextLocaleContainer;
typedef std::unordered_map<int32, TrinityStringLocale> TrinityStringLocaleContainer;
typedef std::unordered_map<uint32, GossipMenuItemsLocale> GossipMenuItemsLocaleContainer;
typedef std::unordered_map<uint32, PointOfInterestLocale> PointOfInterestLocaleContainer;
typedef std::unordered_map<uint32, TrinityString> TrinityStringContainer;
typedef std::multimap<uint32, uint32> QuestRelations; // unit/go -> quest
typedef std::multimap<uint32, uint32> QuestRelationsReverse; // quest -> unit/go
typedef std::pair<QuestRelations::const_iterator, QuestRelations::const_iterator> QuestRelationBounds;
@@ -955,6 +952,8 @@ class ObjectMgr
return _creatureQuestInvolvedRelationsReverse.equal_range(questId);
}
bool LoadTrinityStrings();
void LoadEventScripts();
void LoadSpellScripts();
void LoadWaypointScripts();
@@ -964,8 +963,6 @@ class ObjectMgr
void LoadBroadcastTexts();
void LoadBroadcastTextLocales();
bool LoadTrinityStrings(char const* table, int32 min_value, int32 max_value);
bool LoadTrinityStrings() { return LoadTrinityStrings("trinity_string", MIN_TRINITY_STRING_ID, MAX_TRINITY_STRING_ID); }
void LoadCreatureClassLevelStats();
void LoadCreatureLocales();
void LoadCreatureTemplates();
@@ -1187,14 +1184,15 @@ class ObjectMgr
GameObjectData& NewGOData(uint32 guid) { return _gameObjectDataStore[guid]; }
void DeleteGOData(uint32 guid);
TrinityStringLocale const* GetTrinityStringLocale(int32 entry) const
TrinityString const* GetTrinityString(uint32 entry) const
{
TrinityStringLocaleContainer::const_iterator itr = _trinityStringLocaleStore.find(entry);
if (itr == _trinityStringLocaleStore.end()) return NULL;
TrinityStringContainer::const_iterator itr = _trinityStringStore.find(entry);
if (itr == _trinityStringStore.end())
return nullptr;
return &itr->second;
}
const char *GetTrinityString(int32 entry, LocaleConstant locale_idx) const;
const char *GetTrinityStringForDBCLocale(int32 entry) const { return GetTrinityString(entry, DBCLocaleIndex); }
char const* GetTrinityString(uint32 entry, LocaleConstant locale) const;
char const* GetTrinityStringForDBCLocale(uint32 entry) const { return GetTrinityString(entry, DBCLocaleIndex); }
LocaleConstant GetDBCLocaleIndex() const { return DBCLocaleIndex; }
void SetDBCLocaleIndex(LocaleConstant locale) { DBCLocaleIndex = locale; }
@@ -1438,10 +1436,11 @@ class ObjectMgr
QuestLocaleContainer _questLocaleStore;
NpcTextLocaleContainer _npcTextLocaleStore;
PageTextLocaleContainer _pageTextLocaleStore;
TrinityStringLocaleContainer _trinityStringLocaleStore;
GossipMenuItemsLocaleContainer _gossipMenuItemsLocaleStore;
PointOfInterestLocaleContainer _pointOfInterestLocaleStore;
TrinityStringContainer _trinityStringStore;
CacheVendorItemContainer _cacheVendorItemStore;
CacheTrainerSpellContainer _cacheTrainerSpellStore;

View File

@@ -1192,8 +1192,5 @@ enum TrinityStrings
LANG_NPCINFO_INHABIT_TYPE = 11008,
LANG_NPCINFO_FLAGS_EXTRA = 11009
// NOT RESERVED IDS 12000-1999999999
// For other tables maybe 2000010000-2147483647 (max index)
};
#endif

View File

@@ -621,7 +621,7 @@ void WorldSession::SendNotification(uint32 string_id, ...)
}
}
const char *WorldSession::GetTrinityString(int32 entry) const
char const* WorldSession::GetTrinityString(uint32 entry) const
{
return sObjectMgr->GetTrinityString(entry, GetSessionDbLocaleIndex());
}

View File

@@ -366,7 +366,7 @@ class WorldSession
// Locales
LocaleConstant GetSessionDbcLocale() const { return m_sessionDbcLocale; }
LocaleConstant GetSessionDbLocaleIndex() const { return m_sessionDbLocaleIndex; }
const char *GetTrinityString(int32 entry) const;
char const* GetTrinityString(uint32 entry) const;
uint32 GetLatency() const { return m_latency; }
void SetLatency(uint32 latency) { m_latency = latency; }

View File

@@ -2186,7 +2186,7 @@ namespace Trinity
{
public:
typedef std::vector<WorldPacket*> WorldPacketList;
explicit WorldWorldTextBuilder(int32 textId, va_list* args = NULL) : i_textId(textId), i_args(args) { }
explicit WorldWorldTextBuilder(uint32 textId, va_list* args = NULL) : i_textId(textId), i_args(args) { }
void operator()(WorldPacketList& data_list, LocaleConstant loc_idx)
{
char const* text = sObjectMgr->GetTrinityString(i_textId, loc_idx);
@@ -2219,13 +2219,13 @@ namespace Trinity
}
}
int32 i_textId;
uint32 i_textId;
va_list* i_args;
};
} // namespace Trinity
/// Send a System Message to all players (except self if mentioned)
void World::SendWorldText(int32 string_id, ...)
void World::SendWorldText(uint32 string_id, ...)
{
va_list ap;
va_start(ap, string_id);
@@ -2244,7 +2244,7 @@ void World::SendWorldText(int32 string_id, ...)
}
/// Send a System Message to all GMs (except self if mentioned)
void World::SendGMText(int32 string_id, ...)
void World::SendGMText(uint32 string_id, ...)
{
va_list ap;
va_start(ap, string_id);

View File

@@ -628,9 +628,9 @@ class World
void SetInitialWorldSettings();
void LoadConfigSettings(bool reload = false);
void SendWorldText(int32 string_id, ...);
void SendWorldText(uint32 string_id, ...);
void SendGlobalText(const char* text, WorldSession* self);
void SendGMText(int32 string_id, ...);
void SendGMText(uint32 string_id, ...);
void SendServerMessage(ServerMessageType type, const char *text = "", Player* player = NULL);
void SendGlobalMessage(WorldPacket* packet, WorldSession* self = nullptr, uint32 team = 0);
void SendGlobalGMMessage(WorldPacket* packet, WorldSession* self = nullptr, uint32 team = 0);