[3.3.5] Core/Guilds: Guild cleanup (PR #25422)

This commit is contained in:
Treeston
2020-09-09 20:38:04 +02:00
committed by GitHub
parent 4f636b80e4
commit cd28423a4e
10 changed files with 287 additions and 348 deletions

View File

@@ -8501,7 +8501,7 @@ void ObjectMgr::LoadReservedPlayersNames()
TC_LOG_INFO("server.loading", ">> Loaded %u reserved player names in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
}
bool ObjectMgr::IsReservedName(const std::string& name) const
bool ObjectMgr::IsReservedName(std::string_view name) const
{
std::wstring wstr;
if (!Utf8toWStr (name, wstr))
@@ -8585,7 +8585,7 @@ bool isValidString(const std::wstring& wstr, uint32 strictMask, bool numericOrSp
return false;
}
ResponseCodes ObjectMgr::CheckPlayerName(std::string const& name, LocaleConstant locale, bool create /*= false*/)
ResponseCodes ObjectMgr::CheckPlayerName(std::string_view name, LocaleConstant locale, bool create /*= false*/)
{
std::wstring wname;
if (!Utf8toWStr(name, wname))
@@ -8610,7 +8610,7 @@ ResponseCodes ObjectMgr::CheckPlayerName(std::string const& name, LocaleConstant
return ValidateName(wname, locale);
}
bool ObjectMgr::IsValidCharterName(const std::string& name)
bool ObjectMgr::IsValidCharterName(std::string_view name)
{
std::wstring wname;
if (!Utf8toWStr(name, wname))
@@ -8628,7 +8628,7 @@ bool ObjectMgr::IsValidCharterName(const std::string& name)
return isValidString(wname, strictMask, true);
}
PetNameInvalidReason ObjectMgr::CheckPetName(const std::string& name, LocaleConstant locale)
PetNameInvalidReason ObjectMgr::CheckPetName(std::string_view name, LocaleConstant locale)
{
std::wstring wname;
if (!Utf8toWStr(name, wname))
@@ -8930,7 +8930,7 @@ void ObjectMgr::LoadGameTele()
TC_LOG_INFO("server.loading", ">> Loaded %u GameTeleports in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
}
GameTele const* ObjectMgr::GetGameTele(const std::string& name) const
GameTele const* ObjectMgr::GetGameTele(std::string_view name) const
{
// explicit name case
std::wstring wname;
@@ -8953,7 +8953,7 @@ GameTele const* ObjectMgr::GetGameTele(const std::string& name) const
return alt;
}
GameTele const* ObjectMgr::GetGameTeleExactName(const std::string& name) const
GameTele const* ObjectMgr::GetGameTeleExactName(std::string_view name) const
{
// explicit name case
std::wstring wname;
@@ -9005,7 +9005,7 @@ bool ObjectMgr::AddGameTele(GameTele& tele)
return true;
}
bool ObjectMgr::DeleteGameTele(const std::string& name)
bool ObjectMgr::DeleteGameTele(std::string_view name)
{
// explicit name case
std::wstring wname;
@@ -9680,7 +9680,7 @@ uint32 ObjectMgr::GetScriptId(std::string const& name)
return 0;
ScriptNameContainer::const_iterator itr = std::lower_bound(_scriptNamesStore.begin(), _scriptNamesStore.end(), name);
if (itr == _scriptNamesStore.end() || *itr != name)
if (itr == _scriptNamesStore.end() || (*itr != name))
return 0;
return uint32(itr - _scriptNamesStore.begin());

View File

@@ -1468,12 +1468,12 @@ class TC_GAME_API ObjectMgr
// reserved names
void LoadReservedPlayersNames();
bool IsReservedName(std::string const& name) const;
bool IsReservedName(std::string_view name) const;
// name with valid structure and symbols
static ResponseCodes CheckPlayerName(std::string const& name, LocaleConstant locale, bool create = false);
static PetNameInvalidReason CheckPetName(std::string const& name, LocaleConstant locale);
static bool IsValidCharterName(std::string const& name);
static ResponseCodes CheckPlayerName(std::string_view name, LocaleConstant locale, bool create = false);
static PetNameInvalidReason CheckPetName(std::string_view name, LocaleConstant locale);
static bool IsValidCharterName(std::string_view name);
static bool CheckDeclinedNames(const std::wstring& w_ownname, DeclinedName const& names);
@@ -1483,11 +1483,11 @@ class TC_GAME_API ObjectMgr
if (itr == _gameTeleStore.end()) return nullptr;
return &itr->second;
}
GameTele const* GetGameTele(std::string const& name) const;
GameTele const* GetGameTeleExactName(std::string const& name) const;
GameTele const* GetGameTele(std::string_view name) const;
GameTele const* GetGameTeleExactName(std::string_view name) const;
GameTeleContainer const& GetGameTeleMap() const { return _gameTeleStore; }
bool AddGameTele(GameTele& data);
bool DeleteGameTele(std::string const& name);
bool DeleteGameTele(std::string_view name);
Trainer::Trainer const* GetTrainer(uint32 creatureId) const;

File diff suppressed because it is too large Load Diff

View File

@@ -21,7 +21,9 @@
#include "DatabaseEnvFwd.h"
#include "ObjectGuid.h"
#include "SharedDefines.h"
#include <set>
#include <unordered_map>
#include <unordered_set>
class Item;
class Player;
@@ -274,9 +276,7 @@ class GuildBankRightsAndSlots
uint32 slots;
};
typedef std::vector <GuildBankRightsAndSlots> GuildBankRightsAndSlotsVec;
typedef std::set <uint8> SlotIds;
using SlotIds = std::set<uint8>;
class TC_GAME_API Guild
{
@@ -288,11 +288,11 @@ class TC_GAME_API Guild
Member(ObjectGuid::LowType guildId, ObjectGuid guid, uint8 rankId);
void SetStats(Player* player);
void SetStats(std::string const& name, uint8 level, uint8 _class, uint8 gender, uint32 zoneId, uint32 accountId);
void SetStats(std::string_view name, uint8 level, uint8 _class, uint8 gender, uint32 zoneId, uint32 accountId);
bool CheckStats() const;
void SetPublicNote(std::string const& publicNote);
void SetOfficerNote(std::string const& officerNote);
void SetPublicNote(std::string_view publicNote);
void SetOfficerNote(std::string_view officerNote);
void SetZoneID(uint32 id) { m_zoneId = id; }
void SetLevel(uint8 var) { m_level = var; }
@@ -348,7 +348,7 @@ class TC_GAME_API Guild
std::string m_publicNote;
std::string m_officerNote;
int32 m_bankWithdraw[GUILD_BANK_MAX_TABS + 1];
std::array<int32, GUILD_BANK_MAX_TABS + 1> m_bankWithdraw = {};
};
// Base class for event entries
@@ -432,27 +432,30 @@ class TC_GAME_API Guild
};
// Class encapsulating work with events collection
typedef std::list<LogEntry*> GuildLog;
template <typename Entry>
class LogHolder
{
public:
LogHolder(uint32 maxRecords) : m_maxRecords(maxRecords), m_nextGUID(uint32(GUILD_EVENT_LOG_GUID_UNDEFINED)) { }
~LogHolder();
LogHolder();
// Checks if new log entry can be added to holder
bool CanInsert() const { return m_log.size() < m_maxRecords; }
uint8 GetSize() const { return uint8(m_log.size()); }
// Checks if new log entry can be added to holder when loading from DB
inline bool CanInsert() const { return m_log.size() < m_maxRecords; }
// Adds event from DB to collection
void LoadEvent(LogEntry* entry);
template <typename... Ts>
void LoadEvent(Ts&&... args);
// Adds new event to collection and saves it to DB
void AddEvent(CharacterDatabaseTransaction& trans, LogEntry* entry);
template <typename... Ts>
void AddEvent(CharacterDatabaseTransaction trans, Ts&&... args);
uint32 GetNextGUID();
GuildLog* GetGuildLog() { return &m_log; }
std::list<Entry>& GetGuildLog() { return m_log; }
std::list<Entry> const& GetGuildLog() const { return m_log; }
private:
GuildLog m_log;
uint32 m_maxRecords;
std::list<Entry> m_log;
uint32 const m_maxRecords;
uint32 m_nextGUID;
};
@@ -462,7 +465,7 @@ class TC_GAME_API Guild
public:
RankInfo(): m_guildId(0), m_rankId(GUILD_RANK_NONE), m_rights(GR_RIGHT_EMPTY), m_bankMoneyPerDay(0) { }
RankInfo(ObjectGuid::LowType guildId) : m_guildId(guildId), m_rankId(GUILD_RANK_NONE), m_rights(GR_RIGHT_EMPTY), m_bankMoneyPerDay(0) { }
RankInfo(ObjectGuid::LowType guildId, uint8 rankId, std::string const& name, uint32 rights, uint32 money) :
RankInfo(ObjectGuid::LowType guildId, uint8 rankId, std::string_view name, uint32 rights, uint32 money) :
m_guildId(guildId), m_rankId(rankId), m_name(name), m_rights(rights),
m_bankMoneyPerDay(rankId != GR_GUILDMASTER ? money : GUILD_WITHDRAW_MONEY_UNLIMITED) { }
@@ -472,7 +475,7 @@ class TC_GAME_API Guild
uint8 GetId() const { return m_rankId; }
std::string const& GetName() const { return m_name; }
void SetName(std::string const& name);
void SetName(std::string_view name);
uint32 GetRights() const { return m_rights; }
void SetRights(uint32 rights);
@@ -501,7 +504,7 @@ class TC_GAME_API Guild
std::string m_name;
uint32 m_rights;
uint32 m_bankMoneyPerDay;
GuildBankRightsAndSlots m_bankTabRightsAndSlots[GUILD_BANK_MAX_TABS];
std::array<GuildBankRightsAndSlots, GUILD_BANK_MAX_TABS> m_bankTabRightsAndSlots = {};
};
class BankTab
@@ -513,8 +516,8 @@ class TC_GAME_API Guild
bool LoadItemFromDB(Field* fields);
void Delete(CharacterDatabaseTransaction& trans, bool removeItemsFromDB = false);
void SetInfo(std::string const& name, std::string const& icon);
void SetText(std::string const& text);
void SetInfo(std::string_view name, std::string_view icon);
void SetText(std::string_view text);
void SendText(Guild const* guild, WorldSession* session) const;
std::string const& GetName() const { return m_name; }
@@ -528,7 +531,7 @@ class TC_GAME_API Guild
ObjectGuid::LowType m_guildId;
uint8 m_tabId;
Item* m_items[GUILD_BANK_MAX_SLOTS];
std::array<Item*, GUILD_BANK_MAX_SLOTS> m_items = {};
std::string m_name;
std::string m_icon;
std::string m_text;
@@ -620,18 +623,14 @@ class TC_GAME_API Guild
void CanStoreItemInTab(Item* pItem, uint8 skipSlotId, bool merge, uint32& count);
};
typedef std::unordered_map<uint32, Member*> Members;
typedef std::vector<RankInfo> Ranks;
typedef std::vector<BankTab*> BankTabs;
public:
static void SendCommandResult(WorldSession* session, GuildCommandType type, GuildCommandError errCode, std::string const& param = "");
static void SendCommandResult(WorldSession* session, GuildCommandType type, GuildCommandError errCode, std::string_view param = "");
static void SendSaveEmblemResult(WorldSession* session, GuildEmblemError errCode);
Guild();
~Guild();
bool Create(Player* pLeader, std::string const& name);
bool Create(Player* pLeader, std::string_view name);
void Disband();
// Getters
@@ -644,25 +643,25 @@ class TC_GAME_API Guild
time_t GetCreatedDate() const { return m_createdDate; }
uint64 GetBankMoney() const { return m_bankMoney; }
bool SetName(std::string const& name);
bool SetName(std::string_view name);
// Handle client commands
void HandleRoster(WorldSession* session);
void HandleQuery(WorldSession* session);
void HandleSetMOTD(WorldSession* session, std::string const& motd);
void HandleSetInfo(WorldSession* session, std::string const& info);
void HandleSetMOTD(WorldSession* session, std::string_view motd);
void HandleSetInfo(WorldSession* session, std::string_view info);
void HandleSetEmblem(WorldSession* session, EmblemInfo const& emblemInfo);
void HandleSetLeader(WorldSession* session, std::string const& name);
void HandleSetBankTabInfo(WorldSession* session, uint8 tabId, std::string const& name, std::string const& icon);
void HandleSetMemberNote(WorldSession* session, std::string const& name, std::string const& note, bool officer);
void HandleSetRankInfo(WorldSession* session, uint8 rankId, std::string const& name, uint32 rights, uint32 moneyPerDay, GuildBankRightsAndSlotsVec const& rightsAndSlots);
void HandleSetLeader(WorldSession* session, std::string_view name);
void HandleSetBankTabInfo(WorldSession* session, uint8 tabId, std::string_view name, std::string_view icon);
void HandleSetMemberNote(WorldSession* session, std::string_view name, std::string_view note, bool officer);
void HandleSetRankInfo(WorldSession* session, uint8 rankId, std::string_view name, uint32 rights, uint32 moneyPerDay, std::array<GuildBankRightsAndSlots, GUILD_BANK_MAX_TABS> const& rightsAndSlots);
void HandleBuyBankTab(WorldSession* session, uint8 tabId);
void HandleInviteMember(WorldSession* session, std::string const& name);
void HandleInviteMember(WorldSession* session, std::string_view name);
void HandleAcceptMember(WorldSession* session);
void HandleLeaveMember(WorldSession* session);
void HandleRemoveMember(WorldSession* session, std::string const& name);
void HandleUpdateMemberRank(WorldSession* session, std::string const& name, bool demote);
void HandleAddNewRank(WorldSession* session, std::string const& name);
void HandleRemoveMember(WorldSession* session, std::string_view name);
void HandleUpdateMemberRank(WorldSession* session, std::string_view name, bool demote);
void HandleAddNewRank(WorldSession* session, std::string_view name);
void HandleRemoveRank(WorldSession* session, uint8 rankId);
void HandleRemoveLowestRank(WorldSession* session);
void HandleMemberDepositMoney(WorldSession* session, uint32 amount);
@@ -696,7 +695,7 @@ class TC_GAME_API Guild
bool Validate();
// Broadcasts
void BroadcastToGuild(WorldSession* session, bool officerOnly, std::string const& msg, uint32 language = LANG_UNIVERSAL) const;
void BroadcastToGuild(WorldSession* session, bool officerOnly, std::string_view msg, uint32 language = LANG_UNIVERSAL) const;
void BroadcastPacketToRank(WorldPacket const* packet, uint8 rankId) const;
void BroadcastPacket(WorldPacket const* packet) const;
@@ -706,7 +705,7 @@ class TC_GAME_API Guild
void BroadcastWorker(Do& _do, Player* except = nullptr)
{
for (auto itr = m_members.begin(); itr != m_members.end(); ++itr)
if (Player* player = itr->second->FindConnectedPlayer())
if (Player* player = itr->second.FindConnectedPlayer())
if (player != except)
_do(player);
}
@@ -722,7 +721,7 @@ class TC_GAME_API Guild
void SwapItemsWithInventory(Player* player, bool toChar, uint8 tabId, uint8 slotId, uint8 playerBag, uint8 playerSlotId, uint32 splitedAmount);
// Bank tabs
void SetBankTabText(uint8 tabId, std::string const& text);
void SetBankTabText(uint8 tabId, std::string_view text);
void ResetTimes();
@@ -738,13 +737,13 @@ class TC_GAME_API Guild
uint32 m_accountsNumber;
uint64 m_bankMoney;
Ranks m_ranks;
Members m_members;
BankTabs m_bankTabs;
std::vector<RankInfo> m_ranks;
std::unordered_map<uint32, Member> m_members;
std::vector<BankTab> m_bankTabs;
// These are actually ordered lists. The first element is the oldest entry.
LogHolder* m_eventLog;
LogHolder* m_bankEventLog[GUILD_BANK_MAX_TABS + 1];
LogHolder<EventLogEntry> m_eventLog;
std::array<LogHolder<BankEventLogEntry>, GUILD_BANK_MAX_TABS + 1> m_bankEventLog = {};
private:
inline uint8 _GetRanksSize() const { return uint8(m_ranks.size()); }
@@ -755,46 +754,44 @@ class TC_GAME_API Guild
inline uint8 _GetLowestRankId() const { return uint8(m_ranks.size() - 1); }
inline uint8 _GetPurchasedTabsSize() const { return uint8(m_bankTabs.size()); }
inline BankTab* GetBankTab(uint8 tabId) { return tabId < m_bankTabs.size() ? m_bankTabs[tabId] : nullptr; }
inline BankTab const* GetBankTab(uint8 tabId) const { return tabId < m_bankTabs.size() ? m_bankTabs[tabId] : nullptr; }
inline BankTab* GetBankTab(uint8 tabId) { return tabId < m_bankTabs.size() ? &m_bankTabs[tabId] : nullptr; }
inline BankTab const* GetBankTab(uint8 tabId) const { return tabId < m_bankTabs.size() ? &m_bankTabs[tabId] : nullptr; }
inline Member const* GetMember(ObjectGuid guid) const
{
auto itr = m_members.find(guid.GetCounter());
return itr != m_members.end() ? itr->second : nullptr;
return (itr != m_members.end()) ? &itr->second : nullptr;
}
inline Member* GetMember(ObjectGuid guid)
{
auto itr = m_members.find(guid.GetCounter());
return itr != m_members.end() ? itr->second : nullptr;
return (itr != m_members.end()) ? &itr->second : nullptr;
}
inline Member* GetMember(std::string const& name)
inline Member* GetMember(std::string_view name)
{
for (auto itr = m_members.begin(); itr != m_members.end(); ++itr)
if (itr->second->GetName() == name)
return itr->second;
if (itr->second.GetName() == name)
return &itr->second;
return nullptr;
}
static void _DeleteMemberFromDB(CharacterDatabaseTransaction& trans, ObjectGuid::LowType lowguid);
// Creates log holders (either when loading or when creating guild)
void _CreateLogHolders();
// Tries to create new bank tab
void _CreateNewBankTab();
// Creates default guild ranks with names in given locale
void _CreateDefaultGuildRanks(CharacterDatabaseTransaction& trans, LocaleConstant loc);
// Creates new rank
bool _CreateRank(CharacterDatabaseTransaction& trans, std::string const& name, uint32 rights);
bool _CreateRank(CharacterDatabaseTransaction& trans, std::string_view name, uint32 rights);
// Update account number when member added/removed from guild
void _UpdateAccountsNumber();
bool _IsLeader(Player* player) const;
void _DeleteBankItems(CharacterDatabaseTransaction& trans, bool removeItemsFromDB = false);
bool _ModifyBankMoney(CharacterDatabaseTransaction& trans, uint64 amount, bool add);
void _SetLeaderGUID(Member* pLeader);
void _SetLeaderGUID(Member& pLeader);
void _SetRankBankMoneyPerDay(uint8 rankId, uint32 moneyPerDay);
void _SetRankBankTabRightsAndSlots(uint8 rankId, GuildBankRightsAndSlots rightsAndSlots, bool saveToDB = true);
@@ -804,8 +801,8 @@ class TC_GAME_API Guild
int32 _GetRankBankTabSlotsPerDay(uint8 rankId, uint8 tabId) const;
std::string _GetRankName(uint8 rankId) const;
int32 _GetMemberRemainingSlots(Member const* member, uint8 tabId) const;
int32 _GetMemberRemainingMoney(Member const* member) const;
int32 _GetMemberRemainingSlots(Member const& member, uint8 tabId) const;
int32 _GetMemberRemainingMoney(Member const& member) const;
void _UpdateMemberWithdrawSlots(CharacterDatabaseTransaction& trans, ObjectGuid guid, uint8 tabId);
bool _MemberHasTabRights(ObjectGuid guid, uint8 tabId, uint32 rights) const;
@@ -823,6 +820,6 @@ class TC_GAME_API Guild
void _SendBankContentUpdate(uint8 tabId, SlotIds slots) const;
void _SendBankList(WorldSession* session = nullptr, uint8 tabId = 0, bool sendFullSlots = false, SlotIds* slots = nullptr) const;
void _BroadcastEvent(GuildEvents guildEvent, ObjectGuid guid, char const* param1 = nullptr, char const* param2 = nullptr, char const* param3 = nullptr) const;
void _BroadcastEvent(GuildEvents guildEvent, ObjectGuid guid, std::string_view param1 = "", std::string_view param2 = "", std::string_view param3 = "") const;
};
#endif

