From 438133bce7ade25e91fe268b6deb06da9f812a2c Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 26 Sep 2020 20:13:52 +0700 Subject: [PATCH] =?UTF-8?q?[FIX]=20=D0=9F=D0=BE=D1=82=D0=B5=D0=BD=D1=86?= =?UTF-8?q?=D0=B8=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B=D0=B5=20NPE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../socket/response/auth/AuthResponse.java | 7 +++++++ .../socket/response/auth/JoinServerResponse.java | 4 ++++ .../response/profile/BatchProfileByUsername.java | 16 +++++++++++----- .../socket/response/update/UpdateResponse.java | 4 ++++ 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java index 7d1debd9..1a13ea04 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java @@ -57,6 +57,13 @@ public void execute(ChannelHandlerContext ctx, Client clientData) throws Excepti throw new AuthException("Password decryption error"); } } + if(clientData.isAuth) { + if(LogHelper.isDevEnabled()) { + LogHelper.warning("Client %s double auth", clientData.username == null ? ip : clientData.username); + } + sendError("You are already logged in"); + return; + } AuthProviderPair pair; if (auth_id == null || auth_id.isEmpty()) pair = server.config.getAuthProviderPair(); else pair = server.config.getAuthProviderPair(auth_id); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/JoinServerResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/JoinServerResponse.java index 503f1474..1b67931b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/JoinServerResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/JoinServerResponse.java @@ -25,6 +25,10 @@ public void execute(ChannelHandlerContext ctx, Client client) { sendError("Permissions denied"); return; } + if(username == null || accessToken == null || serverID == null) { + sendError("Invalid request"); + return; + } boolean success; try { server.authHookManager.joinServerHook.hook(this, client); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/BatchProfileByUsername.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/BatchProfileByUsername.java index 198f724e..61f44ba0 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/BatchProfileByUsername.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/BatchProfileByUsername.java @@ -3,6 +3,7 @@ import io.netty.channel.ChannelHandlerContext; import pro.gravit.launcher.events.request.BatchProfileByUsernameRequestEvent; import pro.gravit.launcher.profiles.PlayerProfile; +import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.SimpleResponse; import pro.gravit.utils.helper.LogHelper; @@ -20,14 +21,19 @@ public String getType() { @Override public void execute(ChannelHandlerContext ctx, Client client) throws Exception { BatchProfileByUsernameRequestEvent result = new BatchProfileByUsernameRequestEvent(); + if(list == null) { + sendError("Invalid request"); + return; + } result.playerProfiles = new PlayerProfile[list.length]; for (int i = 0; i < list.length; ++i) { UUID uuid; - if (client.auth == null) { - LogHelper.warning("Client auth is null. Using default."); - uuid = server.config.getAuthProviderPair().handler.usernameToUUID(list[i].username); - } else uuid = client.auth.handler.usernameToUUID(list[i].username); - result.playerProfiles[i] = ProfileByUUIDResponse.getProfile(uuid, list[i].username, list[i].client, client.auth.textureProvider); + AuthProviderPair pair = client.auth; + if (pair == null) { + pair = server.config.getAuthProviderPair(); + } + uuid = pair.handler.usernameToUUID(list[i].username); + result.playerProfiles[i] = ProfileByUUIDResponse.getProfile(uuid, list[i].username, list[i].client, pair.textureProvider); } sendResult(result); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/UpdateResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/UpdateResponse.java index 2dd915f2..d278e82a 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/UpdateResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/UpdateResponse.java @@ -23,6 +23,10 @@ public void execute(ChannelHandlerContext ctx, Client client) { sendError("Access denied"); return; } + if(dirName == null) { + sendError("Invalid request"); + return; + } HashedDir dir = server.updatesDirMap.get(dirName); if (dir == null) { sendError(String.format("Directory %s not found", dirName));