conduit_cli/core/server/
run.rs1use crate::core::events::CoreCallbacks;
2use crate::core::io::project::ProjectFiles;
3use crate::core::runtime::loaders;
4use crate::core::paths::CorePaths;
5use crate::core::runtime::launchers::ServerLauncher;
6use std::error::Error;
7
8pub async fn start_server(
9 paths: &CorePaths,
10 callbacks: &mut dyn CoreCallbacks,
11 show_logs: bool,
12 show_gui: bool,
13) -> Result<(), Box<dyn Error>> {
14 let lock = ProjectFiles::load_lock(paths)?;
15
16 let loader_raw = lock
17 .loader_version
18 .ok_or("No loader version found in lock file")?;
19
20 let loader_info = loaders::LoaderInfo::parse(&loader_raw);
21 let loader_version = loader_info.version;
22
23 let launcher = match loader_info.name.to_lowercase().as_str() {
24 "neoforge" => ServerLauncher::Neoforge,
25 "vanilla" => ServerLauncher::Vanilla,
26 _ => return Err(format!("Unsupported loader: {}", loader_info.name).into()),
27 };
28
29 if !launcher.is_ready(paths, &loader_version) {
30 return Err(format!(
31 "Loader {} version {} is not installed or files are missing.",
32 loader_info.name, loader_version
33 )
34 .into());
35 }
36
37 let config = crate::core::io::server::config::ServerConfig::load(paths.config_path())?;
38
39 launcher
40 .launch(
41 paths,
42 &config,
43 &loader_version,
44 show_logs,
45 show_gui,
46 callbacks,
47 )
48 .await;
49
50 Ok(())
51}