diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageSetupCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageSetupCommand.java index 4c8e58c9a..d58fb3d84 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageSetupCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/manage/ManageSetupCommand.java @@ -1,9 +1,6 @@ package com.djrapitops.plan.command.commands.manage; -import com.djrapitops.plan.api.exceptions.connection.BadRequestException; -import com.djrapitops.plan.api.exceptions.connection.ForbiddenException; -import com.djrapitops.plan.api.exceptions.connection.UnauthorizedServerException; -import com.djrapitops.plan.api.exceptions.connection.WebException; +import com.djrapitops.plan.api.exceptions.connection.*; import com.djrapitops.plan.system.info.InfoSystem; import com.djrapitops.plan.system.settings.Permissions; import com.djrapitops.plan.system.settings.Settings; @@ -47,7 +44,7 @@ public class ManageSetupCommand extends SubCommand { return true; } String address = args[0].toLowerCase(); - if (!address.startsWith("http")) { + if (!address.startsWith("http") || address.endsWith("://")) { sender.sendMessage("§cMake sure you're using the full address (Starts with http:// or https://) - Check Bungee enable log for the full address."); return true; } @@ -67,9 +64,13 @@ public class ManageSetupCommand extends SubCommand { sender.sendMessage("§eConnection succeeded, but Receiving server was a Bukkit server. Use Bungee address instead."); } catch (UnauthorizedServerException e) { sender.sendMessage("§eConnection succeeded, but Receiving server didn't authorize this server. Contact Discord for support"); + } catch (ConnectionFailException e) { + sender.sendMessage("§eConnection failed: " + e.getMessage()); + } catch (InternalErrorException e) { + sender.sendMessage("§eConnection succeeded. " + e.getMessage() + ", check possible ErrorLog on receiving server's debug page."); } catch (WebException e) { Log.toLog(this.getClass(), e); - sender.sendMessage("§cConnection to Bungee WebServer failed: More info on console"); + sender.sendMessage("§cConnection to Bungee WebServer failed: More info in the error log."); } return true; } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionIn.java b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionIn.java index a2ee8dd71..065520cb3 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionIn.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionIn.java @@ -7,6 +7,7 @@ import com.djrapitops.plan.system.info.request.InfoRequest; import com.djrapitops.plan.system.info.request.SetupRequest; import com.djrapitops.plan.system.webserver.Request; import com.djrapitops.plan.system.webserver.response.Response; +import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.utilities.Verify; import java.io.ByteArrayOutputStream; @@ -26,32 +27,43 @@ public class ConnectionIn { public ConnectionIn(Request httpRequest, InfoRequest infoRequest) throws WebException { Verify.nullCheck(httpRequest, infoRequest); - Map variables = readVariables(httpRequest); - checkAuthentication(variables); - - this.variables = variables; + this.variables = readVariables(httpRequest); this.infoRequest = infoRequest; + + checkAuthentication(); } - private void checkAuthentication(Map variables) throws WebException { - String sender = variables.get("sender"); - Verify.nullCheck(sender, () -> new BadRequestException("Sender ('sender') variable not supplied in the request.")); - UUID serverUUID = UUID.fromString(sender); + private void checkAuthentication() throws WebException { + UUID serverUUID = getServerUUID(); try { - if (!Database.getActive().check().isServerInDatabase(serverUUID)) { - if (infoRequest instanceof SetupRequest) { - if (ConnectionSystem.isSetupAllowed()) { - return; - } else { - throw new ForbiddenException("Setup not enabled on this server, use commands to enable."); - } - } - throw new UnauthorizedServerException(sender + " (Sender) was not found from database"); + if (Database.getActive().check().isServerInDatabase(serverUUID)) { + return; } } catch (DBException e) { throw new TransferDatabaseException(e); } + + Log.debug("ConnectionIn: " + infoRequest.getClass().getSimpleName()); + + if (infoRequest instanceof SetupRequest) { + if (!ConnectionSystem.isSetupAllowed()) { + throw new ForbiddenException("Setup not enabled on this server, use commands to enable."); + } + } else { + throw new UnauthorizedServerException(serverUUID + " (Sender) was not found from database"); + } + } + + private UUID getServerUUID() throws BadRequestException { + String sender = variables.get("sender"); + Verify.nullCheck(sender, () -> new BadRequestException("Sender ('sender') variable not supplied in the request.")); + + try { + return UUID.fromString(sender); + } catch (IllegalArgumentException e) { + throw new BadRequestException("Sender ('sender') was not a valid UUID: " + e.getMessage()); + } } private Map readVariables(Request request) throws WebException {