diff --git a/src/protocol/swg/ErrorMessage.java b/src/protocol/swg/ErrorMessage.java index 507561b9..02c4ad00 100644 --- a/src/protocol/swg/ErrorMessage.java +++ b/src/protocol/swg/ErrorMessage.java @@ -49,6 +49,6 @@ public class ErrorMessage extends SWGMessage { result.put(getAsciiString(errorMessage)); result.put((byte)0); - return result; + return result.flip(); } } diff --git a/src/services/LoginService.java b/src/services/LoginService.java index eb843410..0b7bcd0b 100644 --- a/src/services/LoginService.java +++ b/src/services/LoginService.java @@ -92,6 +92,11 @@ public class LoginService implements INetworkDispatch{ public void handlePacket(IoSession session, IoBuffer data) throws Exception { + if (session == null) { + System.out.println("Login attempted with NULL session!"); + return; + } + data = data.order(ByteOrder.LITTLE_ENDIAN); LoginClientId clientID = new LoginClientId(); data.position(0); @@ -116,16 +121,19 @@ public class LoginService implements INetworkDispatch{ err = "user is banned"; break; } - ErrorMessage errMsg = new ErrorMessage("Invalid Login", err); + + // No matter what, this will always show that the login server is unavailable at this time. Removing the error message will just keep the connecting message up. + ErrorMessage errMsg = new ErrorMessage("Wrong Password", "The username or password you entered was incorrect."); session.write(errMsg.serialize()); + Disconnect disconnect = new Disconnect((Integer)session.getAttribute("connectionId"), 6); session.write(disconnect); - session.close(false); + + // Closing the session for some reason will not show any error messages, even if write messages are queued.. + //As result, the infinite "Connecting to galaxy..." loop., also it randomly denies any logins from that client for some reason return; } - System.out.println(user + " successfully logged in."); - Client client = new Client(session.getRemoteAddress()); client.setAccountName(user); client.setPassword(pass); @@ -137,6 +145,16 @@ public class LoginService implements INetworkDispatch{ core.addClient(session, client); + if (!core.getActiveConnectionsMap().containsKey(session)) { + Disconnect disconnect = new Disconnect((Integer)session.getAttribute("connectionId"), 6); + session.write(disconnect); + ErrorMessage errMsg = new ErrorMessage("Error Logging In", "Your client could not be added to the connections at this time."); + session.write(errMsg.serialize()); + session.close(false); + + System.out.println(client.getAccountName() + " was not added to active connections map."); + return; + } /*if(!checkIfAccountExistInGameDB(id)) { createAccountForGameDB(id, user, email, encryptPass); }*/ @@ -153,9 +171,7 @@ public class LoginService implements INetworkDispatch{ ServerNowEpochTime time = new ServerNowEpochTime((int) (System.currentTimeMillis() / 1000)); if (client.getSession().containsAttribute("tradeSession") == true) { - System.out.println("Has attribute: " + session.getAttribute("tradeSession").toString()); client.getSession().removeAttribute("tradeSession"); - System.out.println("Removed tradeSession Attribute @ LoginService.java"); } session.write(time.serialize()); @@ -165,6 +181,8 @@ public class LoginService implements INetworkDispatch{ session.write(serverStatus.serialize()); session.write(jediSlot.serialize()); session.write(characters.serialize()); + + System.out.println(user + " successfully logged in."); } });