int ClanRankHandler::handleQuery(SimulatorThread *sim, CharacterServerData *pld, SimulatorQuery *query, CreatureInstance *creatureInstance) { /* Query: clan.rank Change a members rank. Args: member name, rank name */ if (!g_Config.Clans) return PrepExt_QueryResponseError(sim->SendBuf, query->ID, "Clans are not enabled."); int clanID = creatureInstance->charPtr->clan; if (clanID == 0) return PrepExt_QueryResponseError(sim->SendBuf, query->ID, "You are not in a clan."); if (!g_ClanManager.HasClan(clanID)) return PrepExt_QueryResponseError(sim->SendBuf, query->ID, "Your clan does not exist!"); if (query->argCount < 2) return PrepExt_QueryResponseError(sim->SendBuf, query->ID, "Invalid query->"); std::string memberName = query->args[0]; int newRank = Clans::Rank::GetIDByName(query->args[1].c_str()); int memberCDefID = g_UsedNameDatabase.GetIDByName(memberName); if (memberCDefID == -1) { return PrepExt_QueryResponseError(sim->SendBuf, query->ID, "No such clan member."); } Clans::Clan c = g_ClanManager.GetClan(clanID); Clans::ClanMember me = c.GetMember(pld->CreatureDefID); if (me.mID == 0) return PrepExt_QueryResponseError(sim->SendBuf, query->ID, "You are not in this clan."); Clans::ClanMember them = c.GetMember(memberCDefID); if (them.mID == 0) { return PrepExt_QueryResponseError(sim->SendBuf, query->ID, "Player is not in your clan."); } if (me.mID == them.mID) { return PrepExt_QueryResponseError(sim->SendBuf, query->ID, "Cannot promote or demote yourself."); } if (me.mRank < Clans::Rank::OFFICER) return PrepExt_QueryResponseError(sim->SendBuf, query->ID, "You must be at least an officer to promote or demote others."); if (me.mRank <= them.mRank) return PrepExt_QueryResponseError(sim->SendBuf, query->ID, "You must be of greater rank to promote or demote someone."); if (newRank > me.mRank) return PrepExt_QueryResponseError(sim->SendBuf, query->ID, "You cannot promote someone above your own rank."); if (newRank < Clans::Rank::INITIATE) return PrepExt_QueryResponseError(sim->SendBuf, query->ID, "Cannot demote below Initiate."); if (newRank < Clans::Rank::LEADER && c.mMembers.size() < 2) { return PrepExt_QueryResponseError(sim->SendBuf, query->ID, "Cannot demote, would leave clan without a leader. Disband instead if you want to leave."); } them.mRank = newRank; g_ClanManager.cs.Enter("SimulatorThread::handle_query_clan_info"); c.UpdateMember(them); g_ClanManager.SaveClan(c); g_ClanManager.cs.Leave(); BroadcastClanRankChange(memberName, c, them); return PrepExt_QueryResponseString(sim->SendBuf, query->ID, "OK"); }
int PersonaDeleteHandler::handleQuery(SimulatorThread *sim, CharacterServerData *pld, SimulatorQuery *query, CreatureInstance *creatureInstance) { /* Query: persona.delete Args : [0] index to remove */ if (query->argCount < 1) return PrepExt_QueryResponseError(sim->SendBuf, query->ID, "Invalid query"); int index = query->GetInteger(0); if (index >= 0 && index <= pld->accPtr->MAX_CHARACTER_SLOTS) { int CDefID = pld->accPtr->CharacterSet[index]; CharacterData *cd = g_CharacterManager.RequestCharacter(CDefID, true); if (cd->clan > 0) { Clans::Clan c = g_ClanManager.mClans[cd->clan]; if (c.mId > 0) { Clans::ClanMember me = c.GetMember(CDefID); c.RemoveMember(me); if (c.mMembers.size() < 1) { g_Logs.event->info( "[CLAN] Disbanding clan %v because the last member left.", c.mName.c_str()); g_ClanManager.RemoveClan(c); } else { if (me.mRank == Clans::Rank::LEADER) { Clans::ClanMember nextLeader = c.GetFirstMemberOfRank( Clans::Rank::OFFICER); if (nextLeader.mID == 0) { nextLeader = c.GetFirstMemberOfRank( Clans::Rank::MEMBER); if (nextLeader.mID == 0) { nextLeader = c.GetFirstMemberOfRank( Clans::Rank::INITIATE); if (nextLeader.mID == 0) { g_Logs.event->warn( "[CLAN] There is nobody to pass leadership of clan of %v to! Removing the clan", c.mName.c_str()); g_ClanManager.RemoveClan(c); BroadcastClanDisbandment(c); } } } if (nextLeader.mID != 0) { nextLeader.mRank = Clans::Rank::LEADER; c.UpdateMember(nextLeader); BroadcastClanRankChange(cd->cdef.css.display_name, c, nextLeader); g_ClanManager.SaveClan(c); } } else { g_ClanManager.SaveClan(c); } } } } } g_AccountManager.DeleteCharacter(index, pld->accPtr); return PrepExt_QueryResponseString(sim->SendBuf, query->ID, "OK"); }