浏览代码

BETA: Adding support for custom ConfirmDlg requests using same messageId for example admin commands or wedding.

Rumen Nikiforov 11 年之前
父节点
当前提交
15757cf23e

+ 40 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/enums/PlayerAction.java

@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2004-2014 L2J Server
+ * 
+ * This file is part of L2J Server.
+ * 
+ * L2J Server is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * L2J Server is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.l2jserver.gameserver.enums;
+
+/**
+ * @author UnAfraid
+ */
+public enum PlayerAction
+{
+	ADMIN_COMMAND,
+	USER_ENGAGE;
+	
+	private final int _mask;
+	
+	private PlayerAction()
+	{
+		_mask = (1 << ordinal());
+	}
+	
+	public int getMask()
+	{
+		return _mask;
+	}
+}

+ 40 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java

@@ -93,6 +93,7 @@ import com.l2jserver.gameserver.enums.IllegalActionPunishmentType;
 import com.l2jserver.gameserver.enums.InstanceType;
 import com.l2jserver.gameserver.enums.MountType;
 import com.l2jserver.gameserver.enums.PcRace;
+import com.l2jserver.gameserver.enums.PlayerAction;
 import com.l2jserver.gameserver.enums.PrivateStoreType;
 import com.l2jserver.gameserver.enums.QuestEventType;
 import com.l2jserver.gameserver.enums.Sex;
@@ -844,6 +845,8 @@ public final class L2PcInstance extends L2Playable
 	
 	private boolean _canRevive = true;
 	
+	private volatile int _actionMask;
+	
 	public void setPvpFlagLasts(long time)
 	{
 		_pvpFlagLasts = time;
@@ -14883,4 +14886,41 @@ public final class L2PcInstance extends L2Playable
 	{
 		return PunishmentManager.getInstance().hasPunishment(getObjectId(), PunishmentAffect.CHARACTER, PunishmentType.PARTY_BAN);
 	}
+	
+	/**
+	 * @param act
+	 * @return {@code true} if action was added successfully, {@code false} otherwise.
+	 */
+	public boolean addAction(PlayerAction act)
+	{
+		if (!hasAction(act))
+		{
+			_actionMask |= act.getMask();
+			return true;
+		}
+		return false;
+	}
+	
+	/**
+	 * @param act
+	 * @return {@code true} if action was removed successfully, {@code false} otherwise.
+	 */
+	public boolean removeAction(PlayerAction act)
+	{
+		if (hasAction(act))
+		{
+			_actionMask &= ~act.getMask();
+			return true;
+		}
+		return false;
+	}
+	
+	/**
+	 * @param act
+	 * @return {@code true} if action is present, {@code false} otherwise.
+	 */
+	public boolean hasAction(PlayerAction act)
+	{
+		return (_actionMask & act.getMask()) == act.getMask();
+	}
 }

+ 4 - 3
L2J_Server_BETA/java/com/l2jserver/gameserver/network/clientpackets/DlgAnswer.java

@@ -20,6 +20,7 @@ package com.l2jserver.gameserver.network.clientpackets;
 
 import com.l2jserver.Config;
 import com.l2jserver.gameserver.datatables.AdminTable;
+import com.l2jserver.gameserver.enums.PlayerAction;
 import com.l2jserver.gameserver.handler.AdminCommandHandler;
 import com.l2jserver.gameserver.handler.IAdminCommandHandler;
 import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
@@ -62,16 +63,16 @@ public final class DlgAnswer extends L2GameClientPacket
 		
 		if (_messageId == SystemMessageId.S1.getId())
 		{
-			String cmd = activeChar.getAdminConfirmCmd();
-			if (cmd == null)
+			if (activeChar.removeAction(PlayerAction.USER_ENGAGE))
 			{
 				if (Config.L2JMOD_ALLOW_WEDDING)
 				{
 					activeChar.engageAnswer(_answer);
 				}
 			}
-			else
+			else if (activeChar.removeAction(PlayerAction.ADMIN_COMMAND))
 			{
+				String cmd = activeChar.getAdminConfirmCmd();
 				activeChar.setAdminConfirmCmd(null);
 				if (_answer == 0)
 				{

+ 2 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/network/clientpackets/RequestBypassToServer.java

@@ -29,6 +29,7 @@ import com.l2jserver.gameserver.ai.CtrlIntention;
 import com.l2jserver.gameserver.communitybbs.CommunityBoard;
 import com.l2jserver.gameserver.datatables.AdminTable;
 import com.l2jserver.gameserver.enums.InstanceType;
+import com.l2jserver.gameserver.enums.PlayerAction;
 import com.l2jserver.gameserver.handler.AdminCommandHandler;
 import com.l2jserver.gameserver.handler.BypassHandler;
 import com.l2jserver.gameserver.handler.IAdminCommandHandler;
@@ -158,6 +159,7 @@ public final class RequestBypassToServer extends L2GameClientPacket
 					activeChar.setAdminConfirmCmd(_command);
 					ConfirmDlg dlg = new ConfirmDlg(SystemMessageId.S1);
 					dlg.addString("Are you sure you want execute command " + _command.substring(6) + " ?");
+					activeChar.addAction(PlayerAction.ADMIN_COMMAND);
 					activeChar.sendPacket(dlg);
 				}
 				else