diff options
Diffstat (limited to 'src/main')
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<String> { 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; |