[FEATURE] Событие закрытия клиента, сервис обработки exit/setSecurityManager

This commit is contained in:
Gravit 2019-12-17 11:37:21 +07:00
parent a125fd8e8f
commit 3bfed5c3c7
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
6 changed files with 68 additions and 1 deletions

View file

@ -1,7 +1,9 @@
package pro.gravit.launcher;
import pro.gravit.launcher.api.SystemService;
import pro.gravit.launcher.client.*;
import pro.gravit.launcher.client.events.ClientEngineInitPhase;
import pro.gravit.launcher.client.events.ClientExitPhase;
import pro.gravit.launcher.client.events.ClientPreGuiPhase;
import pro.gravit.launcher.guard.LauncherGuardManager;
import pro.gravit.launcher.gui.NoRuntimeProvider;
@ -10,11 +12,13 @@
import pro.gravit.launcher.managers.ClientGsonManager;
import pro.gravit.launcher.managers.ClientHookManager;
import pro.gravit.launcher.managers.ConsoleManager;
import pro.gravit.launcher.modules.events.ClosePhase;
import pro.gravit.launcher.modules.events.PreConfigPhase;
import pro.gravit.launcher.request.Request;
import pro.gravit.launcher.request.RequestException;
import pro.gravit.launcher.request.auth.RestoreSessionRequest;
import pro.gravit.launcher.request.websockets.StdWebSocketService;
import pro.gravit.launcher.utils.NativeJVMHalt;
import pro.gravit.utils.helper.*;
import java.io.IOException;
@ -53,6 +57,18 @@ public static void checkClass(Class<?> clazz) throws SecurityException {
}
}
public static void exitLauncher(int code)
{
modulesManager.invokeEvent(new ClientExitPhase(code));
try {
System.exit(code);
} catch (Exception e) //Forge Security Manager?
{
NativeJVMHalt.haltA(code);
}
}
public static void main(String... args) throws Throwable {
JVMHelper.checkStackTrace(LauncherEngine.class);
JVMHelper.verifySystemProperties(Launcher.class, true);
@ -84,7 +100,7 @@ public static void main(String... args) throws Throwable {
LogHelper.debug("Launcher started in %dms", endTime - startTime);
//Request.service.close();
//FunctionalBridge.close();
System.exit(0);
SystemService.exit(0);
}
public static void initGson(ClientModuleManager modulesManager) {

View file

@ -1,6 +1,7 @@
package pro.gravit.launcher.api;
import pro.gravit.launcher.ClientPermissions;
import pro.gravit.launcher.profiles.ClientProfile;
import java.util.UUID;
@ -8,6 +9,7 @@ public class AuthService {
public static String username;
public static ClientPermissions permissions = new ClientPermissions();
public static UUID uuid;
public static ClientProfile profile;
public static boolean isAdmin() {
return permissions.canAdmin;

View file

@ -0,0 +1,25 @@
package pro.gravit.launcher.api;
import pro.gravit.launcher.LauncherEngine;
import pro.gravit.launcher.profiles.ClientProfile;
import pro.gravit.utils.helper.LogHelper;
public class SystemService {
private SystemService() {
throw new UnsupportedOperationException();
}
public static void exit(int code)
{
LauncherEngine.exitLauncher(code);
}
public static void setSecurityManager(SecurityManager s)
{
LogHelper.debug("Try set security manager %s", s == null ? "null" : s.getClass().getName());
if(AuthService.profile == null || AuthService.profile.securityManagerConfig == ClientProfile.SecurityManagerConfig.NONE) return;
if(AuthService.profile.securityManagerConfig == ClientProfile.SecurityManagerConfig.CLIENT)
{
System.setSecurityManager(s);
}
//TODO NEXT
}
}

View file

@ -463,6 +463,7 @@ public static void main(String... args) throws Throwable {
HashedDir assetHDir = p.assetHDir, clientHDir = p.clientHDir;
ClientLaunchContext context = new ClientLaunchContext(params, profile, assetHDir, clientHDir);
Launcher.profile = profile;
AuthService.profile = profile;
playerProfile = params.pp;
Request.setSession(params.session);
checkJVMBitsAndVersion();

View file

@ -0,0 +1,11 @@
package pro.gravit.launcher.client.events;
import pro.gravit.launcher.modules.events.ClosePhase;
public class ClientExitPhase extends ClosePhase {
public final int code;
public ClientExitPhase(int code) {
this.code = code;
}
}

View file

@ -69,6 +69,14 @@ public String toString() {
}
public static final boolean profileCaseSensitive = Boolean.getBoolean("launcher.clientProfile.caseSensitive");
public enum SecurityManagerConfig
{
NONE, CLIENT, LAUNCHER, MIXED
}
public enum ClassLoaderConfig
{
AGENT, LAUNCHER
}
private static final FileNameMatcher ASSET_MATCHER = new FileNameMatcher(
new String[0], new String[]{"indexes", "objects"}, new String[0]);
@ -122,6 +130,10 @@ public String toString() {
private final List<String> clientArgs = new ArrayList<>();
@LauncherNetworkAPI
private final List<String> whitelist = new ArrayList<>();
@LauncherNetworkAPI
public SecurityManagerConfig securityManagerConfig = SecurityManagerConfig.CLIENT;
@LauncherNetworkAPI
public ClassLoaderConfig classLoaderConfig = ClassLoaderConfig.LAUNCHER;
@Override
public int compareTo(ClientProfile o) {