View File

@@ -20,6 +20,7 @@
#include "Guild.h"
#include "Log.h"
#include "ObjectMgr.h"
#include "Util.h"
#include "World.h"
GuildMgr::GuildMgr() : NextGuildId(1)
@@ -61,17 +62,12 @@ Guild* GuildMgr::GetGuildById(ObjectGuid::LowType guildId) const
return nullptr;
}
Guild* GuildMgr::GetGuildByName(const std::string& guildName) const
Guild* GuildMgr::GetGuildByName(std::string_view guildName) const
{
std::string search = guildName;
std::transform(search.begin(), search.end(), search.begin(), ::toupper);
for (GuildContainer::const_iterator itr = GuildStore.begin(); itr != GuildStore.end(); ++itr)
{
std::string gname = itr->second->GetName();
std::transform(gname.begin(), gname.end(), gname.begin(), ::toupper);
if (search == gname)
return itr->second;
}
for (auto [id, guild] : GuildStore)
if (StringEqualI(guild->GetName(), guildName))
return guild;
return nullptr;
}

View File

@@ -38,7 +38,7 @@ public:
Guild* GetGuildByLeader(ObjectGuid guid) const;
Guild* GetGuildById(ObjectGuid::LowType guildId) const;
Guild* GetGuildByName(std::string const& guildName) const;
Guild* GetGuildByName(std::string_view guildName) const;
std::string GetGuildNameById(ObjectGuid::LowType guildId) const;
void LoadGuilds();

