void Guild::RemoveGuildMember(PlayerInfo * pMember, WorldSession * pClient) { if(pMember->guild != this) return; if(pClient && pClient->GetPlayer()->m_playerInfo->guild != this) return; if(pClient && !pClient->GetPlayer()->m_playerInfo->guildRank->CanPerformCommand(GR_RIGHT_REMOVE) && pClient->GetPlayer()->m_playerInfo != pMember) { Guild::SendGuildCommandResult(pClient, GUILD_CREATE_S, "", GUILD_PERMISSIONS); return; } if(pMember->guildRank->iId==0) { if(pClient) pClient->SystemMessage("You cannot remove the guild master."); return; } CharacterDatabase.Execute("DELETE FROM guild_data WHERE playerid = %u", pMember->guid); m_lock.Acquire(); GuildMemberMap::iterator itr = m_members.find(pMember); if(itr != m_members.end()) { // this should always exist. if(itr->second->szOfficerNote) free((void*)itr->second->szOfficerNote); if(itr->second->szPublicNote) free((void*)itr->second->szPublicNote); delete itr->second; m_members.erase(itr); } LogGuildEvent(GUILD_EVENT_LEFT, 1, pMember->name); if(pClient && pClient->GetPlayer()->m_playerInfo != pMember) { AddGuildLogEntry(GUILD_LOG_EVENT_REMOVAL, 2, pClient->GetPlayer()->GetLowGUID(), pMember->guid); } else { AddGuildLogEntry(GUILD_LOG_EVENT_LEFT, 1, pMember->guid); } m_lock.Release(); pMember->guildRank=NULL; pMember->guild=NULL; pMember->guildMember=NULL; if(pMember->m_loggedInPlayer) { pMember->m_loggedInPlayer->SetGuildRank(0); pMember->m_loggedInPlayer->SetGuildId(0); } }
bool Guild::SetRankOfMember(PlayerInfo* pMember, uint32 rank) { if(rank > MAX_GUILD_RANKS) return false; GuildRank* newRank = m_ranks[rank]; if(newRank == NULL) return false; GuildMemberMap::iterator itr = m_members.find(pMember); if(itr == m_members.end()) return false; if(rank == 0) SetGuildMaster(pMember); itr->second->pRank = newRank; itr->second->pPlayer->guildRank = newRank; // log it LogGuildEvent(GUILD_EVENT_PROMOTION, 3, pMember->name, pMember->name, newRank->szRankName); AddGuildLogEntry(GUILD_LOG_EVENT_PROMOTION, 3, pMember->guid, pMember->guid, newRank->iId); // update in the database CharacterDatabase.Execute("UPDATE guild_data SET guildRank = %u WHERE playerid = %u AND guildid = %u", newRank->iId, pMember->guid, m_guildId); // if the player is online, update his guildrank if(pMember->m_loggedInPlayer) pMember->m_loggedInPlayer->SetGuildRank(newRank->iId); return true; }
void Guild::DemoteGuildMember(PlayerInfo* pMember, WorldSession* pClient) { if(pClient->GetPlayer()->getPlayerInfo()->guild != this || pMember->guild != this) return; if(!pClient->GetPlayer()->getPlayerInfo()->guildRank->CanPerformCommand(GR_RIGHT_DEMOTE) || pMember->guid == GetGuildLeader() || pClient->GetPlayer()->getPlayerInfo()->guildRank->iId >= pMember->guildRank->iId) { SendGuildCommandResult(pClient, GUILD_PROMOTE_S, "", GUILD_PERMISSIONS); return; } // find the next highest rank uint32 nh = pMember->guildRank->iId + 1; GuildRank* newRank = NULL; m_lock.Acquire(); while(nh < 10 && newRank == NULL) { newRank = m_ranks[nh]; ++nh; } if(newRank == NULL) { m_lock.Release(); pClient->SystemMessage("Could not find a rank to demote this member to."); return; } GuildMemberMap::iterator itr = m_members.find(pMember); if(itr == m_members.end()) { // shouldn't happen m_lock.Release(); return; } itr->second->pRank = newRank; itr->second->pPlayer->guildRank = newRank; // log it LogGuildEvent(GUILD_EVENT_DEMOTION, 3, pClient->GetPlayer()->GetName(), pMember->name, newRank->szRankName); AddGuildLogEntry(GUILD_LOG_EVENT_DEMOTION, 3, pClient->GetPlayer()->GetLowGUID(), pMember->guid, newRank->iId); // update in the database CharacterDatabase.Execute("UPDATE guild_data SET guildRank = %u WHERE playerid = %u AND guildid = %u", newRank->iId, pMember->guid, m_guildId); // if the player is online, update his guildrank if(pMember->m_loggedInPlayer) pMember->m_loggedInPlayer->SetGuildRank(newRank->iId); // release lock m_lock.Release(); }
// adding a member void Guild::AddGuildMember(PlayerInfo* pMember, WorldSession* pClient, int32 ForcedRank /* = -1 */) { //we don't need useless paranoia checks. if(pMember->guild != NULL) return; m_lock.Acquire(); GuildRank* r; if(m_members.size()) { if(ForcedRank > 0) r = m_ranks[ForcedRank]; else if(ForcedRank == -2) r = FindHighestRank(); else r = FindLowestRank(); } else { if(ForcedRank >= 0) r = m_ranks[ForcedRank]; else if(ForcedRank == -2) r = FindHighestRank(); else r = FindLowestRank(); } if(r == NULL) r = FindLowestRank(); if(r == NULL) { // shouldn't happen m_lock.Release(); return; } GuildMember* pm = new GuildMember; memset(pm, 0, sizeof(GuildMember)); pm->pPlayer = pMember; pm->pRank = r; pm->szOfficerNote = pm->szPublicNote = NULL; m_members.insert(make_pair(pMember, pm)); pMember->guild = this; pMember->guildRank = r; pMember->guildMember = pm; if(pMember->m_loggedInPlayer) { pMember->m_loggedInPlayer->SetGuildId(m_guildId); pMember->m_loggedInPlayer->SetGuildRank(r->iId); pMember->m_loggedInPlayer->SendGuildMOTD(); } CharacterDatabase.Execute("INSERT INTO guild_data VALUES(%u, %u, %u, '', '', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)", m_guildId, pMember->guid, r->iId); LogGuildEvent(GUILD_EVENT_JOINED, 1, pMember->name); AddGuildLogEntry(GUILD_LOG_EVENT_JOIN, 1, pMember->guid); m_lock.Release(); }
// adding a member void Guild::AddGuildMember(PlayerInfo * pMember, WorldSession * pClient, int32 ForcedRank /* = -1 */) { if(pMember->guild != NULL) return; if(pClient && pClient->GetPlayer()->m_playerInfo->guild != this) return; if(pClient && !pClient->GetPlayer()->m_playerInfo->guildRank->CanPerformCommand(GR_RIGHT_INVITE)) return; m_lock.Acquire(); GuildRank * r; if(m_members.size()) r = (ForcedRank<=0) ? FindLowestRank() : m_ranks[ForcedRank]; else r = (ForcedRank<0) ? FindLowestRank() : m_ranks[ForcedRank]; if(r==NULL) r=FindLowestRank(); if(r==NULL) { // shouldnt happen m_lock.Release(); return; } GuildMember * pm = new GuildMember; memset(pm, 0, sizeof(GuildMember)); pm->pPlayer = pMember; pm->pRank = r; pm->szOfficerNote = pm->szPublicNote = NULL; m_members.insert(make_pair(pMember, pm)); pMember->guild=this; pMember->guildRank=r; pMember->guildMember=pm; if(pMember->m_loggedInPlayer) { pMember->m_loggedInPlayer->SetGuildId(m_guildId); pMember->m_loggedInPlayer->SetGuildRank(r->iId); } CharacterDatabase.Execute("INSERT INTO guild_data VALUES(%u, %u, %u, '', '', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)", m_guildId, pMember->guid, r->iId); LogGuildEvent(GUILD_EVENT_JOINED, 1, pMember->name); AddGuildLogEntry(GUILD_LOG_EVENT_JOIN, 1, pMember->guid); m_lock.Release(); }
void Guild::RemoveGuildMember(PlayerInfo * pMember, WorldSession * pClient) { if(pMember->guild != this ) return; if(pMember->guildRank->iId==0) { if(pClient != NULL) pClient->SystemMessage("You cannot remove the guild master."); return; } if(pClient != NULL ) { if( pClient->GetPlayer()->m_playerInfo->guild != this) return; if( !pClient->GetPlayer()->m_playerInfo->guildRank->CanPerformCommand(GR_RIGHT_REMOVE) && pClient->GetPlayer()->m_playerInfo != pMember) { Guild::SendGuildCommandResult(pClient, GUILD_CREATE_S, "", GUILD_PERMISSIONS); return; } //as wowwiki says, a global rule should be set too: // Members of the guild can only perform promote/demote/remove actions on those of lower ranks than themselves. PlayerInfo * Initiator = pClient->GetPlayer()->m_playerInfo; if( pMember != Initiator && pMember->guildRank->iId <= Initiator->guildRank->iId && Initiator->guildRank->iId != 0 ) { pClient->SystemMessage("You can only remove lower ranks then yourself."); return; } } CharacterDatabase.Execute("DELETE FROM guild_data WHERE playerid = %u", pMember->guid); m_lock.Acquire(); GuildMemberMap::iterator itr = m_members.find(pMember); if(itr != m_members.end()) { // this should always exist. if(itr->second->szOfficerNote) free((void*)itr->second->szOfficerNote); if(itr->second->szPublicNote) free((void*)itr->second->szPublicNote); delete itr->second; m_members.erase(itr); } if(pClient != NULL && pClient->GetPlayer()->m_playerInfo != pMember) { if(pMember->m_loggedInPlayer) { PlayerPointer plr = objmgr.GetPlayer(pMember->guid); sChatHandler.SystemMessageToPlr(plr, "You have been removed from the guild by %s", pClient->GetPlayer()->GetName()); } LogGuildEvent(GUILD_EVENT_REMOVED, 2, pMember->name, pClient->GetPlayer()->GetName()); AddGuildLogEntry(GUILD_LOG_EVENT_REMOVAL, 2, pClient->GetPlayer()->GetLowGUID(), pMember->guid); } else { LogGuildEvent(GUILD_EVENT_LEFT, 1, pMember->name); AddGuildLogEntry(GUILD_LOG_EVENT_LEFT, 1, pMember->guid); } m_lock.Release(); pMember->guildRank=NULL; pMember->guild=NULL; pMember->guildMember=NULL; if(pMember->m_loggedInPlayer) { pMember->m_loggedInPlayer->SetGuildRank(0); pMember->m_loggedInPlayer->SetGuildId(0); } }
void Guild::DemoteGuildMember(PlayerInfo * pMember, WorldSession * pClient) { if(pClient->GetPlayer()->m_playerInfo->guild != this || pMember->guild != this || pClient->GetPlayer()->m_playerInfo == pMember ) return; if(!pClient->GetPlayer()->m_playerInfo->guildRank->CanPerformCommand(GR_RIGHT_DEMOTE) || pMember->guid == GetGuildLeader()) { SendGuildCommandResult(pClient, GUILD_PROMOTE_S, "", GUILD_PERMISSIONS); return; } //as wowwiki says, a global rule should be set too: // Members of the guild can only perform promote/demote/remove actions on those of lower ranks than themselves. if(pClient != NULL ) { PlayerInfo * Initiator = pClient->GetPlayer()->m_playerInfo; if( pMember->guildRank->iId <= Initiator->guildRank->iId && Initiator->guildRank->iId != 0) { pClient->SystemMessage("You can only demote lower ranks then yourself."); return; } } // find the next highest rank uint32 nh = pMember->guildRank->iId + 1; GuildRank * newRank = NULL; m_lock.Acquire(); while(nh < 10 && newRank == NULL) { newRank = m_ranks[nh]; ++nh; } if(newRank==NULL) { m_lock.Release(); if(pClient != NULL ) pClient->SystemMessage("Could not find a rank to demote this member to."); return; } GuildMemberMap::iterator itr = m_members.find(pMember); if(itr == m_members.end()) { // shouldnt happen m_lock.Release(); return; } itr->second->pRank = newRank; itr->second->pPlayer->guildRank = newRank; // log it LogGuildEvent(GUILD_EVENT_DEMOTION, 3, pClient->GetPlayer()->GetName(), pMember->name, newRank->szRankName); AddGuildLogEntry(GUILD_LOG_EVENT_DEMOTION, 2, pClient->GetPlayer()->GetLowGUID(), pMember->guid, newRank->iId); // update in the database CharacterDatabase.Execute("UPDATE guild_data SET guildRank = %u WHERE playerid = %u AND guildid = %u", newRank->iId, pMember->guid, m_guildId); // if the player is online, update his guildrank if(pMember->m_loggedInPlayer) pMember->m_loggedInPlayer->SetGuildRank(newRank->iId); // release lock m_lock.Release(); }
void Guild::RemoveGuildMember(PlayerInfo* pMember, WorldSession* pClient) { if(pMember->guild != this) return; if(pClient && pClient->GetPlayer()->getPlayerInfo()->guild != this) return; if(pClient) { int RDiff = pMember->guildRank->iId - pClient->GetPlayer()->getPlayerInfo()->guildRank->iId; if((!pClient->GetPlayer()->getPlayerInfo()->guildRank->CanPerformCommand(GR_RIGHT_REMOVE) && pClient->GetPlayer()->getPlayerInfo() != pMember) || (RDiff <= 0 && pClient->GetPlayer()->getPlayerInfo() != pMember)) { Guild::SendGuildCommandResult(pClient, GUILD_CREATE_S, "", GUILD_PERMISSIONS); return; } } if(pMember->guildRank->iId == 0) { if(pClient) pClient->SystemMessage("You cannot remove the guild master."); return; } CharacterDatabase.Execute("DELETE FROM guild_data WHERE playerid = %u", pMember->guid); m_lock.Acquire(); GuildMemberMap::iterator itr = m_members.find(pMember); if(itr != m_members.end()) { // this should always exist. if(itr->second->szOfficerNote) free((void*)itr->second->szOfficerNote); if(itr->second->szPublicNote) free((void*)itr->second->szPublicNote); delete itr->second; m_members.erase(itr); } Player* plr = objmgr.GetPlayer(pMember->guid); if(pClient && pClient->GetPlayer()->getPlayerInfo() != pMember) { if(plr) sChatHandler.SystemMessageToPlr(plr, "You have been kicked from the guild by %s", pClient->GetPlayer()->GetName()); LogGuildEvent(GUILD_EVENT_REMOVED, 2, pMember->name, pClient->GetPlayer()->GetName()); AddGuildLogEntry(GUILD_LOG_EVENT_REMOVAL, 2, pClient->GetPlayer()->GetLowGUID(), pMember->guid); } else { LogGuildEvent(GUILD_EVENT_LEFT, 1, pMember->name); AddGuildLogEntry(GUILD_LOG_EVENT_LEFT, 1, pMember->guid); } m_lock.Release(); pMember->guildRank = NULL; pMember->guild = NULL; pMember->guildMember = NULL; if(plr) { plr->SetGuildRank(0); plr->SetGuildId(0); plr->SendGuildMOTD(); } }