diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketService.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketService.java index 5d3fba8e..42fae12e 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketService.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketService.java @@ -9,6 +9,8 @@ import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import ru.gravit.launcher.hasher.HashedEntry; import ru.gravit.launcher.hasher.HashedEntryAdapter; +import ru.gravit.launcher.request.JsonResultSerializeAdapter; +import ru.gravit.launcher.request.ResultInterface; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.socket.Client; import ru.gravit.launchserver.socket.websocket.json.EchoResponse; @@ -33,6 +35,7 @@ public WebSocketService(ChannelGroup channels, LaunchServer server, GsonBuilder this.server = server; this.gsonBuiler = gson; this.gsonBuiler.registerTypeAdapter(JsonResponseInterface.class, new JsonResponseAdapter(this)); + this.gsonBuiler.registerTypeAdapter(ResultInterface.class,new JsonResultSerializeAdapter()); this.gsonBuiler.registerTypeAdapter(HashedEntry.class, new HashedEntryAdapter()); this.gson = gsonBuiler.create(); } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/events/request/BatchProfileByUsernameRequestEvent.java b/libLauncher/src/main/java/ru/gravit/launcher/events/request/BatchProfileByUsernameRequestEvent.java index f048fb56..18806ac1 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/events/request/BatchProfileByUsernameRequestEvent.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/events/request/BatchProfileByUsernameRequestEvent.java @@ -9,7 +9,6 @@ public class BatchProfileByUsernameRequestEvent implements EventInterface, ResultInterface { private static final UUID uuid = UUID.fromString("c1d6729e-be2c-48cc-b5ae-af8c012232c3"); - public String requesttype = "batchProfileByUsername"; public String error; public PlayerProfile[] playerProfiles; @Override diff --git a/libLauncher/src/main/java/ru/gravit/launcher/events/request/CheckServerEvent.java b/libLauncher/src/main/java/ru/gravit/launcher/events/request/CheckServerEvent.java index 227bde2b..497a9893 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/events/request/CheckServerEvent.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/events/request/CheckServerEvent.java @@ -9,7 +9,6 @@ public class CheckServerEvent implements EventInterface, ResultInterface { private static final UUID _uuid = UUID.fromString("8801d07c-51ba-4059-b61d-fe1f1510b28a"); public String type = "success"; - public String requesttype = "checkServer"; public UUID uuid; public PlayerProfile playerProfile; @Override diff --git a/libLauncher/src/main/java/ru/gravit/launcher/events/request/JoinServerRequestEvent.java b/libLauncher/src/main/java/ru/gravit/launcher/events/request/JoinServerRequestEvent.java index 5bc25436..3a76863c 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/events/request/JoinServerRequestEvent.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/events/request/JoinServerRequestEvent.java @@ -8,7 +8,6 @@ public class JoinServerRequestEvent implements EventInterface, ResultInterface { private static final UUID uuid = UUID.fromString("2a12e7b5-3f4a-4891-a2f9-ea141c8e1995"); public String type = "success"; - public String requesttype = "joinServer"; public JoinServerRequestEvent(boolean allow) { this.allow = allow; diff --git a/libLauncher/src/main/java/ru/gravit/launcher/events/request/LauncherRequestEvent.java b/libLauncher/src/main/java/ru/gravit/launcher/events/request/LauncherRequestEvent.java index 25660de4..55f37ed2 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/events/request/LauncherRequestEvent.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/events/request/LauncherRequestEvent.java @@ -8,7 +8,6 @@ public class LauncherRequestEvent implements EventInterface, ResultInterface { private static final UUID uuid = UUID.fromString("d54cc12a-4f59-4f23-9b10-f527fdd2e38f"); public String type = "success"; - public String requesttype = "launcher"; public String url; public LauncherRequestEvent(boolean needUpdate, String url) { diff --git a/libLauncher/src/main/java/ru/gravit/launcher/events/request/ProfileByUUIDRequestEvent.java b/libLauncher/src/main/java/ru/gravit/launcher/events/request/ProfileByUUIDRequestEvent.java index 537b7e62..27c73810 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/events/request/ProfileByUUIDRequestEvent.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/events/request/ProfileByUUIDRequestEvent.java @@ -9,7 +9,6 @@ public class ProfileByUUIDRequestEvent implements EventInterface, ResultInterface { private static final UUID uuid = UUID.fromString("b9014cf3-4b95-4d38-8c5f-867f190a18a0"); - String requesttype = "profileByUUID"; String error; PlayerProfile playerProfile; diff --git a/libLauncher/src/main/java/ru/gravit/launcher/events/request/ProfileByUsernameRequestEvent.java b/libLauncher/src/main/java/ru/gravit/launcher/events/request/ProfileByUsernameRequestEvent.java index a62c2805..b85829f1 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/events/request/ProfileByUsernameRequestEvent.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/events/request/ProfileByUsernameRequestEvent.java @@ -9,7 +9,6 @@ public class ProfileByUsernameRequestEvent implements EventInterface, ResultInterface { private static final UUID uuid = UUID.fromString("06204302-ff6b-4779-b97d-541e3bc39aa1"); - String requesttype = "profileByUsername"; String error; PlayerProfile playerProfile; diff --git a/libLauncher/src/main/java/ru/gravit/launcher/events/request/ProfilesRequestEvent.java b/libLauncher/src/main/java/ru/gravit/launcher/events/request/ProfilesRequestEvent.java index 8a53513c..3b788f17 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/events/request/ProfilesRequestEvent.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/events/request/ProfilesRequestEvent.java @@ -16,7 +16,6 @@ public ProfilesRequestEvent(List profiles) { this.profiles = profiles; } - String requesttype = "profiles"; String error; @Override public UUID getUUID() { diff --git a/libLauncher/src/main/java/ru/gravit/launcher/events/request/UpdateListRequestEvent.java b/libLauncher/src/main/java/ru/gravit/launcher/events/request/UpdateListRequestEvent.java index abd8f254..73136430 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/events/request/UpdateListRequestEvent.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/events/request/UpdateListRequestEvent.java @@ -9,13 +9,11 @@ public class UpdateListRequestEvent implements EventInterface, ResultInterface { private static final UUID uuid = UUID.fromString("5fa836ae-6b61-401c-96ac-d8396f07ec6b"); public final String type; - public final String requesttype; public final HashedDir dir; public UpdateListRequestEvent(HashedDir dir) { this.dir = dir; type = "success"; - requesttype = "updateList"; } @Override public UUID getUUID() { diff --git a/libLauncher/src/main/java/ru/gravit/launcher/request/JsonResultSerializeAdapter.java b/libLauncher/src/main/java/ru/gravit/launcher/request/JsonResultSerializeAdapter.java new file mode 100644 index 00000000..7e73ba70 --- /dev/null +++ b/libLauncher/src/main/java/ru/gravit/launcher/request/JsonResultSerializeAdapter.java @@ -0,0 +1,21 @@ +package ru.gravit.launcher.request; + +import com.google.gson.*; +import ru.gravit.launcher.request.ResultInterface; + +import java.lang.reflect.Type; + +public class JsonResultSerializeAdapter implements JsonSerializer { + private static final String PROP_NAME = "type"; + + @Override + public JsonElement serialize(ResultInterface src, Type typeOfSrc, JsonSerializationContext context) { + // note : won't work, you must delegate this + JsonObject jo = context.serialize(src).getAsJsonObject(); + + String classPath = src.getType(); + jo.add(PROP_NAME, new JsonPrimitive(classPath)); + + return jo; + } +}