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 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 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"); }