diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java index 3769e19b..e6caf5ae 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java @@ -6,7 +6,7 @@ import pro.gravit.launcher.hasher.HashedEntryAdapter; import pro.gravit.launcher.managers.GsonManager; import pro.gravit.launcher.request.JsonResultSerializeAdapter; -import pro.gravit.launcher.request.ResultInterface; +import pro.gravit.launcher.request.WebSocketEvent; import pro.gravit.launchserver.auth.handler.AuthHandler; import pro.gravit.launchserver.auth.hwid.HWIDHandler; import pro.gravit.launchserver.auth.permissions.PermissionsHandler; @@ -16,7 +16,7 @@ import pro.gravit.launchserver.components.Component; import pro.gravit.launchserver.dao.provider.DaoProvider; import pro.gravit.launchserver.socket.WebSocketService; -import pro.gravit.launchserver.socket.response.JsonResponseInterface; +import pro.gravit.launchserver.socket.response.WebSocketServerResponse; import pro.gravit.utils.UniversalJsonAdapter; public class LaunchServerGsonManager extends GsonManager { @@ -31,8 +31,8 @@ public void registerAdapters(GsonBuilder builder) { builder.registerTypeAdapter(Component.class, new UniversalJsonAdapter<>(Component.providers)); builder.registerTypeAdapter(ProtectHandler.class, new UniversalJsonAdapter<>(ProtectHandler.providers)); builder.registerTypeAdapter(DaoProvider.class, new UniversalJsonAdapter<>(DaoProvider.providers)); - builder.registerTypeAdapter(JsonResponseInterface.class, new UniversalJsonAdapter<>(WebSocketService.providers)); + builder.registerTypeAdapter(WebSocketServerResponse.class, new UniversalJsonAdapter<>(WebSocketService.providers)); builder.registerTypeAdapter(HashedEntry.class, new HashedEntryAdapter()); - builder.registerTypeAdapter(ResultInterface.class, new JsonResultSerializeAdapter()); + builder.registerTypeAdapter(WebSocketEvent.class, new JsonResultSerializeAdapter()); } } 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 41d1dc7b..beac50fd 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java @@ -6,7 +6,6 @@ import java.util.UUID; import com.google.gson.Gson; -import com.google.gson.GsonBuilder; import io.netty.channel.Channel; import io.netty.channel.ChannelFutureListener; @@ -20,10 +19,10 @@ import pro.gravit.launcher.events.request.ErrorRequestEvent; import pro.gravit.launcher.request.Request; import pro.gravit.launcher.request.RequestException; -import pro.gravit.launcher.request.ResultInterface; +import pro.gravit.launcher.request.WebSocketEvent; import pro.gravit.launcher.request.admin.ProxyRequest; import pro.gravit.launchserver.LaunchServer; -import pro.gravit.launchserver.socket.response.JsonResponseInterface; +import pro.gravit.launchserver.socket.response.WebSocketServerResponse; import pro.gravit.launchserver.socket.response.SimpleResponse; import pro.gravit.launchserver.socket.response.admin.AddLogListenerResponse; import pro.gravit.launchserver.socket.response.admin.ExecCommandResponse; @@ -44,13 +43,13 @@ @SuppressWarnings("rawtypes") public class WebSocketService { public final ChannelGroup channels; - public static ProviderMap providers = new ProviderMap<>(); + public static ProviderMap providers = new ProviderMap<>(); public WebSocketService(ChannelGroup channels, LaunchServer server) { this.channels = channels; this.server = server; - //this.gsonBuiler.registerTypeAdapter(JsonResponseInterface.class, new JsonResponseAdapter(this)); - //this.gsonBuiler.registerTypeAdapter(ResultInterface.class, new JsonResultSerializeAdapter()); + //this.gsonBuiler.registerTypeAdapter(WebSocketServerResponse.class, new JsonResponseAdapter(this)); + //this.gsonBuiler.registerTypeAdapter(WebSocketEvent.class, new JsonResultSerializeAdapter()); //this.gsonBuiler.registerTypeAdapter(HashedEntry.class, new HashedEntryAdapter()); this.gson = Launcher.gsonManager.gson; } @@ -61,7 +60,7 @@ public WebSocketService(ChannelGroup channels, LaunchServer server) { public void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client client, String ip) { String request = frame.text(); - JsonResponseInterface response = gson.fromJson(request, JsonResponseInterface.class); + WebSocketServerResponse response = gson.fromJson(request, WebSocketServerResponse.class); if (server.config.netty.proxy.enabled) { if (server.config.netty.proxy.requests.contains(response.getType())) { @@ -83,7 +82,7 @@ public void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client } proxyRequest.isCheckSign = client.checkSign; try { - ResultInterface result = proxyRequest.request(); + WebSocketEvent result = proxyRequest.request(); if (result instanceof AuthRequestEvent) { LogHelper.debug("Client auth params get successful"); AuthRequestEvent authRequestEvent = (AuthRequestEvent) result; @@ -117,7 +116,7 @@ public void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client process(ctx, response, client, ip); } - void process(ChannelHandlerContext ctx, JsonResponseInterface response, Client client, String ip) { + void process(ChannelHandlerContext ctx, WebSocketServerResponse response, Client client, String ip) { if (response instanceof SimpleResponse) { SimpleResponse simpleResponse = (SimpleResponse) response; simpleResponse.server = server; @@ -174,7 +173,7 @@ public static void registerResponses() { } public void sendObject(ChannelHandlerContext ctx, Object obj) { - ctx.channel().writeAndFlush(new TextWebSocketFrame(gson.toJson(obj, ResultInterface.class))); + ctx.channel().writeAndFlush(new TextWebSocketFrame(gson.toJson(obj, WebSocketEvent.class))); } public void sendObject(ChannelHandlerContext ctx, Object obj, Type type) { @@ -183,7 +182,7 @@ public void sendObject(ChannelHandlerContext ctx, Object obj, Type type) { public void sendObjectAll(Object obj) { for (Channel ch : channels) { - ch.writeAndFlush(new TextWebSocketFrame(gson.toJson(obj, ResultInterface.class))); + ch.writeAndFlush(new TextWebSocketFrame(gson.toJson(obj, WebSocketEvent.class))); } } @@ -194,7 +193,7 @@ public void sendObjectAll(Object obj, Type type) { } public void sendObjectAndClose(ChannelHandlerContext ctx, Object obj) { - ctx.channel().writeAndFlush(new TextWebSocketFrame(gson.toJson(obj, ResultInterface.class))).addListener(ChannelFutureListener.CLOSE); + ctx.channel().writeAndFlush(new TextWebSocketFrame(gson.toJson(obj, WebSocketEvent.class))).addListener(ChannelFutureListener.CLOSE); } public void sendObjectAndClose(ChannelHandlerContext ctx, Object obj, Type type) { @@ -205,7 +204,7 @@ public void sendEvent(EventResult obj) { channels.writeAndFlush(new TextWebSocketFrame(gson.toJson(obj))); } - public static class EventResult implements ResultInterface { + public static class EventResult implements WebSocketEvent { public EventResult() { } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/SimpleResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/SimpleResponse.java index 783daaaf..34998f7a 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/SimpleResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/SimpleResponse.java @@ -6,10 +6,9 @@ import pro.gravit.launcher.events.RequestEvent; import pro.gravit.launcher.events.request.ErrorRequestEvent; import pro.gravit.launchserver.LaunchServer; -import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.WebSocketService; -public abstract class SimpleResponse implements JsonResponseInterface { +public abstract class SimpleResponse implements WebSocketServerResponse { public UUID requestUUID; public transient LaunchServer server; public transient WebSocketService service; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/JsonResponseInterface.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/WebSocketServerResponse.java similarity index 65% rename from LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/JsonResponseInterface.java rename to LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/WebSocketServerResponse.java index 1e44ba4e..d4a769d8 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/JsonResponseInterface.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/WebSocketServerResponse.java @@ -1,10 +1,10 @@ package pro.gravit.launchserver.socket.response; import io.netty.channel.ChannelHandlerContext; -import pro.gravit.launcher.request.websockets.RequestInterface; +import pro.gravit.launcher.request.websockets.WebSocketRequest; import pro.gravit.launchserver.socket.Client; -public interface JsonResponseInterface extends RequestInterface { +public interface WebSocketServerResponse extends WebSocketRequest { String getType(); void execute(ChannelHandlerContext ctx, Client client) throws Exception; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/admin/ProxyCommandResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/admin/ProxyCommandResponse.java index 356fd471..16e53c88 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/admin/ProxyCommandResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/admin/ProxyCommandResponse.java @@ -2,11 +2,11 @@ import io.netty.channel.ChannelHandlerContext; import pro.gravit.launchserver.socket.Client; -import pro.gravit.launchserver.socket.response.JsonResponseInterface; +import pro.gravit.launchserver.socket.response.WebSocketServerResponse; import pro.gravit.launchserver.socket.response.SimpleResponse; public class ProxyCommandResponse extends SimpleResponse { - public JsonResponseInterface response; + public WebSocketServerResponse response; public long session; public boolean isCheckSign; diff --git a/LaunchServerConsole/src/main/java/pro/gravit/launchserver/console/LogListenerCommand.java b/LaunchServerConsole/src/main/java/pro/gravit/launchserver/console/LogListenerCommand.java index dab6a1d7..4de6d4ee 100644 --- a/LaunchServerConsole/src/main/java/pro/gravit/launchserver/console/LogListenerCommand.java +++ b/LaunchServerConsole/src/main/java/pro/gravit/launchserver/console/LogListenerCommand.java @@ -3,12 +3,12 @@ import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.request.LogEvent; import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.websockets.RequestInterface; +import pro.gravit.launcher.request.websockets.WebSocketRequest; import pro.gravit.utils.command.Command; import pro.gravit.utils.helper.LogHelper; public class LogListenerCommand extends Command { - public class LogListenerRequest implements RequestInterface { + public class LogListenerRequest implements WebSocketRequest { @LauncherNetworkAPI public LogHelper.OutputTypes outputType; diff --git a/Launcher/src/main/java/pro/gravit/launcher/console/admin/LogListenerCommand.java b/Launcher/src/main/java/pro/gravit/launcher/console/admin/LogListenerCommand.java index 04bf5f4e..8610fa07 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/console/admin/LogListenerCommand.java +++ b/Launcher/src/main/java/pro/gravit/launcher/console/admin/LogListenerCommand.java @@ -3,12 +3,12 @@ import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.request.LogEvent; import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.websockets.RequestInterface; +import pro.gravit.launcher.request.websockets.WebSocketRequest; import pro.gravit.utils.command.Command; import pro.gravit.utils.helper.LogHelper; public class LogListenerCommand extends Command { - public class LogListenerRequest implements RequestInterface { + public class LogListenerRequest implements WebSocketRequest { @LauncherNetworkAPI public LogHelper.OutputTypes outputType; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/RequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/RequestEvent.java index 6ac8df92..a8ea23e5 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/RequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/RequestEvent.java @@ -2,8 +2,8 @@ import java.util.UUID; -import pro.gravit.launcher.request.ResultInterface; +import pro.gravit.launcher.request.WebSocketEvent; -public abstract class RequestEvent implements ResultInterface { +public abstract class RequestEvent implements WebSocketEvent { public UUID requestUUID; } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/LogEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/LogEvent.java index 065e31f2..db2f6f35 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/LogEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/LogEvent.java @@ -1,9 +1,9 @@ package pro.gravit.launcher.events.request; import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.request.ResultInterface; +import pro.gravit.launcher.request.WebSocketEvent; -public class LogEvent implements ResultInterface { +public class LogEvent implements WebSocketEvent { @Override public String getType() { return "log"; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/JsonResultSerializeAdapter.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/JsonResultSerializeAdapter.java index 073d5361..5ca49743 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/JsonResultSerializeAdapter.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/JsonResultSerializeAdapter.java @@ -8,11 +8,11 @@ import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; -public class JsonResultSerializeAdapter implements JsonSerializer { +public class JsonResultSerializeAdapter implements JsonSerializer { private static final String PROP_NAME = "type"; @Override - public JsonElement serialize(ResultInterface src, Type typeOfSrc, JsonSerializationContext context) { + public JsonElement serialize(WebSocketEvent src, Type typeOfSrc, JsonSerializationContext context) { // note : won't work, you must delegate this JsonObject jo = context.serialize(src).getAsJsonObject(); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/PingRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/PingRequest.java index a84a0bfc..cabe6414 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/PingRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/PingRequest.java @@ -2,10 +2,10 @@ import pro.gravit.launcher.request.websockets.StandartClientWebSocketService; -public final class PingRequest extends Request { +public final class PingRequest extends Request { @Override - protected ResultInterface requestDo(StandartClientWebSocketService service) throws Exception { + protected WebSocketEvent requestDo(StandartClientWebSocketService service) throws Exception { return null; } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java index b649ffeb..856ed513 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java @@ -6,11 +6,11 @@ import pro.gravit.launcher.Launcher; import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.request.websockets.RequestInterface; +import pro.gravit.launcher.request.websockets.WebSocketRequest; import pro.gravit.launcher.request.websockets.StandartClientWebSocketService; import pro.gravit.utils.helper.SecurityHelper; -public abstract class Request implements RequestInterface { +public abstract class Request implements WebSocketRequest { private static long session = SecurityHelper.secureRandom.nextLong(); @LauncherNetworkAPI public UUID requestUUID = UUID.randomUUID(); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/ResultInterface.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/WebSocketEvent.java similarity index 63% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/ResultInterface.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/request/WebSocketEvent.java index 6a2f8c3d..a4b9cfef 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/ResultInterface.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/WebSocketEvent.java @@ -1,5 +1,5 @@ package pro.gravit.launcher.request; -public interface ResultInterface { +public interface WebSocketEvent { String getType(); } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/admin/ExecCommandRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/admin/ExecCommandRequest.java index 21f6bc90..c3345f0b 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/admin/ExecCommandRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/admin/ExecCommandRequest.java @@ -3,9 +3,9 @@ import pro.gravit.launcher.LauncherAPI; import pro.gravit.launcher.events.request.ExecCommandRequestEvent; import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.websockets.RequestInterface; +import pro.gravit.launcher.request.websockets.WebSocketRequest; -public class ExecCommandRequest extends Request implements RequestInterface { +public class ExecCommandRequest extends Request implements WebSocketRequest { @LauncherAPI public String cmd; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/admin/ProxyRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/admin/ProxyRequest.java index 34b8e004..ecbc8784 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/admin/ProxyRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/admin/ProxyRequest.java @@ -1,15 +1,15 @@ package pro.gravit.launcher.request.admin; import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.ResultInterface; -import pro.gravit.launcher.request.websockets.RequestInterface; +import pro.gravit.launcher.request.WebSocketEvent; +import pro.gravit.launcher.request.websockets.WebSocketRequest; -public class ProxyRequest extends Request implements RequestInterface { - public RequestInterface response; +public class ProxyRequest extends Request implements WebSocketRequest { + public WebSocketRequest response; public long session; public boolean isCheckSign; - public ProxyRequest(RequestInterface response, long session) { + public ProxyRequest(WebSocketRequest response, long session) { this.response = response; this.session = session; } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/AuthRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/AuthRequest.java index 2307c682..9c26720e 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/AuthRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/AuthRequest.java @@ -5,10 +5,10 @@ import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.request.AuthRequestEvent; import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.websockets.RequestInterface; +import pro.gravit.launcher.request.websockets.WebSocketRequest; import pro.gravit.utils.helper.VerifyHelper; -public final class AuthRequest extends Request implements RequestInterface { +public final class AuthRequest extends Request implements WebSocketRequest { @LauncherNetworkAPI private final String login; @LauncherNetworkAPI diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/CheckServerRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/CheckServerRequest.java index 3cb20590..6c918f4b 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/CheckServerRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/CheckServerRequest.java @@ -4,10 +4,10 @@ import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.request.CheckServerRequestEvent; import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.websockets.RequestInterface; +import pro.gravit.launcher.request.websockets.WebSocketRequest; import pro.gravit.utils.helper.VerifyHelper; -public final class CheckServerRequest extends Request implements RequestInterface { +public final class CheckServerRequest extends Request implements WebSocketRequest { @LauncherNetworkAPI private final String username; @LauncherNetworkAPI diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/GetAvailabilityAuthRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/GetAvailabilityAuthRequest.java index 2be24ef0..aad6870b 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/GetAvailabilityAuthRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/GetAvailabilityAuthRequest.java @@ -2,9 +2,9 @@ import pro.gravit.launcher.events.request.GetAvailabilityAuthRequestEvent; import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.websockets.RequestInterface; +import pro.gravit.launcher.request.websockets.WebSocketRequest; -public class GetAvailabilityAuthRequest extends Request implements RequestInterface { +public class GetAvailabilityAuthRequest extends Request implements WebSocketRequest { @Override public String getType() { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/JoinServerRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/JoinServerRequest.java index f963b9bf..6e2ca2f4 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/JoinServerRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/JoinServerRequest.java @@ -4,11 +4,11 @@ import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.request.JoinServerRequestEvent; import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.websockets.RequestInterface; +import pro.gravit.launcher.request.websockets.WebSocketRequest; import pro.gravit.utils.helper.SecurityHelper; import pro.gravit.utils.helper.VerifyHelper; -public final class JoinServerRequest extends Request implements RequestInterface { +public final class JoinServerRequest extends Request implements WebSocketRequest { // Instance @LauncherNetworkAPI diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/RestoreSessionRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/RestoreSessionRequest.java index 36c6b615..5e15bfbc 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/RestoreSessionRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/RestoreSessionRequest.java @@ -3,9 +3,9 @@ import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.request.RestoreSessionRequestEvent; import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.websockets.RequestInterface; +import pro.gravit.launcher.request.websockets.WebSocketRequest; -public class RestoreSessionRequest extends Request implements RequestInterface { +public class RestoreSessionRequest extends Request implements WebSocketRequest { @LauncherNetworkAPI public long session; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/SetProfileRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/SetProfileRequest.java index 461a0eb3..0cc7d943 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/SetProfileRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/SetProfileRequest.java @@ -4,9 +4,9 @@ import pro.gravit.launcher.events.request.SetProfileRequestEvent; import pro.gravit.launcher.profiles.ClientProfile; import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.websockets.RequestInterface; +import pro.gravit.launcher.request.websockets.WebSocketRequest; -public class SetProfileRequest extends Request implements RequestInterface { +public class SetProfileRequest extends Request implements WebSocketRequest { @LauncherNetworkAPI public String client; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/LauncherRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/LauncherRequest.java index b33f1db4..4b7ac5ea 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/LauncherRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/LauncherRequest.java @@ -11,14 +11,14 @@ import pro.gravit.launcher.downloader.ListDownloader; import pro.gravit.launcher.events.request.LauncherRequestEvent; import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.websockets.RequestInterface; +import pro.gravit.launcher.request.websockets.WebSocketRequest; import pro.gravit.launcher.request.websockets.StandartClientWebSocketService; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.SecurityHelper; -public final class LauncherRequest extends Request implements RequestInterface { +public final class LauncherRequest extends Request implements WebSocketRequest { @LauncherNetworkAPI public byte[] digest; @LauncherNetworkAPI diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/ProfilesRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/ProfilesRequest.java index c02d667c..06f28ebc 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/ProfilesRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/ProfilesRequest.java @@ -2,9 +2,9 @@ import pro.gravit.launcher.events.request.ProfilesRequestEvent; import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.websockets.RequestInterface; +import pro.gravit.launcher.request.websockets.WebSocketRequest; -public final class ProfilesRequest extends Request implements RequestInterface { +public final class ProfilesRequest extends Request implements WebSocketRequest { @Override public String getType() { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateListRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateListRequest.java index 3641439d..463b58ed 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateListRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateListRequest.java @@ -2,9 +2,9 @@ import pro.gravit.launcher.events.request.UpdateListRequestEvent; import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.websockets.RequestInterface; +import pro.gravit.launcher.request.websockets.WebSocketRequest; -public final class UpdateListRequest extends Request implements RequestInterface { +public final class UpdateListRequest extends Request implements WebSocketRequest { @Override public String getType() { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java index bc372234..e6b9234e 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java @@ -21,12 +21,12 @@ import pro.gravit.launcher.hasher.HashedFile; import pro.gravit.launcher.request.Request; import pro.gravit.launcher.request.update.UpdateRequest.State.Callback; -import pro.gravit.launcher.request.websockets.RequestInterface; +import pro.gravit.launcher.request.websockets.WebSocketRequest; import pro.gravit.launcher.request.websockets.StandartClientWebSocketService; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; -public final class UpdateRequest extends Request implements RequestInterface { +public final class UpdateRequest extends Request implements WebSocketRequest { public interface UpdateController { void preUpdate(UpdateRequest request, UpdateRequestEvent e) throws IOException; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/BatchProfileByUsernameRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/BatchProfileByUsernameRequest.java index b0f5a7d9..e304e7a9 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/BatchProfileByUsernameRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/BatchProfileByUsernameRequest.java @@ -6,12 +6,12 @@ import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.request.BatchProfileByUsernameRequestEvent; import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.websockets.RequestInterface; +import pro.gravit.launcher.request.websockets.WebSocketRequest; import pro.gravit.launcher.serialize.SerializeLimits; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.VerifyHelper; -public final class BatchProfileByUsernameRequest extends Request implements RequestInterface { +public final class BatchProfileByUsernameRequest extends Request implements WebSocketRequest { class Entry { @LauncherNetworkAPI String username; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/ProfileByUUIDRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/ProfileByUUIDRequest.java index 7166a6ad..171b1116 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/ProfileByUUIDRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/ProfileByUUIDRequest.java @@ -7,9 +7,9 @@ import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.request.ProfileByUUIDRequestEvent; import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.websockets.RequestInterface; +import pro.gravit.launcher.request.websockets.WebSocketRequest; -public final class ProfileByUUIDRequest extends Request implements RequestInterface { +public final class ProfileByUUIDRequest extends Request implements WebSocketRequest { @LauncherNetworkAPI private final UUID uuid; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/ProfileByUsernameRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/ProfileByUsernameRequest.java index fef8eb91..190c6f8a 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/ProfileByUsernameRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/ProfileByUsernameRequest.java @@ -4,10 +4,10 @@ import pro.gravit.launcher.LauncherNetworkAPI; import pro.gravit.launcher.events.request.ProfileByUsernameRequestEvent; import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.websockets.RequestInterface; +import pro.gravit.launcher.request.websockets.WebSocketRequest; import pro.gravit.utils.helper.VerifyHelper; -public final class ProfileByUsernameRequest extends Request implements RequestInterface { +public final class ProfileByUsernameRequest extends Request implements WebSocketRequest { @LauncherNetworkAPI private final String username; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java index 7e2217cc..afba8c8c 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java @@ -15,7 +15,7 @@ import pro.gravit.launcher.events.request.*; import pro.gravit.launcher.hasher.HashedEntry; import pro.gravit.launcher.hasher.HashedEntryAdapter; -import pro.gravit.launcher.request.ResultInterface; +import pro.gravit.launcher.request.WebSocketEvent; import pro.gravit.utils.helper.LogHelper; public class ClientWebSocketService extends ClientJSONPoint { @@ -24,8 +24,8 @@ public class ClientWebSocketService extends ClientJSONPoint { public OnCloseCallback onCloseCallback; public final Boolean onConnect; public ReconnectCallback reconnectCallback; - private HashMap> requests; - private HashMap> results; + private HashMap> requests; + private HashMap> results; private HashSet handlers; public ClientWebSocketService(GsonBuilder gsonBuilder, String address, int i) throws SSLException { @@ -34,8 +34,8 @@ public ClientWebSocketService(GsonBuilder gsonBuilder, String address, int i) th results = new HashMap<>(); handlers = new HashSet<>(); this.gsonBuilder = gsonBuilder; - this.gsonBuilder.registerTypeAdapter(RequestInterface.class, new JsonRequestAdapter(this)); - this.gsonBuilder.registerTypeAdapter(ResultInterface.class, new JsonResultAdapter(this)); + this.gsonBuilder.registerTypeAdapter(WebSocketRequest.class, new JsonRequestAdapter(this)); + this.gsonBuilder.registerTypeAdapter(WebSocketEvent.class, new JsonResultAdapter(this)); this.gsonBuilder.registerTypeAdapter(HashedEntry.class, new HashedEntryAdapter()); this.gson = gsonBuilder.create(); this.onConnect = true; @@ -53,7 +53,7 @@ private static URI createURL(String address) { @Override void onMessage(String message) { - ResultInterface result = gson.fromJson(message, ResultInterface.class); + WebSocketEvent result = gson.fromJson(message, WebSocketEvent.class); for (EventHandler handler : handlers) { handler.process(result); } @@ -81,15 +81,15 @@ public interface ReconnectCallback { void onReconnect() throws IOException; } - public Class getRequestClass(String key) { + public Class getRequestClass(String key) { return requests.get(key); } - public Class getResultClass(String key) { + public Class getResultClass(String key) { return results.get(key); } - public void registerRequest(String key, Class clazz) { + public void registerRequest(String key, Class clazz) { requests.put(key, clazz); } @@ -97,7 +97,7 @@ public void registerRequests() { } - public void registerResult(String key, Class clazz) { + public void registerResult(String key, Class clazz) { results.put(key, clazz); } @@ -148,7 +148,7 @@ public void sendObject(Object obj) throws IOException { if (ch == null || !ch.isActive()) reconnectCallback.onReconnect(); //if(isClosed() && reconnectCallback != null) // reconnectCallback.onReconnect(); - send(gson.toJson(obj, RequestInterface.class)); + send(gson.toJson(obj, WebSocketRequest.class)); } public void sendObject(Object obj, Type type) throws IOException { @@ -161,6 +161,6 @@ public void sendObject(Object obj, Type type) throws IOException { @FunctionalInterface public interface EventHandler { - void process(ResultInterface resultInterface); + void process(WebSocketEvent webSocketEvent); } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/JsonRequestAdapter.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/JsonRequestAdapter.java index 38906c6b..18946738 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/JsonRequestAdapter.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/JsonRequestAdapter.java @@ -13,7 +13,7 @@ import pro.gravit.utils.helper.LogHelper; -public class JsonRequestAdapter implements JsonSerializer, JsonDeserializer { +public class JsonRequestAdapter implements JsonSerializer, JsonDeserializer { private final ClientWebSocketService service; private static final String PROP_NAME = "type"; @@ -22,19 +22,19 @@ public JsonRequestAdapter(ClientWebSocketService service) { } @Override - public RequestInterface deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + public WebSocketRequest deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); - Class cls = service.getRequestClass(typename); + Class cls = service.getRequestClass(typename); if (cls == null) { LogHelper.error("Request type %s not found", typename); } - return (RequestInterface) context.deserialize(json, cls); + return (WebSocketRequest) context.deserialize(json, cls); } @Override - public JsonElement serialize(RequestInterface src, Type typeOfSrc, JsonSerializationContext context) { + public JsonElement serialize(WebSocketRequest src, Type typeOfSrc, JsonSerializationContext context) { // note : won't work, you must delegate this JsonObject jo = context.serialize(src).getAsJsonObject(); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/JsonResultAdapter.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/JsonResultAdapter.java index a95ff2e6..2c057dd7 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/JsonResultAdapter.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/JsonResultAdapter.java @@ -11,10 +11,10 @@ import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; -import pro.gravit.launcher.request.ResultInterface; +import pro.gravit.launcher.request.WebSocketEvent; import pro.gravit.utils.helper.LogHelper; -public class JsonResultAdapter implements JsonSerializer, JsonDeserializer { +public class JsonResultAdapter implements JsonSerializer, JsonDeserializer { private final ClientWebSocketService service; private static final String PROP_NAME = "type"; @@ -23,19 +23,19 @@ public JsonResultAdapter(ClientWebSocketService service) { } @Override - public ResultInterface deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + public WebSocketEvent deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); - Class cls = service.getResultClass(typename); + Class cls = service.getResultClass(typename); if (cls == null) { LogHelper.error("Result type %s not found", typename); } - return (ResultInterface) context.deserialize(json, cls); + return (WebSocketEvent) context.deserialize(json, cls); } @Override - public JsonElement serialize(ResultInterface src, Type typeOfSrc, JsonSerializationContext context) { + public JsonElement serialize(WebSocketEvent src, Type typeOfSrc, JsonSerializationContext context) { // note : won't work, you must delegate this JsonObject jo = context.serialize(src).getAsJsonObject(); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StandartClientWebSocketService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StandartClientWebSocketService.java index e2866a07..71161e8e 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StandartClientWebSocketService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StandartClientWebSocketService.java @@ -12,7 +12,7 @@ import pro.gravit.launcher.events.request.ErrorRequestEvent; import pro.gravit.launcher.request.Request; import pro.gravit.launcher.request.RequestException; -import pro.gravit.launcher.request.ResultInterface; +import pro.gravit.launcher.request.WebSocketEvent; import pro.gravit.utils.helper.CommonHelper; import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.LogHelper; @@ -24,12 +24,12 @@ public StandartClientWebSocketService(GsonBuilder gsonBuilder, String address, i super(gsonBuilder, address, i); } - public class RequestFuture implements Future { + public class RequestFuture implements Future { public final WaitEventHandler.ResultEvent event; public boolean isCanceled = false; @SuppressWarnings("rawtypes") - public RequestFuture(RequestInterface request) throws IOException { + public RequestFuture(WebSocketRequest request) throws IOException { event = new WaitEventHandler.ResultEvent(); event.type = request.getType(); if (request instanceof Request) { @@ -57,14 +57,14 @@ public boolean isDone() { } @Override - public ResultInterface get() throws InterruptedException, ExecutionException { + public WebSocketEvent get() throws InterruptedException, ExecutionException { if (isCanceled) return null; while (!event.ready) { synchronized (event) { event.wait(); } } - ResultInterface result = event.result; + WebSocketEvent result = event.result; waitEventHandler.requests.remove(event); if (event.result.getType().equals("error") || event.result.getType().equals("exception")) { ErrorRequestEvent errorRequestEvent = (ErrorRequestEvent) event.result; @@ -74,14 +74,14 @@ public ResultInterface get() throws InterruptedException, ExecutionException { } @Override - public ResultInterface get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException { + public WebSocketEvent get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException { if (isCanceled) return null; while (!event.ready) { synchronized (event) { event.wait(timeout); } } - ResultInterface result = event.result; + WebSocketEvent result = event.result; waitEventHandler.requests.remove(event); if (event.result.getType().equals("error") || event.result.getType().equals("exception")) { ErrorRequestEvent errorRequestEvent = (ErrorRequestEvent) event.result; @@ -91,9 +91,9 @@ public ResultInterface get(long timeout, TimeUnit unit) throws InterruptedExcept } } - public ResultInterface sendRequest(RequestInterface request) throws IOException, InterruptedException { + public WebSocketEvent sendRequest(WebSocketRequest request) throws IOException, InterruptedException { RequestFuture future = new RequestFuture(request); - ResultInterface result; + WebSocketEvent result; try { result = future.get(); } catch (ExecutionException e) { @@ -102,7 +102,7 @@ public ResultInterface sendRequest(RequestInterface request) throws IOException, return result; } - public RequestFuture asyncSendRequest(RequestInterface request) throws IOException { + public RequestFuture asyncSendRequest(WebSocketRequest request) throws IOException { return new RequestFuture(request); } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WaitEventHandler.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WaitEventHandler.java index 50a4849b..860454cd 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WaitEventHandler.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WaitEventHandler.java @@ -5,14 +5,14 @@ import java.util.concurrent.ConcurrentHashMap; import pro.gravit.launcher.events.RequestEvent; -import pro.gravit.launcher.request.ResultInterface; +import pro.gravit.launcher.request.WebSocketEvent; import pro.gravit.utils.helper.LogHelper; public class WaitEventHandler implements ClientWebSocketService.EventHandler { public Set requests = ConcurrentHashMap.newKeySet(); @Override - public void process(ResultInterface result) { + public void process(WebSocketEvent result) { LogHelper.debug("Processing event %s type", result.getType()); UUID checkUUID = null; if (result instanceof RequestEvent) { @@ -36,7 +36,7 @@ public void process(ResultInterface result) { } public static class ResultEvent { - public ResultInterface result; + public WebSocketEvent result; public UUID uuid; public String type; public boolean ready; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/RequestInterface.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WebSocketRequest.java similarity index 66% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/RequestInterface.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WebSocketRequest.java index 86c5638e..a98a592c 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/RequestInterface.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WebSocketRequest.java @@ -1,5 +1,5 @@ package pro.gravit.launcher.request.websockets; -public interface RequestInterface { +public interface WebSocketRequest { String getType(); }