diff options
author | Äkwav <16632490+Ekwav@users.noreply.github.com> | 2021-11-06 05:24:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-06 05:24:38 +0100 |
commit | 9cd8209e52a257c06eccb570eca6b5f67448b2af (patch) | |
tree | 229d71ae0acf7eed5c5602c406f2003f2ade5f78 | |
parent | e7ad35aec14bc4804762843948973fc4af687c04 (diff) | |
parent | 3453fc835b8807637e04e28b529cd8a88ce1e098 (diff) | |
download | COFL-9cd8209e52a257c06eccb570eca6b5f67448b2af.tar.gz COFL-9cd8209e52a257c06eccb570eca6b5f67448b2af.tar.bz2 COFL-9cd8209e52a257c06eccb570eca6b5f67448b2af.zip |
Merge pull request #37 from Coflnet/feature/connect-command
Implement connect command
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; |