3
0
Fork 0

Fixed some shit

This commit is contained in:
thomas 2022-02-07 03:07:05 +01:00
parent 5ce32db5e2
commit f2147e34da
4 changed files with 29 additions and 36 deletions

View file

@ -57,7 +57,7 @@ public class NetworkingService {
* @param abstractPacket Received Packet * @param abstractPacket Received Packet
*/ */
public void triggerPacket(AbstractPacket abstractPacket) { 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()); ThemeParkConnectorLogger.toConsole("Unknown handler for packet channel " + abstractPacket.getChannel());
return; return;
} }

View file

@ -99,9 +99,6 @@ public class SocketConnector {
if (!ThemeParkConnector.getInstance().getAPI().getStateService().isConnected()) if (!ThemeParkConnector.getInstance().getAPI().getStateService().isConnected())
return; return;
if(!client.isConnected())
return;
String data = client.getUsedToken() + "@" + ThemeParkConnector.getGson().toJson(packet); String data = client.getUsedToken() + "@" + ThemeParkConnector.getGson().toJson(packet);
socket.emit("data", data); socket.emit("data", data);
} }

View file

@ -21,11 +21,18 @@ public class ClientConnectHandler extends PayloadHandler<ClientConnectPayload> {
* @param payload ClientConnectPayload * @param payload ClientConnectPayload
*/ */
public void onReceive(ClientConnectPayload payload) { public void onReceive(ClientConnectPayload payload) {
ClientConnection connection = ThemeParkConnector.getInstance().getAPI().getNetworkingService().getClient(payload.getUUID());
if(connection == null)
return;
ThemeParkConnectorAPI api = ThemeParkConnector.getInstance().getAPI(); 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())) { if(!api.getAuthenticationService().matchToken(payload.getUUID(), payload.getToken(), payload.getAttractionID())) {
denyRequest( denyRequest(
api, api,
@ -84,7 +91,6 @@ public class ClientConnectHandler extends PayloadHandler<ClientConnectPayload> {
) )
); );
connection.setUsedToken(payload.getToken());
connection.onConnect(); connection.onConnect();
for(INetworkingEvent event : ThemeParkConnector.getInstance().getAPI().getNetworkingService().getEvents()) for(INetworkingEvent event : ThemeParkConnector.getInstance().getAPI().getNetworkingService().getEvents())

View file

@ -21,30 +21,22 @@ import java.util.Date;
/** /**
* License class for SBDevelopment * License class for SBDevelopment
* *
* v1.6 - Changed on 06-08-2020 * v1.8 - Changed on 24-01-2022
* *
* @author Stijn [SBDeveloper] * @author Stijn [SBDeveloper]
* @since 23-12-2019 * @since 23-12-2019
*/ */
public class License implements Listener { public class License implements Listener {
/* private final JavaPlugin plugin; // The plugin instance
This file is part of ThemeParkRidecountAddon. private final String license; // The license code
Copyright (c) 2018-2020 SBDevelopment - All Rights Reserved private final String prefix; // The correct prefix for this plugin
Unauthorized copying of this file, via any medium is strictly prohibited private String invalidReason = null; // The reason the license is invalid, if null it's not invalid!
Proprietary and confidential private static Boolean valid = null; // If true, it's valid, if false, it's not valid, if null it's not checked!
Written by Stijn Bannink <stijnbannink23@gmail.com>, 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!
/** /**
* Construct a new license * Construct a new license
* @param plugin The Main class [Javaplugin] * @param plugin The plugin
* @param prefix The prefix, like TPP or AF * @param prefix The wanted prefix, like TPP or AF
* @param license The license from the config * @param license The license from the config
*/ */
public License(JavaPlugin plugin, String prefix, String license) { public License(JavaPlugin plugin, String prefix, String license) {
@ -63,7 +55,7 @@ public class License implements Listener {
Player p = e.getPlayer(); Player p = e.getPlayer();
if (p.isOp() || p.hasPermission("sbd.licensemessages")) { 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) { 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; return;
} }
@ -167,7 +159,6 @@ public class License implements Listener {
private void activate() { private void activate() {
//STEP 1: Send license activate request //STEP 1: Send license activate request
String url = "https://sbdplugins.nl/wp-json/lmfwc/v2/licenses/activate/" + this.license + "?port=" + Bukkit.getServer().getPort(); String url = "https://sbdplugins.nl/wp-json/lmfwc/v2/licenses/activate/" + this.license + "?port=" + Bukkit.getServer().getPort();
JsonObject response; JsonObject response;
try { try {
response = sendGETRequestJSON(url); response = sendGETRequestJSON(url);
@ -177,7 +168,7 @@ public class License implements Listener {
} }
if (response == null) { 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; return;
} }
@ -235,9 +226,10 @@ public class License implements Listener {
con.setRequestProperty("User-Agent", "Mozilla/5.0"); con.setRequestProperty("User-Agent", "Mozilla/5.0");
String authStringEnc = "Y2tfMGEzNWEzMWE2NzExNmM3NDg2MGEwYTJhNjUxNGVjZjM4NTBmM2JmMDpjc185NmYxZGNlYjI4MWRkZDExOTBjMzQ3ZjJjYzMwMGNjZTIzYWNhODI1"; String authStringEnc = "Y2tfMGEzNWEzMWE2NzExNmM3NDg2MGEwYTJhNjUxNGVjZjM4NTBmM2JmMDpjc185NmYxZGNlYjI4MWRkZDExOTBjMzQ3ZjJjYzMwMGNjZTIzYWNhODI1";
con.setRequestProperty("Authorization", "Basic " + authStringEnc); con.setRequestProperty("Authorization", "Basic " + authStringEnc);
con.setConnectTimeout(5000); //Timeout after 5 sec.
con.setReadTimeout(5000); //Timeout after 5 sec.
int code = con.getResponseCode(); int code = con.getResponseCode();
if (code == 404) { if (code == 404) {
disable("404_error");
return null; return null;
} }
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
@ -248,8 +240,7 @@ public class License implements Listener {
} }
in.close(); in.close();
JsonParser parser = new JsonParser(); return new JsonParser().parse(response.toString()).getAsJsonObject(); //parseString is only available from 1.18, so keep deprecated function!
return parser.parse(response.toString()).getAsJsonObject();
} }
private boolean checkPortValue(int input, String dataValue) { private boolean checkPortValue(int input, String dataValue) {
@ -293,10 +284,9 @@ public class License implements Listener {
/** /**
* Check if the license is valid * 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; return valid;
} }
} }