mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
[FIX] 2 NPE
This commit is contained in:
parent
6af348606b
commit
a8b96a2adf
3 changed files with 26 additions and 4 deletions
|
@ -63,7 +63,7 @@ public void invoke(String... args) throws Exception {
|
|||
public abstract void ban(List<HWID> 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,24 +15,41 @@ public class UniversalJsonAdapter<R> implements JsonSerializer<R>, JsonDeseriali
|
|||
public final ProviderMap<R> providerMap;
|
||||
public final String name;
|
||||
public final String PROP_NAME;
|
||||
public final boolean printErrorIfUnknownType;
|
||||
|
||||
public UniversalJsonAdapter(ProviderMap<R> providerMap) {
|
||||
this.providerMap = providerMap;
|
||||
this.name = providerMap.getName();
|
||||
this.PROP_NAME = "type";
|
||||
printErrorIfUnknownType = true;
|
||||
}
|
||||
|
||||
public UniversalJsonAdapter(ProviderMap<R> providerMap, String PROP_NAME) {
|
||||
this.providerMap = providerMap;
|
||||
this.name = providerMap.getName();
|
||||
this.PROP_NAME = PROP_NAME;
|
||||
printErrorIfUnknownType = true;
|
||||
}
|
||||
|
||||
public UniversalJsonAdapter(ProviderMap<R> 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<R> 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<? extends R> 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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue