conduit_cli/server_launcher/
mod.rs1use std::path::PathBuf;
2
3use crate::{
4 core::events::{CoreCallbacks, CoreEvent},
5 server_launcher::generic_launcher::{LaunchCommand, launch_generic_server},
6};
7
8mod chat;
9mod generic_launcher;
10mod log_processor;
11
12pub enum ServerLauncher {
13 Neoforge,
14 Vanilla,
15}
16
17impl ServerLauncher {
18 pub async fn launch(
19 &self,
20 path: PathBuf,
21 show_logs: bool,
22 show_gui: bool,
23 callbacks: &mut dyn CoreCallbacks,
24 ) {
25 let launch_cmd = match self {
26 Self::Neoforge => {
27 let (shell, mut args) = if cfg!(target_os = "windows") {
28 ("cmd", vec!["/C", "run.bat"])
29 } else {
30 ("sh", vec!["run.sh"])
31 };
32 if !show_gui {
33 args.push("nogui");
34 }
35
36 LaunchCommand {
37 program: shell.to_string(),
38 args: args.iter().map(|s| s.to_string()).collect(),
39 current_dir: path,
40 }
41 }
42 Self::Vanilla => LaunchCommand {
43 program: "java".to_string(),
44 args: vec![
45 "-Xmx2G".into(),
46 "-jar".into(),
47 "server.jar".into(),
48 "nogui".into(),
49 ],
50 current_dir: path,
51 },
52 };
53
54 if let Err(e) = launch_generic_server(launch_cmd, callbacks, show_logs).await {
55 callbacks.on_event(CoreEvent::Error(format!("Launcher failed: {}", e)));
56 }
57 }
58}