diff --git a/src/main/java/nl/iobyte/themeparkconnector/api/network/NetworkingService.java b/src/main/java/nl/iobyte/themeparkconnector/api/network/NetworkingService.java index e08863e..8cc243d 100644 --- a/src/main/java/nl/iobyte/themeparkconnector/api/network/NetworkingService.java +++ b/src/main/java/nl/iobyte/themeparkconnector/api/network/NetworkingService.java @@ -57,7 +57,7 @@ public class NetworkingService { * @param abstractPacket Received Packet */ public void triggerPacket(AbstractPacket abstractPacket) { - if (packetHandlerMap.get(abstractPacket.getChannel()) == null) { + if (!packetHandlerMap.containsKey(abstractPacket.getChannel())) { ThemeParkConnectorLogger.toConsole("Unknown handler for packet channel " + abstractPacket.getChannel()); return; } diff --git a/src/main/java/nl/iobyte/themeparkconnector/api/network/io/SocketConnector.java b/src/main/java/nl/iobyte/themeparkconnector/api/network/io/SocketConnector.java index da846b9..1c7ca03 100644 --- a/src/main/java/nl/iobyte/themeparkconnector/api/network/io/SocketConnector.java +++ b/src/main/java/nl/iobyte/themeparkconnector/api/network/io/SocketConnector.java @@ -99,9 +99,6 @@ public class SocketConnector { if (!ThemeParkConnector.getInstance().getAPI().getStateService().isConnected()) return; - if(!client.isConnected()) - return; - String data = client.getUsedToken() + "@" + ThemeParkConnector.getGson().toJson(packet); socket.emit("data", data); } diff --git a/src/main/java/nl/iobyte/themeparkconnector/api/packet/handlers/ClientConnectHandler.java b/src/main/java/nl/iobyte/themeparkconnector/api/packet/handlers/ClientConnectHandler.java index f806921..ea06aa6 100644 --- a/src/main/java/nl/iobyte/themeparkconnector/api/packet/handlers/ClientConnectHandler.java +++ b/src/main/java/nl/iobyte/themeparkconnector/api/packet/handlers/ClientConnectHandler.java @@ -21,11 +21,18 @@ public class ClientConnectHandler extends PayloadHandler { * @param payload ClientConnectPayload */ public void onReceive(ClientConnectPayload payload) { - ClientConnection connection = ThemeParkConnector.getInstance().getAPI().getNetworkingService().getClient(payload.getUUID()); - if(connection == null) - return; - ThemeParkConnectorAPI api = ThemeParkConnector.getInstance().getAPI(); + ClientConnection connection = api.getNetworkingService().getClient(payload.getUUID()); + if(connection == null) { + denyRequest( + api, + payload.getUUID(), + "No client connection found for uuid" + ); + return; + } + + connection.setUsedToken(payload.getToken()); if(!api.getAuthenticationService().matchToken(payload.getUUID(), payload.getToken(), payload.getAttractionID())) { denyRequest( api, @@ -84,7 +91,6 @@ public class ClientConnectHandler extends PayloadHandler { ) ); - connection.setUsedToken(payload.getToken()); connection.onConnect(); for(INetworkingEvent event : ThemeParkConnector.getInstance().getAPI().getNetworkingService().getEvents()) diff --git a/src/main/java/nl/iobyte/themeparkconnector/sbd/License.java b/src/main/java/nl/iobyte/themeparkconnector/sbd/License.java index 6cd6602..4f08b7d 100644 --- a/src/main/java/nl/iobyte/themeparkconnector/sbd/License.java +++ b/src/main/java/nl/iobyte/themeparkconnector/sbd/License.java @@ -21,30 +21,22 @@ import java.util.Date; /** * License class for SBDevelopment * - * v1.6 - Changed on 06-08-2020 + * v1.8 - Changed on 24-01-2022 * * @author Stijn [SBDeveloper] * @since 23-12-2019 */ public class License implements Listener { - /* - This file is part of ThemeParkRidecountAddon. - Copyright (c) 2018-2020 SBDevelopment - All Rights Reserved - Unauthorized copying of this file, via any medium is strictly prohibited - Proprietary and confidential - Written by Stijn Bannink , January 2020 - */ - - private JavaPlugin plugin; // The plugin instance - private String license; // The license code - private String prefix; // The correct prefix for this plugin - private String invalidReason; // The reason the license is invalid, if null it's not invalid! - private static Boolean valid; // If true, it's valid, if false, it's not valid, if null it's not checked! + private final JavaPlugin plugin; // The plugin instance + private final String license; // The license code + private final String prefix; // The correct prefix for this plugin + private String invalidReason = null; // The reason the license is invalid, if null it's not invalid! + private static Boolean valid = null; // If true, it's valid, if false, it's not valid, if null it's not checked! /** * Construct a new license - * @param plugin The Main class [Javaplugin] - * @param prefix The prefix, like TPP or AF + * @param plugin The plugin + * @param prefix The wanted prefix, like TPP or AF * @param license The license from the config */ public License(JavaPlugin plugin, String prefix, String license) { @@ -63,7 +55,7 @@ public class License implements Listener { Player p = e.getPlayer(); if (p.isOp() || p.hasPermission("sbd.licensemessages")) { - Bukkit.getScheduler().runTaskLater(this.plugin, () -> p.sendMessage(ChatColor.GOLD + "[" + ChatColor.RED + this.plugin.getName() + ChatColor.GOLD + "] " + ChatColor.RED + "The license is incorrect! Reason: " + ChatColor.GOLD + this.invalidReason), 3 * 20L /* 3 sec */); + Bukkit.getScheduler().runTaskLater(this.plugin, () -> p.sendMessage(ChatColor.GOLD + "[" + ChatColor.RED + this.plugin.getName() + ChatColor.GOLD + "] " + ChatColor.RED + "The license is incorrect! Reason: " + ChatColor.GOLD + this.invalidReason), 5 * 20L /* 5 sec */); } } @@ -89,7 +81,7 @@ public class License implements Listener { } if (response == null) { - disable("Couldn't send the request."); + disable("Failed to request license information. Check if you entered a license in the plugin configuration."); return; } @@ -167,7 +159,6 @@ public class License implements Listener { private void activate() { //STEP 1: Send license activate request String url = "https://sbdplugins.nl/wp-json/lmfwc/v2/licenses/activate/" + this.license + "?port=" + Bukkit.getServer().getPort(); - JsonObject response; try { response = sendGETRequestJSON(url); @@ -177,7 +168,7 @@ public class License implements Listener { } if (response == null) { - disable("Couldn't send the activate request."); + disable("Failed to request license information. Check if you entered a license in the plugin configuration."); return; } @@ -235,9 +226,10 @@ public class License implements Listener { con.setRequestProperty("User-Agent", "Mozilla/5.0"); String authStringEnc = "Y2tfMGEzNWEzMWE2NzExNmM3NDg2MGEwYTJhNjUxNGVjZjM4NTBmM2JmMDpjc185NmYxZGNlYjI4MWRkZDExOTBjMzQ3ZjJjYzMwMGNjZTIzYWNhODI1"; con.setRequestProperty("Authorization", "Basic " + authStringEnc); + con.setConnectTimeout(5000); //Timeout after 5 sec. + con.setReadTimeout(5000); //Timeout after 5 sec. int code = con.getResponseCode(); if (code == 404) { - disable("404_error"); return null; } BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); @@ -248,8 +240,7 @@ public class License implements Listener { } in.close(); - JsonParser parser = new JsonParser(); - return parser.parse(response.toString()).getAsJsonObject(); + return new JsonParser().parse(response.toString()).getAsJsonObject(); //parseString is only available from 1.18, so keep deprecated function! } private boolean checkPortValue(int input, String dataValue) { @@ -293,10 +284,9 @@ public class License implements Listener { /** * Check if the license is valid * - * @return true -> VALID, false -> INVALID, null -> UNCHECKED + * @return true = VALID, false = INVALID, null = UNCHECKED */ - public static boolean isValid() { + public static Boolean isValid() { return valid; } - -} +} \ No newline at end of file