From 01d6587c119459e48e97eacba2fb2b3fbe095b5f Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 28 Jan 2019 20:25:49 +0700 Subject: [PATCH 01/14] =?UTF-8?q?[FIX]=20=D0=A4=D0=B8=D0=BA=D1=81=20=D0=B0?= =?UTF-8?q?=D0=B2=D1=82=D0=BE=D1=80=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D0=B8=20?= =?UTF-8?q?=D0=B8=20CheckServer=20=D0=B2=20WebSockets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../websocket/json/auth/AuthResponse.java | 32 ++++++++++++++----- .../json/auth/CheckServerResponse.java | 14 ++++++-- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java index bb6fc899..bd9df2dd 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java @@ -1,13 +1,17 @@ package ru.gravit.launchserver.socket.websocket.json.auth; import io.netty.channel.ChannelHandlerContext; +import ru.gravit.launcher.ClientPermissions; import ru.gravit.launcher.HWID; +import ru.gravit.launcher.OshiHWID; import ru.gravit.launcher.profiles.ClientProfile; +import ru.gravit.launcher.profiles.PlayerProfile; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.auth.AuthException; import ru.gravit.launchserver.auth.hwid.HWIDException; import ru.gravit.launchserver.auth.provider.AuthProvider; import ru.gravit.launchserver.auth.provider.AuthProviderResult; +import ru.gravit.launchserver.response.profile.ProfileByUUIDResponse; import ru.gravit.launchserver.socket.Client; import ru.gravit.launchserver.socket.websocket.WebSocketService; import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface; @@ -15,6 +19,7 @@ import ru.gravit.utils.helper.VerifyHelper; import java.util.Collection; +import java.util.UUID; public class AuthResponse implements JsonResponseInterface { public String login; @@ -22,7 +27,7 @@ public class AuthResponse implements JsonResponseInterface { public String password; - public AuthResponse(String login, String password, int authid, HWID hwid) { + public AuthResponse(String login, String password, int authid, OshiHWID hwid) { this.login = login; this.password = password; this.authid = authid; @@ -30,7 +35,7 @@ public AuthResponse(String login, String password, int authid, HWID hwid) { } public int authid; - public HWID hwid; + public OshiHWID hwid; @Override public String getType() { @@ -40,6 +45,7 @@ public String getType() { @Override public void execute(WebSocketService service, ChannelHandlerContext ctx, Client clientData) throws Exception { try { + Result result = new Result(); String ip = IOHelper.getIP(ctx.channel().remoteAddress()); if (LaunchServer.server.limiter.isLimit(ip)) { AuthProvider.authError(LaunchServer.server.config.authRejectString); @@ -49,10 +55,12 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client AuthProvider.authError("Don't skip Launcher Update"); return; } + ru.gravit.launchserver.response.auth.AuthResponse.AuthContext context = new ru.gravit.launchserver.response.auth.AuthResponse.AuthContext(0, login, password.length(), client, null, false); AuthProvider provider = LaunchServer.server.config.authProvider[authid]; - AuthProviderResult result = provider.auth(login, password, ip); - if (!VerifyHelper.isValidUsername(result.username)) { - AuthProvider.authError(String.format("Illegal result: '%s'", result.username)); + LaunchServer.server.authHookManager.preHook(context, clientData); + AuthProviderResult aresult = provider.auth(login, password, ip); + if (!VerifyHelper.isValidUsername(aresult.username)) { + AuthProvider.authError(String.format("Illegal result: '%s'", aresult.username)); return; } Collection profiles = LaunchServer.server.getProfiles(); @@ -67,10 +75,15 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client if (clientData.profile == null) { throw new AuthException("You profile not found"); } - LaunchServer.server.config.hwidHandler.check(hwid, result.username); + UUID uuid = LaunchServer.server.config.authHandler.auth(aresult); + LaunchServer.server.config.hwidHandler.check(hwid, aresult.username); + LaunchServer.server.authHookManager.postHook(context, clientData); clientData.isAuth = true; - clientData.permissions = result.permissions; - service.sendObject(ctx, new WebSocketService.SuccessResult("auth")); + clientData.permissions = aresult.permissions; + result.accessToken = aresult.accessToken; + result.permissions = clientData.permissions; + result.playerProfile = ProfileByUUIDResponse.getProfile(LaunchServer.server,uuid,aresult.username,client); + service.sendObject(ctx, result); } catch (AuthException | HWIDException e) { service.sendObject(ctx, new WebSocketService.ErrorResult(e.getMessage())); } @@ -81,5 +94,8 @@ public Result() { } public String error; + public ClientPermissions permissions; + public PlayerProfile playerProfile; + public String accessToken; } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/CheckServerResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/CheckServerResponse.java index db7940ce..b437182e 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/CheckServerResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/CheckServerResponse.java @@ -1,16 +1,21 @@ package ru.gravit.launchserver.socket.websocket.json.auth; import io.netty.channel.ChannelHandlerContext; +import ru.gravit.launcher.profiles.PlayerProfile; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.auth.AuthException; +import ru.gravit.launchserver.response.profile.ProfileByUUIDResponse; import ru.gravit.launchserver.socket.Client; import ru.gravit.launchserver.socket.websocket.WebSocketService; import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface; import ru.gravit.utils.helper.LogHelper; +import java.util.UUID; + public class CheckServerResponse implements JsonResponseInterface { public String serverID; public String username; + public String client; @Override public String getType() { @@ -18,9 +23,12 @@ public String getType() { } @Override - public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) { + public void execute(WebSocketService service, ChannelHandlerContext ctx, Client pClient) { + Result result = new Result(); try { - LaunchServer.server.config.authHandler.checkServer(username, serverID); + result.uuid = LaunchServer.server.config.authHandler.checkServer(username, serverID); + if(result.uuid != null) + result.playerProfile = ProfileByUUIDResponse.getProfile(LaunchServer.server,result.uuid,username,client); } catch (AuthException e) { service.sendObject(ctx, new WebSocketService.ErrorResult(e.getMessage())); return; @@ -35,5 +43,7 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client public class Result { public String type = "success"; public String requesttype = "checkServer"; + public UUID uuid; + public PlayerProfile playerProfile; } } From 9ea4c051d5b4a25759bdd5b60038744f57f80fbb Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 28 Jan 2019 20:33:39 +0700 Subject: [PATCH 02/14] [FEATURE] Add ProfilesResponse WebSockets --- .../socket/websocket/WebSocketService.java | 2 ++ .../websocket/json/auth/ProfilesResponse.java | 33 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/ProfilesResponse.java 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 31d5a726..5d3fba8e 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 @@ -17,6 +17,7 @@ import ru.gravit.launchserver.socket.websocket.json.auth.AuthResponse; import ru.gravit.launchserver.socket.websocket.json.auth.CheckServerResponse; import ru.gravit.launchserver.socket.websocket.json.auth.JoinServerResponse; +import ru.gravit.launchserver.socket.websocket.json.auth.ProfilesResponse; import ru.gravit.launchserver.socket.websocket.json.update.LauncherResponse; import ru.gravit.launchserver.socket.websocket.json.update.UpdateListResponse; import ru.gravit.utils.helper.LogHelper; @@ -69,6 +70,7 @@ public void registerResponses() { registerResponse("auth", AuthResponse.class); registerResponse("checkServer", CheckServerResponse.class); registerResponse("joinServer", JoinServerResponse.class); + registerResponse("profiles", ProfilesResponse.class); registerResponse("launcherUpdate", LauncherResponse.class); registerResponse("updateList", UpdateListResponse.class); registerResponse("cmdExec", UpdateListResponse.class); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/ProfilesResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/ProfilesResponse.java new file mode 100644 index 00000000..a4586bc2 --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/ProfilesResponse.java @@ -0,0 +1,33 @@ +package ru.gravit.launchserver.socket.websocket.json.auth; + +import io.netty.channel.ChannelHandlerContext; +import ru.gravit.launcher.profiles.ClientProfile; +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.socket.Client; +import ru.gravit.launchserver.socket.websocket.WebSocketService; +import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface; + +import java.util.List; + +public class ProfilesResponse implements JsonResponseInterface { + @Override + public String getType() { + return "profiles"; + } + + @Override + public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { + service.sendObject(ctx, new Result((List) LaunchServer.server.getProfiles())); + } + public class Result + { + List profiles; + + public Result(List profiles) { + this.profiles = profiles; + } + + String requesttype = "profilesList"; + String error; + } +} From 2937d70866391a06f69b85239387260abf4272d7 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 28 Jan 2019 20:56:20 +0700 Subject: [PATCH 03/14] =?UTF-8?q?[FIX]=20=D0=A4=D0=B8=D0=BA=D1=81=20=D0=B0?= =?UTF-8?q?=D0=B2=D1=82=D0=BE=D1=80=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D0=B8=20?= =?UTF-8?q?=D1=81=D0=B5=D1=80=D0=B2=D0=B5=D1=80=D0=B0=20=D0=B8=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B8=20=D0=BB=D0=B0=D1=83?= =?UTF-8?q?=D0=BD=D1=87=D0=B5=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../socket/websocket/json/auth/AuthResponse.java | 7 ++++++- .../socket/websocket/json/update/LauncherResponse.java | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java index bd9df2dd..1238e716 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java @@ -35,7 +35,12 @@ public AuthResponse(String login, String password, int authid, OshiHWID hwid) { } public int authid; + public ConnectTypes type; public OshiHWID hwid; + enum ConnectTypes + { + SERVER,CLIENT + } @Override public String getType() { @@ -51,7 +56,7 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client AuthProvider.authError(LaunchServer.server.config.authRejectString); return; } - if (!clientData.checkSign) { + if (type == ConnectTypes.SERVER &&!clientData.checkSign) { AuthProvider.authError("Don't skip Launcher Update"); return; } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/LauncherResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/LauncherResponse.java index 4eab94ae..c026ba28 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/LauncherResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/update/LauncherResponse.java @@ -31,6 +31,7 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client byte[] hash = LaunchServer.server.launcherBinary.getBytes().getDigest(); if (hash == null) service.sendObjectAndClose(ctx, new Result(true, JAR_URL)); if (Arrays.equals(bytes, hash)) { + client.checkSign = true; service.sendObject(ctx, new Result(false, JAR_URL)); } else { service.sendObjectAndClose(ctx, new Result(true, JAR_URL)); @@ -40,6 +41,7 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client byte[] hash = LaunchServer.server.launcherEXEBinary.getBytes().getDigest(); if (hash == null) service.sendObjectAndClose(ctx, new Result(true, EXE_URL)); if (Arrays.equals(bytes, hash)) { + client.checkSign = true; service.sendObject(ctx, new Result(false, EXE_URL)); } else { service.sendObjectAndClose(ctx, new Result(true, EXE_URL)); From 43de166d228f38a6a236e6fcd2b5910938863d96 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 28 Jan 2019 21:08:06 +0700 Subject: [PATCH 04/14] =?UTF-8?q?[FIX]=20=D0=A4=D0=B8=D0=BA=D1=81=20=D0=B0?= =?UTF-8?q?=D0=B2=D1=82=D0=BE=D1=80=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D0=B8=20?= =?UTF-8?q?=D1=81=D0=B5=D1=80=D0=B2=D0=B5=D1=80=D0=B0=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../socket/websocket/json/auth/AuthResponse.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java index 1238e716..e49c887f 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java @@ -35,9 +35,9 @@ public AuthResponse(String login, String password, int authid, OshiHWID hwid) { } public int authid; - public ConnectTypes type; + public ConnectTypes authType; public OshiHWID hwid; - enum ConnectTypes + public enum ConnectTypes { SERVER,CLIENT } @@ -56,7 +56,7 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client AuthProvider.authError(LaunchServer.server.config.authRejectString); return; } - if (type == ConnectTypes.SERVER &&!clientData.checkSign) { + if (authType == ConnectTypes.SERVER &&!clientData.checkSign) { AuthProvider.authError("Don't skip Launcher Update"); return; } @@ -81,7 +81,8 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client throw new AuthException("You profile not found"); } UUID uuid = LaunchServer.server.config.authHandler.auth(aresult); - LaunchServer.server.config.hwidHandler.check(hwid, aresult.username); + if(authType == ConnectTypes.CLIENT) + LaunchServer.server.config.hwidHandler.check(hwid, aresult.username); LaunchServer.server.authHookManager.postHook(context, clientData); clientData.isAuth = true; clientData.permissions = aresult.permissions; From a6686029a5fd3ea2d487003bce3479c0e2e525f3 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 28 Jan 2019 21:16:11 +0700 Subject: [PATCH 05/14] =?UTF-8?q?[FIX]=20=D0=A4=D0=B8=D0=BA=D1=81=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B8=D0=B2=D0=B8=D0=BB=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B8=20=D0=B0=D0=B2=D1=82=D0=BE=D1=80=D0=B8=D0=B7=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../socket/websocket/json/auth/AuthResponse.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java index e49c887f..b1280931 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java @@ -39,7 +39,7 @@ public AuthResponse(String login, String password, int authid, OshiHWID hwid) { public OshiHWID hwid; public enum ConnectTypes { - SERVER,CLIENT + SERVER,CLIENT,BOT } @Override @@ -56,10 +56,19 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client AuthProvider.authError(LaunchServer.server.config.authRejectString); return; } - if (authType == ConnectTypes.SERVER &&!clientData.checkSign) { + if (authType != ConnectTypes.CLIENT &&!clientData.checkSign) { AuthProvider.authError("Don't skip Launcher Update"); return; } + clientData.permissions = LaunchServer.server.config.permissionsHandler.getPermissions(login); + if(authType == ConnectTypes.BOT && !clientData.permissions.canBot) + { + AuthProvider.authError("authType: BOT not allowed for this account"); + } + if(authType == ConnectTypes.SERVER && !clientData.permissions.canServer) + { + AuthProvider.authError("authType: SERVER not allowed for this account"); + } ru.gravit.launchserver.response.auth.AuthResponse.AuthContext context = new ru.gravit.launchserver.response.auth.AuthResponse.AuthContext(0, login, password.length(), client, null, false); AuthProvider provider = LaunchServer.server.config.authProvider[authid]; LaunchServer.server.authHookManager.preHook(context, clientData); From 52609413a269dd588a9b2d2a8b6f8d837c6998a9 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 28 Jan 2019 21:39:23 +0700 Subject: [PATCH 06/14] =?UTF-8?q?[FEATURE]=20=D0=9F=D0=BE=D1=80=D1=82?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D1=8B=20=D0=B7=D0=B0=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D1=81=D1=8B=20=D0=BF=D1=80=D0=BE=D1=84=D0=B8=D0=BB?= =?UTF-8?q?=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../websocket/json/auth/ProfilesResponse.java | 4 ++ .../json/profile/BatchProfileByUsername.java | 41 ++++++++++++ .../json/profile/ProfileByUUIDResponse.java | 62 +++++++++++++++++++ .../json/profile/ProfileByUsername.java | 37 +++++++++++ 4 files changed, 144 insertions(+) create mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/profile/BatchProfileByUsername.java create mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/profile/ProfileByUUIDResponse.java create mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/profile/ProfileByUsername.java diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/ProfilesResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/ProfilesResponse.java index a4586bc2..f08f71c1 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/ProfilesResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/ProfilesResponse.java @@ -17,6 +17,10 @@ public String getType() { @Override public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { + if(!client.isAuth) + { + service.sendObject(ctx, new WebSocketService.ErrorResult("Access denied")); + } service.sendObject(ctx, new Result((List) LaunchServer.server.getProfiles())); } public class Result diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/profile/BatchProfileByUsername.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/profile/BatchProfileByUsername.java new file mode 100644 index 00000000..d18c3d05 --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/profile/BatchProfileByUsername.java @@ -0,0 +1,41 @@ +package ru.gravit.launchserver.socket.websocket.json.profile; + +import io.netty.channel.ChannelHandlerContext; +import ru.gravit.launcher.profiles.PlayerProfile; +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.socket.Client; +import ru.gravit.launchserver.socket.websocket.WebSocketService; +import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface; + +import java.util.UUID; + +public class BatchProfileByUsername implements JsonResponseInterface { + class Entry + { + String username; + String client; + } + Entry[] list; + @Override + public String getType() { + return "batchProfileByUsername"; + } + + @Override + public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { + Result result = new Result(); + result.playerProfiles = new PlayerProfile[list.length]; + for(int i=0;i Date: Mon, 28 Jan 2019 21:44:38 +0700 Subject: [PATCH 07/14] =?UTF-8?q?[FEATURE]=20=D0=9F=D0=BE=D1=80=D1=82?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=20SetProfileResponse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../websocket/json/auth/ProfilesResponse.java | 1 + .../json/auth/SetProfileResponse.java | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/SetProfileResponse.java diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/ProfilesResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/ProfilesResponse.java index f08f71c1..29c9581b 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/ProfilesResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/ProfilesResponse.java @@ -20,6 +20,7 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client if(!client.isAuth) { service.sendObject(ctx, new WebSocketService.ErrorResult("Access denied")); + return; } service.sendObject(ctx, new Result((List) LaunchServer.server.getProfiles())); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/SetProfileResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/SetProfileResponse.java new file mode 100644 index 00000000..83e41ee2 --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/SetProfileResponse.java @@ -0,0 +1,39 @@ +package ru.gravit.launchserver.socket.websocket.json.auth; + +import io.netty.channel.ChannelHandlerContext; +import ru.gravit.launcher.profiles.ClientProfile; +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.socket.Client; +import ru.gravit.launchserver.socket.websocket.WebSocketService; +import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface; + +import java.util.Collection; + +public class SetProfileResponse implements JsonResponseInterface { + @Override + public String getType() { + return "setProfile"; + } + + @Override + public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { + if(!client.isAuth) + { + service.sendObject(ctx, new WebSocketService.ErrorResult("Access denied")); + return; + } + Collection profiles = LaunchServer.server.getProfiles(); + for (ClientProfile p : profiles) { + if (p.getTitle().equals(client)) { + if (!p.isWhitelistContains(client.username)) { + service.sendObject(ctx, new WebSocketService.ErrorResult(LaunchServer.server.config.whitelistRejectString)); + return; + } + client.profile = p; + service.sendObject(ctx, new WebSocketService.SuccessResult(getType())); + break; + } + } + service.sendObject(ctx, new WebSocketService.ErrorResult("Profile not found")); + } +} From 1ce4b6f11b77b1cfe2e2e0708aed453b23d58f02 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 28 Jan 2019 22:28:12 +0700 Subject: [PATCH 08/14] =?UTF-8?q?[FEATURE]=20=D0=9F=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=D1=81=20RequestEvent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../websocket/json/auth/AuthResponse.java | 15 ++--------- .../json/auth/CheckServerResponse.java | 14 +++-------- .../json/auth/JoinServerResponse.java | 13 ++-------- .../websocket/json/auth/ProfilesResponse.java | 14 ++--------- .../json/profile/BatchProfileByUsername.java | 9 ++----- .../json/profile/ProfileByUUIDResponse.java | 14 ++--------- .../json/profile/ProfileByUsername.java | 14 ++--------- .../json/update/LauncherResponse.java | 25 ++++++------------- .../json/update/UpdateListResponse.java | 14 ++--------- .../events/request/AuthRequestEvent.java | 14 +++++++++++ .../BatchProfileByUsernameRequestEvent.java | 10 ++++++++ .../events/request/CheckServerEvent.java | 12 +++++++++ .../request/JoinServerRequestEvent.java | 12 +++++++++ .../events/request/LauncherRequestEvent.java | 14 +++++++++++ .../request/ProfileByUUIDRequestEvent.java | 14 +++++++++++ .../ProfileByUsernameRequestEvent.java | 14 +++++++++++ .../events/request/ProfilesRequestEvent.java | 17 +++++++++++++ .../request/UpdateListRequestEvent.java | 15 +++++++++++ 18 files changed, 146 insertions(+), 108 deletions(-) create mode 100644 libLauncher/src/main/java/ru/gravit/launcher/events/request/AuthRequestEvent.java create mode 100644 libLauncher/src/main/java/ru/gravit/launcher/events/request/BatchProfileByUsernameRequestEvent.java create mode 100644 libLauncher/src/main/java/ru/gravit/launcher/events/request/CheckServerEvent.java create mode 100644 libLauncher/src/main/java/ru/gravit/launcher/events/request/JoinServerRequestEvent.java create mode 100644 libLauncher/src/main/java/ru/gravit/launcher/events/request/LauncherRequestEvent.java create mode 100644 libLauncher/src/main/java/ru/gravit/launcher/events/request/ProfileByUUIDRequestEvent.java create mode 100644 libLauncher/src/main/java/ru/gravit/launcher/events/request/ProfileByUsernameRequestEvent.java create mode 100644 libLauncher/src/main/java/ru/gravit/launcher/events/request/ProfilesRequestEvent.java create mode 100644 libLauncher/src/main/java/ru/gravit/launcher/events/request/UpdateListRequestEvent.java diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java index b1280931..74368989 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/AuthResponse.java @@ -1,11 +1,9 @@ package ru.gravit.launchserver.socket.websocket.json.auth; import io.netty.channel.ChannelHandlerContext; -import ru.gravit.launcher.ClientPermissions; -import ru.gravit.launcher.HWID; import ru.gravit.launcher.OshiHWID; +import ru.gravit.launcher.events.request.AuthRequestEvent; import ru.gravit.launcher.profiles.ClientProfile; -import ru.gravit.launcher.profiles.PlayerProfile; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.auth.AuthException; import ru.gravit.launchserver.auth.hwid.HWIDException; @@ -50,7 +48,7 @@ public String getType() { @Override public void execute(WebSocketService service, ChannelHandlerContext ctx, Client clientData) throws Exception { try { - Result result = new Result(); + AuthRequestEvent result = new AuthRequestEvent(); String ip = IOHelper.getIP(ctx.channel().remoteAddress()); if (LaunchServer.server.limiter.isLimit(ip)) { AuthProvider.authError(LaunchServer.server.config.authRejectString); @@ -104,13 +102,4 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client } } - public class Result { - public Result() { - } - - public String error; - public ClientPermissions permissions; - public PlayerProfile playerProfile; - public String accessToken; - } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/CheckServerResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/CheckServerResponse.java index b437182e..c615542d 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/CheckServerResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/CheckServerResponse.java @@ -1,7 +1,7 @@ package ru.gravit.launchserver.socket.websocket.json.auth; import io.netty.channel.ChannelHandlerContext; -import ru.gravit.launcher.profiles.PlayerProfile; +import ru.gravit.launcher.events.request.CheckServerEvent; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.auth.AuthException; import ru.gravit.launchserver.response.profile.ProfileByUUIDResponse; @@ -10,8 +10,6 @@ import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface; import ru.gravit.utils.helper.LogHelper; -import java.util.UUID; - public class CheckServerResponse implements JsonResponseInterface { public String serverID; public String username; @@ -24,7 +22,7 @@ public String getType() { @Override public void execute(WebSocketService service, ChannelHandlerContext ctx, Client pClient) { - Result result = new Result(); + CheckServerEvent result = new CheckServerEvent(); try { result.uuid = LaunchServer.server.config.authHandler.checkServer(username, serverID); if(result.uuid != null) @@ -37,13 +35,7 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client service.sendObject(ctx, new WebSocketService.ErrorResult("Internal authHandler error")); return; } - service.sendObject(ctx, new Result()); + service.sendObject(ctx, new CheckServerEvent()); } - public class Result { - public String type = "success"; - public String requesttype = "checkServer"; - public UUID uuid; - public PlayerProfile playerProfile; - } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/JoinServerResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/JoinServerResponse.java index 612c9e4a..56eeb0d2 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/JoinServerResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/JoinServerResponse.java @@ -1,6 +1,7 @@ package ru.gravit.launchserver.socket.websocket.json.auth; import io.netty.channel.ChannelHandlerContext; +import ru.gravit.launcher.events.request.JoinServerRequestEvent; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.auth.AuthException; import ru.gravit.launchserver.socket.Client; @@ -31,17 +32,7 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client service.sendObject(ctx, new WebSocketService.ErrorResult("Internal authHandler error")); return; } - service.sendObject(ctx, new Result(success)); + service.sendObject(ctx, new JoinServerRequestEvent(success)); } - public class Result { - public String type = "success"; - public String requesttype = "checkServer"; - - public Result(boolean allow) { - this.allow = allow; - } - - public boolean allow; - } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/ProfilesResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/ProfilesResponse.java index 29c9581b..778b1caa 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/ProfilesResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/auth/ProfilesResponse.java @@ -1,6 +1,7 @@ package ru.gravit.launchserver.socket.websocket.json.auth; import io.netty.channel.ChannelHandlerContext; +import ru.gravit.launcher.events.request.ProfilesRequestEvent; import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.socket.Client; @@ -22,17 +23,6 @@ public void execute(WebSocketService service, ChannelHandlerContext ctx, Client service.sendObject(ctx, new WebSocketService.ErrorResult("Access denied")); return; } - service.sendObject(ctx, new Result((List) LaunchServer.server.getProfiles())); - } - public class Result - { - List profiles; - - public Result(List profiles) { - this.profiles = profiles; - } - - String requesttype = "profilesList"; - String error; + service.sendObject(ctx, new ProfilesRequestEvent((List) LaunchServer.server.getProfiles())); } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/profile/BatchProfileByUsername.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/profile/BatchProfileByUsername.java index d18c3d05..22fade29 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/profile/BatchProfileByUsername.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/profile/BatchProfileByUsername.java @@ -1,6 +1,7 @@ package ru.gravit.launchserver.socket.websocket.json.profile; import io.netty.channel.ChannelHandlerContext; +import ru.gravit.launcher.events.request.BatchProfileByUsernameRequestEvent; import ru.gravit.launcher.profiles.PlayerProfile; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.socket.Client; @@ -23,7 +24,7 @@ public String getType() { @Override public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { - Result result = new Result(); + BatchProfileByUsernameRequestEvent result = new BatchProfileByUsernameRequestEvent(); result.playerProfiles = new PlayerProfile[list.length]; for(int i=0;i profiles; + + public ProfilesRequestEvent(List profiles) { + this.profiles = profiles; + } + + String requesttype = "profilesList"; + String error; +} 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 new file mode 100644 index 00000000..5ec26e3c --- /dev/null +++ b/libLauncher/src/main/java/ru/gravit/launcher/events/request/UpdateListRequestEvent.java @@ -0,0 +1,15 @@ +package ru.gravit.launcher.events.request; + +import ru.gravit.launcher.hasher.HashedDir; + +public class UpdateListRequestEvent { + public final String type; + public final String requesttype; + public final HashedDir dir; + + public UpdateListRequestEvent(HashedDir dir) { + this.dir = dir; + type = "success"; + requesttype = "updateList"; + } +} From 2e4acb721a47b77fae52e419adade1c0bb0c5d73 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 28 Jan 2019 22:35:49 +0700 Subject: [PATCH 09/14] =?UTF-8?q?[FEATURE]=20=D0=9E=D1=81=D0=BD=D0=B0?= =?UTF-8?q?=D1=89=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B2=D1=81=D0=B5=D1=85=20Eve?= =?UTF-8?q?nt=20UUID'=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launcher/events/request/AuthRequestEvent.java | 11 ++++++++++- .../request/BatchProfileByUsernameRequestEvent.java | 10 +++++++++- .../launcher/events/request/CheckServerEvent.java | 8 +++++++- .../events/request/JoinServerRequestEvent.java | 11 ++++++++++- .../launcher/events/request/LauncherRequestEvent.java | 11 ++++++++++- .../events/request/ProfileByUUIDRequestEvent.java | 10 +++++++++- .../events/request/ProfileByUsernameRequestEvent.java | 10 +++++++++- .../launcher/events/request/ProfilesRequestEvent.java | 9 ++++++++- .../events/request/UpdateListRequestEvent.java | 10 +++++++++- 9 files changed, 81 insertions(+), 9 deletions(-) diff --git a/libLauncher/src/main/java/ru/gravit/launcher/events/request/AuthRequestEvent.java b/libLauncher/src/main/java/ru/gravit/launcher/events/request/AuthRequestEvent.java index 87277366..4610afa6 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/events/request/AuthRequestEvent.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/events/request/AuthRequestEvent.java @@ -2,8 +2,12 @@ import ru.gravit.launcher.ClientPermissions; import ru.gravit.launcher.profiles.PlayerProfile; +import ru.gravit.utils.event.EventInterface; -public class AuthRequestEvent { +import java.util.UUID; + +public class AuthRequestEvent implements EventInterface { + private static final UUID uuid = UUID.fromString("77e1bfd7-adf9-4f5d-87d6-a7dd068deb74"); public AuthRequestEvent() { } @@ -11,4 +15,9 @@ public AuthRequestEvent() { public ClientPermissions permissions; public PlayerProfile playerProfile; public String accessToken; + + @Override + public UUID getUUID() { + return uuid; + } } 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 c494bfa3..cf121936 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 @@ -1,10 +1,18 @@ package ru.gravit.launcher.events.request; import ru.gravit.launcher.profiles.PlayerProfile; +import ru.gravit.utils.event.EventInterface; -public class BatchProfileByUsernameRequestEvent +import java.util.UUID; + +public class BatchProfileByUsernameRequestEvent implements EventInterface { + private static final UUID uuid = UUID.fromString("c1d6729e-be2c-48cc-b5ae-af8c012232c3"); public String requesttype = "batchProfileByUsername"; public String error; public PlayerProfile[] playerProfiles; + @Override + public UUID getUUID() { + return uuid; + } } 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 272308ed..3b2fbcb0 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 @@ -1,12 +1,18 @@ package ru.gravit.launcher.events.request; import ru.gravit.launcher.profiles.PlayerProfile; +import ru.gravit.utils.event.EventInterface; import java.util.UUID; -public class CheckServerEvent { +public class CheckServerEvent implements EventInterface { + 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 + public UUID getUUID() { + return _uuid; + } } 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 068b5f3f..674103ea 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 @@ -1,6 +1,11 @@ package ru.gravit.launcher.events.request; -public class JoinServerRequestEvent { +import ru.gravit.utils.event.EventInterface; + +import java.util.UUID; + +public class JoinServerRequestEvent implements EventInterface { + private static final UUID uuid = UUID.fromString("2a12e7b5-3f4a-4891-a2f9-ea141c8e1995"); public String type = "success"; public String requesttype = "checkServer"; @@ -9,4 +14,8 @@ public JoinServerRequestEvent(boolean allow) { } public boolean allow; + @Override + public UUID getUUID() { + return uuid; + } } 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 c939693f..52c69bf9 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 @@ -1,6 +1,11 @@ package ru.gravit.launcher.events.request; -public class LauncherRequestEvent { +import ru.gravit.utils.event.EventInterface; + +import java.util.UUID; + +public class LauncherRequestEvent implements EventInterface { + private static final UUID uuid = UUID.fromString("d54cc12a-4f59-4f23-9b10-f527fdd2e38f"); public String type = "success"; public String requesttype = "launcherUpdate"; public String url; @@ -11,4 +16,8 @@ public LauncherRequestEvent(boolean needUpdate, String url) { } public boolean needUpdate; + @Override + public UUID getUUID() { + return uuid; + } } 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 5284749f..c0cdd5dd 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 @@ -1,9 +1,13 @@ package ru.gravit.launcher.events.request; import ru.gravit.launcher.profiles.PlayerProfile; +import ru.gravit.utils.event.EventInterface; -public class ProfileByUUIDRequestEvent +import java.util.UUID; + +public class ProfileByUUIDRequestEvent implements EventInterface { + private static final UUID uuid = UUID.fromString("b9014cf3-4b95-4d38-8c5f-867f190a18a0"); String requesttype = "profileByUUID"; String error; PlayerProfile playerProfile; @@ -11,4 +15,8 @@ public class ProfileByUUIDRequestEvent public ProfileByUUIDRequestEvent(PlayerProfile playerProfile) { this.playerProfile = playerProfile; } + @Override + public UUID getUUID() { + return uuid; + } } 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 0347cd90..ff836a30 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 @@ -1,9 +1,13 @@ package ru.gravit.launcher.events.request; import ru.gravit.launcher.profiles.PlayerProfile; +import ru.gravit.utils.event.EventInterface; -public class ProfileByUsernameRequestEvent +import java.util.UUID; + +public class ProfileByUsernameRequestEvent implements EventInterface { + private static final UUID uuid = UUID.fromString("06204302-ff6b-4779-b97d-541e3bc39aa1"); String requesttype = "profileByUsername"; String error; PlayerProfile playerProfile; @@ -11,4 +15,8 @@ public class ProfileByUsernameRequestEvent public ProfileByUsernameRequestEvent(PlayerProfile playerProfile) { this.playerProfile = playerProfile; } + @Override + public UUID getUUID() { + return uuid; + } } 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 de2d70f6..1ce300ae 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 @@ -1,11 +1,14 @@ package ru.gravit.launcher.events.request; import ru.gravit.launcher.profiles.ClientProfile; +import ru.gravit.utils.event.EventInterface; import java.util.List; +import java.util.UUID; -public class ProfilesRequestEvent +public class ProfilesRequestEvent implements EventInterface { + private static final UUID uuid = UUID.fromString("2f26fbdf-598a-46dd-92fc-1699c0e173b1"); List profiles; public ProfilesRequestEvent(List profiles) { @@ -14,4 +17,8 @@ public ProfilesRequestEvent(List profiles) { String requesttype = "profilesList"; String error; + @Override + public UUID getUUID() { + return uuid; + } } 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 5ec26e3c..c3a1e761 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 @@ -1,8 +1,12 @@ package ru.gravit.launcher.events.request; import ru.gravit.launcher.hasher.HashedDir; +import ru.gravit.utils.event.EventInterface; -public class UpdateListRequestEvent { +import java.util.UUID; + +public class UpdateListRequestEvent implements EventInterface { + private static final UUID uuid = UUID.fromString("5fa836ae-6b61-401c-96ac-d8396f07ec6b"); public final String type; public final String requesttype; public final HashedDir dir; @@ -12,4 +16,8 @@ public UpdateListRequestEvent(HashedDir dir) { type = "success"; requesttype = "updateList"; } + @Override + public UUID getUUID() { + return uuid; + } } From 92cb0b06286a28b6cf749416019082395c0d6d74 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 28 Jan 2019 23:08:51 +0700 Subject: [PATCH 10/14] =?UTF-8?q?[FEATURE]=20=D0=9A=D0=BB=D0=B8=D0=B5?= =?UTF-8?q?=D0=BD=D1=82=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=BE=D1=81=D0=BD=D0=BE=D0=B2=D0=B5=20notifyAll?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../request/websockets/ClientJSONPoint.java | 7 +-- .../websockets/ClientWebSocketService.java | 44 +++++++++++++------ .../websockets/JsonRequestAdapter.java | 2 +- .../request/websockets/JsonResultAdapter.java | 35 +++++++++++++++ .../request/websockets/ResultInterface.java | 2 +- .../request/websockets/WaitEventHandler.java | 28 ++++++++++++ 6 files changed, 96 insertions(+), 22 deletions(-) create mode 100644 LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/JsonResultAdapter.java create mode 100644 LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WaitEventHandler.java diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientJSONPoint.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientJSONPoint.java index eb4c9aa0..1d6c7ff0 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientJSONPoint.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientJSONPoint.java @@ -25,11 +25,6 @@ @ClientEndpoint public class ClientJSONPoint { public Session session = null; - private ClientWebSocketService service; - - public void setService(ClientWebSocketService service) { - this.service = service; - } @OnOpen public void onOpen(final Session session_r) { @@ -44,7 +39,7 @@ public void processError(final Throwable t) { @OnMessage public void processMessage(Reader message) { - service.processMessage(message); + } public void send(String js) throws IOException { diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientWebSocketService.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientWebSocketService.java index 5ce34a4e..6c770a25 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientWebSocketService.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientWebSocketService.java @@ -8,35 +8,41 @@ import java.io.IOException; import java.io.Reader; import java.util.HashMap; +import java.util.HashSet; -public class ClientWebSocketService { +public class ClientWebSocketService extends ClientJSONPoint { public final GsonBuilder gsonBuilder; public final Gson gson; - public final ClientJSONPoint point; - private HashMap> requests; - private HashMap> results; + private HashMap> requests; + private HashMap> results; + private HashSet handlers; - public ClientWebSocketService(GsonBuilder gsonBuilder, ClientJSONPoint point) { + public ClientWebSocketService(GsonBuilder gsonBuilder) { requests = new HashMap<>(); results = new HashMap<>(); + handlers = new HashSet<>(); this.gsonBuilder = gsonBuilder; gsonBuilder.registerTypeAdapter(RequestInterface.class, new JsonRequestAdapter(this)); gsonBuilder.registerTypeAdapter(HashedEntry.class, new HashedEntryAdapter()); this.gson = gsonBuilder.create(); - this.point = point; - point.setService(this); } - + @Override public void processMessage(Reader reader) { ResultInterface result = gson.fromJson(reader, ResultInterface.class); - result.process(); + for(EventHandler handler : handlers) + { + handler.process(result); + } } - public Class getRequestClass(String key) { + public Class getRequestClass(String key) { return requests.get(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); } @@ -44,7 +50,7 @@ public void registerRequests() { } - public void registerResult(String key, Class clazz) { + public void registerResult(String key, Class clazz) { results.put(key, clazz); } @@ -52,11 +58,21 @@ public void registerResults() { } + public void registerHandler(EventHandler eventHandler) + { + handlers.add(eventHandler); + } + public void sendObjectAsync(Object obj) throws IOException { - point.sendAsync(gson.toJson(obj)); + sendAsync(gson.toJson(obj)); } public void sendObject(Object obj) throws IOException { - point.send(gson.toJson(obj)); + send(gson.toJson(obj)); + } + @FunctionalInterface + public interface EventHandler + { + void process(ResultInterface resultInterface); } } diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/JsonRequestAdapter.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/JsonRequestAdapter.java index da6d860d..be546079 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/JsonRequestAdapter.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/JsonRequestAdapter.java @@ -15,7 +15,7 @@ public JsonRequestAdapter(ClientWebSocketService service) { @Override public RequestInterface 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); return (RequestInterface) context.deserialize(json, cls); diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/JsonResultAdapter.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/JsonResultAdapter.java new file mode 100644 index 00000000..babe8b78 --- /dev/null +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/JsonResultAdapter.java @@ -0,0 +1,35 @@ +package ru.gravit.launcher.request.websockets; + +import com.google.gson.*; +import ru.gravit.launcher.request.update.LauncherRequest; + +import java.lang.reflect.Type; + +public class JsonResultAdapter implements JsonSerializer, JsonDeserializer { + private final ClientWebSocketService service; + private static final String PROP_NAME = "type"; + + public JsonResultAdapter(ClientWebSocketService service) { + this.service = service; + } + + @Override + public ResultInterface deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString(); + Class cls = service.getResultClass(typename); + + + return (ResultInterface) context.deserialize(json, cls); + } + + @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; + } +} diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ResultInterface.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ResultInterface.java index bc30c1f0..57e7d2b5 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ResultInterface.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ResultInterface.java @@ -1,5 +1,5 @@ package ru.gravit.launcher.request.websockets; public interface ResultInterface { - void process(); + String getType(); } diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WaitEventHandler.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WaitEventHandler.java new file mode 100644 index 00000000..364e7299 --- /dev/null +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WaitEventHandler.java @@ -0,0 +1,28 @@ +package ru.gravit.launcher.request.websockets; + +import java.util.HashSet; + +public class WaitEventHandler implements ClientWebSocketService.EventHandler { + public HashSet requests; + @Override + public void process(ResultInterface result) { + for(ResultEvent r : requests) + { + if(r.type.equals(result.getType())) + { + synchronized (r) + { + r.result = result; + r.ready = true; + r.notifyAll(); + } + } + } + } + public class ResultEvent + { + public ResultInterface result; + public String type; + public boolean ready; + } +} From 872698829111705e1585a6fcdba957bb841ca7a8 Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 28 Jan 2019 23:14:13 +0700 Subject: [PATCH 11/14] =?UTF-8?q?[FEATURE]=20=D0=A0=D0=B5=D0=B0=D0=BB?= =?UTF-8?q?=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20ResultInterface=20=D0=BA?= =?UTF-8?q?=D0=BB=D0=B0=D1=81=D1=81=D0=B0=D0=BC=D0=B8=20RequestEvent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../request/websockets/ClientWebSocketService.java | 1 + .../launcher/request/websockets/JsonResultAdapter.java | 2 +- .../launcher/request/websockets/WaitEventHandler.java | 2 ++ .../launcher/events/request/AuthRequestEvent.java | 8 +++++++- .../request/BatchProfileByUsernameRequestEvent.java | 8 +++++++- .../launcher/events/request/CheckServerEvent.java | 8 +++++++- .../events/request/JoinServerRequestEvent.java | 10 ++++++++-- .../launcher/events/request/LauncherRequestEvent.java | 10 ++++++++-- .../events/request/ProfileByUUIDRequestEvent.java | 8 +++++++- .../events/request/ProfileByUsernameRequestEvent.java | 8 +++++++- .../launcher/events/request/ProfilesRequestEvent.java | 10 ++++++++-- .../events/request/UpdateListRequestEvent.java | 8 +++++++- .../ru/gravit/launcher/request}/ResultInterface.java | 2 +- 13 files changed, 71 insertions(+), 14 deletions(-) rename {LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets => libLauncher/src/main/java/ru/gravit/launcher/request}/ResultInterface.java (56%) diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientWebSocketService.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientWebSocketService.java index 6c770a25..b343e34b 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientWebSocketService.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ClientWebSocketService.java @@ -4,6 +4,7 @@ import com.google.gson.GsonBuilder; import ru.gravit.launcher.hasher.HashedEntry; import ru.gravit.launcher.hasher.HashedEntryAdapter; +import ru.gravit.launcher.request.ResultInterface; import java.io.IOException; import java.io.Reader; diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/JsonResultAdapter.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/JsonResultAdapter.java index babe8b78..1ddd605d 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/JsonResultAdapter.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/JsonResultAdapter.java @@ -1,7 +1,7 @@ package ru.gravit.launcher.request.websockets; import com.google.gson.*; -import ru.gravit.launcher.request.update.LauncherRequest; +import ru.gravit.launcher.request.ResultInterface; import java.lang.reflect.Type; diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WaitEventHandler.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WaitEventHandler.java index 364e7299..4dd1fc61 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WaitEventHandler.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WaitEventHandler.java @@ -1,5 +1,7 @@ package ru.gravit.launcher.request.websockets; +import ru.gravit.launcher.request.ResultInterface; + import java.util.HashSet; public class WaitEventHandler implements ClientWebSocketService.EventHandler { diff --git a/libLauncher/src/main/java/ru/gravit/launcher/events/request/AuthRequestEvent.java b/libLauncher/src/main/java/ru/gravit/launcher/events/request/AuthRequestEvent.java index 4610afa6..c378c916 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/events/request/AuthRequestEvent.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/events/request/AuthRequestEvent.java @@ -2,11 +2,12 @@ import ru.gravit.launcher.ClientPermissions; import ru.gravit.launcher.profiles.PlayerProfile; +import ru.gravit.launcher.request.ResultInterface; import ru.gravit.utils.event.EventInterface; import java.util.UUID; -public class AuthRequestEvent implements EventInterface { +public class AuthRequestEvent implements EventInterface, ResultInterface { private static final UUID uuid = UUID.fromString("77e1bfd7-adf9-4f5d-87d6-a7dd068deb74"); public AuthRequestEvent() { } @@ -20,4 +21,9 @@ public AuthRequestEvent() { public UUID getUUID() { return uuid; } + + @Override + public String getType() { + return "auth"; + } } 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 cf121936..f048fb56 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 @@ -1,11 +1,12 @@ package ru.gravit.launcher.events.request; import ru.gravit.launcher.profiles.PlayerProfile; +import ru.gravit.launcher.request.ResultInterface; import ru.gravit.utils.event.EventInterface; import java.util.UUID; -public class BatchProfileByUsernameRequestEvent implements EventInterface +public class BatchProfileByUsernameRequestEvent implements EventInterface, ResultInterface { private static final UUID uuid = UUID.fromString("c1d6729e-be2c-48cc-b5ae-af8c012232c3"); public String requesttype = "batchProfileByUsername"; @@ -15,4 +16,9 @@ public class BatchProfileByUsernameRequestEvent implements EventInterface public UUID getUUID() { return uuid; } + + @Override + public String getType() { + return "batchProfileByUsername"; + } } 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 3b2fbcb0..227bde2b 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 @@ -1,11 +1,12 @@ package ru.gravit.launcher.events.request; import ru.gravit.launcher.profiles.PlayerProfile; +import ru.gravit.launcher.request.ResultInterface; import ru.gravit.utils.event.EventInterface; import java.util.UUID; -public class CheckServerEvent implements EventInterface { +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"; @@ -15,4 +16,9 @@ public class CheckServerEvent implements EventInterface { public UUID getUUID() { return _uuid; } + + @Override + public String getType() { + return "checkServe"; + } } 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 674103ea..5bc25436 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 @@ -1,13 +1,14 @@ package ru.gravit.launcher.events.request; +import ru.gravit.launcher.request.ResultInterface; import ru.gravit.utils.event.EventInterface; import java.util.UUID; -public class JoinServerRequestEvent implements EventInterface { +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 = "checkServer"; + public String requesttype = "joinServer"; public JoinServerRequestEvent(boolean allow) { this.allow = allow; @@ -18,4 +19,9 @@ public JoinServerRequestEvent(boolean allow) { public UUID getUUID() { return uuid; } + + @Override + public String getType() { + return "joinServer"; + } } 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 52c69bf9..25660de4 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 @@ -1,13 +1,14 @@ package ru.gravit.launcher.events.request; +import ru.gravit.launcher.request.ResultInterface; import ru.gravit.utils.event.EventInterface; import java.util.UUID; -public class LauncherRequestEvent implements EventInterface { +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 = "launcherUpdate"; + public String requesttype = "launcher"; public String url; public LauncherRequestEvent(boolean needUpdate, String url) { @@ -20,4 +21,9 @@ public LauncherRequestEvent(boolean needUpdate, String url) { public UUID getUUID() { return uuid; } + + @Override + public String getType() { + return "launcher"; + } } 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 c0cdd5dd..537b7e62 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 @@ -1,11 +1,12 @@ package ru.gravit.launcher.events.request; import ru.gravit.launcher.profiles.PlayerProfile; +import ru.gravit.launcher.request.ResultInterface; import ru.gravit.utils.event.EventInterface; import java.util.UUID; -public class ProfileByUUIDRequestEvent implements EventInterface +public class ProfileByUUIDRequestEvent implements EventInterface, ResultInterface { private static final UUID uuid = UUID.fromString("b9014cf3-4b95-4d38-8c5f-867f190a18a0"); String requesttype = "profileByUUID"; @@ -19,4 +20,9 @@ public ProfileByUUIDRequestEvent(PlayerProfile playerProfile) { public UUID getUUID() { return uuid; } + + @Override + public String getType() { + return "profileByUUID"; + } } 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 ff836a30..a62c2805 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 @@ -1,11 +1,12 @@ package ru.gravit.launcher.events.request; import ru.gravit.launcher.profiles.PlayerProfile; +import ru.gravit.launcher.request.ResultInterface; import ru.gravit.utils.event.EventInterface; import java.util.UUID; -public class ProfileByUsernameRequestEvent implements EventInterface +public class ProfileByUsernameRequestEvent implements EventInterface, ResultInterface { private static final UUID uuid = UUID.fromString("06204302-ff6b-4779-b97d-541e3bc39aa1"); String requesttype = "profileByUsername"; @@ -19,4 +20,9 @@ public ProfileByUsernameRequestEvent(PlayerProfile playerProfile) { public UUID getUUID() { return uuid; } + + @Override + public String getType() { + return "profileByUsername"; + } } 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 1ce300ae..8a53513c 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 @@ -1,12 +1,13 @@ package ru.gravit.launcher.events.request; import ru.gravit.launcher.profiles.ClientProfile; +import ru.gravit.launcher.request.ResultInterface; import ru.gravit.utils.event.EventInterface; import java.util.List; import java.util.UUID; -public class ProfilesRequestEvent implements EventInterface +public class ProfilesRequestEvent implements EventInterface, ResultInterface { private static final UUID uuid = UUID.fromString("2f26fbdf-598a-46dd-92fc-1699c0e173b1"); List profiles; @@ -15,10 +16,15 @@ public ProfilesRequestEvent(List profiles) { this.profiles = profiles; } - String requesttype = "profilesList"; + String requesttype = "profiles"; String error; @Override public UUID getUUID() { return uuid; } + + @Override + public String getType() { + return "profiles"; + } } 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 c3a1e761..abd8f254 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 @@ -1,11 +1,12 @@ package ru.gravit.launcher.events.request; import ru.gravit.launcher.hasher.HashedDir; +import ru.gravit.launcher.request.ResultInterface; import ru.gravit.utils.event.EventInterface; import java.util.UUID; -public class UpdateListRequestEvent implements EventInterface { +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; @@ -20,4 +21,9 @@ public UpdateListRequestEvent(HashedDir dir) { public UUID getUUID() { return uuid; } + + @Override + public String getType() { + return "updateList"; + } } diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ResultInterface.java b/libLauncher/src/main/java/ru/gravit/launcher/request/ResultInterface.java similarity index 56% rename from LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ResultInterface.java rename to libLauncher/src/main/java/ru/gravit/launcher/request/ResultInterface.java index 57e7d2b5..814c26a6 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/ResultInterface.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/request/ResultInterface.java @@ -1,4 +1,4 @@ -package ru.gravit.launcher.request.websockets; +package ru.gravit.launcher.request; public interface ResultInterface { String getType(); From dd4f97313e0fa1b625d70933ce25c1180f65975e Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 28 Jan 2019 23:21:24 +0700 Subject: [PATCH 12/14] =?UTF-8?q?[FEATURE]=20=D0=98=D1=81=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20type?= =?UTF-8?q?=20=D0=B2=D0=BC=D0=B5=D1=81=D1=82=D0=BE=20requesttype?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../socket/websocket/WebSocketService.java | 3 +++ .../BatchProfileByUsernameRequestEvent.java | 1 - .../events/request/CheckServerEvent.java | 1 - .../request/JoinServerRequestEvent.java | 1 - .../events/request/LauncherRequestEvent.java | 1 - .../request/ProfileByUUIDRequestEvent.java | 1 - .../ProfileByUsernameRequestEvent.java | 1 - .../events/request/ProfilesRequestEvent.java | 1 - .../request/UpdateListRequestEvent.java | 2 -- .../request/JsonResultSerializeAdapter.java | 21 +++++++++++++++++++ 10 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 libLauncher/src/main/java/ru/gravit/launcher/request/JsonResultSerializeAdapter.java 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; + } +} From 0d804a0558dcab54dc785801146660a632a04ede Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 28 Jan 2019 23:29:54 +0700 Subject: [PATCH 13/14] =?UTF-8?q?[FEATURE]=20=D0=9C=D0=BE=D1=81=D1=82=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D1=81=D1=82=D0=B0=D1=80=D1=8B=D1=85=20Req?= =?UTF-8?q?uest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../websockets/LegacyRequestBridge.java | 23 +++++++++++++++++++ .../request/websockets/WaitEventHandler.java | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/LegacyRequestBridge.java diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/LegacyRequestBridge.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/LegacyRequestBridge.java new file mode 100644 index 00000000..03659c42 --- /dev/null +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/LegacyRequestBridge.java @@ -0,0 +1,23 @@ +package ru.gravit.launcher.request.websockets; + +import ru.gravit.launcher.request.ResultInterface; + +import java.io.IOException; + +public class LegacyRequestBridge { + public static WaitEventHandler waitEventHandler = new WaitEventHandler(); + public static ClientWebSocketService service; + public static ResultInterface sendRequest(RequestInterface request) throws IOException, InterruptedException { + WaitEventHandler.ResultEvent e = new WaitEventHandler.ResultEvent(); + e.type = request.getType(); + waitEventHandler.requests.add(e); + service.sendObject(request); + while(!e.ready) + { + e.wait(); + } + ResultInterface result = e.result; + waitEventHandler.requests.remove(e); + return result; + } +} diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WaitEventHandler.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WaitEventHandler.java index 4dd1fc61..45aa9f78 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WaitEventHandler.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/WaitEventHandler.java @@ -21,7 +21,7 @@ public void process(ResultInterface result) { } } } - public class ResultEvent + public static class ResultEvent { public ResultInterface result; public String type; From 9adf69932c94265b8c4d525e4864a0411095104b Mon Sep 17 00:00:00 2001 From: Gravit Date: Tue, 29 Jan 2019 22:31:41 +0700 Subject: [PATCH 14/14] =?UTF-8?q?[FIX]=20=D0=A4=D0=B8=D0=BA=D1=81=20=D1=81?= =?UTF-8?q?=D0=B8=D0=BD=D1=85=D1=80=D0=BE=D0=BD=D0=B8=D0=B7=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D0=B8=20=D0=B2=20LegacyRequestBridge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launcher/request/websockets/LegacyRequestBridge.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/LegacyRequestBridge.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/LegacyRequestBridge.java index 03659c42..d6c9aa06 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/LegacyRequestBridge.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/websockets/LegacyRequestBridge.java @@ -14,7 +14,10 @@ public static ResultInterface sendRequest(RequestInterface request) throws IOExc service.sendObject(request); while(!e.ready) { - e.wait(); + synchronized(e) + { + e.wait(); + } } ResultInterface result = e.result; waitEventHandler.requests.remove(e);