diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketFrameHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketFrameHandler.java index f62f8191..8f83b39d 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketFrameHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketFrameHandler.java @@ -2,8 +2,6 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufInputStream; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.group.ChannelGroup; @@ -12,14 +10,11 @@ import io.netty.handler.codec.http.websocketx.WebSocketFrame; import io.netty.util.concurrent.GlobalEventExecutor; import ru.gravit.launchserver.LaunchServer; -import ru.gravit.launchserver.socket.websocket.json.JsonResponse; +import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface; import ru.gravit.launchserver.socket.websocket.json.JsonResponseAdapter; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; -import java.io.InputStreamReader; -import java.io.Reader; - public class WebSocketFrameHandler extends SimpleChannelInboundHandler { public static final ChannelGroup channels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE); public static Gson gson; @@ -28,7 +23,7 @@ public class WebSocketFrameHandler extends SimpleChannelInboundHandler, JsonDeserializer { +public class JsonResponseAdapter implements JsonSerializer, JsonDeserializer { static HashMap map = new HashMap<>(); private static final String PROP_NAME = "type"; static { map.put("echo",EchoResponse.class); } @Override - public JsonResponse deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + public JsonResponseInterface deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); Class cls = map.get(typename); - return (JsonResponse) context.deserialize(json, cls); + return (JsonResponseInterface) context.deserialize(json, cls); } @Override - public JsonElement serialize(JsonResponse src, Type typeOfSrc, JsonSerializationContext context) { + public JsonElement serialize(JsonResponseInterface src, Type typeOfSrc, JsonSerializationContext context) { // note : won't work, you must delegate this JsonObject jo = context.serialize(src).getAsJsonObject(); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/JsonResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/JsonResponseInterface.java similarity index 89% rename from LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/JsonResponse.java rename to LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/JsonResponseInterface.java index ab7dc308..37c0ad95 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/JsonResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/JsonResponseInterface.java @@ -4,7 +4,7 @@ import io.netty.handler.codec.http.websocketx.WebSocketFrame; import ru.gravit.launchserver.socket.websocket.WebSocketService; -public interface JsonResponse { +public interface JsonResponseInterface { String getType(); void execute(WebSocketService service,ChannelHandlerContext ctx) throws Exception; } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/SimpleResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/SimpleResponse.java new file mode 100644 index 00000000..db90577d --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/SimpleResponse.java @@ -0,0 +1,16 @@ +package ru.gravit.launchserver.socket.websocket.json; + +import io.netty.channel.ChannelHandlerContext; +import ru.gravit.launchserver.socket.websocket.WebSocketService; + +public class SimpleResponse implements JsonResponseInterface { + @Override + public String getType() { + return null; + } + + @Override + public void execute(WebSocketService service, ChannelHandlerContext ctx) throws Exception { + + } +} diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java index edd7ec1b..b3a49d97 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java @@ -1,8 +1,6 @@ package ru.gravit.launchserver.socket.websocket.json.auth; import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; -import io.netty.handler.codec.http.websocketx.WebSocketFrame; import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.serialize.signed.SignedObjectHolder; import ru.gravit.launchserver.LaunchServer; @@ -11,15 +9,14 @@ import ru.gravit.launchserver.auth.hwid.HWIDException; import ru.gravit.launchserver.auth.provider.AuthProvider; import ru.gravit.launchserver.auth.provider.AuthProviderResult; -import ru.gravit.launchserver.socket.websocket.WebSocketFrameHandler; import ru.gravit.launchserver.socket.websocket.WebSocketService; -import ru.gravit.launchserver.socket.websocket.json.JsonResponse; +import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.VerifyHelper; import java.util.Collection; -public class AuthResponse implements JsonResponse { +public class AuthResponse implements JsonResponseInterface { public String login; public String client; private LaunchServer server = LaunchServer.server;