[FEATURE] ConfigService

This commit is contained in:
Gravita 2023-11-28 18:21:32 +07:00
parent d2f34ced28
commit 3754a327b0
4 changed files with 38 additions and 6 deletions

View file

@ -16,7 +16,6 @@ public class CheckServerResponse extends SimpleResponse {
private transient final Logger logger = LogManager.getLogger(); private transient final Logger logger = LogManager.getLogger();
public String serverID; public String serverID;
public String username; public String username;
public String serverName;
public boolean needHardware; public boolean needHardware;
public boolean needProperties; public boolean needProperties;

View file

@ -0,0 +1,11 @@
package pro.gravit.launcher.api;
public class ConfigService {
public static boolean disableLogging;
public static String serverName;
public static CheckServerConfig checkServerConfig = new CheckServerConfig();
public static class CheckServerConfig {
public boolean needProperties;
public boolean needHardware;
}
}

View file

@ -12,8 +12,6 @@ public final class CheckServerRequest extends Request<CheckServerRequestEvent> i
@LauncherNetworkAPI @LauncherNetworkAPI
public final String serverID; public final String serverID;
@LauncherNetworkAPI @LauncherNetworkAPI
public String serverName;
@LauncherNetworkAPI
public boolean needHardware; public boolean needHardware;
@LauncherNetworkAPI @LauncherNetworkAPI
public boolean needProperties; public boolean needProperties;
@ -24,10 +22,9 @@ public CheckServerRequest(String username, String serverID) {
this.serverID = VerifyHelper.verifyServerID(serverID); this.serverID = VerifyHelper.verifyServerID(serverID);
} }
public CheckServerRequest(String username, String serverID, String serverName, boolean needHardware, boolean needProperties) { public CheckServerRequest(String username, String serverID, boolean needHardware, boolean needProperties) {
this.username = username; this.username = username;
this.serverID = serverID; this.serverID = VerifyHelper.verifyServerID(serverID);
this.serverName = serverName;
this.needHardware = needHardware; this.needHardware = needHardware;
this.needProperties = needProperties; this.needProperties = needProperties;
} }

View file

@ -5,6 +5,7 @@
import pro.gravit.launcher.LauncherConfig; import pro.gravit.launcher.LauncherConfig;
import pro.gravit.launcher.api.AuthService; import pro.gravit.launcher.api.AuthService;
import pro.gravit.launcher.api.ClientService; import pro.gravit.launcher.api.ClientService;
import pro.gravit.launcher.api.ConfigService;
import pro.gravit.launcher.api.KeyService; import pro.gravit.launcher.api.KeyService;
import pro.gravit.launcher.config.JsonConfigurable; import pro.gravit.launcher.config.JsonConfigurable;
import pro.gravit.launcher.events.request.AuthRequestEvent; import pro.gravit.launcher.events.request.AuthRequestEvent;
@ -68,6 +69,13 @@ public void restore() throws Exception {
Request.addAllExtendedToken(config.extendedTokens); Request.addAllExtendedToken(config.extendedTokens);
} }
Request.RequestRestoreReport report = Request.restore(config.oauth != null, false, false); Request.RequestRestoreReport report = Request.restore(config.oauth != null, false, false);
if(report.userInfo != null) {
if(report.userInfo.playerProfile != null) {
AuthService.username = report.userInfo.playerProfile.username;
AuthService.uuid = report.userInfo.playerProfile.uuid;
}
AuthService.permissions = report.userInfo.permissions;
}
} }
public void getProfiles() throws Exception { public void getProfiles() throws Exception {
@ -80,6 +88,7 @@ public void getProfiles() throws Exception {
this.serverProfile = srv; this.serverProfile = srv;
this.profile = p; this.profile = p;
Launcher.profile = p; Launcher.profile = p;
AuthService.profile = p;
LogHelper.debug("Found profile: %s", Launcher.profile.getTitle()); LogHelper.debug("Found profile: %s", Launcher.profile.getTitle());
isFound = true; isFound = true;
break; break;
@ -199,6 +208,10 @@ public void run(String... args) throws Throwable {
ClientService.classLoaderControl = classLoaderControl; ClientService.classLoaderControl = classLoaderControl;
ClientService.baseURLs = classLoaderControl.getURLs(); ClientService.baseURLs = classLoaderControl.getURLs();
ClientService.nativePath = config.nativesDir; ClientService.nativePath = config.nativesDir;
ConfigService.serverName = config.serverName;
if(config.configServiceSettings != null) {
config.configServiceSettings.apply();
}
LogHelper.info("Start Minecraft Server"); LogHelper.info("Start Minecraft Server");
LogHelper.debug("Invoke main method %s with %s", classname, launch.getClass().getName()); LogHelper.debug("Invoke main method %s with %s", classname, launch.getClass().getName());
try { try {
@ -274,5 +287,17 @@ public static final class Config {
public boolean enableHacks; public boolean enableHacks;
public Map<String, String> properties; public Map<String, String> properties;
public ConfigServiceSettings configServiceSettings = new ConfigServiceSettings();
public static class ConfigServiceSettings {
public boolean disableLogging = false;
public boolean checkServerNeedProperties = false;
public boolean checkServerNeedHardware = false;
public void apply() {
ConfigService.disableLogging = disableLogging;
ConfigService.checkServerConfig.needHardware = checkServerNeedHardware;
ConfigService.checkServerConfig.needProperties = checkServerNeedProperties;
}
}
} }
} }