diff options
author | Florian Rinke <develop@torui.de> | 2021-10-11 17:52:17 +0200 |
---|---|---|
committer | Florian Rinke <develop@torui.de> | 2021-10-11 17:52:17 +0200 |
commit | 16b9821f55eec8f4a77ee1743cbc3f9b4ba3e303 (patch) | |
tree | c7ede24fb2a7c0871c92c66fe4b4f7806344d326 /src/main/java/de/torui/coflsky/websocket/WSClient.java | |
parent | 9e923dbdf82b2a1fbebcb9c4559400f921104229 (diff) | |
download | COFL-16b9821f55eec8f4a77ee1743cbc3f9b4ba3e303.tar.gz COFL-16b9821f55eec8f4a77ee1743cbc3f9b4ba3e303.tar.bz2 COFL-16b9821f55eec8f4a77ee1743cbc3f9b4ba3e303.zip |
implements #11, #8
Diffstat (limited to 'src/main/java/de/torui/coflsky/websocket/WSClient.java')
-rw-r--r-- | src/main/java/de/torui/coflsky/websocket/WSClient.java | 68 |
1 files changed, 9 insertions, 59 deletions
diff --git a/src/main/java/de/torui/coflsky/websocket/WSClient.java b/src/main/java/de/torui/coflsky/websocket/WSClient.java index c4ad799..3cb2de2 100644 --- a/src/main/java/de/torui/coflsky/websocket/WSClient.java +++ b/src/main/java/de/torui/coflsky/websocket/WSClient.java @@ -14,7 +14,7 @@ import com.neovisionaries.ws.client.WebSocketException; import com.neovisionaries.ws.client.WebSocketFactory; import com.neovisionaries.ws.client.WebSocketState; import net.minecraft.client.Minecraft; - +import de.torui.coflsky.CoflSky; import de.torui.coflsky.WSCommandHandler; import de.torui.coflsky.core.Command; import de.torui.coflsky.core.StringCommand; @@ -38,10 +38,12 @@ public class WSClient extends WebSocketAdapter { } public URI uri; public WebSocket socket; + public boolean shouldRun = false; public WebSocketState currentState = WebSocketState.CLOSED; public WSClient(URI uri) { this.uri = uri; + } public void start() throws IOException, WebSocketException, NoSuchAlgorithmException { @@ -95,6 +97,11 @@ public class WSClient extends WebSocketAdapter { public void onStateChanged(WebSocket websocket, WebSocketState newState) throws Exception { System.out.println("WebSocket Changed state to: " + newState); currentState = newState; + + if(newState == WebSocketState.CLOSED && shouldRun) { + CoflSky.Wrapper.restartWebsocketConnection(); + } + super.onStateChanged(websocket, newState); } @@ -124,61 +131,4 @@ public class WSClient extends WebSocketAdapter { -} - -/* -public class WSClient extends WebSocketClient{ - - public static Gson gson; - - public static WSClient Instancce; - - - static { - gson = new GsonBuilder()/*.setFieldNamingStrategy(new FieldNamingStrategy() { - @Override - public String translateName(Field f) { - - String name = f.getName(); - char firstChar = name.charAt(0); - return Character.toLowerCase(firstChar) + name.substring(1); - } - })*.create(); - } - - public WSClient(URI serverUri) { - super(serverUri); - - } - - @Override - public void onOpen(ServerHandshake handshakedata) { - - } - - @Override - public void onMessage(String message) { - //System.out.println(message); - - Command cmd = gson.fromJson(message, Command.class); - //System.out.println(cmd); - WSCommandHandler.HandleCommand(cmd, Minecraft.getMinecraft().thePlayer); - } - - @Override - public void onClose(int code, String reason, boolean remote) { - System.out.printf("code: %n reason:%s remote:%b", code, reason,remote); - } - - @Override - public void onError(Exception ex) { - ex.printStackTrace(); - } - - public void SendCommand(Command command) { - String json = gson.toJson(command); - this.send(json); - } - -} -*/ +}
\ No newline at end of file |