Преглед изворни кода

Preventing EnterWorld request after being in-game

Thanks to: Tryskell
Zoey76 пре 6 година
родитељ
комит
5cd1edf163

Разлика између датотеке није приказан због своје велике величине
+ 164 - 332
src/main/java/com/l2jserver/gameserver/network/L2GameClient.java


+ 64 - 65
src/main/java/com/l2jserver/gameserver/network/L2GamePacketHandler.java

@@ -41,16 +41,13 @@ import com.l2jserver.util.Util;
  * Note: If for a given exception a packet needs to be handled on more then one state, then it should be added to all these states.
  * @author KenM
  */
-public final class L2GamePacketHandler implements IPacketHandler<L2GameClient>, IClientFactory<L2GameClient>, IMMOExecutor<L2GameClient>
-{
+public final class L2GamePacketHandler implements IPacketHandler<L2GameClient>, IClientFactory<L2GameClient>, IMMOExecutor<L2GameClient> {
 	private static final Logger _log = Logger.getLogger(L2GamePacketHandler.class.getName());
 	
 	// implementation
 	@Override
-	public ReceivablePacket<L2GameClient> handlePacket(ByteBuffer buf, L2GameClient client)
-	{
-		if (client.dropPacket())
-		{
+	public ReceivablePacket<L2GameClient> handlePacket(ByteBuffer buf, L2GameClient client) {
+		if (client.dropPacket()) {
 			return null;
 		}
 		
@@ -60,11 +57,9 @@ public final class L2GamePacketHandler implements IPacketHandler<L2GameClient>,
 		ReceivablePacket<L2GameClient> msg = null;
 		GameClientState state = client.getState();
 		
-		switch (state)
-		{
+		switch (state) {
 			case CONNECTED:
-				switch (opcode)
-				{
+				switch (opcode) {
 					case 0x0e:
 						msg = new ProtocolVersion();
 						break;
@@ -77,8 +72,7 @@ public final class L2GamePacketHandler implements IPacketHandler<L2GameClient>,
 				}
 				break;
 			case AUTHED:
-				switch (opcode)
-				{
+				switch (opcode) {
 					case 0x00:
 						msg = new Logout();
 						break;
@@ -99,21 +93,16 @@ public final class L2GamePacketHandler implements IPacketHandler<L2GameClient>,
 						break;
 					case 0xd0:
 						int id2 = -1;
-						if (buf.remaining() >= 2)
-						{
+						if (buf.remaining() >= 2) {
 							id2 = buf.getShort() & 0xffff;
-						}
-						else
-						{
-							if (Config.PACKET_HANDLER_DEBUG)
-							{
+						} else {
+							if (Config.PACKET_HANDLER_DEBUG) {
 								_log.warning("Client: " + client.toString() + " sent a 0xd0 without the second opcode.");
 							}
 							break;
 						}
 						
-						switch (id2)
-						{
+						switch (id2) {
 							case 0x36:
 								msg = new RequestGotoLobby();
 								break;
@@ -135,9 +124,43 @@ public final class L2GamePacketHandler implements IPacketHandler<L2GameClient>,
 						break;
 				}
 				break;
+			case JOINING: {
+				switch (opcode) {
+					case 0x11: {
+						msg = new EnterWorld();
+						break;
+					}
+					case 0xd0: {
+						int id2 = -1;
+						if (buf.remaining() >= 2) {
+							id2 = buf.getShort() & 0xffff;
+						} else {
+							if (Config.PACKET_HANDLER_DEBUG) {
+								_log.warning("Client: " + client.toString() + " sent a 0xd0 without the second opcode.");
+							}
+							break;
+						}
+						
+						switch (id2) {
+							case 0x01: {
+								msg = new RequestManorList();
+								break;
+							}
+							default: {
+								printDebugDoubleOpcode(opcode, id2, buf, state, client);
+								break;
+							}
+						}
+					}
+					default: {
+						printDebug(opcode, buf, state, client);
+						break;
+					}
+				}
+				break;
+			}
 			case IN_GAME:
-				switch (opcode)
-				{
+				switch (opcode) {
 					case 0x00:
 						msg = new Logout();
 						break;
@@ -174,9 +197,6 @@ public final class L2GamePacketHandler implements IPacketHandler<L2GameClient>,
 					case 0x10:
 						// Say
 						break;
-					case 0x11:
-						msg = new EnterWorld();
-						break;
 					case 0x12:
 						// CharacterSelect, in case of player spam clicks on loginscreen
 						break;
@@ -278,8 +298,7 @@ public final class L2GamePacketHandler implements IPacketHandler<L2GameClient>,
 						msg = new Appearing();
 						break;
 					case 0x3b:
-						if (Config.ALLOW_WAREHOUSE)
-						{
+						if (Config.ALLOW_WAREHOUSE) {
 							msg = new SendWareHouseDepositList();
 						}
 						break;
@@ -324,20 +343,15 @@ public final class L2GamePacketHandler implements IPacketHandler<L2GameClient>,
 						break;
 					case 0x4a:
 						int id_2 = -1;
-						if (buf.remaining() >= 2)
-						{
+						if (buf.remaining() >= 2) {
 							id_2 = buf.getShort() & 0xffff;
-						}
-						else
-						{
-							if (Config.PACKET_HANDLER_DEBUG)
-							{
+						} else {
+							if (Config.PACKET_HANDLER_DEBUG) {
 								_log.warning("Client: " + client.toString() + " sent a 0x4a without the second opcode.");
 							}
 							break;
 						}
-						switch (id_2)
-						{
+						switch (id_2) {
 							case 0x00:
 								// SuperCmdCharacterInfo
 								break;
@@ -693,21 +707,16 @@ public final class L2GamePacketHandler implements IPacketHandler<L2GameClient>,
 						break;
 					case 0xd0:
 						int id2 = -1;
-						if (buf.remaining() >= 2)
-						{
+						if (buf.remaining() >= 2) {
 							id2 = buf.getShort() & 0xffff;
-						}
-						else
-						{
-							if (Config.PACKET_HANDLER_DEBUG)
-							{
+						} else {
+							if (Config.PACKET_HANDLER_DEBUG) {
 								_log.warning("Client: " + client.toString() + " sent a 0xd0 without the second opcode.");
 							}
 							break;
 						}
 						
-						switch (id2)
-						{
+						switch (id2) {
 							case 0x01:
 								msg = new RequestManorList();
 								break;
@@ -953,17 +962,13 @@ public final class L2GamePacketHandler implements IPacketHandler<L2GameClient>,
 								break;
 							case 0x51:
 								id3 = 0;
-								if (buf.remaining() >= 4)
-								{
+								if (buf.remaining() >= 4) {
 									id3 = buf.getInt();
-								}
-								else
-								{
+								} else {
 									_log.warning("Client: " + client.toString() + " sent a 0xd0:0x51 without the third opcode.");
 									break;
 								}
-								switch (id3)
-								{
+								switch (id3) {
 									case 0x00:
 										msg = new RequestBookMarkSlotInfo();
 										break;
@@ -1157,11 +1162,9 @@ public final class L2GamePacketHandler implements IPacketHandler<L2GameClient>,
 		return msg;
 	}
 	
-	private void printDebug(int opcode, ByteBuffer buf, GameClientState state, L2GameClient client)
-	{
+	private void printDebug(int opcode, ByteBuffer buf, GameClientState state, L2GameClient client) {
 		client.onUnknownPacket();
-		if (!Config.PACKET_HANDLER_DEBUG)
-		{
+		if (!Config.PACKET_HANDLER_DEBUG) {
 			return;
 		}
 		
@@ -1172,11 +1175,9 @@ public final class L2GamePacketHandler implements IPacketHandler<L2GameClient>,
 		_log.warning(Util.printData(array, size));
 	}
 	
-	private void printDebugDoubleOpcode(int opcode, int id2, ByteBuffer buf, GameClientState state, L2GameClient client)
-	{
+	private void printDebugDoubleOpcode(int opcode, int id2, ByteBuffer buf, GameClientState state, L2GameClient client) {
 		client.onUnknownPacket();
-		if (!Config.PACKET_HANDLER_DEBUG)
-		{
+		if (!Config.PACKET_HANDLER_DEBUG) {
 			return;
 		}
 		
@@ -1189,14 +1190,12 @@ public final class L2GamePacketHandler implements IPacketHandler<L2GameClient>,
 	
 	// impl
 	@Override
-	public L2GameClient create(MMOConnection<L2GameClient> con)
-	{
+	public L2GameClient create(MMOConnection<L2GameClient> con) {
 		return new L2GameClient(con);
 	}
 	
 	@Override
-	public void execute(ReceivablePacket<L2GameClient> rp)
-	{
+	public void execute(ReceivablePacket<L2GameClient> rp) {
 		rp.getClient().execute(rp);
 	}
 }

+ 22 - 42
src/main/java/com/l2jserver/gameserver/network/clientpackets/CharacterSelect.java

@@ -18,6 +18,8 @@
  */
 package com.l2jserver.gameserver.network.clientpackets;
 
+import static com.l2jserver.gameserver.network.L2GameClient.GameClientState.JOINING;
+
 import java.util.logging.Level;
 import java.util.logging.LogRecord;
 import java.util.logging.Logger;
@@ -37,19 +39,14 @@ import com.l2jserver.gameserver.model.events.returns.TerminateReturn;
 import com.l2jserver.gameserver.model.punishment.PunishmentAffect;
 import com.l2jserver.gameserver.model.punishment.PunishmentType;
 import com.l2jserver.gameserver.network.L2GameClient;
-import com.l2jserver.gameserver.network.L2GameClient.GameClientState;
 import com.l2jserver.gameserver.network.serverpackets.CharSelected;
 import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
 import com.l2jserver.gameserver.network.serverpackets.SSQInfo;
 import com.l2jserver.gameserver.network.serverpackets.ServerClose;
 
-/**
- * This class ...
- * @version $Revision: 1.5.2.1.2.5 $ $Date: 2005/03/27 15:29:30 $
- */
-public class CharacterSelect extends L2GameClientPacket
-{
+public class CharacterSelect extends L2GameClientPacket {
 	private static final String _C__12_CHARACTERSELECT = "[C] 12 CharacterSelect";
+	
 	protected static final Logger _logAccounting = Logger.getLogger("accounting");
 	
 	// cd
@@ -65,8 +62,7 @@ public class CharacterSelect extends L2GameClientPacket
 	private int _unk4; // new in C4
 	
 	@Override
-	protected void readImpl()
-	{
+	protected void readImpl() {
 		_charSlot = readD();
 		_unk1 = readH();
 		_unk2 = readD();
@@ -75,53 +71,43 @@ public class CharacterSelect extends L2GameClientPacket
 	}
 	
 	@Override
-	protected void runImpl()
-	{
+	protected void runImpl() {
 		final L2GameClient client = getClient();
-		if (!client.getFloodProtectors().getCharacterSelect().tryPerformAction("CharacterSelect"))
-		{
+		if (!client.getFloodProtectors().getCharacterSelect().tryPerformAction("CharacterSelect")) {
 			return;
 		}
 		
-		if (SecondaryAuthData.getInstance().isEnabled() && !client.getSecondaryAuth().isAuthed())
-		{
+		if (SecondaryAuthData.getInstance().isEnabled() && !client.getSecondaryAuth().isAuthed()) {
 			client.getSecondaryAuth().openDialog();
 			return;
 		}
 		
 		// We should always be able to acquire the lock
 		// But if we can't lock then nothing should be done (i.e. repeated packet)
-		if (client.getActiveCharLock().tryLock())
-		{
-			try
-			{
+		if (client.getActiveCharLock().tryLock()) {
+			try {
 				// should always be null
 				// but if not then this is repeated packet and nothing should be done here
-				if (client.getActiveChar() == null)
-				{
+				if (client.getActiveChar() == null) {
 					final CharSelectInfoPackage info = client.getCharSelection(_charSlot);
-					if (info == null)
-					{
+					if (info == null) {
 						return;
 					}
 					
 					// Banned?
 					if (PunishmentManager.getInstance().hasPunishment(info.getObjectId(), PunishmentAffect.CHARACTER, PunishmentType.BAN) || PunishmentManager.getInstance().hasPunishment(client.getAccountName(), PunishmentAffect.ACCOUNT, PunishmentType.BAN)
-						|| PunishmentManager.getInstance().hasPunishment(client.getConnectionAddress().getHostAddress(), PunishmentAffect.IP, PunishmentType.BAN))
-					{
+						|| PunishmentManager.getInstance().hasPunishment(client.getConnectionAddress().getHostAddress(), PunishmentAffect.IP, PunishmentType.BAN)) {
 						client.close(ServerClose.STATIC_PACKET);
 						return;
 					}
 					
 					// Selected character is banned (compatibility with previous versions).
-					if (info.getAccessLevel() < 0)
-					{
+					if (info.getAccessLevel() < 0) {
 						client.close(ServerClose.STATIC_PACKET);
 						return;
 					}
 					
-					if ((Config.L2JMOD_DUALBOX_CHECK_MAX_PLAYERS_PER_IP > 0) && !AntiFeedManager.getInstance().tryAddClient(AntiFeedManager.GAME_ID, client, Config.L2JMOD_DUALBOX_CHECK_MAX_PLAYERS_PER_IP))
-					{
+					if ((Config.L2JMOD_DUALBOX_CHECK_MAX_PLAYERS_PER_IP > 0) && !AntiFeedManager.getInstance().tryAddClient(AntiFeedManager.GAME_ID, client, Config.L2JMOD_DUALBOX_CHECK_MAX_PLAYERS_PER_IP)) {
 						final NpcHtmlMessage msg = new NpcHtmlMessage();
 						msg.setFile(info.getHtmlPrefix(), "data/html/mods/IPRestriction.htm");
 						msg.replace("%max%", String.valueOf(AntiFeedManager.getInstance().getLimit(client, Config.L2JMOD_DUALBOX_CHECK_MAX_PLAYERS_PER_IP)));
@@ -130,15 +116,13 @@ public class CharacterSelect extends L2GameClientPacket
 					}
 					
 					// The L2PcInstance must be created here, so that it can be attached to the L2GameClient
-					if (Config.DEBUG)
-					{
+					if (Config.DEBUG) {
 						_log.fine("selected slot:" + _charSlot);
 					}
 					
 					// load up character from disk
 					final L2PcInstance cha = client.loadCharFromDisk(_charSlot);
-					if (cha == null)
-					{
+					if (cha == null) {
 						return; // handled in L2GameClient
 					}
 					L2World.getInstance().addPlayerToWorld(cha);
@@ -149,27 +133,24 @@ public class CharacterSelect extends L2GameClientPacket
 					cha.setOnlineStatus(true, true);
 					
 					final TerminateReturn terminate = EventDispatcher.getInstance().notifyEvent(new OnPlayerSelect(cha, cha.getObjectId(), cha.getName(), getClient()), Containers.Players(), TerminateReturn.class);
-					if ((terminate != null) && terminate.terminate())
-					{
+					if ((terminate != null) && terminate.terminate()) {
 						cha.deleteMe();
 						return;
 					}
 					
 					sendPacket(new SSQInfo());
 					
-					client.setState(GameClientState.IN_GAME);
+					client.setState(JOINING);
 					CharSelected cs = new CharSelected(cha, client.getSessionId().playOkID1);
 					sendPacket(cs);
 				}
 			}
-			finally
-			{
+			finally {
 				client.getActiveCharLock().unlock();
 			}
 			
 			LogRecord record = new LogRecord(Level.INFO, "Logged in");
-			record.setParameters(new Object[]
-			{
+			record.setParameters(new Object[] {
 				client
 			});
 			_logAccounting.log(record);
@@ -177,8 +158,7 @@ public class CharacterSelect extends L2GameClientPacket
 	}
 	
 	@Override
-	public String getType()
-	{
+	public String getType() {
 		return _C__12_CHARACTERSELECT;
 	}
 }

+ 3 - 0
src/main/java/com/l2jserver/gameserver/network/clientpackets/EnterWorld.java

@@ -25,6 +25,7 @@ import static com.l2jserver.gameserver.model.TeleportWhereType.TOWN;
 import static com.l2jserver.gameserver.model.skills.CommonSkill.THE_VANQUISHED_OF_WAR;
 import static com.l2jserver.gameserver.model.skills.CommonSkill.THE_VICTOR_OF_WAR;
 import static com.l2jserver.gameserver.model.zone.ZoneId.SIEGE;
+import static com.l2jserver.gameserver.network.L2GameClient.GameClientState.IN_GAME;
 import static com.l2jserver.gameserver.network.SystemMessageId.CLAN_MEMBERSHIP_TERMINATED;
 import static com.l2jserver.gameserver.network.SystemMessageId.CLAN_MEMBER_S1_LOGGED_IN;
 import static com.l2jserver.gameserver.network.SystemMessageId.FRIEND_S1_HAS_LOGGED_IN;
@@ -165,6 +166,8 @@ public class EnterWorld extends L2GameClientPacket {
 			}
 		}
 		
+		getClient().setState(IN_GAME);
+		
 		// Apply special GM properties to the GM when entering
 		if (activeChar.isGM()) {
 			if (Config.GM_STARTUP_INVULNERABLE && AdminData.getInstance().hasAccess("admin_invul", activeChar.getAccessLevel())) {

+ 16 - 32
src/main/java/com/l2jserver/log/formatter/AccountingFormatter.java

@@ -28,74 +28,58 @@ import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
 import com.l2jserver.gameserver.network.L2GameClient;
 import com.l2jserver.util.StringUtil;
 
-public class AccountingFormatter extends Formatter
-{
+public class AccountingFormatter extends Formatter {
 	private final SimpleDateFormat dateFmt = new SimpleDateFormat("dd MMM H:mm:ss");
 	
 	@Override
-	public String format(LogRecord record)
-	{
+	public String format(LogRecord record) {
 		final Object[] params = record.getParameters();
 		final StringBuilder output = StringUtil.startAppend(30 + record.getMessage().length() + (params == null ? 0 : params.length * 10), "[", dateFmt.format(new Date(record.getMillis())), "] ", record.getMessage());
 		
-		if (params != null)
-		{
-			for (Object p : params)
-			{
-				if (p == null)
-				{
+		if (params != null) {
+			for (Object p : params) {
+				if (p == null) {
 					continue;
 				}
 				
 				StringUtil.append(output, ", ");
 				
-				if (p instanceof L2GameClient)
-				{
+				if (p instanceof L2GameClient) {
 					final L2GameClient client = (L2GameClient) p;
 					String address = null;
-					try
-					{
-						if (!client.isDetached())
-						{
+					try {
+						if (!client.isDetached()) {
 							address = client.getConnection().getInetAddress().getHostAddress();
 						}
 					}
-					catch (Exception e)
-					{
+					catch (Exception e) {
 						
 					}
 					
-					switch (client.getState())
-					{
+					switch (client.getState()) {
+						case JOINING:
 						case IN_GAME:
-							if (client.getActiveChar() != null)
-							{
+							if (client.getActiveChar() != null) {
 								StringUtil.append(output, client.getActiveChar().getName());
 								StringUtil.append(output, "(", String.valueOf(client.getActiveChar().getObjectId()), ") ");
 							}
 						case AUTHED:
-							if (client.getAccountName() != null)
-							{
+							if (client.getAccountName() != null) {
 								StringUtil.append(output, client.getAccountName(), " ");
 							}
 						case CONNECTED:
-							if (address != null)
-							{
+							if (address != null) {
 								StringUtil.append(output, address);
 							}
 							break;
 						default:
 							throw new IllegalStateException("Missing state on switch");
 					}
-				}
-				else if (p instanceof L2PcInstance)
-				{
+				} else if (p instanceof L2PcInstance) {
 					L2PcInstance player = (L2PcInstance) p;
 					StringUtil.append(output, player.getName());
 					StringUtil.append(output, "(", String.valueOf(player.getObjectId()), ")");
-				}
-				else
-				{
+				} else {
 					StringUtil.append(output, p.toString());
 				}
 			}

Неке датотеке нису приказане због велике количине промена