[FEATURE] Использование type вместо requesttype

This commit is contained in:
Gravit 2019-01-28 23:21:24 +07:00
parent 8726988291
commit dd4f97313e
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
10 changed files with 24 additions and 9 deletions

View file

@ -9,6 +9,8 @@
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import ru.gravit.launcher.hasher.HashedEntry; import ru.gravit.launcher.hasher.HashedEntry;
import ru.gravit.launcher.hasher.HashedEntryAdapter; 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.LaunchServer;
import ru.gravit.launchserver.socket.Client; import ru.gravit.launchserver.socket.Client;
import ru.gravit.launchserver.socket.websocket.json.EchoResponse; import ru.gravit.launchserver.socket.websocket.json.EchoResponse;
@ -33,6 +35,7 @@ public WebSocketService(ChannelGroup channels, LaunchServer server, GsonBuilder
this.server = server; this.server = server;
this.gsonBuiler = gson; this.gsonBuiler = gson;
this.gsonBuiler.registerTypeAdapter(JsonResponseInterface.class, new JsonResponseAdapter(this)); this.gsonBuiler.registerTypeAdapter(JsonResponseInterface.class, new JsonResponseAdapter(this));
this.gsonBuiler.registerTypeAdapter(ResultInterface.class,new JsonResultSerializeAdapter());
this.gsonBuiler.registerTypeAdapter(HashedEntry.class, new HashedEntryAdapter()); this.gsonBuiler.registerTypeAdapter(HashedEntry.class, new HashedEntryAdapter());
this.gson = gsonBuiler.create(); this.gson = gsonBuiler.create();
} }

View file

@ -9,7 +9,6 @@
public class BatchProfileByUsernameRequestEvent implements EventInterface, ResultInterface public class BatchProfileByUsernameRequestEvent implements EventInterface, ResultInterface
{ {
private static final UUID uuid = UUID.fromString("c1d6729e-be2c-48cc-b5ae-af8c012232c3"); private static final UUID uuid = UUID.fromString("c1d6729e-be2c-48cc-b5ae-af8c012232c3");
public String requesttype = "batchProfileByUsername";
public String error; public String error;
public PlayerProfile[] playerProfiles; public PlayerProfile[] playerProfiles;
@Override @Override

View file

@ -9,7 +9,6 @@
public class CheckServerEvent implements EventInterface, ResultInterface { public class CheckServerEvent implements EventInterface, ResultInterface {
private static final UUID _uuid = UUID.fromString("8801d07c-51ba-4059-b61d-fe1f1510b28a"); private static final UUID _uuid = UUID.fromString("8801d07c-51ba-4059-b61d-fe1f1510b28a");
public String type = "success"; public String type = "success";
public String requesttype = "checkServer";
public UUID uuid; public UUID uuid;
public PlayerProfile playerProfile; public PlayerProfile playerProfile;
@Override @Override

View file

@ -8,7 +8,6 @@
public class JoinServerRequestEvent implements EventInterface, ResultInterface { public class JoinServerRequestEvent implements EventInterface, ResultInterface {
private static final UUID uuid = UUID.fromString("2a12e7b5-3f4a-4891-a2f9-ea141c8e1995"); private static final UUID uuid = UUID.fromString("2a12e7b5-3f4a-4891-a2f9-ea141c8e1995");
public String type = "success"; public String type = "success";
public String requesttype = "joinServer";
public JoinServerRequestEvent(boolean allow) { public JoinServerRequestEvent(boolean allow) {
this.allow = allow; this.allow = allow;

View file

@ -8,7 +8,6 @@
public class LauncherRequestEvent implements EventInterface, ResultInterface { public class LauncherRequestEvent implements EventInterface, ResultInterface {
private static final UUID uuid = UUID.fromString("d54cc12a-4f59-4f23-9b10-f527fdd2e38f"); private static final UUID uuid = UUID.fromString("d54cc12a-4f59-4f23-9b10-f527fdd2e38f");
public String type = "success"; public String type = "success";
public String requesttype = "launcher";
public String url; public String url;
public LauncherRequestEvent(boolean needUpdate, String url) { public LauncherRequestEvent(boolean needUpdate, String url) {

View file

@ -9,7 +9,6 @@
public class ProfileByUUIDRequestEvent implements EventInterface, ResultInterface public class ProfileByUUIDRequestEvent implements EventInterface, ResultInterface
{ {
private static final UUID uuid = UUID.fromString("b9014cf3-4b95-4d38-8c5f-867f190a18a0"); private static final UUID uuid = UUID.fromString("b9014cf3-4b95-4d38-8c5f-867f190a18a0");
String requesttype = "profileByUUID";
String error; String error;
PlayerProfile playerProfile; PlayerProfile playerProfile;

View file

@ -9,7 +9,6 @@
public class ProfileByUsernameRequestEvent implements EventInterface, ResultInterface public class ProfileByUsernameRequestEvent implements EventInterface, ResultInterface
{ {
private static final UUID uuid = UUID.fromString("06204302-ff6b-4779-b97d-541e3bc39aa1"); private static final UUID uuid = UUID.fromString("06204302-ff6b-4779-b97d-541e3bc39aa1");
String requesttype = "profileByUsername";
String error; String error;
PlayerProfile playerProfile; PlayerProfile playerProfile;

View file

@ -16,7 +16,6 @@ public ProfilesRequestEvent(List<ClientProfile> profiles) {
this.profiles = profiles; this.profiles = profiles;
} }
String requesttype = "profiles";
String error; String error;
@Override @Override
public UUID getUUID() { public UUID getUUID() {

View file

@ -9,13 +9,11 @@
public class UpdateListRequestEvent implements EventInterface, ResultInterface { public class UpdateListRequestEvent implements EventInterface, ResultInterface {
private static final UUID uuid = UUID.fromString("5fa836ae-6b61-401c-96ac-d8396f07ec6b"); private static final UUID uuid = UUID.fromString("5fa836ae-6b61-401c-96ac-d8396f07ec6b");
public final String type; public final String type;
public final String requesttype;
public final HashedDir dir; public final HashedDir dir;
public UpdateListRequestEvent(HashedDir dir) { public UpdateListRequestEvent(HashedDir dir) {
this.dir = dir; this.dir = dir;
type = "success"; type = "success";
requesttype = "updateList";
} }
@Override @Override
public UUID getUUID() { public UUID getUUID() {

View file

@ -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<ResultInterface> {
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;
}
}