[FEATURE] serverName in ServerWrapper

This commit is contained in:
Gravita 2020-12-17 17:52:25 +07:00
parent 62c8ca878e
commit ce70cab736
2 changed files with 26 additions and 14 deletions

View file

@ -4,10 +4,12 @@
import pro.gravit.launcher.Launcher; import pro.gravit.launcher.Launcher;
import pro.gravit.launcher.LauncherConfig; import pro.gravit.launcher.LauncherConfig;
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.ProfilesRequestEvent; import pro.gravit.launcher.events.request.ProfilesRequestEvent;
import pro.gravit.launcher.modules.events.PostInitPhase; import pro.gravit.launcher.modules.events.PostInitPhase;
import pro.gravit.launcher.modules.events.PreConfigPhase; import pro.gravit.launcher.modules.events.PreConfigPhase;
import pro.gravit.launcher.profiles.ClientProfile; import pro.gravit.launcher.profiles.ClientProfile;
import pro.gravit.launcher.profiles.PlayerProfile;
import pro.gravit.launcher.profiles.optional.actions.OptionalAction; import pro.gravit.launcher.profiles.optional.actions.OptionalAction;
import pro.gravit.launcher.request.Request; import pro.gravit.launcher.request.Request;
import pro.gravit.launcher.request.RequestException; import pro.gravit.launcher.request.RequestException;
@ -46,6 +48,8 @@ public class ServerWrapper extends JsonConfigurable<ServerWrapper.Config> {
public ClassLoader loader; public ClassLoader loader;
public ClientPermissions permissions; public ClientPermissions permissions;
public ClientProfile profile; public ClientProfile profile;
public PlayerProfile playerProfile;
public ClientProfile.ServerProfile serverProfile;
public ServerWrapper(Type type, Path configPath) { public ServerWrapper(Type type, Path configPath) {
super(type, configPath); super(type, configPath);
@ -70,20 +74,28 @@ public boolean auth() {
try { try {
Launcher.getConfig(); Launcher.getConfig();
AuthRequest request = new AuthRequest(config.login, config.password, config.auth_id, AuthRequest.ConnectTypes.API); AuthRequest request = new AuthRequest(config.login, config.password, config.auth_id, AuthRequest.ConnectTypes.API);
permissions = request.request().permissions; AuthRequestEvent authResult = request.request();
permissions = authResult.permissions;
playerProfile = authResult.playerProfile;
ProfilesRequestEvent result = new ProfilesRequest().request(); ProfilesRequestEvent result = new ProfilesRequest().request();
for (ClientProfile p : result.profiles) { for (ClientProfile p : result.profiles) {
LogHelper.debug("Get profile: %s", p.getTitle()); LogHelper.debug("Get profile: %s", p.getTitle());
if (p.getTitle().equals(config.title)) { boolean isFound = false;
profile = p; for(ClientProfile.ServerProfile srv : p.getServers())
Launcher.profile = p; {
LogHelper.debug("Found profile: %s", Launcher.profile.getTitle()); if(srv != null && srv.name.equals(config.serverName)) {
break; this.serverProfile = srv;
this.profile = p;
Launcher.profile = p;
LogHelper.debug("Found profile: %s", Launcher.profile.getTitle());
isFound = true;
break;
}
} }
if(isFound) break;
} }
if (profile == null) { if (profile == null) {
LogHelper.error("Your profile not found"); LogHelper.warning("Not connected to ServerProfile. May be serverName incorrect?");
if (config.stopOnError) System.exit(-1);
} }
return true; return true;
} catch (Throwable e) { } catch (Throwable e) {
@ -183,7 +195,7 @@ public void run(String... args) throws Throwable {
} }
auth(); auth();
}; };
LogHelper.info("ServerWrapper: Project %s, LaunchServer address: %s. Title: %s", config.projectname, config.address, config.title); LogHelper.info("ServerWrapper: Project %s, LaunchServer address: %s. Title: %s", config.projectname, config.address, Launcher.profile != null ? Launcher.profile.getTitle() : "unknown");
LogHelper.info("Minecraft Version (for profile): %s", wrapper.profile == null ? "unknown" : wrapper.profile.getVersion().name); LogHelper.info("Minecraft Version (for profile): %s", wrapper.profile == null ? "unknown" : wrapper.profile.getVersion().name);
LogHelper.info("Start Minecraft Server"); LogHelper.info("Start Minecraft Server");
LogHelper.debug("Invoke main method %s", mainClass.getName()); LogHelper.debug("Invoke main method %s", mainClass.getName());
@ -228,7 +240,7 @@ public void setConfig(Config config) {
@Override @Override
public Config getDefaultConfig() { public Config getDefaultConfig() {
Config newConfig = new Config(); Config newConfig = new Config();
newConfig.title = "Your profile title"; newConfig.serverName = "your server name";
newConfig.projectname = "MineCraft"; newConfig.projectname = "MineCraft";
newConfig.login = "login"; newConfig.login = "login";
newConfig.password = "password"; newConfig.password = "password";
@ -244,9 +256,11 @@ public Config getDefaultConfig() {
} }
public static final class Config { public static final class Config {
@Deprecated
public String title; public String title;
public String projectname; public String projectname;
public String address; public String address;
public String serverName;
public WebSocketConf websocket; public WebSocketConf websocket;
public int reconnectCount; public int reconnectCount;
public int reconnectSleep; public int reconnectSleep;

View file

@ -46,6 +46,8 @@ public void run() throws IOException {
} }
} }
LogHelper.info("Found MainClass %s", mainClassName); LogHelper.info("Found MainClass %s", mainClassName);
System.out.println("Print your server name:");
wrapper.config.serverName = commands.commandHandler.readLine();
System.out.println("Print launchserver websocket host( ws://host:port/api ):"); System.out.println("Print launchserver websocket host( ws://host:port/api ):");
String address = commands.commandHandler.readLine(); String address = commands.commandHandler.readLine();
wrapper.config.mainclass = mainClassName; wrapper.config.mainclass = mainClassName;
@ -56,14 +58,10 @@ public void run() throws IOException {
String login = commands.commandHandler.readLine(); String login = commands.commandHandler.readLine();
System.out.println("Print server account password:"); System.out.println("Print server account password:");
String password = commands.commandHandler.readLine(); String password = commands.commandHandler.readLine();
System.out.println("Print profile title:");
String title = commands.commandHandler.readLine();
wrapper.config.login = login; wrapper.config.login = login;
wrapper.config.password = password; wrapper.config.password = password;
wrapper.config.title = title;
wrapper.config.stopOnError = false; wrapper.config.stopOnError = false;
wrapper.updateLauncherConfig(); wrapper.updateLauncherConfig();
if (wrapper.auth()) { if (wrapper.auth()) {
break; break;
} else { } else {