Skip to content

Commit

Permalink
7.5.0
Browse files Browse the repository at this point in the history
- NEW: Server version can now easily be defined in general.yml (useful for CLI versions of autoplug). See comments in the config for details. This also removes the need of having multiple versions for each updater individually.
- FIX: Wrong status of isRunning for proxies and steam game servers resulting in set to private even though they are running.
- NEW: Added console output when configs are modified to make users understand that they are live configs. Note It's recommended to disable auto-save to prevent console spam. Many options that previously required a restart now do not anymore.
  • Loading branch information
Osiris-Team committed Dec 19, 2023
1 parent 6513cdd commit 76520d3
Show file tree
Hide file tree
Showing 22 changed files with 640 additions and 201 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<groupId>com.osiris.autoplug.client</groupId>
<artifactId>autoplug-client</artifactId>
<version>7.4.0</version>
<version>7.5.0</version>
<packaging>jar</packaging>

<name>AutoPlug-Client</name>
Expand Down Expand Up @@ -91,7 +91,7 @@
<dependency>
<groupId>com.github.Osiris-Team</groupId>
<artifactId>Dyml</artifactId>
<version>9.6.1</version>
<version>9.8.2</version>
</dependency>

<dependency>
Expand Down
85 changes: 15 additions & 70 deletions src/main/java/com/osiris/autoplug/client/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,8 @@
import com.osiris.autoplug.client.managers.SyncFilesManager;
import com.osiris.autoplug.client.network.local.ConPluginCommandReceive;
import com.osiris.autoplug.client.network.online.ConMain;
import com.osiris.autoplug.client.tasks.updater.java.TaskJavaUpdater;
import com.osiris.autoplug.client.tasks.updater.mods.TaskModsUpdater;
import com.osiris.autoplug.client.tasks.updater.plugins.TaskPluginsUpdater;
import com.osiris.autoplug.client.tasks.updater.self.TaskSelfUpdater;
import com.osiris.autoplug.client.tasks.updater.server.TaskServerUpdater;
import com.osiris.autoplug.client.ui.MainWindow;
import com.osiris.autoplug.client.utils.*;
import com.osiris.autoplug.client.utils.tasks.MyBThreadManager;
import com.osiris.autoplug.client.utils.tasks.UtilsTasks;
import com.osiris.dyml.Yaml;
import com.osiris.dyml.YamlSection;
import com.osiris.jlib.logger.AL;
Expand All @@ -34,17 +27,17 @@
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;

import static com.osiris.autoplug.client.utils.GD.WORKING_DIR;

