From 854d0a8a685d55d9c583f0e110085c09fbb5eba3 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 31 Mar 2024 10:20:44 -0400 Subject: [PATCH] Handler created for commitnewcharmsg --- .../CommitNewCharacterMsgHandler.java | 64 +++++++++++++++++++ .../server/login/LoginServerMsgHandler.java | 39 +---------- 2 files changed, 65 insertions(+), 38 deletions(-) create mode 100644 src/engine/net/client/handlers/CommitNewCharacterMsgHandler.java diff --git a/src/engine/net/client/handlers/CommitNewCharacterMsgHandler.java b/src/engine/net/client/handlers/CommitNewCharacterMsgHandler.java new file mode 100644 index 00000000..48767e28 --- /dev/null +++ b/src/engine/net/client/handlers/CommitNewCharacterMsgHandler.java @@ -0,0 +1,64 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// 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.CommitNewCharacterMsg; +import engine.objects.PlayerCharacter; +import engine.server.MBServerStatics; +import engine.server.login.LoginServerMsgHandler; +import org.pmw.tinylog.Logger; + +public class CommitNewCharacterMsgHandler extends AbstractClientMsgHandler { + + public CommitNewCharacterMsgHandler() { + super(CommitNewCharacterMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + if (origin.getAccount() == null) + return true; + + CommitNewCharacterMsg msg = (CommitNewCharacterMsg) baseMsg; + + try { + // Check to see if there is an available slot. + if (origin.getAccount().characterMap.size() >= MBServerStatics.MAX_NUM_OF_CHARACTERS) { + LoginServerMsgHandler.sendCharacterSelectScreen(SessionManager.getSession(origin)); + return true; + } + + PlayerCharacter newPlayer = PlayerCharacter.generatePCFromCommitNewCharacterMsg(origin.getAccount(), msg, origin); + + if (newPlayer == null) { + Logger.info("Player returned null while creating character."); + LoginServerMsgHandler.sendCharacterSelectScreen(SessionManager.getSession(origin), true); + return true; + } + + PlayerCharacter.initializePlayer(newPlayer); + origin.getAccount().characterMap.putIfAbsent(newPlayer.getObjectUUID(), newPlayer); + + // Send back to Character Select Screen + LoginServerMsgHandler.sendCharacterSelectScreen(SessionManager.getSession(origin), true); + + } catch (Exception e) { + Logger.error(e); + LoginServerMsgHandler.sendCharacterSelectScreen(SessionManager.getSession(origin), true); + } + + 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 6c0a7d51..ca60e1f6 100644 --- a/src/engine/server/login/LoginServerMsgHandler.java +++ b/src/engine/server/login/LoginServerMsgHandler.java @@ -72,10 +72,6 @@ public class LoginServerMsgHandler implements NetMsgHandler { try { switch (protocolMsg) { - case CREATECHAR: - this.CommitNewCharacter((CommitNewCharacterMsg) clientNetMsg, origin); - break; - case REMOVECHAR: this.DeleteCharacter((DeleteCharacterMsg) clientNetMsg, origin); break; @@ -126,7 +122,7 @@ public class LoginServerMsgHandler implements NetMsgHandler { sendCharacterSelectScreen(s, false); } - private static void sendCharacterSelectScreen(Session s, boolean fromCommit) { + public static void sendCharacterSelectScreen(Session s, boolean fromCommit) { if (s.getAccount() != null) { CharSelectScreenMsg cssm = new CharSelectScreenMsg(s, fromCommit); @@ -137,39 +133,6 @@ public class LoginServerMsgHandler implements NetMsgHandler { } } - private void CommitNewCharacter(CommitNewCharacterMsg commitNewCharacterMessage, ClientConnection clientConnection) { - - Session session = SessionManager.getSession(clientConnection); - - if (session.getAccount() == null) - return; - - try { - // Check to see if there is an available slot. - if (session.getAccount().characterMap.size() >= MBServerStatics.MAX_NUM_OF_CHARACTERS) { - this.sendCharacterSelectScreen(session); - return; - } - - PlayerCharacter pc = PlayerCharacter.generatePCFromCommitNewCharacterMsg(session.getAccount(), commitNewCharacterMessage, clientConnection); - - if (pc == null) { - Logger.info("Player returned null while creating character."); - this.sendCharacterSelectScreen(session, true); - return; - } - - PlayerCharacter.initializePlayer(pc); - session.getAccount().characterMap.putIfAbsent(pc.getObjectUUID(), pc); - // Send back to Character Select Screen - this.sendCharacterSelectScreen(session, true); - - } catch (Exception e) { - Logger.error(e); - this.sendCharacterSelectScreen(session, true); - } - } - private void DeleteCharacter(DeleteCharacterMsg msg, ClientConnection origin) { try {