From d2f34ced287b825bbaef03bc0d0baaf175476b58 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Mon, 27 Nov 2023 22:41:49 +0700 Subject: [PATCH] [FEATURE][EXPERIMENTAL] Add ClientServer and AuthService to ServerWrapper, extended check server, remove deprecated interfaces --- .../auth/core/AbstractSQLCoreProvider.java | 22 ++++++---- .../auth/core/AuthCoreProvider.java | 23 ----------- .../auth/core/MySQLCoreProvider.java | 41 ++++++++++++++----- .../provider/AuthSupportAssetUpload.java | 2 +- .../AuthSupportExtendedCheckServer.java | 11 +++++ .../provider/AuthSupportHardware.java | 5 --- .../AuthSupportRemoteClientAccess.java | 9 ---- .../session/UserSessionSupportHardware.java | 8 ++++ .../session/UserSessionSupportProperties.java | 7 ++++ .../interfaces/user/UserSupportHardware.java | 7 ---- .../launchserver/manangers/AuthManager.java | 27 +++++++++--- .../response/auth/CheckServerResponse.java | 15 ++++++- .../auth/GetAvailabilityAuthResponse.java | 1 - .../pro/gravit/launcher/api/AuthService.java | 9 ++++ .../gravit/launcher/api/ClientService.java | 1 - .../pro/gravit/launcher/api/KeyService.java | 2 + .../request/CheckServerRequestEvent.java | 7 ++++ .../request/auth/CheckServerRequest.java | 14 +++++++ .../client/ClientLauncherEntryPoint.java | 1 + .../gravit/launcher/server/ServerWrapper.java | 17 +++++--- build.gradle | 2 +- 21 files changed, 151 insertions(+), 80 deletions(-) create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportExtendedCheckServer.java delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportRemoteClientAccess.java create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/session/UserSessionSupportHardware.java create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/session/UserSessionSupportProperties.java delete mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/user/UserSupportHardware.java rename {LauncherClient => LauncherAPI}/src/main/java/pro/gravit/launcher/api/AuthService.java (69%) rename {LauncherClient => LauncherAPI}/src/main/java/pro/gravit/launcher/api/ClientService.java (92%) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AbstractSQLCoreProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AbstractSQLCoreProvider.java index 4028feeb..7306b88b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AbstractSQLCoreProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AbstractSQLCoreProvider.java @@ -108,7 +108,7 @@ public UserSession getUserSessionByOAuthAccessToken(String accessToken) throws O if (user == null) { return null; } - return new SQLUserSession(user); + return createSession(user); } catch (ExpiredJwtException e) { throw new OAuthAccessTokenExpired(); } catch (JwtException e) { @@ -133,13 +133,13 @@ public AuthManager.AuthReport refreshAccessToken(String refreshToken, AuthRespon return null; } var accessToken = LegacySessionHelper.makeAccessJwtTokenFromString(user, LocalDateTime.now(Clock.systemUTC()).plusSeconds(expireSeconds), server.keyAgreementManager.ecdsaPrivateKey); - return new AuthManager.AuthReport(null, accessToken, refreshToken, SECONDS.toMillis(expireSeconds), new SQLUserSession(user)); + return new AuthManager.AuthReport(null, accessToken, refreshToken, SECONDS.toMillis(expireSeconds), createSession(user)); } @Override public AuthManager.AuthReport authorize(String login, AuthResponse.AuthContext context, AuthRequest.AuthPasswordInterface password, boolean minecraftAccess) throws IOException { - SQLUser SQLUser = (SQLUser) getUserByLogin(login); - if (SQLUser == null) { + SQLUser user = (SQLUser) getUserByLogin(login); + if (user == null) { throw AuthException.userNotFound(); } if (context != null) { @@ -147,16 +147,16 @@ public AuthManager.AuthReport authorize(String login, AuthResponse.AuthContext c if (plainPassword == null) { throw AuthException.wrongPassword(); } - if (!passwordVerifier.check(SQLUser.password, plainPassword.password)) { + if (!passwordVerifier.check(user.password, plainPassword.password)) { throw AuthException.wrongPassword(); } } - SQLUserSession session = new SQLUserSession(SQLUser); - var accessToken = LegacySessionHelper.makeAccessJwtTokenFromString(SQLUser, LocalDateTime.now(Clock.systemUTC()).plusSeconds(expireSeconds), server.keyAgreementManager.ecdsaPrivateKey); - var refreshToken = SQLUser.username.concat(".").concat(LegacySessionHelper.makeRefreshTokenFromPassword(SQLUser.username, SQLUser.password, server.keyAgreementManager.legacySalt)); + SQLUserSession session = createSession(user); + var accessToken = LegacySessionHelper.makeAccessJwtTokenFromString(user, LocalDateTime.now(Clock.systemUTC()).plusSeconds(expireSeconds), server.keyAgreementManager.ecdsaPrivateKey); + var refreshToken = user.username.concat(".").concat(LegacySessionHelper.makeRefreshTokenFromPassword(user.username, user.password, server.keyAgreementManager.legacySalt)); if (minecraftAccess) { String minecraftAccessToken = SecurityHelper.randomStringToken(); - updateAuth(SQLUser, minecraftAccessToken); + updateAuth(user, minecraftAccessToken); return AuthManager.AuthReport.ofOAuthWithMinecraft(minecraftAccessToken, accessToken, refreshToken, SECONDS.toMillis(expireSeconds), session); } else { return AuthManager.AuthReport.ofOAuth(accessToken, refreshToken, SECONDS.toMillis(expireSeconds), session); @@ -299,6 +299,10 @@ private List queryPermissions(String sql, String value) throws SQLExcept } } + protected SQLUserSession createSession(SQLUser user) { + return new SQLUserSession(user); + } + public boolean isEnabledPermissions() { return permissionsPermissionColumn != null; } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AuthCoreProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AuthCoreProvider.java index 99805cc2..f1d8cf7d 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AuthCoreProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AuthCoreProvider.java @@ -16,7 +16,6 @@ import pro.gravit.launchserver.auth.core.interfaces.provider.AuthSupportGetAllUsers; import pro.gravit.launchserver.auth.core.interfaces.provider.AuthSupportHardware; import pro.gravit.launchserver.auth.core.interfaces.provider.AuthSupportRegistration; -import pro.gravit.launchserver.auth.core.interfaces.user.UserSupportHardware; import pro.gravit.launchserver.manangers.AuthManager; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.auth.AuthResponse; @@ -176,28 +175,6 @@ public void invoke(String... args) throws Exception { } } }); - map.put("getuserhardware", new SubCommand("[username]", "get hardware by username") { - @Override - public void invoke(String... args) throws Exception { - verifyArgs(args, 1); - User user = getUserByUUID(UUID.fromString(args[0])); - if (user == null) { - logger.info("User {} not found", args[0]); - } - UserSupportHardware hardware = instance.fetchUserHardware(user); - if (hardware == null) { - logger.error("Method fetchUserHardware return null"); - return; - } - UserHardware userHardware = hardware.getHardware(); - if (userHardware == null) { - logger.info("User {} not contains hardware info", args[0]); - } else { - logger.info("UserHardware: {}", userHardware); - logger.info("HardwareInfo(JSON): {}", Launcher.gsonManager.gson.toJson(userHardware.getHardwareInfo())); - } - } - }); map.put("findmulti", new SubCommand("[hardware id]", "get all users in one hardware id") { @Override public void invoke(String... args) throws Exception { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MySQLCoreProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MySQLCoreProvider.java index 28a95a42..ce093a2e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MySQLCoreProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MySQLCoreProvider.java @@ -7,7 +7,7 @@ import pro.gravit.launchserver.auth.SQLSourceConfig; import pro.gravit.launchserver.auth.core.interfaces.UserHardware; import pro.gravit.launchserver.auth.core.interfaces.provider.AuthSupportHardware; -import pro.gravit.launchserver.auth.core.interfaces.user.UserSupportHardware; +import pro.gravit.launchserver.auth.core.interfaces.session.UserSessionSupportHardware; import pro.gravit.utils.helper.IOHelper; import java.io.ByteArrayInputStream; @@ -260,6 +260,34 @@ public void unbanHardware(UserHardware hardware) { } } + @Override + protected SQLUserSession createSession(SQLUser user) { + return new MySQLUserSession(user); + } + + public class MySQLUserSession extends SQLUserSession implements UserSessionSupportHardware { + private transient MySQLUser mySQLUser; + protected transient MySQLUserHardware hardware; + + public MySQLUserSession(SQLUser user) { + super(user); + mySQLUser = (MySQLUser) user; + } + + @Override + public String getHardwareId() { + return mySQLUser.hwidId == 0 ? null : String.valueOf(mySQLUser.hwidId); + } + + @Override + public UserHardware getHardware() { + if(hardware == null) { + hardware = (MySQLUserHardware) getHardwareInfoById(String.valueOf(mySQLUser.hwidId)); + } + return hardware; + } + } + public static class MySQLUserHardware implements UserHardware { private final HardwareReportRequest.HardwareInfo hardwareInfo; private final long id; @@ -304,23 +332,14 @@ public String toString() { } } - public class MySQLUser extends SQLUser implements UserSupportHardware { + public class MySQLUser extends SQLUser { protected long hwidId; - protected transient MySQLUserHardware hardware; public MySQLUser(UUID uuid, String username, String accessToken, String serverId, String password, ClientPermissions permissions, long hwidId) { super(uuid, username, accessToken, serverId, password, permissions); this.hwidId = hwidId; } - @Override - public UserHardware getHardware() { - if (hardware != null) return hardware; - MySQLUserHardware result = (MySQLUserHardware) getHardwareInfoById(String.valueOf(hwidId)); - hardware = result; - return result; - } - @Override public String toString() { return "MySQLUser{" + diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportAssetUpload.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportAssetUpload.java index f738804f..f1978698 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportAssetUpload.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportAssetUpload.java @@ -9,7 +9,7 @@ import java.util.Set; @Feature(GetAssetUploadUrlRequestEvent.FEATURE_NAME) -public interface AuthSupportAssetUpload { +public interface AuthSupportAssetUpload extends AuthSupport { String getAssetUploadUrl(String name, User user); default AuthRequestEvent.OAuthRequestEvent getAssetUploadToken(String name, User user) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportExtendedCheckServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportExtendedCheckServer.java new file mode 100644 index 00000000..fb188782 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportExtendedCheckServer.java @@ -0,0 +1,11 @@ +package pro.gravit.launchserver.auth.core.interfaces.provider; + +import pro.gravit.launchserver.auth.core.User; +import pro.gravit.launchserver.auth.core.UserSession; +import pro.gravit.launchserver.socket.Client; + +import java.io.IOException; + +public interface AuthSupportExtendedCheckServer { + UserSession extendedCheckServer(Client client, String username, String serverID) throws IOException; +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportHardware.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportHardware.java index b3f1f761..943e4993 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportHardware.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportHardware.java @@ -4,7 +4,6 @@ import pro.gravit.launchserver.auth.core.User; import pro.gravit.launchserver.auth.core.UserSession; import pro.gravit.launchserver.auth.core.interfaces.UserHardware; -import pro.gravit.launchserver.auth.core.interfaces.user.UserSupportHardware; import pro.gravit.launchserver.helper.DamerauHelper; import java.util.Arrays; @@ -28,10 +27,6 @@ public interface AuthSupportHardware extends AuthSupport { void unbanHardware(UserHardware hardware); - default UserSupportHardware fetchUserHardware(User user) { - return (UserSupportHardware) user; - } - default void normalizeHardwareInfo(HardwareReportRequest.HardwareInfo hardwareInfo) { if (hardwareInfo.baseboardSerialNumber != null) hardwareInfo.baseboardSerialNumber = hardwareInfo.baseboardSerialNumber.trim(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportRemoteClientAccess.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportRemoteClientAccess.java deleted file mode 100644 index 6fa5d411..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportRemoteClientAccess.java +++ /dev/null @@ -1,9 +0,0 @@ -package pro.gravit.launchserver.auth.core.interfaces.provider; - -import java.util.List; - -public interface AuthSupportRemoteClientAccess { - String getClientApiUrl(); - - List getClientApiFeatures(); -} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/session/UserSessionSupportHardware.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/session/UserSessionSupportHardware.java new file mode 100644 index 00000000..8c8b06cf --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/session/UserSessionSupportHardware.java @@ -0,0 +1,8 @@ +package pro.gravit.launchserver.auth.core.interfaces.session; + +import pro.gravit.launchserver.auth.core.interfaces.UserHardware; + +public interface UserSessionSupportHardware { + String getHardwareId(); + UserHardware getHardware(); +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/session/UserSessionSupportProperties.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/session/UserSessionSupportProperties.java new file mode 100644 index 00000000..3bbda98c --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/session/UserSessionSupportProperties.java @@ -0,0 +1,7 @@ +package pro.gravit.launchserver.auth.core.interfaces.session; + +import java.util.Map; + +public interface UserSessionSupportProperties { + Map getProperties(); +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/user/UserSupportHardware.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/user/UserSupportHardware.java deleted file mode 100644 index a52da511..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/user/UserSupportHardware.java +++ /dev/null @@ -1,7 +0,0 @@ -package pro.gravit.launchserver.auth.core.interfaces.user; - -import pro.gravit.launchserver.auth.core.interfaces.UserHardware; - -public interface UserSupportHardware { - UserHardware getHardware(); -} 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 8c24e6d6..5b7c3c21 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.provider.AuthSupportExtendedCheckServer; import pro.gravit.launchserver.auth.core.interfaces.session.UserSessionSupportKeys; import pro.gravit.launchserver.auth.core.interfaces.user.UserSupportProperties; import pro.gravit.launchserver.auth.core.interfaces.user.UserSupportTextures; @@ -161,9 +162,16 @@ public UserSessionSupportKeys.ClientProfileKeys createClientProfileKeys(UUID pla public CheckServerReport checkServer(Client client, String username, String serverID) throws IOException { if (client.auth == null) return null; - User user = client.auth.core.checkServer(client, username, serverID); - if (user == null) return null; - else return CheckServerReport.ofUser(user, getPlayerProfile(client.auth, user)); + var supportExtended = client.auth.core.isSupport(AuthSupportExtendedCheckServer.class); + if(supportExtended != null) { + var session = supportExtended.extendedCheckServer(client, username, serverID); + if(session == null) return null; + return CheckServerReport.ofUserSession(session, getPlayerProfile(client.auth, session.getUser())); + } else { + var user = client.auth.core.checkServer(client, username, serverID); + if (user == null) return null; + return CheckServerReport.ofUser(user, getPlayerProfile(client.auth, user)); + } } public boolean joinServer(Client client, String username, UUID uuid, String accessToken, String serverID) throws IOException { @@ -322,20 +330,27 @@ public boolean accept(Client client, AuthProviderPair pair, String extendedToken public static class CheckServerReport { public UUID uuid; public User user; + public UserSession session; public PlayerProfile playerProfile; - public CheckServerReport(UUID uuid, User user, PlayerProfile playerProfile) { + public CheckServerReport(UUID uuid, User user, UserSession session, PlayerProfile playerProfile) { this.uuid = uuid; this.user = user; + this.session = session; this.playerProfile = playerProfile; } public static CheckServerReport ofUser(User user, PlayerProfile playerProfile) { - return new CheckServerReport(user.getUUID(), user, playerProfile); + return new CheckServerReport(user.getUUID(), user, null, playerProfile); + } + + public static CheckServerReport ofUserSession(UserSession session, PlayerProfile playerProfile) { + var user = session.getUser(); + return new CheckServerReport(user.getUUID(), user, session, playerProfile); } public static CheckServerReport ofUUID(UUID uuid, PlayerProfile playerProfile) { - return new CheckServerReport(uuid, null, playerProfile); + return new CheckServerReport(uuid, null, null, playerProfile); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/CheckServerResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/CheckServerResponse.java index 71f5a255..7795a9bb 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/CheckServerResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/CheckServerResponse.java @@ -5,6 +5,8 @@ import org.apache.logging.log4j.Logger; import pro.gravit.launcher.events.request.CheckServerRequestEvent; import pro.gravit.launchserver.auth.AuthException; +import pro.gravit.launchserver.auth.core.interfaces.session.UserSessionSupportHardware; +import pro.gravit.launchserver.auth.core.interfaces.session.UserSessionSupportProperties; import pro.gravit.launchserver.manangers.AuthManager; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.SimpleResponse; @@ -14,7 +16,9 @@ public class CheckServerResponse extends SimpleResponse { private transient final Logger logger = LogManager.getLogger(); public String serverID; public String username; - public String client; + public String serverName; + public boolean needHardware; + public boolean needProperties; @Override public String getType() { @@ -37,6 +41,15 @@ public void execute(ChannelHandlerContext ctx, Client pClient) { } result.playerProfile = report.playerProfile; result.uuid = report.uuid; + if(report.session != null) { + result.sessionId = report.session.getID(); + if(needProperties && report.session instanceof UserSessionSupportProperties supportProperties) { + result.sessionProperties = supportProperties.getProperties(); + } + if(needHardware && report.session instanceof UserSessionSupportHardware supportHardware) { + result.hardwareId = supportHardware.getHardwareId(); + } + } server.authHookManager.postCheckServerHook.hook(report, pClient); logger.debug("checkServer: {} uuid: {} serverID: {}", result.playerProfile == null ? null : result.playerProfile.username, result.uuid, serverID); } catch (AuthException | HookException e) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/GetAvailabilityAuthResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/GetAvailabilityAuthResponse.java index fcc16ae8..913218c1 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/GetAvailabilityAuthResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/GetAvailabilityAuthResponse.java @@ -3,7 +3,6 @@ import io.netty.channel.ChannelHandlerContext; import pro.gravit.launcher.events.request.GetAvailabilityAuthRequestEvent; import pro.gravit.launchserver.auth.AuthProviderPair; -import pro.gravit.launchserver.auth.core.interfaces.provider.AuthSupportRemoteClientAccess; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.SimpleResponse; diff --git a/LauncherClient/src/main/java/pro/gravit/launcher/api/AuthService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/api/AuthService.java similarity index 69% rename from LauncherClient/src/main/java/pro/gravit/launcher/api/AuthService.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/api/AuthService.java index 93b90de9..0020d954 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/api/AuthService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/api/AuthService.java @@ -3,6 +3,7 @@ import pro.gravit.launcher.ClientPermissions; import pro.gravit.launcher.profiles.ClientProfile; +import java.util.List; import java.util.UUID; public class AuthService { @@ -14,4 +15,12 @@ public class AuthService { public static boolean hasPermission(String permission) { return permissions.hasPerm(permission); } + + public static boolean hasRole(String role) { + return permissions.hasRole(role); + } + + public static List getRoles() { + return permissions.getRoles(); + } } diff --git a/LauncherClient/src/main/java/pro/gravit/launcher/api/ClientService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/api/ClientService.java similarity index 92% rename from LauncherClient/src/main/java/pro/gravit/launcher/api/ClientService.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/api/ClientService.java index a065319d..50c3a8da 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/api/ClientService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/api/ClientService.java @@ -1,6 +1,5 @@ package pro.gravit.launcher.api; -import pro.gravit.launcher.utils.ApiBridgeService; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.launch.ClassLoaderControl; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/api/KeyService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/api/KeyService.java index aea481d8..5976d4f8 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/api/KeyService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/api/KeyService.java @@ -1,7 +1,9 @@ package pro.gravit.launcher.api; +import java.security.interfaces.ECPublicKey; import java.security.interfaces.RSAPublicKey; public class KeyService { public static RSAPublicKey serverRsaPublicKey; + public static ECPublicKey serverEcPublicKey; } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/CheckServerRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/CheckServerRequestEvent.java index d4fc571a..47a78f93 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/CheckServerRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/CheckServerRequestEvent.java @@ -4,6 +4,7 @@ import pro.gravit.launcher.events.RequestEvent; import pro.gravit.launcher.profiles.PlayerProfile; +import java.util.Map; import java.util.UUID; @@ -14,6 +15,12 @@ public class CheckServerRequestEvent extends RequestEvent { public UUID uuid; @LauncherNetworkAPI public PlayerProfile playerProfile; + @LauncherNetworkAPI + public String sessionId; + @LauncherNetworkAPI + public String hardwareId; + @LauncherNetworkAPI + public Map sessionProperties; public CheckServerRequestEvent(PlayerProfile playerProfile) { this.playerProfile = playerProfile; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/CheckServerRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/CheckServerRequest.java index ac647341..d59fc144 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/CheckServerRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/CheckServerRequest.java @@ -11,6 +11,12 @@ public final class CheckServerRequest extends Request i public final String username; @LauncherNetworkAPI public final String serverID; + @LauncherNetworkAPI + public String serverName; + @LauncherNetworkAPI + public boolean needHardware; + @LauncherNetworkAPI + public boolean needProperties; public CheckServerRequest(String username, String serverID) { @@ -18,6 +24,14 @@ public CheckServerRequest(String username, String serverID) { this.serverID = VerifyHelper.verifyServerID(serverID); } + public CheckServerRequest(String username, String serverID, String serverName, boolean needHardware, boolean needProperties) { + this.username = username; + this.serverID = serverID; + this.serverName = serverName; + this.needHardware = needHardware; + this.needProperties = needProperties; + } + @Override public String getType() { return "checkServer"; diff --git a/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java b/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java index 64f292fe..368d2967 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java +++ b/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java @@ -176,6 +176,7 @@ private static void realMain(String[] args) throws Throwable { AuthService.username = params.playerProfile.username; AuthService.uuid = params.playerProfile.uuid; KeyService.serverRsaPublicKey = Launcher.getConfig().rsaPublicKey; + KeyService.serverEcPublicKey = Launcher.getConfig().ecdsaPublicKey; modulesManager.invokeEvent(new ClientProcessReadyEvent(params)); LogHelper.debug("Starting JVM and client WatchService"); FileNameMatcher assetMatcher = profile.getAssetUpdateMatcher(); diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java index 6884ef9b..c92f4caa 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java @@ -3,6 +3,8 @@ import pro.gravit.launcher.ClientPermissions; import pro.gravit.launcher.Launcher; import pro.gravit.launcher.LauncherConfig; +import pro.gravit.launcher.api.AuthService; +import pro.gravit.launcher.api.ClientService; import pro.gravit.launcher.api.KeyService; import pro.gravit.launcher.config.JsonConfigurable; import pro.gravit.launcher.events.request.AuthRequestEvent; @@ -39,11 +41,7 @@ public class ServerWrapper extends JsonConfigurable { public static ServerWrapper wrapper; public static ClassLoaderControl classLoaderControl; public Config config; - public PublicURLClassLoader ucp; - public ClassLoader loader; - public ClientPermissions permissions; public ClientProfile profile; - public PlayerProfile playerProfile; public ClientProfile.ServerProfile serverProfile; public ServerWrapper(Type type, Path configPath) { @@ -69,7 +67,7 @@ public void restore() throws Exception { if(config.extendedTokens != null) { Request.addAllExtendedToken(config.extendedTokens); } - Request.restore(); + Request.RequestRestoreReport report = Request.restore(config.oauth != null, false, false); } public void getProfiles() throws Exception { @@ -144,6 +142,9 @@ public void run(String... args) throws Throwable { if(config.encodedServerRsaPublicKey != null) { KeyService.serverRsaPublicKey = SecurityHelper.toPublicRSAKey(config.encodedServerRsaPublicKey); } + if(config.encodedServerEcPublicKey != null) { + KeyService.serverEcPublicKey = SecurityHelper.toPublicECDSAKey(config.encodedServerEcPublicKey); + } String classname = (config.mainclass == null || config.mainclass.isEmpty()) ? args[0] : config.mainclass; if (classname.length() == 0) { LogHelper.error("MainClass not found. Please set MainClass for ServerWrapper.json or first commandline argument"); @@ -192,6 +193,12 @@ public void run(String... args) throws Throwable { options.enableHacks = config.enableHacks; options.moduleConf = config.moduleConf; classLoaderControl = launch.init(config.classpath.stream().map(Paths::get).collect(Collectors.toCollection(ArrayList::new)), config.nativesDir, options); + if(ServerAgent.isAgentStarted()) { + ClientService.instrumentation = ServerAgent.inst; + } + ClientService.classLoaderControl = classLoaderControl; + ClientService.baseURLs = classLoaderControl.getURLs(); + ClientService.nativePath = config.nativesDir; LogHelper.info("Start Minecraft Server"); LogHelper.debug("Invoke main method %s with %s", classname, launch.getClass().getName()); try { diff --git a/build.gradle b/build.gradle index 7c41c2e6..aff07ff7 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ id 'org.openjfx.javafxplugin' version '0.0.10' apply false } group = 'pro.gravit.launcher' -version = '5.5.2' +version = '5.5.3-SNAPSHOT' apply from: 'props.gradle'