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 ClanLeaveHandler::handleQuery(SimulatorThread *sim, CharacterServerData *pld, SimulatorQuery *query, CreatureInstance *creatureInstance) { /* Query: clan.leave Leave a clan. */ 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!"); 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, "Player is not in your clan."); } c.RemoveMember(me); g_ClanManager.SaveClan(c); int wpos = 0; wpos += PutByte(&sim->SendBuf[wpos], 43); wpos += PutShort(&sim->SendBuf[wpos], 0); wpos += PutByte(&sim->SendBuf[wpos], 12); wpos += PutStringUTF(&sim->SendBuf[wpos], creatureInstance->charPtr->cdef.css.display_name); PutShort(&sim->SendBuf[1], wpos - 3); SIMULATOR_IT it; for (it = Simulator.begin(); it != Simulator.end(); ++it) { if (it->isConnected == true && it->ProtocolState == 1) { if (it->pld.CreatureDefID == pld->CreatureDefID) { int wpos2 = 0; wpos2 += PutByte(&sim->Aux2[wpos2], 43); wpos2 += PutShort(&sim->Aux2[wpos2], 0); wpos2 += PutByte(&sim->Aux2[wpos2], 13); PutShort(&sim->Aux2[1], wpos2 - 3); it->AttemptSend(sim->Aux2, wpos2); } else if (c.HasMember(it->pld.CreatureDefID)) { it->AttemptSend(sim->SendBuf, wpos); } } } return PrepExt_QueryResponseString(sim->SendBuf, query->ID, "OK"); }
int ClanMotdHandler::handleQuery(SimulatorThread *sim, CharacterServerData *pld, SimulatorQuery *query, CreatureInstance *creatureInstance) { /* Query: clan.motd Set the motd. Args: [none] */ if (!g_Config.Clans) return PrepExt_QueryResponseError(sim->SendBuf, query->ID, "Clans are not enabled."); if (query->argCount < 1) return PrepExt_QueryResponseError(sim->SendBuf, query->ID, "Invalid query->"); 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!"); Clans::Clan c = g_ClanManager.GetClan(clanID); Clans::ClanMember member = c.GetMember(pld->CreatureDefID); if (member.mRank < Clans::Rank::OFFICER) { return PrepExt_QueryResponseError(sim->SendBuf, query->ID, "Must be at least an officer to set the MOTD!"); } c.mMOTD = query->args[0]; g_ClanManager.SaveClan(c); int wpos = 0; wpos += PutByte(&sim->SendBuf[wpos], 43); //_handleFriendNotificationMsg wpos += PutShort(&sim->SendBuf[wpos], 0); wpos += PutByte(&sim->SendBuf[wpos], 5); wpos += PutStringUTF(&sim->SendBuf[wpos], c.mMOTD.c_str()); PutShort(&sim->SendBuf[1], wpos - 3); SIMULATOR_IT it; for (it = Simulator.begin(); it != Simulator.end(); ++it) if (it->isConnected == true && it->ProtocolState == 1) if (c.HasMember(it->pld.CreatureDefID)) it->AttemptSend(sim->SendBuf, wpos); Util::SafeFormat(sim->Aux2, sizeof(sim->Aux2), "Clan '%s' - %s", c.mName.c_str(), c.mMOTD.c_str()); g_SimulatorManager.BroadcastMessage(sim->Aux2); return PrepExt_QueryResponseString(sim->SendBuf, query->ID, "OK"); }
int ClanInviteHandler::handleQuery(SimulatorThread *sim, CharacterServerData *pld, SimulatorQuery *query, CreatureInstance *creatureInstance) { /* Query: clan.invite Invite a player. Args: [none] */ if (!g_Config.Clans) return PrepExt_QueryResponseError(sim->SendBuf, query->ID, "Clans are not enabled."); if (query->argCount < 1) return PrepExt_QueryResponseError(sim->SendBuf, query->ID, "Invalid query->"); 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!"); Clans::Clan c = g_ClanManager.GetClan(clanID); Clans::ClanMember member = c.GetMember(pld->CreatureDefID); if (member.mRank < Clans::Rank::OFFICER) { return PrepExt_QueryResponseError(sim->SendBuf, query->ID, "Must be at least an officer to invite a player!"); } std::string invitee = query->args[0]; CharacterData *cd = g_CharacterManager.GetCharacterByName(invitee.c_str()); if (cd == NULL) { Util::SafeFormat(sim->Aux2, sizeof(sim->Aux2), "%s is not online.", invitee.c_str()); return PrepExt_QueryResponseError(sim->SendBuf, query->ID, sim->Aux2); } SendClanInvite(c, member, cd->cdef.CreatureDefID); c.mPendingMembers.push_back(cd->cdef.CreatureDefID); g_ClanManager.SaveClan(c); return PrepExt_QueryResponseString(sim->SendBuf, query->ID, "OK"); }
int ClanRemoveHandler::handleQuery(SimulatorThread *sim, CharacterServerData *pld, SimulatorQuery *query, CreatureInstance *creatureInstance) { /* Query: clan.remove Remove a clan member. Args: [member] */ if (!g_Config.Clans) return PrepExt_QueryResponseError(sim->SendBuf, query->ID, "Clans are not enabled."); if (query->argCount < 1) return PrepExt_QueryResponseError(sim->SendBuf, query->ID, "Invalid query->"); 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!"); Clans::Clan c = g_ClanManager.GetClan(clanID); Clans::ClanMember me = c.GetMember(pld->CreatureDefID); if (me.mRank < Clans::Rank::OFFICER) { return PrepExt_QueryResponseError(sim->SendBuf, query->ID, "Must be at least an officer to remove a clan me"); } // The target member std::string memberName = query->args[0]; int memberCDefID = g_UsedNameDatabase.GetIDByName(memberName); if (memberCDefID == -1) { return PrepExt_QueryResponseError(sim->SendBuf, query->ID, "No such clan member."); } if (memberCDefID == pld->CreatureDefID) { return PrepExt_QueryResponseError(sim->SendBuf, query->ID, "Cannot remove yourself from a clan."); } Clans::ClanMember them = c.GetMember(memberCDefID); if (them.mID == 0) { return PrepExt_QueryResponseError(sim->SendBuf, query->ID, "Player is not in your clan."); } c.RemoveMember(them); CharacterData *memberCd = g_CharacterManager.RequestCharacter(memberCDefID, true); if (memberCd != NULL) { memberCd->clan = 0; memberCd->pendingChanges++; } g_ClanManager.SaveClan(c); int wpos = 0; wpos += PutByte(&sim->SendBuf[wpos], 43); wpos += PutShort(&sim->SendBuf[wpos], 0); wpos += PutByte(&sim->SendBuf[wpos], 12); wpos += PutStringUTF(&sim->SendBuf[wpos], memberName.c_str()); PutShort(&sim->SendBuf[1], wpos - 3); SIMULATOR_IT it; for (it = Simulator.begin(); it != Simulator.end(); ++it) { if (it->isConnected == true && it->ProtocolState == 1) { if (it->pld.CreatureDefID == memberCDefID) { int wpos2 = 0; wpos2 += PutByte(&sim->Aux2[wpos2], 43); wpos2 += PutShort(&sim->Aux2[wpos2], 0); wpos2 += PutByte(&sim->Aux2[wpos2], 13); PutShort(&sim->Aux2[1], wpos2 - 3); it->AttemptSend(sim->Aux2, wpos2); } else if (c.HasMember(it->pld.CreatureDefID)) { it->AttemptSend(sim->SendBuf, wpos); } } } return PrepExt_QueryResponseString(sim->SendBuf, query->ID, "OK"); }
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 ClanInviteAcceptHandler::handleQuery(SimulatorThread *sim, CharacterServerData *pld, SimulatorQuery *query, CreatureInstance *creatureInstance) { /* Query: clan.invite Invite a player. Args: [none] */ if (!g_Config.Clans) return PrepExt_QueryResponseError(sim->SendBuf, query->ID, "Clans are not enabled."); if (query->argCount < 1) return PrepExt_QueryResponseError(sim->SendBuf, query->ID, "Invalid query->"); int myClanID = creatureInstance->charPtr->clan; if (myClanID != 0) return PrepExt_QueryResponseError(sim->SendBuf, query->ID, "You are already in a clan."); int clanID = g_ClanManager.FindClanID(query->args[0].c_str()); if (clanID == -1) return PrepExt_QueryResponseError(sim->SendBuf, query->ID, "The clan does not exist!"); Clans::Clan c = g_ClanManager.GetClan(clanID); std::vector<int>::iterator pendingIt = std::find(c.mPendingMembers.begin(), c.mPendingMembers.end(), pld->CreatureDefID); if (pendingIt == c.mPendingMembers.end()) { return PrepExt_QueryResponseError(sim->SendBuf, query->ID, "No invite found!"); } c.mPendingMembers.erase(pendingIt); creatureInstance->charPtr->clan = clanID; creatureInstance->charPtr->pendingChanges++; Clans::ClanMember member; member.mID = pld->CreatureDefID; member.mRank = Clans::Rank::INITIATE; g_ClanManager.cs.Enter("ClanInviteAcceptHandler::handleQuery"); c.mMembers.push_back(member); g_ClanManager.SaveClan(c); int wpos = 0; wpos += PutByte(&sim->SendBuf[wpos], 43); wpos += PutShort(&sim->SendBuf[wpos], 0); wpos += PutByte(&sim->SendBuf[wpos], 11); wpos += PutStringUTF(&sim->SendBuf[wpos], creatureInstance->charPtr->cdef.css.display_name); wpos += PutInteger(&sim->SendBuf[wpos], creatureInstance->charPtr->cdef.css.level); wpos += PutInteger(&sim->SendBuf[wpos], creatureInstance->charPtr->cdef.css.profession); PutShort(&sim->SendBuf[1], wpos - 3); SIMULATOR_IT it; for (it = Simulator.begin(); it != Simulator.end(); ++it) { if (it->isConnected == true && it->ProtocolState == 1) { if (it->pld.CreatureDefID == pld->CreatureDefID) { int wpos2 = 0; wpos2 += PutByte(&sim->Aux2[wpos2], 43); wpos2 += PutShort(&sim->Aux2[wpos2], 0); wpos2 += PutByte(&sim->Aux2[wpos2], 9); wpos2 += PutStringUTF(&sim->Aux2[wpos2], c.mName.c_str()); PutShort(&sim->Aux2[1], wpos2 - 3); it->AttemptSend(sim->Aux2, wpos2); } else if (c.HasMember(it->pld.CreatureDefID)) { it->AttemptSend(sim->SendBuf, wpos); } } } g_ClanManager.cs.Leave(); 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"); }