View File

@@ -169,7 +169,7 @@ void WorldSession::HandleGuildSetRankPermissions(WorldPackets::Guild::GuildSetRa
if (!guild)
return;
GuildBankRightsAndSlotsVec rightsAndSlots(GUILD_BANK_MAX_TABS);
std::array<GuildBankRightsAndSlots, GUILD_BANK_MAX_TABS> rightsAndSlots;
for (uint8 tabId = 0; tabId < GUILD_BANK_MAX_TABS; ++tabId)
rightsAndSlots[tabId] = GuildBankRightsAndSlots(tabId, uint8(packet.TabFlags[tabId]), uint32(packet.TabWithdrawItemLimit[tabId]));

View File

@@ -122,7 +122,7 @@ ByteBuffer& operator<<(ByteBuffer& data, WorldPackets::Guild::GuildRosterMemberD
WorldPacket const* WorldPackets::Guild::GuildEvent::Write()
{
_worldPacket << uint8(Type);
uint8 paramCount = Params[2] ? 3 : (Params[1] ? 2 : (Params[0] ? 1 : 0));
uint8 paramCount = Params[2].empty() ? (Params[1].empty() ? (Params[0].empty() ? 0 : 1) : 2) : 3;
_worldPacket << uint8(paramCount);
for (uint8 i = 0; i < paramCount; ++i)
_worldPacket << Params[i];

View File

@@ -207,7 +207,7 @@ namespace WorldPackets
WorldPacket const* Write() override;
uint8 Type = 0;
std::array<char const*, 3> Params = { };
std::array<std::string_view, 3> Params = { };
ObjectGuid Guid;
};

View File

@@ -20,6 +20,7 @@
#include "ByteBuffer.h"
#include "Tuples.h"
#include <string_view>
namespace WorldPackets
{
@@ -76,6 +77,7 @@ namespace WorldPackets
bool empty() const { return _storage.empty(); }
char const* c_str() const { return _storage.c_str(); }
operator std::string_view() const { return _storage; }
operator std::string&() { return _storage; }
operator std::string const&() const { return _storage; }