public class Main {
// Do not init fields directly here, but instead in main() after logger was initialised
//public static NonBlockingPipedInputStream PIPED_IN;
public static final ConMain CON = new ConMain();
public static Target TARGET = null;
public static ConMain CON;
public static UpdateCheckerThread UPDATE_CHECKER_THREAD = null;

/**
* @param _args arguments separated by spaces. <br>
Expand Down Expand Up @@ -186,29 +179,7 @@ public static void main(String[] _args) {

// Loads or creates all needed configuration files
GeneralConfig generalConfig = new GeneralConfig();
String target = generalConfig.autoplug_target_software.asString();
while (true) {
if (target == null) {
for (String comment : generalConfig.autoplug_target_software.getComments()) {
AL.info(comment);
}
AL.info("Please enter a valid option and press enter:");
target = new Scanner(System.in).nextLine();
generalConfig.autoplug_target_software.setValues(target);
generalConfig.save();
} else {
TARGET = Target.fromString(target);
if (TARGET != null) break;
for (String comment : generalConfig.autoplug_target_software.getComments()) {
AL.info(comment);
}
AL.info("The selected target software '" + target + "' is not a valid option.");
AL.info("Please enter a valid option and press enter:");
target = new Scanner(System.in).nextLine();
generalConfig.autoplug_target_software.setValues(target);
generalConfig.save();
}
}
GD.determineTarget(generalConfig);
utilsConfig.checkForDeprecatedSections(generalConfig);
allModules.addAll(generalConfig.getAllInEdit());

Expand Down Expand Up @@ -251,6 +222,9 @@ public static void main(String[] _args) {
utilsConfig.checkForDeprecatedSections(sharedFilesConfig);
allModules.addAll(sharedFilesConfig.getAllInEdit());

PluginsConfig pluginsConfig = new PluginsConfig();
ModsConfig modsConfig = new ModsConfig();

utilsConfig.printAllModulesToDebugExceptServerKey(allModules, generalConfig.server_key.asString());
AL.info("Checked configs, took " + (System.currentTimeMillis() - now) + "ms");

Expand Down Expand Up @@ -285,56 +259,27 @@ public static void main(String[] _args) {
try {
if (updaterConfig.global_recurring_checks.asBoolean()) {
now = System.currentTimeMillis();
new Thread(() -> {
try {
while (true) {
long last = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss")
.parse(new SystemConfig().timestamp_last_updater_tasks.asString())
.getTime();
long now1 = System.currentTimeMillis();
long msSinceLast = now1 - last;
long msLeft = (new UpdaterConfig().global_recurring_checks_intervall.asInt() * 3600000L) // 1h in ms
- msSinceLast;
if (msLeft > 0) Thread.sleep(msLeft);
AL.info("Running tasks from recurring update-checker thread.");
MyBThreadManager man = new UtilsTasks().createManagerAndPrinter();
TaskSelfUpdater selfUpdater = new TaskSelfUpdater("SelfUpdater", man.manager);
TaskJavaUpdater taskJavaUpdater = new TaskJavaUpdater("JavaUpdater", man.manager);
TaskServerUpdater taskServerUpdater = new TaskServerUpdater("ServerUpdater", man.manager);
TaskPluginsUpdater taskPluginsUpdater = new TaskPluginsUpdater("PluginsUpdater", man.manager);
TaskModsUpdater taskModsUpdater = new TaskModsUpdater("ModsUpdater", man.manager);
selfUpdater.start();
while (!selfUpdater.isFinished()) // Wait until the self updater finishes
Thread.sleep(1000);
taskJavaUpdater.start();
taskServerUpdater.start();
taskPluginsUpdater.start();
taskModsUpdater.start();
while (!man.manager.isFinished())
Thread.sleep(1000);
}
} catch (Exception e) {
AL.warn(e);
}
}).start();
UPDATE_CHECKER_THREAD = new UpdateCheckerThread();
UPDATE_CHECKER_THREAD.start();
AL.info("Started update-checker thread with " + updaterConfig.global_recurring_checks_intervall.asString() + "h intervall, took " + (System.currentTimeMillis() - now) + "ms");
}
} catch (Exception e) {
AL.warn(e);
}

CON = new ConMain();
CON.open();

AL.info("Initialised successfully.");
AL.info("Enter .help for a list of all commands.");
AL.info("| ------------------------------------------- |");
AL.info("Enter .help for a list of all commands.");

CON.open();

if (TARGET != Target.MINECRAFT_CLIENT)
if (GD.TARGET != Target.MINECRAFT_CLIENT)
new ConPluginCommandReceive();

new ThreadUserInput().start();

if (TARGET != Target.MINECRAFT_CLIENT && generalConfig.server_auto_start.asBoolean())
if (GD.TARGET != Target.MINECRAFT_CLIENT && generalConfig.server_auto_start.asBoolean())
Server.start();

// Execute arguments as commands if existing
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/com/osiris/autoplug/client/configs/BackupConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Osiris-Team.
* Copyright (c) 2021-2023 Osiris-Team.
* All rights reserved.
*
* This software is copyrighted work, licensed under the terms
Expand All @@ -19,7 +19,8 @@
import java.util.ArrayList;
import java.util.List;

public class BackupConfig extends Yaml {
public class BackupConfig extends MyYaml {
private static final boolean isFileListenerRegistered = false;

public YamlSection backup;
public YamlSection backup_max_days;
Expand All @@ -40,6 +41,10 @@ public class BackupConfig extends Yaml {

public BackupConfig() throws IOException, DuplicateKeyException, YamlReaderException, IllegalListException, NotLoadedException, IllegalKeyException, YamlWriterException {
super(System.getProperty("user.dir") + "/autoplug/backup.yml");

addSingletonConfigFileEventListener(e -> {
});

lockFile();
load();
String name = getFileNameWithoutExt();
Expand Down Expand Up @@ -144,4 +149,8 @@ public List<File> getIncludedFiles() {
return files;
}

@Override
public Yaml validateValues() {
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,27 @@
package com.osiris.autoplug.client.configs;

import com.osiris.autoplug.client.managers.FileManager;
import com.osiris.autoplug.client.ui.MainWindow;
import com.osiris.autoplug.client.utils.GD;
import com.osiris.autoplug.client.utils.UtilsJar;
import com.osiris.autoplug.client.utils.UtilsNative;
import com.osiris.dyml.SmartString;
import com.osiris.dyml.Yaml;
import com.osiris.dyml.YamlSection;
import com.osiris.dyml.exceptions.*;
import com.osiris.jlib.logger.AL;

import java.io.IOException;

public class GeneralConfig extends Yaml {
public class GeneralConfig extends MyYaml {
public YamlSection autoplug_auto_stop;
public YamlSection autoplug_target_software;
public YamlSection autoplug_start_on_boot;
public YamlSection autoplug_system_tray;
public YamlSection autoplug_system_tray_theme;

public YamlSection server_key;
public YamlSection server_version;
public YamlSection server_auto_start;
public YamlSection server_auto_eula;
public YamlSection server_start_command;
Expand All @@ -41,6 +46,43 @@ public GeneralConfig() throws NotLoadedException, YamlReaderException, YamlWrite

public GeneralConfig(boolean save) throws IOException, DuplicateKeyException, YamlReaderException, IllegalListException, YamlWriterException, NotLoadedException, IllegalKeyException {
super(System.getProperty("user.dir") + "/autoplug/general.yml");

addSingletonConfigFileEventListener(e -> {

try {
GD.determineTarget(this);
} catch (Exception ex) {
AL.warn(ex);
}

try {
if (this.autoplug_start_on_boot.asBoolean())
new UtilsNative().enableStartOnBootIfNeeded(new UtilsJar().getThisJar());
else new UtilsNative().disableStartOnBootIfNeeded();
} catch (Exception ex) {
AL.warn(ex);
}

try {
if (this.autoplug_system_tray.asBoolean()) {
boolean firstStart = MainWindow.GET == null;
new MainWindow();
if (firstStart) AL.info("Started system-tray GUI.");
} else {
boolean isRunning = MainWindow.GET != null;
if (isRunning) {
MainWindow.GET.close();
AL.info("Stopped system-tray GUI.");
}
}
} catch (Exception ex) {
AL.warn(ex);
}

if (MainWindow.GET != null) MainWindow.GET.initTheme(this);

});

lockFile();
load();
String name = getFileNameWithoutExt();
Expand Down Expand Up @@ -68,8 +110,7 @@ public GeneralConfig(boolean save) throws IOException, DuplicateKeyException, Ya
"If you have no GUI its recommended to install software like \"screen\" for virtual terminals and edit the script accordingly.");
autoplug_target_software = put(name, "autoplug", "target-software").setComments(
"Select the target software AutoPlug was installed on.",
"Available options: MINECRAFT_CLIENT, MINECRAFT_SERVER, MINDUSTRY_SERVER, OTHER.",
"When changed, requires an AutoPlug restart to take effect.");
"Available options: MINECRAFT_CLIENT, MINECRAFT_SERVER, MINDUSTRY_SERVER, OTHER.");
autoplug_system_tray = put(name, "autoplug", "system-tray", "enable").setDefValues("false");
autoplug_system_tray_theme = put(name, "autoplug", "system-tray", "theme").setDefValues("light")
.setComments("Select between: light, dark and darcula.");
Expand All @@ -80,6 +121,9 @@ public GeneralConfig(boolean save) throws IOException, DuplicateKeyException, Ya
"The Server-Key enables remote access from your account.\n" +
"No matter what, keep this key private to ensure your servers security!");

server_version = put(name, "server", "version").setComments(
"Leave empty to determine it automatically via the server jar.",
"Set this if the above fails, or you are running as CLI, or you just want to force a specific version.");
server_auto_start = put(name, "server", "auto-start").setDefValues("true").setComments(
"Starts your server with the start of AutoPlug.");
server_auto_eula = put(name, "server", "auto-eula").setDefValues("true").setComments(
Expand Down Expand Up @@ -156,12 +200,12 @@ public GeneralConfig(boolean save) throws IOException, DuplicateKeyException, Ya
"Supported paths are relative (starting with './' which is the servers root directory) and absolute paths.")
.setDefValues("true ./autoplug/logs", "./autoplug/downloads");

validateOptions();
if (save) save();
unlockFile();
}

private void validateOptions() {
@Override
public Yaml validateValues() {
return this;
}

}
20 changes: 16 additions & 4 deletions src/main/java/com/osiris/autoplug/client/configs/LoggerConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Osiris-Team.
* Copyright (c) 2021-2023 Osiris-Team.
* All rights reserved.
*
* This software is copyrighted work, licensed under the terms
Expand All @@ -8,13 +8,15 @@

package com.osiris.autoplug.client.configs;

import com.osiris.autoplug.client.network.online.connections.ConAutoPlugConsoleSend;
import com.osiris.dyml.Yaml;
import com.osiris.dyml.YamlSection;
import com.osiris.dyml.exceptions.*;
import com.osiris.jlib.logger.AL;

import java.io.IOException;

public class LoggerConfig extends Yaml {
public class LoggerConfig extends MyYaml {
public YamlSection debug;
public YamlSection autoplug_label;
public YamlSection force_ansi;
Expand All @@ -29,6 +31,13 @@ public class LoggerConfig extends Yaml {

public LoggerConfig() throws IOException, DuplicateKeyException, YamlReaderException, IllegalListException, YamlWriterException, NotLoadedException, IllegalKeyException {
super(System.getProperty("user.dir") + "/autoplug/logger.yml");

addSingletonConfigFileEventListener(e -> {
boolean isDebug = this.debug.asBoolean();
AL.isDebugEnabled = isDebug;
ConAutoPlugConsoleSend.isDebug = isDebug;
});

lockFile();
load();
String name = getFileNameWithoutExt();
Expand All @@ -47,8 +56,7 @@ public LoggerConfig() throws IOException, DuplicateKeyException, YamlReaderExcep

debug = put(name, "debug").setDefValues("false").setComments(
"Writes the debug output to console.\n" +
"The log file contains the debug output by default and this option wont affect that.\n" +
"This is the only setting that needs a restart to work.");
"The log file contains the debug output by default and this option wont affect that.\n");

autoplug_label = put(name, "autoplug-label").setDefValues("AP");
force_ansi = put(name, "force-ANSI").setDefValues("false").setComments(
Expand Down Expand Up @@ -85,4 +93,8 @@ public LoggerConfig() throws IOException, DuplicateKeyException, YamlReaderExcep
}


@Override
public Yaml validateValues() {
return this;
}
}
Loading

0 comments on commit 76520d3

Please sign in to comment.