From 4e5e49606c3b62577bba1b4aa74a338b42bebbc1 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 31 Mar 2024 10:37:03 -0400 Subject: [PATCH] Methods moved out of old login handler --- .../handlers/ClientLoginInfoMsgHandler.java | 25 ++++---- .../CommitNewCharacterMsgHandler.java | 10 ++-- .../handlers/DeleteCharacterMsgHandler.java | 13 ++--- .../GameServerIPRequestMsgHandler.java | 8 +-- .../client/handlers/ServerInfoMsgHandler.java | 4 +- .../handlers/VersionInfoMsgHandler.java | 7 +-- src/engine/objects/PlayerCharacter.java | 11 ++-- src/engine/server/login/LoginServer.java | 53 ++++++++++++++++- .../server/login/LoginServerMsgHandler.java | 57 ------------------- 9 files changed, 88 insertions(+), 100 deletions(-) diff --git a/src/engine/net/client/handlers/ClientLoginInfoMsgHandler.java b/src/engine/net/client/handlers/ClientLoginInfoMsgHandler.java index c19c5045..ca4cc92f 100644 --- a/src/engine/net/client/handlers/ClientLoginInfoMsgHandler.java +++ b/src/engine/net/client/handlers/ClientLoginInfoMsgHandler.java @@ -20,7 +20,6 @@ import engine.objects.Account; import engine.objects.PlayerCharacter; import engine.server.MBServerStatics; import engine.server.login.LoginServer; -import engine.server.login.LoginServerMsgHandler; import engine.session.Session; import org.pmw.tinylog.Logger; @@ -49,17 +48,17 @@ public class ClientLoginInfoMsgHandler extends AbstractClientMsgHandler { // Check to see if there is actually any data in uname.pass if (uname.length() == 0) { - LoginServerMsgHandler.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "The username provided was zero length.", origin); + LoginServer.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "The username provided was zero length.", origin); return true; } if (pass.length() == 0) { - LoginServerMsgHandler.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "The password provided was zero length.", origin); + LoginServer.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "The password provided was zero length.", origin); return true; } if (LoginServer.loginServerRunning == false) { - LoginServerMsgHandler.KickToLogin(MBServerStatics.LOGINERROR_LOGINSERVER_BUSY, "", origin); + LoginServer.KickToLogin(MBServerStatics.LOGINERROR_LOGINSERVER_BUSY, "", origin); return true; } @@ -73,7 +72,7 @@ public class ClientLoginInfoMsgHandler extends AbstractClientMsgHandler { if (account == null) { if (ConfigManager.MB_LOGIN_AUTOREG.getValue().equalsIgnoreCase("false")) { - LoginServerMsgHandler.KickToLogin(MBServerStatics.LOGINERROR_INVALID_USERNAME_PASSWORD, "Could not find account (" + uname + ')', origin); + LoginServer.KickToLogin(MBServerStatics.LOGINERROR_INVALID_USERNAME_PASSWORD, "Could not find account (" + uname + ')', origin); Logger.info("Could not find account (" + uname + ')'); return true; } @@ -83,7 +82,7 @@ public class ClientLoginInfoMsgHandler extends AbstractClientMsgHandler { account = DbManager.AccountQueries.GET_ACCOUNT(uname); if (account == null) { - LoginServerMsgHandler.KickToLogin(MBServerStatics.LOGINERROR_INVALID_USERNAME_PASSWORD, "Could not find account (" + uname + ')', origin); + LoginServer.KickToLogin(MBServerStatics.LOGINERROR_INVALID_USERNAME_PASSWORD, "Could not find account (" + uname + ')', origin); Logger.info("Could not auto-create (" + uname + ')'); return true; } @@ -96,7 +95,7 @@ public class ClientLoginInfoMsgHandler extends AbstractClientMsgHandler { // Check number invalid login attempts. If 5 or greater, kick to login. if (account.getLoginAttempts() >= MBServerStatics.MAX_LOGIN_ATTEMPTS) { - LoginServerMsgHandler.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Too many login in attempts for '" + uname + '\'', origin); + LoginServer.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Too many login in attempts for '" + uname + '\'', origin); Logger.info("Too many login in attempts for '" + uname + '\''); return true; } @@ -110,19 +109,19 @@ public class ClientLoginInfoMsgHandler extends AbstractClientMsgHandler { if (!account.passIsValid(pass, origin.getClientIpAddress(), origin.machineID)) { account.incrementLoginAttempts(); - LoginServerMsgHandler.KickToLogin(MBServerStatics.LOGINERROR_INVALID_USERNAME_PASSWORD, "", origin); + LoginServer.KickToLogin(MBServerStatics.LOGINERROR_INVALID_USERNAME_PASSWORD, "", origin); Logger.info("Incorrect password(" + uname + ')'); return true; } } catch (IllegalArgumentException e1) { - LoginServerMsgHandler.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "", origin); + LoginServer.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "", origin); Logger.info("Failed forum account validation(" + uname + ')'); } // Account deactivated if (account.status.equals(Enum.AccountStatus.BANNED)) { - LoginServerMsgHandler.KickToLogin(MBServerStatics.LOGINERROR_NO_MORE_PLAYTIME_ON_ACCOUNT, "", origin); + LoginServer.KickToLogin(MBServerStatics.LOGINERROR_NO_MORE_PLAYTIME_ON_ACCOUNT, "", origin); return true; } @@ -132,7 +131,7 @@ public class ClientLoginInfoMsgHandler extends AbstractClientMsgHandler { // If there is, then the account is in use and must be handled: // kick the 'other connection' if (session != null) - LoginServerMsgHandler.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Your account has been accessed from a different IP & Port.", session.getConn()); // Logout the character + LoginServer.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Your account has been accessed from a different IP & Port.", session.getConn()); // Logout the character // TODO implement character logout @@ -153,10 +152,10 @@ public class ClientLoginInfoMsgHandler extends AbstractClientMsgHandler { // send character select screen try { - LoginServerMsgHandler.sendCharacterSelectScreen(session); + LoginServer.sendCharacterSelectScreen(session); } catch (Exception e) { Logger.error("Unable to Send Character Select Screen to client"); - LoginServerMsgHandler.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Unable to send Character Select Screen to client.", origin); + LoginServer.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Unable to send Character Select Screen to client.", origin); return true; } diff --git a/src/engine/net/client/handlers/CommitNewCharacterMsgHandler.java b/src/engine/net/client/handlers/CommitNewCharacterMsgHandler.java index 48767e28..4deffdd9 100644 --- a/src/engine/net/client/handlers/CommitNewCharacterMsgHandler.java +++ b/src/engine/net/client/handlers/CommitNewCharacterMsgHandler.java @@ -15,7 +15,7 @@ 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 engine.server.login.LoginServer; import org.pmw.tinylog.Logger; public class CommitNewCharacterMsgHandler extends AbstractClientMsgHandler { @@ -35,7 +35,7 @@ public class CommitNewCharacterMsgHandler extends AbstractClientMsgHandler { 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)); + LoginServer.sendCharacterSelectScreen(SessionManager.getSession(origin)); return true; } @@ -43,7 +43,7 @@ public class CommitNewCharacterMsgHandler extends AbstractClientMsgHandler { if (newPlayer == null) { Logger.info("Player returned null while creating character."); - LoginServerMsgHandler.sendCharacterSelectScreen(SessionManager.getSession(origin), true); + LoginServer.sendCharacterSelectScreen(SessionManager.getSession(origin), true); return true; } @@ -51,11 +51,11 @@ public class CommitNewCharacterMsgHandler extends AbstractClientMsgHandler { origin.getAccount().characterMap.putIfAbsent(newPlayer.getObjectUUID(), newPlayer); // Send back to Character Select Screen - LoginServerMsgHandler.sendCharacterSelectScreen(SessionManager.getSession(origin), true); + LoginServer.sendCharacterSelectScreen(SessionManager.getSession(origin), true); } catch (Exception e) { Logger.error(e); - LoginServerMsgHandler.sendCharacterSelectScreen(SessionManager.getSession(origin), true); + LoginServer.sendCharacterSelectScreen(SessionManager.getSession(origin), true); } return true; diff --git a/src/engine/net/client/handlers/DeleteCharacterMsgHandler.java b/src/engine/net/client/handlers/DeleteCharacterMsgHandler.java index 72ae672d..b45b2fa1 100644 --- a/src/engine/net/client/handlers/DeleteCharacterMsgHandler.java +++ b/src/engine/net/client/handlers/DeleteCharacterMsgHandler.java @@ -17,7 +17,6 @@ import engine.objects.GuildStatusController; import engine.objects.PlayerCharacter; import engine.server.MBServerStatics; import engine.server.login.LoginServer; -import engine.server.login.LoginServerMsgHandler; import engine.session.Session; import org.pmw.tinylog.Logger; @@ -47,19 +46,19 @@ public class DeleteCharacterMsgHandler extends AbstractClientMsgHandler { if (playerCharacter == null) { Logger.error("Delete Error: PlayerID=" + msg.getCharacterUUID() + " not found."); - LoginServerMsgHandler.sendCharacterSelectScreen(session); + LoginServer.sendCharacterSelectScreen(session); return true; } if (session.getAccount() == null) { Logger.error("Delete Error: Account not found."); - LoginServerMsgHandler.sendCharacterSelectScreen(session); + LoginServer.sendCharacterSelectScreen(session); return true; } if (playerCharacter.getAccount().equals(session.getAccount()) == false) { Logger.error("Delete Error: Character " + playerCharacter.getName() + " does not belong to account " + origin.getAccount().getUname()); - LoginServerMsgHandler.sendCharacterSelectScreen(session); + LoginServer.sendCharacterSelectScreen(session); return true; } @@ -67,7 +66,7 @@ public class DeleteCharacterMsgHandler extends AbstractClientMsgHandler { //TODO either find an error or just gdisband. if (GuildStatusController.isGuildLeader(playerCharacter.getGuildStatus())) { - LoginServerMsgHandler.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Cannot delete a guild leader.", origin); + LoginServer.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Cannot delete a guild leader.", origin); return true; } @@ -75,7 +74,7 @@ public class DeleteCharacterMsgHandler extends AbstractClientMsgHandler { if (LoginServer.getActiveBaneQuery(playerCharacter)) { Logger.info("Character " + playerCharacter.getName() + " has unresolved bane"); - LoginServerMsgHandler.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Player has unresolved bane.", origin); + LoginServer.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Player has unresolved bane.", origin); return true; } @@ -84,7 +83,7 @@ public class DeleteCharacterMsgHandler extends AbstractClientMsgHandler { // TODO Delete Equipment // Resend Character Select Screen. - LoginServerMsgHandler.sendCharacterSelectScreen(session); + LoginServer.sendCharacterSelectScreen(session); } catch (Exception e) { Logger.error(e); diff --git a/src/engine/net/client/handlers/GameServerIPRequestMsgHandler.java b/src/engine/net/client/handlers/GameServerIPRequestMsgHandler.java index 164a0b8a..5d16b81d 100644 --- a/src/engine/net/client/handlers/GameServerIPRequestMsgHandler.java +++ b/src/engine/net/client/handlers/GameServerIPRequestMsgHandler.java @@ -17,7 +17,7 @@ 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.server.login.LoginServer; import engine.session.CSSession; import engine.session.Session; import engine.util.ByteUtils; @@ -45,14 +45,14 @@ public class GameServerIPRequestMsgHandler extends AbstractClientMsgHandler { 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); + LoginServer.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); + LoginServer.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Failed to update Session Information", origin); return true; } } catch (Exception e) { @@ -68,7 +68,7 @@ public class GameServerIPRequestMsgHandler extends AbstractClientMsgHandler { if (!origin.sendMsg(gameServerIPResponseMsg)) { Logger.error("Failed to send message"); - LoginServerMsgHandler.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Unable to send GameServerIPResponseMsg to client.", origin); + LoginServer.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Unable to send GameServerIPResponseMsg to client.", origin); } diff --git a/src/engine/net/client/handlers/ServerInfoMsgHandler.java b/src/engine/net/client/handlers/ServerInfoMsgHandler.java index 6eebb470..5d84be0d 100644 --- a/src/engine/net/client/handlers/ServerInfoMsgHandler.java +++ b/src/engine/net/client/handlers/ServerInfoMsgHandler.java @@ -14,7 +14,7 @@ import engine.net.client.msg.ClientNetMsg; import engine.net.client.msg.ServerInfoMsg; import engine.objects.PlayerCharacter; import engine.server.MBServerStatics; -import engine.server.login.LoginServerMsgHandler; +import engine.server.login.LoginServer; import org.pmw.tinylog.Logger; public class ServerInfoMsgHandler extends AbstractClientMsgHandler { @@ -40,7 +40,7 @@ public class ServerInfoMsgHandler extends AbstractClientMsgHandler { if (!origin.sendMsg(sim)) { Logger.error("Failed to send message"); - LoginServerMsgHandler.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Unable to send ServerInfoMsg to client.", origin); + LoginServer.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Unable to send ServerInfoMsg to client.", origin); } return true; diff --git a/src/engine/net/client/handlers/VersionInfoMsgHandler.java b/src/engine/net/client/handlers/VersionInfoMsgHandler.java index 7305c47d..06ecffb5 100644 --- a/src/engine/net/client/handlers/VersionInfoMsgHandler.java +++ b/src/engine/net/client/handlers/VersionInfoMsgHandler.java @@ -15,7 +15,6 @@ import engine.net.client.msg.login.VersionInfoMsg; import engine.objects.PlayerCharacter; import engine.server.MBServerStatics; import engine.server.login.LoginServer; -import engine.server.login.LoginServerMsgHandler; public class VersionInfoMsgHandler extends AbstractClientMsgHandler { @@ -43,7 +42,7 @@ public class VersionInfoMsgHandler extends AbstractClientMsgHandler { cMinorVer = msg.getMinorVersion(); if (!cMajorVer.equals(LoginServer.getDefaultVersionInfo().getMajorVersion())) { - LoginServerMsgHandler.KickToLogin(MBServerStatics.LOGINERROR_INCORRECT_CLIENT_VERSION, "Major Version Failure: " + cMajorVer, origin); + LoginServer.KickToLogin(MBServerStatics.LOGINERROR_INCORRECT_CLIENT_VERSION, "Major Version Failure: " + cMajorVer, origin); return true; } @@ -53,12 +52,12 @@ public class VersionInfoMsgHandler extends AbstractClientMsgHandler { } */ if (cMinorVer == null) { - LoginServerMsgHandler.KickToLogin(MBServerStatics.LOGINERROR_INCORRECT_CLIENT_VERSION, "Minor Version Failure: ", origin); + LoginServer.KickToLogin(MBServerStatics.LOGINERROR_INCORRECT_CLIENT_VERSION, "Minor Version Failure: ", origin); return true; } if (cMinorVer.length() < 8 || cMinorVer.length() > 16) { - LoginServerMsgHandler.KickToLogin(MBServerStatics.LOGINERROR_INCORRECT_CLIENT_VERSION, "Minor Version Failure: ", origin); + LoginServer.KickToLogin(MBServerStatics.LOGINERROR_INCORRECT_CLIENT_VERSION, "Minor Version Failure: ", origin); return true; } diff --git a/src/engine/objects/PlayerCharacter.java b/src/engine/objects/PlayerCharacter.java index db630df8..dde0689d 100644 --- a/src/engine/objects/PlayerCharacter.java +++ b/src/engine/objects/PlayerCharacter.java @@ -38,7 +38,6 @@ import engine.net.client.msg.login.CommitNewCharacterMsg; import engine.powers.EffectsBase; import engine.server.MBServerStatics; import engine.server.login.LoginServer; -import engine.server.login.LoginServerMsgHandler; import engine.server.world.WorldServer; import engine.util.MiscUtils; import org.joda.time.DateTime; @@ -740,28 +739,28 @@ public class PlayerCharacter extends AbstractCharacter { String lastName = msg.getLastName().trim(); if (firstName.length() < 3) { - LoginServerMsgHandler.sendInvalidNameMsg(firstName, lastName, MBServerStatics.INVALIDNAME_FIRSTNAME_MUST_BE_LONGER, + LoginServer.sendInvalidNameMsg(firstName, lastName, MBServerStatics.INVALIDNAME_FIRSTNAME_MUST_BE_LONGER, clientConnection); return null; } // Ensure names are below required length if (firstName.length() > 15 || lastName.length() > 15) { - LoginServerMsgHandler.sendInvalidNameMsg(firstName, lastName, MBServerStatics.INVALIDNAME_FIRSTANDLAST_MUST_BE_SHORTER, + LoginServer.sendInvalidNameMsg(firstName, lastName, MBServerStatics.INVALIDNAME_FIRSTANDLAST_MUST_BE_SHORTER, clientConnection); return null; } // Check if firstname is valid if (MiscUtils.checkIfFirstNameInvalid(firstName)) { - LoginServerMsgHandler.sendInvalidNameMsg(firstName, lastName, MBServerStatics.INVALIDNAME_PLEASE_CHOOSE_ANOTHER_FIRSTNAME, + LoginServer.sendInvalidNameMsg(firstName, lastName, MBServerStatics.INVALIDNAME_PLEASE_CHOOSE_ANOTHER_FIRSTNAME, clientConnection); return null; } // Check if last name is valid if (MiscUtils.checkIfLastNameInvalid(lastName)) { - LoginServerMsgHandler.sendInvalidNameMsg(firstName, lastName, MBServerStatics.INVALIDNAME_LASTNAME_UNAVAILABLE, + LoginServer.sendInvalidNameMsg(firstName, lastName, MBServerStatics.INVALIDNAME_LASTNAME_UNAVAILABLE, clientConnection); return null; } @@ -1136,7 +1135,7 @@ public class PlayerCharacter extends AbstractCharacter { // This must be the very last check before calling the // DB to create the character record if (DbManager.PlayerCharacterQueries.IS_CHARACTER_NAME_UNIQUE(firstName) == false) { - LoginServerMsgHandler.sendInvalidNameMsg(firstName, lastName, MBServerStatics.INVALIDNAME_FIRSTNAME_UNAVAILABLE, + LoginServer.sendInvalidNameMsg(firstName, lastName, MBServerStatics.INVALIDNAME_FIRSTNAME_UNAVAILABLE, clientConnection); return null; } diff --git a/src/engine/server/login/LoginServer.java b/src/engine/server/login/LoginServer.java index 4b0eef28..0e917598 100644 --- a/src/engine/server/login/LoginServer.java +++ b/src/engine/server/login/LoginServer.java @@ -13,15 +13,18 @@ import engine.Enum; import engine.gameManager.*; import engine.job.JobScheduler; import engine.jobs.CSessionCleanupJob; +import engine.jobs.DisconnectJob; +import engine.net.Dispatch; +import engine.net.DispatchMessage; import engine.net.Network; import engine.net.client.ClientConnection; import engine.net.client.ClientConnectionManager; import engine.net.client.Protocol; -import engine.net.client.msg.login.ServerStatusMsg; -import engine.net.client.msg.login.VersionInfoMsg; +import engine.net.client.msg.login.*; import engine.objects.*; import engine.server.MBServerStatics; import engine.server.world.WorldServer; +import engine.session.Session; import engine.util.ByteUtils; import engine.util.ThreadUtils; import org.pmw.tinylog.Configurator; @@ -170,6 +173,52 @@ public class LoginServer { return portInUse; } + public static void sendInvalidNameMsg(String firstName, String lastName, int errorCode, ClientConnection clientConnection) { + + InvalidNameMsg invalidNameMessage; + + if (firstName.length() > 256 || lastName.length() > 256) + invalidNameMessage = new InvalidNameMsg(firstName, lastName, errorCode); + else + invalidNameMessage = new InvalidNameMsg(firstName, lastName, errorCode); + + clientConnection.sendMsg(invalidNameMessage); + } + + public static void KickToLogin(int errCode, String message, ClientConnection origin) { + LoginErrorMsg msg = new LoginErrorMsg(errCode, message); + + PlayerCharacter player = origin.getPlayerCharacter(); + + if (player == null) { + origin.sendMsg(msg); + } else { + Dispatch dispatch = Dispatch.borrow(player, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); + } + + + Logger.info("Kicking to Login. Message: '" + message + '\''); + + DisconnectJob dj = new DisconnectJob(origin); + JobScheduler.getInstance().scheduleJob(dj, 250); + } + + public static void sendCharacterSelectScreen(Session s) { + sendCharacterSelectScreen(s, false); + } + + public static void sendCharacterSelectScreen(Session s, boolean fromCommit) { + + if (s.getAccount() != null) { + CharSelectScreenMsg cssm = new CharSelectScreenMsg(s, fromCommit); + s.getConn().sendMsg(cssm); + } else { + Logger.error("No Account Found: Unable to Send Character Select Screen"); + KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Unable to send Character Select Screen to client.", s.getConn()); + } + } + private void exec() { diff --git a/src/engine/server/login/LoginServerMsgHandler.java b/src/engine/server/login/LoginServerMsgHandler.java index dfb77038..404a11a5 100644 --- a/src/engine/server/login/LoginServerMsgHandler.java +++ b/src/engine/server/login/LoginServerMsgHandler.java @@ -9,21 +9,10 @@ package engine.server.login; -import engine.Enum.DispatchChannel; -import engine.job.JobScheduler; -import engine.jobs.DisconnectJob; -import engine.net.Dispatch; -import engine.net.DispatchMessage; 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.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.Session; import org.pmw.tinylog.Logger; public class LoginServerMsgHandler implements NetMsgHandler { @@ -35,18 +24,6 @@ public class LoginServerMsgHandler implements NetMsgHandler { this.server = server; } - public static void sendInvalidNameMsg(String firstName, String lastName, int errorCode, ClientConnection clientConnection) { - - InvalidNameMsg invalidNameMessage; - - if (firstName.length() > 256 || lastName.length() > 256) - invalidNameMessage = new InvalidNameMsg(firstName, lastName, errorCode); - else - invalidNameMessage = new InvalidNameMsg(firstName, lastName, errorCode); - - clientConnection.sendMsg(invalidNameMessage); - } - /* * ========================================================================= * Client Messages @@ -67,38 +44,4 @@ public class LoginServerMsgHandler implements NetMsgHandler { } - public static void KickToLogin(int errCode, String message, ClientConnection origin) { - LoginErrorMsg msg = new LoginErrorMsg(errCode, message); - - PlayerCharacter player = origin.getPlayerCharacter(); - - if (player == null) { - origin.sendMsg(msg); - } else { - Dispatch dispatch = Dispatch.borrow(player, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); - } - - - Logger.info("Kicking to Login. Message: '" + message + '\''); - - DisconnectJob dj = new DisconnectJob(origin); - JobScheduler.getInstance().scheduleJob(dj, 250); - } - - public static void sendCharacterSelectScreen(Session s) { - sendCharacterSelectScreen(s, false); - } - - public static void sendCharacterSelectScreen(Session s, boolean fromCommit) { - - if (s.getAccount() != null) { - CharSelectScreenMsg cssm = new CharSelectScreenMsg(s, fromCommit); - s.getConn().sendMsg(cssm); - } else { - Logger.error("No Account Found: Unable to Send Character Select Screen"); - LoginServerMsgHandler.KickToLogin(MBServerStatics.LOGINERROR_UNABLE_TO_LOGIN, "Unable to send Character Select Screen to client.", s.getConn()); - } - } - }