From 5a5fd8155c08669614178a1e50668072e3def36b Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 06:52:11 -0400 Subject: [PATCH] Handler created for StuckMsg --- src/engine/gameManager/MovementManager.java | 26 -------- src/engine/net/client/ClientMessagePump.java | 8 +-- src/engine/net/client/Protocol.java | 2 +- .../net/client/handlers/StuckMsgHandler.java | 61 +++++++++++++++++++ .../{StuckCommandMsg.java => StuckMsg.java} | 6 +- 5 files changed, 69 insertions(+), 34 deletions(-) create mode 100644 src/engine/net/client/handlers/StuckMsgHandler.java rename src/engine/net/client/msg/{StuckCommandMsg.java => StuckMsg.java} (91%) diff --git a/src/engine/gameManager/MovementManager.java b/src/engine/gameManager/MovementManager.java index 644569b7..a5743a77 100644 --- a/src/engine/gameManager/MovementManager.java +++ b/src/engine/gameManager/MovementManager.java @@ -14,9 +14,6 @@ import engine.Enum.ModType; import engine.Enum.SourceType; import engine.InterestManagement.InterestManager; import engine.exception.MsgSendException; -import engine.job.JobContainer; -import engine.job.JobScheduler; -import engine.jobs.StuckJob; import engine.math.Bounds; import engine.math.Vector3f; import engine.math.Vector3fImmutable; @@ -30,7 +27,6 @@ import engine.server.MBServerStatics; import org.pmw.tinylog.Logger; import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; import static engine.math.FastMath.sqr; @@ -474,26 +470,4 @@ public enum MovementManager { ac.teleport(ac.getLoc()); } - public static void stuck(ClientConnection origin) { - - PlayerCharacter sourcePlayer = origin.getPlayerCharacter(); - - if (sourcePlayer == null) - return; - - if (sourcePlayer.getTimers().containsKey("Stuck")) - return; - - StuckJob sj = new StuckJob(sourcePlayer); - JobContainer jc = JobScheduler.getInstance().scheduleJob(sj, 10000); // Convert - ConcurrentHashMap timers = sourcePlayer.getTimers(); - - if (timers != null) { - if (timers.containsKey("Stuck")) { - timers.get("Stuck").cancelJob(); - timers.remove("Stuck"); - } - timers.put("Stuck", jc); - } - } } diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 081b7851..7fca0893 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -9,7 +9,10 @@ package engine.net.client; -import engine.gameManager.*; +import engine.gameManager.ChatManager; +import engine.gameManager.PowersManager; +import engine.gameManager.SessionManager; +import engine.gameManager.TradeManager; import engine.net.NetMsgHandler; import engine.net.client.handlers.AbstractClientMsgHandler; import engine.net.client.msg.*; @@ -138,9 +141,6 @@ public class ClientMessagePump implements NetMsgHandler { case ARCTRACKINGLIST: PowersManager.trackWindow((TrackWindowMsg) msg, origin); break; - case STUCK: - MovementManager.stuck(origin); - break; case CHANNELMUTE: break; case KEEPALIVESERVERCLIENT: diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index 429a8ece..4109a450 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -200,7 +200,7 @@ public enum Protocol { SHOWVAULTINVENTORY(0xD1FB4842, null, null), // Show Vault Inventory SOCIALCHANNEL(0x2BF58FA6, SocialMsg.class, SocialMsgHandler.class), // Socials STANDARDALERT(0xFA0A24BB, ErrorPopupMsg.class, null), //Popup messages - STUCK(0x3D04AF3A, StuckCommandMsg.class, null), // /Stuck Command + STUCK(0x3D04AF3A, StuckMsg.class, StuckMsgHandler.class), // /Stuck Command SWEARINGUILD(0x389B66B1, SwearInGuildMsg.class, SwearInGuildHandler.class), SYNC(0x49ec109f, null, null), //Client/Server loc sync SYSTEMBROADCASTCHANNEL(0x2FAD89D1, ChatSystemMsg.class, null), // Chat Channel: System Message diff --git a/src/engine/net/client/handlers/StuckMsgHandler.java b/src/engine/net/client/handlers/StuckMsgHandler.java new file mode 100644 index 00000000..5558d542 --- /dev/null +++ b/src/engine/net/client/handlers/StuckMsgHandler.java @@ -0,0 +1,61 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package engine.net.client.handlers; + +import engine.exception.MsgSendException; +import engine.job.JobContainer; +import engine.job.JobScheduler; +import engine.jobs.StuckJob; +import engine.net.client.ClientConnection; +import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.StuckMsg; +import engine.objects.PlayerCharacter; + +import java.util.concurrent.ConcurrentHashMap; + +public class StuckMsgHandler extends AbstractClientMsgHandler { + + public StuckMsgHandler() { + super(StuckMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter playerCharacter = origin.getPlayerCharacter(); + + // Member variable declaration + + StuckMsg msg; + + // Member variable assignment + + msg = (StuckMsg) baseMsg; + + if (playerCharacter == null) + return true; + + if (playerCharacter.getTimers().containsKey("Stuck")) + return true; + + StuckJob sj = new StuckJob(playerCharacter); + JobContainer jc = JobScheduler.getInstance().scheduleJob(sj, 10000); // Convert + ConcurrentHashMap timers = playerCharacter.getTimers(); + + if (timers != null) { + if (timers.containsKey("Stuck")) { + timers.get("Stuck").cancelJob(); + timers.remove("Stuck"); + } + timers.put("Stuck", jc); + } + return true; + } + +} \ No newline at end of file diff --git a/src/engine/net/client/msg/StuckCommandMsg.java b/src/engine/net/client/msg/StuckMsg.java similarity index 91% rename from src/engine/net/client/msg/StuckCommandMsg.java rename to src/engine/net/client/msg/StuckMsg.java index 2058633e..b598cb15 100644 --- a/src/engine/net/client/msg/StuckCommandMsg.java +++ b/src/engine/net/client/msg/StuckMsg.java @@ -16,12 +16,12 @@ import engine.net.ByteBufferWriter; import engine.net.client.Protocol; -public class StuckCommandMsg extends ClientNetMsg { +public class StuckMsg extends ClientNetMsg { /** * This is the general purpose constructor. */ - public StuckCommandMsg() { + public StuckMsg() { super(Protocol.STUCK); } @@ -31,7 +31,7 @@ public class StuckCommandMsg extends ClientNetMsg { * past the limit) then this constructor Throws that Exception to the * caller. */ - public StuckCommandMsg(AbstractConnection origin, ByteBufferReader reader) { + public StuckMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.STUCK, origin, reader); }