[Bug Fix] Fix GetLeaderName() for Groups (#4184)

* [Bug Fix] Fix GetLeaderName() for Groups

# Notes
- We were getting bogus data in this.
- Made it its own method.

* Remove ExpeditionRequest::GetGroupLeaderName()
This commit is contained in:
Alex King 2024-03-13 21:52:02 -04:00 committed by GitHub
parent e48dae2392
commit b29c26becb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 32 additions and 24 deletions

View File

@ -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) 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); std::string query = StringFormat("SELECT `leadername`, `maintank`, `assist`, `puller`, `marknpc`, `mentoree`, `mentor_percent`, `leadershipaa` FROM `group_leaders` WHERE `gid` = %lu",(unsigned long)gid);

View File

@ -205,6 +205,8 @@ public:
std::string GetGroupLeaderForLogin(std::string character_name); 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); 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); uint32 GetGroupID(const char* name);
void ClearGroup(uint32 gid = 0); void ClearGroup(uint32 gid = 0);

View File

@ -2152,7 +2152,7 @@ Group *EntityList::GetGroupByLeaderName(const char *leader)
iterator = group_list.begin(); iterator = group_list.begin();
while (iterator != group_list.end()) { while (iterator != group_list.end()) {
if (!strcmp((*iterator)->GetLeaderName(), leader)) if (!strcmp((*iterator)->GetLeaderName().c_str(), leader))
return *iterator; return *iterator;
++iterator; ++iterator;
} }

View File

@ -125,7 +125,7 @@ bool ExpeditionRequest::CanGroupRequest(Group* group)
} }
// Group::GetLeaderName() is broken if group formed across zones, ask database instead // 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); m_leader_id = m_leader ? m_leader->CharacterID() : database.GetCharacterID(m_leader_name);
std::vector<std::string> member_names; std::vector<std::string> member_names;
@ -148,13 +148,6 @@ bool ExpeditionRequest::CanGroupRequest(Group* group)
return CanMembersJoin(member_names); 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<std::string>& member_names) bool ExpeditionRequest::CanMembersJoin(const std::vector<std::string>& member_names)
{ {
if (member_names.empty()) if (member_names.empty())

View File

@ -54,7 +54,6 @@ private:
bool CanRaidRequest(Raid* raid); bool CanRaidRequest(Raid* raid);
bool CanGroupRequest(Group* group); bool CanGroupRequest(Group* group);
bool CheckMembersForConflicts(const std::vector<std::string>& member_names); bool CheckMembersForConflicts(const std::vector<std::string>& member_names);
std::string GetGroupLeaderName(uint32_t group_id);
bool IsPlayerCountValidated(); bool IsPlayerCountValidated();
bool SaveLeaderLockouts(const std::vector<ExpeditionLockoutTimer>& leader_lockouts); bool SaveLeaderLockouts(const std::vector<ExpeditionLockoutTimer>& leader_lockouts);
void SendLeaderMemberInExpedition(const std::string& member_name, bool is_solo); void SendLeaderMemberInExpedition(const std::string& member_name, bool is_solo);

View File

@ -620,7 +620,7 @@ bool Group::DelMemberOOZ(const char *Name) {
if(!strcasecmp(Name, membername[i])) if(!strcasecmp(Name, membername[i]))
// This shouldn't be called if the member is in this zone. // This shouldn't be called if the member is in this zone.
if(!members[i]) { if(!members[i]) {
if(!strncmp(GetLeaderName(), Name, 64)) if(!strncmp(GetLeaderName().c_str(), Name, 64))
{ {
//TODO: Transfer leadership if leader disbands OOZ. //TODO: Transfer leadership if leader disbands OOZ.
UpdateGroupAAs(); UpdateGroupAAs();
@ -703,7 +703,7 @@ bool Group::DelMember(Mob* oldmember, bool ignoresender)
} }
} }
if (!GetLeaderName()) if (GetLeaderName().empty())
{ {
DisbandGroup(); DisbandGroup();
return true; return true;
@ -1676,7 +1676,7 @@ void Group::NotifyMainTank(Client *c, uint8 toggle)
strn0cpy(grs->Name1, MainTankName.c_str(), sizeof(grs->Name1)); 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; 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->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; 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->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; grs->RoleNumber = 3;
@ -2511,8 +2511,6 @@ bool Group::IsLeader(const char* name) {
return false; return false;
} }
std::string Group::GetGroupLeaderName(uint32 group_id) { std::string Group::GetLeaderName() {
char leader_name_buffer[64] = { 0 }; return database.GetGroupLeaderName(GetID());
database.GetGroupLeadershipInfo(group_id, leader_name_buffer);
return std::string(leader_name_buffer);
} }

View File

@ -76,7 +76,7 @@ public:
void SplitMoney(uint32 copper, uint32 silver, uint32 gold, uint32 platinum, Client *splitter = nullptr); void SplitMoney(uint32 copper, uint32 silver, uint32 gold, uint32 platinum, Client *splitter = nullptr);
inline void SetLeader(Mob* c){ leader = c; }; inline void SetLeader(Mob* c){ leader = c; };
inline Mob* GetLeader() { return leader; }; inline Mob* GetLeader() { return leader; };
const char* GetLeaderName() { return GetGroupLeaderName(GetID()).c_str(); }; std::string GetLeaderName();
void SendHPManaEndPacketsTo(Mob* newmember); void SendHPManaEndPacketsTo(Mob* newmember);
void SendHPPacketsFrom(Mob* member); void SendHPPacketsFrom(Mob* member);
void SendManaPacketFrom(Mob* member); void SendManaPacketFrom(Mob* member);
@ -177,8 +177,6 @@ private:
int mentor_percent; int mentor_percent;
XTargetAutoHaters m_autohatermgr; XTargetAutoHaters m_autohatermgr;
std::string GetGroupLeaderName(uint32 group_id);
}; };
#endif #endif

View File

@ -72,7 +72,7 @@ Lua_Mob Lua_Group::GetLeader() {
return self->GetLeader(); return self->GetLeader();
} }
const char *Lua_Group::GetLeaderName() { std::string Lua_Group::GetLeaderName() {
Lua_Safe_Call_String(); Lua_Safe_Call_String();
return self->GetLeaderName(); return self->GetLeaderName();
} }

View File

@ -39,7 +39,7 @@ public:
void SplitMoney(uint32 copper, uint32 silver, uint32 gold, uint32 platinum, Lua_Client splitter); void SplitMoney(uint32 copper, uint32 silver, uint32 gold, uint32 platinum, Lua_Client splitter);
void SetLeader(Lua_Mob c); void SetLeader(Lua_Mob c);
Lua_Mob GetLeader(); Lua_Mob GetLeader();
const char *GetLeaderName(); std::string GetLeaderName();
bool IsLeader(const char* name); bool IsLeader(const char* name);
bool IsLeader(Lua_Mob c); bool IsLeader(Lua_Mob c);
int GroupCount(); int GroupCount();