diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/HWIDHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/HWIDHandler.java index 77ba174b..9fc786cf 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/HWIDHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/hwid/HWIDHandler.java @@ -63,7 +63,7 @@ public void invoke(String... args) throws Exception { public abstract void ban(List hwid) throws HWIDException; public void check(HWID hwid, String username) throws HWIDException { - if (hwid.isNull()) return; + if (hwid == null || hwid.isNull()) return; check0(hwid, username); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java index 0eb2ff09..3c060a60 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java @@ -66,6 +66,11 @@ public WebSocketService(ChannelGroup channels, LaunchServer server) { public void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client client, String ip) { String request = frame.text(); WebSocketServerResponse response = gson.fromJson(request, WebSocketServerResponse.class); + if(response == null) + { + RequestEvent event= new ErrorRequestEvent("This type of request is not supported"); + sendObject(ctx, event); + } process(ctx, response, client, ip); } diff --git a/LauncherCore/src/main/java/pro/gravit/utils/UniversalJsonAdapter.java b/LauncherCore/src/main/java/pro/gravit/utils/UniversalJsonAdapter.java index 221df950..209354cb 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/UniversalJsonAdapter.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/UniversalJsonAdapter.java @@ -15,24 +15,41 @@ public class UniversalJsonAdapter implements JsonSerializer, JsonDeseriali public final ProviderMap providerMap; public final String name; public final String PROP_NAME; + public final boolean printErrorIfUnknownType; public UniversalJsonAdapter(ProviderMap providerMap) { this.providerMap = providerMap; this.name = providerMap.getName(); this.PROP_NAME = "type"; + printErrorIfUnknownType = true; } public UniversalJsonAdapter(ProviderMap providerMap, String PROP_NAME) { this.providerMap = providerMap; this.name = providerMap.getName(); this.PROP_NAME = PROP_NAME; + printErrorIfUnknownType = true; + } + + public UniversalJsonAdapter(ProviderMap providerMap, String name, String PROP_NAME, boolean printErrorIfUnknownType) { + this.providerMap = providerMap; + this.name = name; + this.PROP_NAME = PROP_NAME; + this.printErrorIfUnknownType = printErrorIfUnknownType; + } + + public UniversalJsonAdapter(ProviderMap providerMap, String name, boolean printErrorIfUnknownType) { + this.providerMap = providerMap; + this.name = name; + this.PROP_NAME = "type"; + this.printErrorIfUnknownType = printErrorIfUnknownType; } public R deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); Class cls = providerMap.getClass(typename); if (cls == null) { - LogHelper.error("%s %s not found", name, typename); + if(printErrorIfUnknownType) LogHelper.error("%s %s not found", name, typename); return null; } return context.deserialize(json, cls); @@ -48,9 +65,9 @@ public JsonElement serialize(R src, Type typeOfSrc, JsonSerializationContext con } if(classPath == null) { - LogHelper.warning("Class %s type null", src.getClass()); + if(printErrorIfUnknownType) LogHelper.warning("Class %s type null", src.getClass()); } - jo.add(PROP_NAME, new JsonPrimitive(classPath)); + else jo.add(PROP_NAME, new JsonPrimitive(classPath)); return jo; }