From f62f11a66c2c324fd45975dfd69982c61c796338 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 31 Mar 2024 10:33:46 -0400 Subject: [PATCH] Handler created for GameServerIPRequestMsg --- .../GameServerIPRequestMsgHandler.java | 78 +++++++++++++++++++ .../server/login/LoginServerMsgHandler.java | 70 +---------------- 2 files changed, 81 insertions(+), 67 deletions(-) create mode 100644 src/engine/net/client/handlers/GameServerIPRequestMsgHandler.java diff --git a/src/engine/net/client/handlers/GameServerIPRequestMsgHandler.java b/src/engine/net/client/handlers/GameServerIPRequestMsgHandler.java new file mode 100644 index 00000000..164a0b8a --- /dev/null +++ b/src/engine/net/client/handlers/GameServerIPRequestMsgHandler.java @@ -0,0 +1,78 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package engine.net.client.handlers; + +import engine.exception.MsgSendException; +import engine.gameManager.SessionManager; +import engine.net.client.ClientConnection; +import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.login.GameServerIPRequestMsg; +import engine.net.client.msg.login.GameServerIPResponseMsg; +import engine.objects.Account; +import engine.objects.PlayerCharacter; +import engine.server.MBServerStatics; +import engine.server.login.LoginServerMsgHandler; +import engine.session.CSSession; +import engine.session.Session; +import engine.util.ByteUtils; +import org.pmw.tinylog.Logger; + +public class GameServerIPRequestMsgHandler extends AbstractClientMsgHandler { + + public GameServerIPRequestMsgHandler() { + super(GameServerIPRequestMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter playerCharacter = origin.getPlayerCharacter(); + Session session = SessionManager.getSession(origin); + + // Member variable declaration + + GameServerIPRequestMsg msg; + + // Member variable assignment + + msg = (GameServerIPRequestMsg) baseMsg; + + if (playerCharacter == null) { + Logger.info("Unable to find character ID " + msg.getCharacterUUID()); + LoginServerMsgHandler.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "PlayerCharacter lookup failed in .RequestGameServer().", origin); + return true; + } + + try { + if (!CSSession.updateCrossServerSession(ByteUtils.byteArrayToSafeStringHex(origin.getSecretKeyBytes()), msg.getCharacterUUID())) { + Logger.info("Failed to update Cross server session, Kicking to Login for Character " + playerCharacter.getObjectUUID()); + LoginServerMsgHandler.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Failed to update Session Information", origin); + return true; + } + } catch (Exception e) { + Logger.info("Failed to update Cross server session, Kicking to Login for Character " + playerCharacter.getObjectUUID()); + Logger.error(e); + } + + // Set the last character used. + Account account = session.getAccount(); + account.setLastCharIDUsed(msg.getCharacterUUID()); + + GameServerIPResponseMsg gameServerIPResponseMsg = new GameServerIPResponseMsg(); + + if (!origin.sendMsg(gameServerIPResponseMsg)) { + Logger.error("Failed to send message"); + LoginServerMsgHandler.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Unable to send GameServerIPResponseMsg to client.", origin); + } + + + return true; + } + +} \ No newline at end of file diff --git a/src/engine/server/login/LoginServerMsgHandler.java b/src/engine/server/login/LoginServerMsgHandler.java index 2edb70f0..dfb77038 100644 --- a/src/engine/server/login/LoginServerMsgHandler.java +++ b/src/engine/server/login/LoginServerMsgHandler.java @@ -10,9 +10,6 @@ package engine.server.login; import engine.Enum.DispatchChannel; -import engine.Enum.GameObjectType; -import engine.gameManager.DbManager; -import engine.gameManager.SessionManager; import engine.job.JobScheduler; import engine.jobs.DisconnectJob; import engine.net.Dispatch; @@ -21,14 +18,12 @@ import engine.net.NetMsgHandler; import engine.net.client.ClientConnection; import engine.net.client.Protocol; import engine.net.client.msg.ClientNetMsg; -import engine.net.client.msg.login.*; -import engine.objects.Account; +import engine.net.client.msg.login.CharSelectScreenMsg; +import engine.net.client.msg.login.InvalidNameMsg; +import engine.net.client.msg.login.LoginErrorMsg; import engine.objects.PlayerCharacter; import engine.server.MBServerStatics; -import engine.session.CSSession; import engine.session.Session; -import engine.util.ByteUtils; -import engine.util.StringUtils; import org.pmw.tinylog.Logger; public class LoginServerMsgHandler implements NetMsgHandler { @@ -68,29 +63,6 @@ public class LoginServerMsgHandler implements NetMsgHandler { ClientConnection origin = (ClientConnection) clientNetMsg.getOrigin(); Protocol protocolMsg = clientNetMsg.getProtocolMsg(); - try { - - switch (protocolMsg) { - - case SELECTCHAR: - this.RequestGameServer((GameServerIPRequestMsg) clientNetMsg, origin); - break; - - case TARGETOBJECT: - // Why is this being sent to login server? - break; - - default: - String ocHex = StringUtils.toHexString(protocolMsg.opcode); - Logger.error("Cannot not handle Opcode: " + ocHex); - return false; - } - - } catch (Exception e) { - Logger.error("protocolMsg:" + protocolMsg + e.toString()); - return false; - } - return true; } @@ -129,40 +101,4 @@ public class LoginServerMsgHandler implements NetMsgHandler { } } - private void RequestGameServer(GameServerIPRequestMsg gameServerIPRequestMessage, ClientConnection conn) { - - Session session; - PlayerCharacter player; - - session = SessionManager.getSession(conn); - player = (PlayerCharacter) DbManager.getObject(GameObjectType.PlayerCharacter, gameServerIPRequestMessage.getCharacterUUID()); - - if (player == null) { - Logger.info("Unable to find character ID " + gameServerIPRequestMessage.getCharacterUUID()); - KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "PlayerCharacter lookup failed in .RequestGameServer().", conn); - return; - } - - try { - if (!CSSession.updateCrossServerSession(ByteUtils.byteArrayToSafeStringHex(conn.getSecretKeyBytes()), gameServerIPRequestMessage.getCharacterUUID())) { - Logger.info("Failed to update Cross server session, Kicking to Login for Character " + player.getObjectUUID()); - this.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Failed to update Session Information", conn); - return; - } - } catch (Exception e) { - Logger.info("Failed to update Cross server session, Kicking to Login for Character " + player.getObjectUUID()); - Logger.error(e); - } - - // Set the last character used. - Account account = session.getAccount(); - account.setLastCharIDUsed(gameServerIPRequestMessage.getCharacterUUID()); - - GameServerIPResponseMsg gameServerIPResponseMsg = new GameServerIPResponseMsg(); - - if (!conn.sendMsg(gameServerIPResponseMsg)) { - Logger.error("Failed to send message"); - this.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Unable to send GameServerIPResponseMsg to client.", conn); - } - } }