Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,26 @@ pub struct RunArgs {
/// Exit on code 8 instead of applying updates
#[arg(long)]
pub no_restart: bool,

/// Acknowledge that loading early plugins is unsupported
#[arg(long)]
pub accept_early_plugins: bool,

/// Allow op commands
#[arg(long)]
pub allow_op: bool,

/// Enable automatic backups
#[arg(long)]
pub backup: bool,

/// Backup directory
#[arg(long)]
pub backup_dir: Option<PathBuf>,

/// Backup frequency in minutes
#[arg(long)]
pub backup_frequency: Option<u16>,
}

#[derive(Parser, Debug)]
Expand Down
27 changes: 27 additions & 0 deletions src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ async fn ensure_server_files(server_dir: &Path, jar_path: &Path, config: &AppCon
}

/// Run the server with auto-update loop
#[allow(clippy::too_many_arguments)]
async fn run_server_loop(
args: &RunArgs,
config: &AppConfig,
Expand Down Expand Up @@ -157,6 +158,27 @@ async fn run_server_loop(
config.defaults.ip.clone()
};

// Determine accept_early_plugins (CLI overrides config)
let accept_early_plugins =
args.accept_early_plugins || config.defaults.accept_early_plugins;

// Determine allow_op (CLI overrides config)
let allow_op = args.allow_op || config.defaults.allow_op;

// Determine backup settings
let backup_enabled = args.backup || config.defaults.backup.enabled;
let backup_dir: Option<PathBuf> =
args.backup_dir
.clone()
.or(config.defaults.backup.path.clone());
let backup_frequency = args.backup_frequency.or_else(|| {
if config.defaults.backup.frequency != 0 {
Some(config.defaults.backup.frequency)
} else {
None
}
});

// Run the server
let exit_code = runner
.run(
Expand All @@ -167,6 +189,11 @@ async fn run_server_loop(
&ip,
&assets_path,
args.jvm_args.as_deref(),
accept_early_plugins,
allow_op,
backup_enabled,
backup_dir.as_ref(),
backup_frequency,
)
.await?;

Expand Down
41 changes: 41 additions & 0 deletions src/config/app_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ pub struct DefaultsConfig {
pub port: u16,
pub ip: String,
pub aot_enabled: bool,
pub accept_early_plugins: bool,
pub allow_op: bool,
pub backup: BackupConfig,
}

impl Default for DefaultsConfig {
Expand All @@ -43,6 +46,9 @@ impl Default for DefaultsConfig {
port: 5520,
ip: "0.0.0.0".to_string(),
aot_enabled: true,
accept_early_plugins: false,
allow_op: false,
backup: BackupConfig::default(),
}
}
}
Expand Down Expand Up @@ -88,6 +94,15 @@ pub struct UpdateConfig {
pub auto_apply: bool,
}

/// Backup configuration
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(default)]
pub struct BackupConfig {
pub enabled: bool,
pub path: Option<PathBuf>,
pub frequency: u16,
}

impl Default for UpdateConfig {
fn default() -> Self {
Self {
Expand Down Expand Up @@ -175,6 +190,32 @@ fn merge_configs(base: AppConfig, overlay: AppConfig) -> AppConfig {
} else {
base.defaults.ip
},
accept_early_plugins: if overlay.defaults.accept_early_plugins
!= DefaultsConfig::default().accept_early_plugins
{
overlay.defaults.accept_early_plugins
} else {
base.defaults.accept_early_plugins
},
allow_op: if overlay.defaults.allow_op != DefaultsConfig::default().allow_op {
overlay.defaults.allow_op
} else {
base.defaults.allow_op
},
backup: BackupConfig {
enabled: overlay.defaults.backup.enabled || base.defaults.backup.enabled,
path: overlay
.defaults
.backup
.path
.clone()
.or(base.defaults.backup.path.clone()),
frequency: if overlay.defaults.backup.frequency != 0 {
overlay.defaults.backup.frequency
} else {
base.defaults.backup.frequency
},
},
aot_enabled: overlay.defaults.aot_enabled,
},
java: JavaConfig {
Expand Down
26 changes: 26 additions & 0 deletions src/server/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ impl ServerRunner {
ip: &str,
assets_path: &PathBuf,
jvm_args: Option<&str>,
accept_early_plugins: bool,
allow_op: bool,
backup_enabled: bool,
backup_dir: Option<&PathBuf>,
backup_frequency: Option<u16>,
) -> Result<i32> {
if !self.jar_path.exists() {
anyhow::bail!("HytaleServer.jar not found at {}", self.jar_path.display());
Expand Down Expand Up @@ -84,6 +89,27 @@ impl ServerRunner {
cmd.arg("--assets").arg(assets_path);
cmd.arg("--bind").arg(format!("{}:{}", ip, port));

// Early plugins acceptance
if accept_early_plugins {
cmd.arg("--accept-early-plugins");
}

// Allow op
if allow_op {
cmd.arg("--allow-op");
}

// Backup settings
if backup_enabled {
cmd.arg("--backup");
if let Some(dir) = backup_dir {
cmd.arg("--backup-dir").arg(dir);
}
if let Some(freq) = backup_frequency {
cmd.arg("--backup-frequency").arg(freq.to_string());
}
}

// Interactive console - inherit stdin/stdout/stderr
cmd.stdin(Stdio::inherit());
cmd.stdout(Stdio::inherit());
Expand Down
Loading