diff options
Diffstat (limited to 'src')
5 files changed, 27 insertions, 4 deletions
diff --git a/src/main/java/de/torui/coflsky/CoflSkyCommand.java b/src/main/java/de/torui/coflsky/CoflSkyCommand.java index 20cfeba..e7ba17c 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; @@ -126,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/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/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<ZonedDateTime>() { + public static Gson gson = new GsonBuilder() .registerTypeAdapter(ZonedDateTime.class, new TypeAdapter<ZonedDateTime>() { @Override public void write(JsonWriter out, ZonedDateTime value) throws IOException { out.value(value.toString()); 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; |