From c8e84aced2868da43bc30b8843166664e4b3ae33 Mon Sep 17 00:00:00 2001 From: Florian Rinke Date: Sat, 6 Nov 2021 02:43:41 +0100 Subject: Implement Ticket --- src/main/java/de/torui/coflsky/CoflSkyCommand.java | 19 +++++++++++++++++++ .../de/torui/coflsky/commands/JsonStringCommand.java | 4 +++- src/main/java/de/torui/coflsky/network/WSClient.java | 2 ++ .../de/torui/coflsky/network/WSClientWrapper.java | 2 +- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/torui/coflsky/CoflSkyCommand.java b/src/main/java/de/torui/coflsky/CoflSkyCommand.java index 20cfeba..411a943 100644 --- a/src/main/java/de/torui/coflsky/CoflSkyCommand.java +++ b/src/main/java/de/torui/coflsky/CoflSkyCommand.java @@ -2,6 +2,7 @@ package de.torui.coflsky; import java.io.IOException; import java.util.Arrays; +import java.util.Base64; import java.util.List; import de.torui.coflsky.commands.Command; @@ -89,6 +90,24 @@ public class CoflSkyCommand extends CommandBase { case "reset": HandleReset(); break; + case "connect": + + if(args.length == 2) { + String destination = args[1]; + + if(!destination.contains("://")) { + destination = new String(Base64.getDecoder().decode(destination)); + } + sender.addChatMessage(new ChatComponentText("Stopping connection!")); + CoflSky.Wrapper.stop(); + sender.addChatMessage(new ChatComponentText("Opening connection to " + destination)); + if(CoflSky.Wrapper.initializeNewSocket(destination)) { + sender.addChatMessage(new ChatComponentText("Success")); + } else { + sender.addChatMessage(new ChatComponentText("Could not open connection, please check the logs")); + } + } + break; default: CommandNotRecognized(args, sender); return; diff --git a/src/main/java/de/torui/coflsky/commands/JsonStringCommand.java b/src/main/java/de/torui/coflsky/commands/JsonStringCommand.java index 6bc22d8..a4ee15e 100644 --- a/src/main/java/de/torui/coflsky/commands/JsonStringCommand.java +++ b/src/main/java/de/torui/coflsky/commands/JsonStringCommand.java @@ -3,10 +3,12 @@ package de.torui.coflsky.commands; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; +import de.torui.coflsky.network.WSClient; + public class JsonStringCommand extends Command { public JsonStringCommand(String type, String data) { - this.setType(CommandType.valueOf(type)); + this.setType(WSClient.gson.fromJson(type, CommandType.class)); this.setData(data); } diff --git a/src/main/java/de/torui/coflsky/network/WSClient.java b/src/main/java/de/torui/coflsky/network/WSClient.java index cd23b30..b5a94a5 100644 --- a/src/main/java/de/torui/coflsky/network/WSClient.java +++ b/src/main/java/de/torui/coflsky/network/WSClient.java @@ -68,6 +68,8 @@ public class WSClient extends WebSocketAdapter { // by calling WebSocketFactory.setVerifyHostname(false). factory.setVerifyHostname(false); factory.*/ + factory.setVerifyHostname(false); + factory.setSSLContext(NaiveSSLContext.getInstance("TLSv1.2")); factory.setConnectionTimeout(10*1000); this.socket = factory.createSocket(uri); this.socket.addListener(this); diff --git a/src/main/java/de/torui/coflsky/network/WSClientWrapper.java b/src/main/java/de/torui/coflsky/network/WSClientWrapper.java index 044dd65..640d151 100644 --- a/src/main/java/de/torui/coflsky/network/WSClientWrapper.java +++ b/src/main/java/de/torui/coflsky/network/WSClientWrapper.java @@ -84,7 +84,7 @@ public class WSClientWrapper { - private boolean initializeNewSocket(String uriPrefix) { + public boolean initializeNewSocket(String uriPrefix) { String uri = uriPrefix; -- cgit From 3453fc835b8807637e04e28b529cd8a88ce1e098 Mon Sep 17 00:00:00 2001 From: Florian Rinke Date: Sat, 6 Nov 2021 03:05:57 +0100 Subject: minor fix for /cofl status --- src/main/java/de/torui/coflsky/CoflSkyCommand.java | 2 +- .../java/de/torui/coflsky/minecraft_integration/CoflSessionManager.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/torui/coflsky/CoflSkyCommand.java b/src/main/java/de/torui/coflsky/CoflSkyCommand.java index 411a943..e7ba17c 100644 --- a/src/main/java/de/torui/coflsky/CoflSkyCommand.java +++ b/src/main/java/de/torui/coflsky/CoflSkyCommand.java @@ -145,7 +145,7 @@ public class CoflSkyCommand extends CommandBase { try { CoflSession session = CoflSessionManager.GetCoflSession(PlayerDataProvider.getUsername()); - String sessionString = WSClient.gson.toJson(session); + String sessionString = CoflSessionManager.gson.toJson(session); status += " session=" + sessionString; } catch (IOException e) { } diff --git a/src/main/java/de/torui/coflsky/minecraft_integration/CoflSessionManager.java b/src/main/java/de/torui/coflsky/minecraft_integration/CoflSessionManager.java index 49f18f7..6f74bf4 100644 --- a/src/main/java/de/torui/coflsky/minecraft_integration/CoflSessionManager.java +++ b/src/main/java/de/torui/coflsky/minecraft_integration/CoflSessionManager.java @@ -29,7 +29,7 @@ import com.google.gson.stream.JsonWriter; import net.minecraftforge.fml.common.Loader; public class CoflSessionManager { - private static Gson gson = new GsonBuilder() .registerTypeAdapter(ZonedDateTime.class, new TypeAdapter() { + public static Gson gson = new GsonBuilder() .registerTypeAdapter(ZonedDateTime.class, new TypeAdapter() { @Override public void write(JsonWriter out, ZonedDateTime value) throws IOException { out.value(value.toString()); -- cgit