int ClanInfoHandler::handleQuery(SimulatorThread *sim, CharacterServerData *pld, SimulatorQuery *query, CreatureInstance *creatureInstance) { /* Query: clan.info Retrieves the clan info of the Simulator player. Args: [none] */ int wpos = 0; wpos += PutByte(&sim->SendBuf[wpos], 1); //_handleQueryResultMsg wpos += PutShort(&sim->SendBuf[wpos], 0); //Message size wpos += PutInteger(&sim->SendBuf[wpos], query->ID); //Query response index int clanID = creatureInstance->charPtr->clan; if (!g_Config.Clans || clanID == 0 || !g_ClanManager.HasClan(clanID)) { wpos += PutShort(&sim->SendBuf[wpos], 0); } else { Clans::Clan c = g_ClanManager.GetClan(clanID); Clans::ClanMember leader = c.GetFirstMemberOfRank(Clans::Rank::LEADER); wpos += PutShort(&sim->SendBuf[wpos], 3); wpos += PutByte(&sim->SendBuf[wpos], 1); wpos += PutStringUTF(&sim->SendBuf[wpos], c.mName.c_str()); //Clan name wpos += PutByte(&sim->SendBuf[wpos], 1); wpos += PutStringUTF(&sim->SendBuf[wpos], c.mMOTD.c_str()); //Message of the day wpos += PutByte(&sim->SendBuf[wpos], 1); wpos += PutStringUTF(&sim->SendBuf[wpos], pld->CreatureDefID == leader.mID ? "true" : "false"); //Clan leader's name. } PutShort(&sim->SendBuf[1], wpos - 3); return wpos; }
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"); }