From 2b117f6717a39263f2a8ffd6ce237c3ad5f7e526 Mon Sep 17 00:00:00 2001 From: Gravita Date: Thu, 17 Mar 2022 22:55:30 +0700 Subject: [PATCH] [FEATURE] UserSupportProperties extension --- .../auth/core/HttpAuthCoreProvider.java | 25 ++++++++++++++++- .../user/UserSupportProperties.java | 7 +++++ .../launchserver/manangers/AuthManager.java | 28 +++++++++++-------- .../launcher/profiles/PlayerProfile.java | 12 ++++++++ 4 files changed, 59 insertions(+), 13 deletions(-) create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/user/UserSupportProperties.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/HttpAuthCoreProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/HttpAuthCoreProvider.java index 0b0fd659..8c3b0402 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/HttpAuthCoreProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/HttpAuthCoreProvider.java @@ -10,6 +10,7 @@ import pro.gravit.launchserver.HttpRequester; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.auth.AuthException; +import pro.gravit.launchserver.auth.core.interfaces.user.UserSupportProperties; import pro.gravit.launchserver.auth.core.interfaces.user.UserSupportTextures; import pro.gravit.launchserver.helper.HttpHelper; import pro.gravit.launchserver.manangers.AuthManager; @@ -18,7 +19,9 @@ import pro.gravit.utils.helper.CommonHelper; import java.io.IOException; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.UUID; public class HttpAuthCoreProvider extends AuthCoreProvider { @@ -243,7 +246,7 @@ public RefreshTokenRequest(String refreshToken, AuthResponse.AuthContext context } } - public static class HttpUser implements User, UserSupportTextures { + public static class HttpUser implements User, UserSupportTextures, UserSupportProperties { private String username; private UUID uuid; private String serverId; @@ -251,6 +254,7 @@ public static class HttpUser implements User, UserSupportTextures { private ClientPermissions permissions; private Texture skin; private Texture cloak; + private Map properties; public HttpUser() { } @@ -273,6 +277,17 @@ public HttpUser(String username, UUID uuid, String serverId, String accessToken, this.cloak = cloak; } + public HttpUser(String username, UUID uuid, String serverId, String accessToken, ClientPermissions permissions, Texture skin, Texture cloak, Map properties) { + this.username = username; + this.uuid = uuid; + this.serverId = serverId; + this.accessToken = accessToken; + this.permissions = permissions; + this.skin = skin; + this.cloak = cloak; + this.properties = properties; + } + @Override public String getUsername() { return username; @@ -307,6 +322,14 @@ public Texture getSkinTexture() { public Texture getCloakTexture() { return cloak; } + + @Override + public Map getProperties() { + if(properties == null) { + return new HashMap<>(); + } + return properties; + } } public static class HttpUserSession implements UserSession { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/user/UserSupportProperties.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/user/UserSupportProperties.java new file mode 100644 index 00000000..7fb0e6b2 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/user/UserSupportProperties.java @@ -0,0 +1,7 @@ +package pro.gravit.launchserver.auth.core.interfaces.user; + +import java.util.Map; + +public interface UserSupportProperties { + Map getProperties(); +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/AuthManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/AuthManager.java index 1da9a340..5fafa6bc 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/AuthManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/AuthManager.java @@ -16,6 +16,7 @@ import pro.gravit.launchserver.auth.core.AuthCoreProvider; import pro.gravit.launchserver.auth.core.User; import pro.gravit.launchserver.auth.core.UserSession; +import pro.gravit.launchserver.auth.core.interfaces.user.UserSupportProperties; import pro.gravit.launchserver.auth.core.interfaces.user.UserSupportTextures; import pro.gravit.launchserver.auth.texture.TextureProvider; import pro.gravit.launchserver.socket.Client; @@ -26,10 +27,7 @@ import javax.crypto.Cipher; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.UUID; +import java.util.*; public class AuthManager { private transient final LaunchServer server; @@ -206,7 +204,7 @@ public PlayerProfile getPlayerProfile(Client client) { if (playerProfile != null) return playerProfile; } if (client.auth.textureProvider != null) { - return getPlayerProfile(client.uuid, client.username, client.profile == null ? null : client.profile.getTitle(), client.auth.textureProvider); + return getPlayerProfile(client.uuid, client.username, client.profile == null ? null : client.profile.getTitle(), client.auth.textureProvider, new HashMap<>()); } // Return combined profile return new PlayerProfile(client.uuid, client.username, null, null); @@ -229,7 +227,7 @@ public PlayerProfile getPlayerProfile(AuthProviderPair pair, String username, Cl return null; } if (pair.textureProvider != null) { - return getPlayerProfile(uuid, username, profile == null ? null : profile.getTitle(), pair.textureProvider); + return getPlayerProfile(uuid, username, profile == null ? null : profile.getTitle(), pair.textureProvider, new HashMap<>()); } return new PlayerProfile(uuid, username, null, null); } @@ -251,27 +249,33 @@ public PlayerProfile getPlayerProfile(AuthProviderPair pair, UUID uuid, ClientPr return null; } if (pair.textureProvider != null) { - return getPlayerProfile(uuid, username, profile == null ? null : profile.getTitle(), pair.textureProvider); + return getPlayerProfile(uuid, username, profile == null ? null : profile.getTitle(), pair.textureProvider, new HashMap<>()); } - return new PlayerProfile(uuid, username, null, null); + return new PlayerProfile(uuid, username, null, null, new HashMap<>()); } public PlayerProfile getPlayerProfile(AuthProviderPair pair, User user) { + Map properties; + if(user instanceof UserSupportProperties userSupportProperties) { + properties = userSupportProperties.getProperties(); + } else { + properties = new HashMap<>(); + } if (user instanceof UserSupportTextures) { - return new PlayerProfile(user.getUUID(), user.getUsername(), ((UserSupportTextures) user).getSkinTexture(), ((UserSupportTextures) user).getCloakTexture()); + return new PlayerProfile(user.getUUID(), user.getUsername(), ((UserSupportTextures) user).getSkinTexture(), ((UserSupportTextures) user).getCloakTexture(), properties); } if (pair.textureProvider == null) { throw new NullPointerException("TextureProvider not found"); } - return getPlayerProfile(user.getUUID(), user.getUsername(), "", pair.textureProvider); + return getPlayerProfile(user.getUUID(), user.getUsername(), "", pair.textureProvider, properties); } - private PlayerProfile getPlayerProfile(UUID uuid, String username, String client, TextureProvider textureProvider) { + private PlayerProfile getPlayerProfile(UUID uuid, String username, String client, TextureProvider textureProvider, Map properties) { // Get skin texture TextureProvider.SkinAndCloakTextures textures = textureProvider.getTextures(uuid, username, client); // Return combined profile - return new PlayerProfile(uuid, username, textures.skin, textures.cloak); + return new PlayerProfile(uuid, username, textures.skin, textures.cloak, properties); } public AuthRequest.AuthPasswordInterface decryptPassword(AuthRequest.AuthPasswordInterface password) throws AuthException { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/PlayerProfile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/PlayerProfile.java index 09ebeac1..c3ca799b 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/PlayerProfile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/PlayerProfile.java @@ -3,6 +3,8 @@ import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.VerifyHelper; +import java.util.HashMap; +import java.util.Map; import java.util.Objects; import java.util.UUID; @@ -11,6 +13,7 @@ public final class PlayerProfile { public final UUID uuid; public final String username; public final Texture skin, cloak; + public final Map properties; public PlayerProfile(UUID uuid, String username, Texture skin, Texture cloak) { @@ -18,6 +21,15 @@ public PlayerProfile(UUID uuid, String username, Texture skin, Texture cloak) { this.username = username; this.skin = skin; this.cloak = cloak; + this.properties = new HashMap<>(); + } + + public PlayerProfile(UUID uuid, String username, Texture skin, Texture cloak, Map properties) { + this.uuid = Objects.requireNonNull(uuid, "uuid"); + this.username = username; + this.skin = skin; + this.cloak = cloak; + this.properties = properties; } public static PlayerProfile newOfflineProfile(String username) {