Beispiel #1
0
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");
}
Beispiel #2
0
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");
}
Beispiel #3
0
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");
}