conduit_cli/core/runtime/launchers/
mod.rs1use std::path::Path;
2
3use crate::core::{
4 events::{CoreCallbacks, CoreEvent},
5 io::server::config::ServerConfig,
6 paths::CorePaths, runtime::launchers::generic_launcher::{LaunchCommand, launch_generic_server},
7};
8
9mod chat;
10mod generic_launcher;
11mod log_processor;
12
13pub enum ServerLauncher {
14 Neoforge,
15 Vanilla,
16}
17
18impl ServerLauncher {
19 pub fn is_ready(&self, paths: &CorePaths, version: &str) -> bool {
20 match self {
21 Self::Neoforge => {
22 let dir = paths.neoforge_version_dir(version);
23 dir.join("unix_args.txt").exists() && dir.join("win_args.txt").exists()
24 }
25 Self::Vanilla => paths.project_dir().join("server.jar").exists(),
26 }
27 }
28
29 pub async fn launch(
30 &self,
31 paths: &CorePaths,
32 config: &ServerConfig,
33 loader_version: &str,
34 show_logs: bool,
35 show_gui: bool,
36 callbacks: &mut dyn CoreCallbacks,
37 ) {
38 let launch_cmd = match self {
39 Self::Neoforge => {
40 let mut args = Vec::new();
41
42 args.push(format!("-Xmx{}", config.performance.max_ram));
43 args.push(format!("-Xms{}", config.performance.min_ram));
44
45 for jvm_arg in &config.performance.jvm_args {
46 args.push(jvm_arg.clone());
47 }
48
49 let arg_file = if cfg!(target_os = "windows") {
50 "win_args.txt"
51 } else {
52 "unix_args.txt"
53 };
54
55 let relative_args_path = Path::new("libraries")
56 .join("net/neoforged/neoforge")
57 .join(loader_version)
58 .join(arg_file);
59
60 args.push(format!("@{}", relative_args_path.display()));
61
62 if !show_gui {
63 args.push("nogui".to_string());
64 }
65
66 LaunchCommand {
67 program: "java".to_string(),
68 args,
69 current_dir: paths.project_dir().to_path_buf(),
70 }
71 }
72 Self::Vanilla => LaunchCommand {
73 program: "java".to_string(),
74 args: vec![
75 format!("-Xmx{}", config.performance.max_ram),
76 format!("-Xms{}", config.performance.min_ram),
77 "-jar".into(),
78 "server.jar".into(),
79 "nogui".into(),
80 ],
81 current_dir: paths.project_dir().to_path_buf(),
82 },
83 };
84
85 if let Err(e) = launch_generic_server(launch_cmd, callbacks, show_logs).await {
86 callbacks.on_event(CoreEvent::Error(format!("Launcher failed: {e}")));
87 }
88 }
89}