diff --git a/src/api/app/actions/init/mod.rs b/src/api/app/actions/init/mod.rs new file mode 100644 index 0000000..3574d6f --- /dev/null +++ b/src/api/app/actions/init/mod.rs @@ -0,0 +1,41 @@ +use std::sync::Arc; + +use anyhow::Result; +use cliclack::{input, intro}; +use tokio::sync::RwLock; + +use crate::api::{app::App, models::{network::Network, server::Server}}; + +impl App { + pub async fn init_server(&mut self) -> Result<()> { + intro("initializing server")?; + + let name: String = input("Name of the server?") + .interact()?; + + let mut server = Server { + name, + port: None, + sources: vec![], + }; + + self.server = Some(Arc::new(RwLock::new(server))); + + Ok(()) + } + + pub async fn init_network(&mut self) -> Result<()> { + intro("initializing network")?; + + let name: String = input("Name of the network?") + .interact()?; + + let mut nw = Network { + name, + }; + + self.network = Some(Arc::new(RwLock::new(nw))); + + Ok(()) + } +} diff --git a/src/api/app/actions/mod.rs b/src/api/app/actions/mod.rs index 110d33e..d6162b2 100644 --- a/src/api/app/actions/mod.rs +++ b/src/api/app/actions/mod.rs @@ -1,3 +1,5 @@ mod build; +mod init; pub use build::*; +pub use init::*; diff --git a/src/api/app/mod.rs b/src/api/app/mod.rs index 3d1c5fc..d965e75 100644 --- a/src/api/app/mod.rs +++ b/src/api/app/mod.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use anyhow::{Context, Result}; use tokio::sync::RwLock; -use super::models::{network::Network, Addon, Server}; +use super::models::{network::Network, Addon, server::Server}; pub mod actions; diff --git a/src/api/models/mod.rs b/src/api/models/mod.rs index a5d250f..2be555e 100644 --- a/src/api/models/mod.rs +++ b/src/api/models/mod.rs @@ -1,4 +1,3 @@ -mod server; mod modpack_source; mod step; mod env; @@ -8,8 +7,8 @@ pub mod packwiz; pub mod mrpack; pub mod unsup; pub mod network; +pub mod server; -pub use server::*; pub use modpack_source::*; pub use step::*; pub use addon::*; diff --git a/src/api/models/network/mod.rs b/src/api/models/network/mod.rs index 57cb30e..ee0c985 100644 --- a/src/api/models/network/mod.rs +++ b/src/api/models/network/mod.rs @@ -1,3 +1,3 @@ pub struct Network { - + pub name: String, } diff --git a/src/api/models/server/mod.rs b/src/api/models/server/mod.rs index 73f2d9e..cd6091b 100644 --- a/src/api/models/server/mod.rs +++ b/src/api/models/server/mod.rs @@ -2,6 +2,12 @@ use serde::{Serialize, Deserialize}; use super::AddonSource; +mod server_type; +mod server_flavor; + +pub use server_type::*; +pub use server_flavor::*; + #[derive(Debug, Deserialize, Serialize, Clone, PartialEq)] #[serde(default)] pub struct Server { diff --git a/src/api/models/server/server_flavor.rs b/src/api/models/server/server_flavor.rs new file mode 100644 index 0000000..c1b1f25 --- /dev/null +++ b/src/api/models/server/server_flavor.rs @@ -0,0 +1,34 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, PartialEq, Clone, Copy, Serialize, Deserialize)] +pub enum ServerFlavor { + Vanilla, + Modded, + Patched, + Proxy, +} + +impl ServerFlavor { + pub fn supports_datapacks(&self) -> bool { + match self { + ServerFlavor::Proxy => false, + _ => true, + } + } + + pub fn supports_mods(&self) -> bool { + match self { + ServerFlavor::Modded => true, + _ => false, + } + } + + pub fn supports_plugins(&self) -> bool { + match self { + ServerFlavor::Vanilla => false, + ServerFlavor::Modded => false, + ServerFlavor::Patched => true, + ServerFlavor::Proxy => true, + } + } +} diff --git a/src/api/models/server/server_type.rs b/src/api/models/server/server_type.rs new file mode 100644 index 0000000..c191412 --- /dev/null +++ b/src/api/models/server/server_type.rs @@ -0,0 +1,73 @@ +use serde::{Deserialize, Serialize}; +use crate::api::utils::serde::*; + +#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)] +#[serde(rename_all = "lowercase")] +pub enum BuildToolsFlavor { + #[default] + Spigot, + CraftBukkit, +} + +#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] +#[serde(tag = "type", rename_all = "lowercase")] +pub enum ServerType { + Vanilla { + mc_version: String, + }, + + PaperMC { + project: String, + #[serde(default = "str_latest")] + build: String, + }, + + Purpur { + #[serde(default = "str_latest")] + build: String, + }, + + Fabric { + #[serde(default = "str_latest")] + loader: String, + + #[serde(default = "str_latest")] + installer: String, + }, + + Quilt { + #[serde(default = "str_latest")] + loader: String, + + #[serde(default = "str_latest")] + installer: String, + }, + + NeoForge { + #[serde(default = "str_latest")] + loader: String, + }, + + Forge { + #[serde(default = "str_latest")] + loader: String, + }, + + BuildTools { + #[serde(default = "BuildToolsFlavor::default")] + software: BuildToolsFlavor, + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default = "Vec::new")] + args: Vec, + }, + + Paper {}, + Velocity {}, + Waterfall {}, + BungeeCord {}, + + Downloadable { + //#[serde(flatten)] + //inner: Downloadable, + }, +} diff --git a/src/api/utils/mod.rs b/src/api/utils/mod.rs index 8c5952c..13ff7f6 100644 --- a/src/api/utils/mod.rs +++ b/src/api/utils/mod.rs @@ -1,2 +1,3 @@ pub mod hashing; pub mod accessor; +pub mod serde; diff --git a/src/api/utils/serde.rs b/src/api/utils/serde.rs new file mode 100644 index 0000000..c3fa15a --- /dev/null +++ b/src/api/utils/serde.rs @@ -0,0 +1,3 @@ +pub fn str_latest() -> String { + "latest".to_owned() +} diff --git a/src/commands/init.rs b/src/commands/init.rs index 3a2c203..2bcccfd 100644 --- a/src/commands/init.rs +++ b/src/commands/init.rs @@ -11,6 +11,8 @@ pub struct Args { -pub async fn run(app: App, args: Args) -> Result<()> { +pub async fn run(mut app: App, args: Args) -> Result<()> { + + Ok(()) }