Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug Fix] Added additional crash checks to zone and world guild_mgr #4105

Merged
merged 1 commit into from Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions world/wguild_mgr.cpp
Expand Up @@ -369,6 +369,10 @@ bool WorldGuildManager::LoadTributes()
bool WorldGuildManager::RefreshGuild(uint32 guild_id)
{
auto temp_guild = GetGuildByGuildID(guild_id);
if (!temp_guild) {
return false;
}

BaseGuildManager::GuildInfo temp_guild_detail;

if (temp_guild) {
Expand All @@ -389,6 +393,11 @@ bool WorldGuildManager::RefreshGuild(uint32 guild_id)
LogGuilds("Found guild id [{}]. Loading details.....", db_guild.id);
_CreateGuild(db_guild.id, db_guild.name, db_guild.leader, db_guild.minstatus, db_guild.motd, db_guild.motd_setter, db_guild.channel, db_guild.url, db_guild.favor);
auto guild = GetGuildByGuildID(guild_id);
if (!guild) {
LogError("Error refreshing guild id {}", guild_id);
return false;
}

auto where_filter = fmt::format("guild_id = '{}'", guild_id);
auto guild_ranks = GuildRanksRepository::GetWhere(*m_db, where_filter);
for (auto const& r : guild_ranks) {
Expand Down
71 changes: 39 additions & 32 deletions zone/guild_mgr.cpp
Expand Up @@ -514,14 +514,18 @@ void ZoneGuildManager::ProcessWorldPacket(ServerPacket *pack)
}
case ServerOP_GuildPermissionUpdate: {
if (is_zone_loaded) {
auto *sgpus = (ServerGuildPermissionUpdate_Struct *) pack->pBuffer;
auto res = m_guilds.find(sgpus->guild_id);
if (sgpus->function_value) {
res->second->functions[sgpus->function_id].perm_value |= (1UL << (8 - sgpus->rank));
}
else {
res->second->functions[sgpus->function_id].perm_value &= ~(1UL << (8 - sgpus->rank));
}
auto *sgpus = (ServerGuildPermissionUpdate_Struct *)pack->pBuffer;
auto guild = GetGuildByGuildID(sgpus->guild_id);
if (!guild) {
return;
}

if (sgpus->function_value) {
guild->functions[sgpus->function_id].perm_value |= (1UL << (8 - sgpus->rank));
}
else {
guild->functions[sgpus->function_id].perm_value &= ~(1UL << (8 - sgpus->rank));
}

auto outapp = new EQApplicationPacket(OP_GuildUpdate, sizeof(GuildPermission_Struct));
auto *guuacs = (GuildPermission_Struct *) outapp->pBuffer;
Expand Down Expand Up @@ -1489,16 +1493,20 @@ bool GuildBankManager::AllowedToWithdraw(uint32 GuildID, uint16 Area, uint16 Slo

void ZoneGuildManager::UpdateRankPermission(uint32 gid, uint32 charid, uint32 fid, uint32 rank, uint32 value)
{
auto res = m_guilds.find(gid);
if (value) {
res->second->functions[fid].perm_value |= (1UL << (8 - rank));
}
else {
res->second->functions[fid].perm_value &= ~(1UL << (8 - rank));
}
auto query = fmt::format("UPDATE guild_permissions SET permission = {} WHERE perm_id = {} AND guild_id = {};", res->second->functions[fid].perm_value, fid, gid);
auto results = m_db->QueryDatabase(query);
auto guild = GetGuildByGuildID(gid);
if (!guild) {
return;
}

if (value) {
guild->functions[fid].perm_value |= (1UL << (8 - rank));
}
else {
guild->functions[fid].perm_value &= ~(1UL << (8 - rank));
}
auto query = fmt::format("UPDATE guild_permissions SET permission = {} WHERE perm_id = {} AND guild_id = {};",
guild->functions[fid].perm_value, fid, gid);
auto results = m_db->QueryDatabase(query);
}

void ZoneGuildManager::SendPermissionUpdate(uint32 guild_id, uint32 rank, uint32 function_id, uint32 value)
Expand Down Expand Up @@ -1534,21 +1542,20 @@ void ZoneGuildManager::SendRankName(uint32 guild_id, uint32 rank, std::string ra

void ZoneGuildManager::SendAllRankNames(uint32 guild_id, uint32 char_id)
{
auto guild = m_guilds.find(guild_id);
auto c = entity_list.GetClientByCharID(char_id);
if (c)
{
auto outapp = new EQApplicationPacket(OP_GuildUpdate, sizeof(GuildUpdateUCPStruct));
GuildUpdateUCPStruct* gucp = (GuildUpdateUCPStruct*)outapp->pBuffer;
for (int i = GUILD_LEADER; i <= GUILD_RECRUIT; i++)
{
gucp->payload.rank_name.rank = i;
strn0cpy(gucp->payload.rank_name.rank_name, guild->second->rank_names[i].c_str(), sizeof(gucp->payload.rank_name.rank_name));
gucp->action = GuildUpdateRanks;
c->QueuePacket(outapp);
}
safe_delete(outapp);
}
auto guild = GetGuildByGuildID(guild_id);
auto c = entity_list.GetClientByCharID(char_id);
if (guild && c) {
auto outapp = new EQApplicationPacket(OP_GuildUpdate, sizeof(GuildUpdateUCPStruct));
GuildUpdateUCPStruct *gucp = (GuildUpdateUCPStruct *)outapp->pBuffer;
for (int i = GUILD_LEADER; i <= GUILD_RECRUIT; i++) {
gucp->payload.rank_name.rank = i;
strn0cpy(gucp->payload.rank_name.rank_name, guild->rank_names[i].c_str(),
sizeof(gucp->payload.rank_name.rank_name));
gucp->action = GuildUpdateRanks;
c->QueuePacket(outapp);
}
safe_delete(outapp);
}
}

BaseGuildManager::GuildInfo* ZoneGuildManager::GetGuildByGuildID(uint32 guild_id)
Expand Down