diff --git a/common/database.cpp b/common/database.cpp index d80b6d0dc..98fa2c5df 100644 --- a/common/database.cpp +++ b/common/database.cpp @@ -1389,6 +1389,24 @@ void Database::SetGroupLeaderName(uint32 gid, const char* name) { } } +std::string Database::GetGroupLeaderName(uint32 group_id) +{ + const std::string& query = fmt::format( + "SELECT `leadername` FROM `group_leaders` WHERE `gid` = {}", + group_id + ); + + auto results = QueryDatabase(query); + + if (!results.Success() || !results.RowCount()) { + return std::string(); + } + + auto row = results.begin(); + + return row[0]; +} + char *Database::GetGroupLeadershipInfo(uint32 gid, char* leaderbuf, char* maintank, char* assist, char* puller, char *marknpc, char *mentoree, int *mentor_percent, GroupLeadershipAA_Struct* GLAA) { std::string query = StringFormat("SELECT `leadername`, `maintank`, `assist`, `puller`, `marknpc`, `mentoree`, `mentor_percent`, `leadershipaa` FROM `group_leaders` WHERE `gid` = %lu",(unsigned long)gid); diff --git a/common/database.h b/common/database.h index 1ab16f180..850632b7f 100644 --- a/common/database.h +++ b/common/database.h @@ -205,6 +205,8 @@ public: std::string GetGroupLeaderForLogin(std::string character_name); char* GetGroupLeadershipInfo(uint32 gid, char* leaderbuf, char* maintank = nullptr, char* assist = nullptr, char* puller = nullptr, char *marknpc = nullptr, char *mentoree = nullptr, int *mentor_percent = nullptr, GroupLeadershipAA_Struct* GLAA = nullptr); + std::string GetGroupLeaderName(uint32 group_id); + uint32 GetGroupID(const char* name); void ClearGroup(uint32 gid = 0); diff --git a/zone/entity.cpp b/zone/entity.cpp index 69b76ec67..1a40ccb6a 100644 --- a/zone/entity.cpp +++ b/zone/entity.cpp @@ -2152,7 +2152,7 @@ Group *EntityList::GetGroupByLeaderName(const char *leader) iterator = group_list.begin(); while (iterator != group_list.end()) { - if (!strcmp((*iterator)->GetLeaderName(), leader)) + if (!strcmp((*iterator)->GetLeaderName().c_str(), leader)) return *iterator; ++iterator; } diff --git a/zone/expedition_request.cpp b/zone/expedition_request.cpp index 0fbf90af9..0a19532a6 100644 --- a/zone/expedition_request.cpp +++ b/zone/expedition_request.cpp @@ -125,7 +125,7 @@ bool ExpeditionRequest::CanGroupRequest(Group* group) } // Group::GetLeaderName() is broken if group formed across zones, ask database instead - m_leader_name = m_leader ? m_leader->GetName() : GetGroupLeaderName(group->GetID()); // group->GetLeaderName(); + m_leader_name = m_leader ? m_leader->GetName() : group->GetLeaderName(); m_leader_id = m_leader ? m_leader->CharacterID() : database.GetCharacterID(m_leader_name); std::vector member_names; @@ -148,13 +148,6 @@ bool ExpeditionRequest::CanGroupRequest(Group* group) return CanMembersJoin(member_names); } -std::string ExpeditionRequest::GetGroupLeaderName(uint32_t group_id) -{ - char leader_name_buffer[64] = { 0 }; - database.GetGroupLeadershipInfo(group_id, leader_name_buffer); - return std::string(leader_name_buffer); -} - bool ExpeditionRequest::CanMembersJoin(const std::vector& member_names) { if (member_names.empty()) diff --git a/zone/expedition_request.h b/zone/expedition_request.h index 6f1396a42..059aa71de 100644 --- a/zone/expedition_request.h +++ b/zone/expedition_request.h @@ -54,7 +54,6 @@ private: bool CanRaidRequest(Raid* raid); bool CanGroupRequest(Group* group); bool CheckMembersForConflicts(const std::vector& member_names); - std::string GetGroupLeaderName(uint32_t group_id); bool IsPlayerCountValidated(); bool SaveLeaderLockouts(const std::vector& leader_lockouts); void SendLeaderMemberInExpedition(const std::string& member_name, bool is_solo); diff --git a/zone/groups.cpp b/zone/groups.cpp index 913c0fdfd..6ffa06655 100644 --- a/zone/groups.cpp +++ b/zone/groups.cpp @@ -620,7 +620,7 @@ bool Group::DelMemberOOZ(const char *Name) { if(!strcasecmp(Name, membername[i])) // This shouldn't be called if the member is in this zone. if(!members[i]) { - if(!strncmp(GetLeaderName(), Name, 64)) + if(!strncmp(GetLeaderName().c_str(), Name, 64)) { //TODO: Transfer leadership if leader disbands OOZ. UpdateGroupAAs(); @@ -703,7 +703,7 @@ bool Group::DelMember(Mob* oldmember, bool ignoresender) } } - if (!GetLeaderName()) + if (GetLeaderName().empty()) { DisbandGroup(); return true; @@ -1676,7 +1676,7 @@ void Group::NotifyMainTank(Client *c, uint8 toggle) strn0cpy(grs->Name1, MainTankName.c_str(), sizeof(grs->Name1)); - strn0cpy(grs->Name2, GetLeaderName(), sizeof(grs->Name2)); + strn0cpy(grs->Name2, GetLeaderName().c_str(), sizeof(grs->Name2)); grs->RoleNumber = 1; @@ -1729,7 +1729,7 @@ void Group::NotifyMainAssist(Client *c, uint8 toggle) strn0cpy(grs->Name1, MainAssistName.c_str(), sizeof(grs->Name1)); - strn0cpy(grs->Name2, GetLeaderName(), sizeof(grs->Name2)); + strn0cpy(grs->Name2, GetLeaderName().c_str(), sizeof(grs->Name2)); grs->RoleNumber = 2; @@ -1771,7 +1771,7 @@ void Group::NotifyPuller(Client *c, uint8 toggle) strn0cpy(grs->Name1, PullerName.c_str(), sizeof(grs->Name1)); - strn0cpy(grs->Name2, GetLeaderName(), sizeof(grs->Name2)); + strn0cpy(grs->Name2, GetLeaderName().c_str(), sizeof(grs->Name2)); grs->RoleNumber = 3; @@ -2511,8 +2511,6 @@ bool Group::IsLeader(const char* name) { return false; } -std::string Group::GetGroupLeaderName(uint32 group_id) { - char leader_name_buffer[64] = { 0 }; - database.GetGroupLeadershipInfo(group_id, leader_name_buffer); - return std::string(leader_name_buffer); +std::string Group::GetLeaderName() { + return database.GetGroupLeaderName(GetID()); } diff --git a/zone/groups.h b/zone/groups.h index c49d4c0a2..0232e74f6 100644 --- a/zone/groups.h +++ b/zone/groups.h @@ -76,7 +76,7 @@ public: void SplitMoney(uint32 copper, uint32 silver, uint32 gold, uint32 platinum, Client *splitter = nullptr); inline void SetLeader(Mob* c){ leader = c; }; inline Mob* GetLeader() { return leader; }; - const char* GetLeaderName() { return GetGroupLeaderName(GetID()).c_str(); }; + std::string GetLeaderName(); void SendHPManaEndPacketsTo(Mob* newmember); void SendHPPacketsFrom(Mob* member); void SendManaPacketFrom(Mob* member); @@ -177,8 +177,6 @@ private: int mentor_percent; XTargetAutoHaters m_autohatermgr; - - std::string GetGroupLeaderName(uint32 group_id); }; #endif diff --git a/zone/lua_group.cpp b/zone/lua_group.cpp index 67eb986c9..6d18e37c8 100644 --- a/zone/lua_group.cpp +++ b/zone/lua_group.cpp @@ -72,7 +72,7 @@ Lua_Mob Lua_Group::GetLeader() { return self->GetLeader(); } -const char *Lua_Group::GetLeaderName() { +std::string Lua_Group::GetLeaderName() { Lua_Safe_Call_String(); return self->GetLeaderName(); } diff --git a/zone/lua_group.h b/zone/lua_group.h index 41cced5e1..949740d66 100644 --- a/zone/lua_group.h +++ b/zone/lua_group.h @@ -39,7 +39,7 @@ public: void SplitMoney(uint32 copper, uint32 silver, uint32 gold, uint32 platinum, Lua_Client splitter); void SetLeader(Lua_Mob c); Lua_Mob GetLeader(); - const char *GetLeaderName(); + std::string GetLeaderName(); bool IsLeader(const char* name); bool IsLeader(Lua_Mob c); int GroupCount();