diff --git a/LaunchServer/source/LaunchServer.java b/LaunchServer/source/LaunchServer.java index dab9f64..53ed341 100644 --- a/LaunchServer/source/LaunchServer.java +++ b/LaunchServer/source/LaunchServer.java @@ -178,8 +178,8 @@ LogHelper.info("Loading plugin.js script"); try { loadScript(IOHelper.toURL(scriptFile)); - } catch (Throwable exc) { - LogHelper.error(exc); + } catch (Exception e) { + throw new RuntimeException("Error while loading plugin.js", e); } } diff --git a/LaunchServer/source/auth/MySQLSourceConfig.java b/LaunchServer/source/auth/MySQLSourceConfig.java index 233e97d..8e3128f 100644 --- a/LaunchServer/source/auth/MySQLSourceConfig.java +++ b/LaunchServer/source/auth/MySQLSourceConfig.java @@ -98,7 +98,7 @@ // Set pool settings hikariSource.setPoolName(poolName); hikariSource.setMaximumPoolSize(MAX_POOL_SIZE); - hikariSource.setValidationTimeout(TIMEOUT * 1000); + hikariSource.setValidationTimeout(TIMEOUT * 1000L); // Replace source with hds source = hikariSource; diff --git a/LaunchServer/source/auth/handler/CachedAuthHandler.java b/LaunchServer/source/auth/handler/CachedAuthHandler.java index 203b9ba..8280dd8 100644 --- a/LaunchServer/source/auth/handler/CachedAuthHandler.java +++ b/LaunchServer/source/auth/handler/CachedAuthHandler.java @@ -26,7 +26,7 @@ public final synchronized UUID auth(String username, String accessToken) throws IOException { Entry entry = getEntry(username); if (entry == null || !updateAuth(entry.uuid, entry.username, accessToken)) { - return authError(String.format("Account doesn't exist: '%s'", username)); + return authError(String.format("UUID is null for username '%s'", username)); } // Update cached access token (and username case) diff --git a/LaunchServer/source/command/auth/AuthCommand.java b/LaunchServer/source/command/auth/AuthCommand.java index f4d3ef8..b0b4da8 100644 --- a/LaunchServer/source/command/auth/AuthCommand.java +++ b/LaunchServer/source/command/auth/AuthCommand.java @@ -6,7 +6,6 @@ import launcher.helper.SecurityHelper; import launchserver.LaunchServer; import launchserver.command.Command; -import launchserver.command.CommandException; public final class AuthCommand extends Command { public AuthCommand(LaunchServer server) { @@ -35,9 +34,6 @@ // Authenticate on server (and get UUID) String accessToken = SecurityHelper.randomStringToken(); UUID uuid = server.config.authHandler.auth(username, accessToken); - if (uuid == null) { - throw new CommandException("Can't assing UUID (Command)"); - } // Print auth successful message LogHelper.subInfo("UUID: %s, Username: '%s', Access Token: '%s'", uuid, username, accessToken); diff --git a/LaunchServer/source/response/auth/AuthResponse.java b/LaunchServer/source/response/auth/AuthResponse.java index 0648992..e91b3de 100644 --- a/LaunchServer/source/response/auth/AuthResponse.java +++ b/LaunchServer/source/response/auth/AuthResponse.java @@ -51,7 +51,7 @@ return; } catch (Exception e) { LogHelper.error(e); - requestError("Internal auth error"); + requestError("Internal auth provider error"); return; } debug("Auth: '%s' -> '%s'", login, username); @@ -64,6 +64,10 @@ } catch (AuthException e) { requestError(e.getMessage()); return; + } catch (Exception e) { + LogHelper.error(e); + requestError("Internal auth handler error"); + return; } writeNoError(output); diff --git a/LaunchServer/source/response/auth/CheckServerResponse.java b/LaunchServer/source/response/auth/CheckServerResponse.java index c0e133c..319a9b8 100644 --- a/LaunchServer/source/response/auth/CheckServerResponse.java +++ b/LaunchServer/source/response/auth/CheckServerResponse.java @@ -3,11 +3,13 @@ import java.io.IOException; import java.util.UUID; +import launcher.helper.LogHelper; import launcher.helper.VerifyHelper; import launcher.request.auth.JoinServerRequest; import launcher.serialize.HInput; import launcher.serialize.HOutput; import launchserver.LaunchServer; +import launchserver.auth.AuthException; import launchserver.response.Response; import launchserver.response.profile.ProfileByUUIDResponse; @@ -22,15 +24,24 @@ String serverID = JoinServerRequest.verifyServerID(input.readASCII(41)); // With minus sign debug("Username: %s, Server ID: %s", username, serverID); - // Check server - UUID uuid = server.config.authHandler.checkServer(username, serverID); - if (uuid == null) { - output.writeBoolean(false); + // Try check server with auth handler + UUID uuid; + try { + uuid = server.config.authHandler.checkServer(username, serverID); + } catch (AuthException e) { + requestError(e.getMessage()); + return; + } catch (Exception e) { + LogHelper.error(e); + requestError("Internal auth handler error"); return; } + writeNoError(output); - // Return server ID - output.writeBoolean(true); - ProfileByUUIDResponse.getProfile(server, uuid, username).write(output); + // Write profile and UUID + output.writeBoolean(uuid != null); + if (uuid != null) { + ProfileByUUIDResponse.getProfile(server, uuid, username).write(output); + } } } diff --git a/LaunchServer/source/response/auth/JoinServerResponse.java b/LaunchServer/source/response/auth/JoinServerResponse.java index 21f7523..0469c0e 100644 --- a/LaunchServer/source/response/auth/JoinServerResponse.java +++ b/LaunchServer/source/response/auth/JoinServerResponse.java @@ -2,12 +2,14 @@ import java.io.IOException; +import launcher.helper.LogHelper; import launcher.helper.SecurityHelper; import launcher.helper.VerifyHelper; import launcher.request.auth.JoinServerRequest; import launcher.serialize.HInput; import launcher.serialize.HOutput; import launchserver.LaunchServer; +import launchserver.auth.AuthException; import launchserver.response.Response; public final class JoinServerResponse extends Response { @@ -21,8 +23,22 @@ String accessToken = SecurityHelper.verifyToken(input.readASCII(-SecurityHelper.TOKEN_STRING_LENGTH)); String serverID = JoinServerRequest.verifyServerID(input.readASCII(41)); // With minus sign - // Try join server with auth manager + // Try join server with auth handler debug("Username: '%s', Access token: %s, Server ID: %s", username, accessToken, serverID); - output.writeBoolean(server.config.authHandler.joinServer(username, accessToken, serverID)); + boolean success; + try { + success = server.config.authHandler.joinServer(username, accessToken, serverID); + } catch (AuthException e) { + requestError(e.getMessage()); + return; + } catch (Exception e) { + LogHelper.error(e); + requestError("Internal auth handler error"); + return; + } + writeNoError(output); + + // Write response + output.writeBoolean(success); } } diff --git a/Launcher/source/helper/IOHelper.java b/Launcher/source/helper/IOHelper.java index b002a1e..64e4bff 100644 --- a/Launcher/source/helper/IOHelper.java +++ b/Launcher/source/helper/IOHelper.java @@ -587,7 +587,7 @@ new URL(url).toURI(); return url; } catch (MalformedURLException | URISyntaxException e) { - throw new IllegalArgumentException(e); + throw new IllegalArgumentException("Invalid URL", e); } } diff --git a/Launcher/source/request/auth/CheckServerRequest.java b/Launcher/source/request/auth/CheckServerRequest.java index 068ca37..90b14a6 100644 --- a/Launcher/source/request/auth/CheckServerRequest.java +++ b/Launcher/source/request/auth/CheckServerRequest.java @@ -38,6 +38,7 @@ output.flush(); // Read response + readError(input); return input.readBoolean() ? new PlayerProfile(input) : null; } } diff --git a/Launcher/source/request/auth/JoinServerRequest.java b/Launcher/source/request/auth/JoinServerRequest.java index 7683c37..04e9210 100644 --- a/Launcher/source/request/auth/JoinServerRequest.java +++ b/Launcher/source/request/auth/JoinServerRequest.java @@ -45,6 +45,7 @@ output.flush(); // Read response + readError(input); return input.readBoolean(); }