Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Neoforge support #410

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ target/

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

.idea/
1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ hex = "0.4.3"
toml = "0.7.4"
which = "5.0.0"
bollard = "*"
regex = "1.7.2"
[dependencies.uuid]
version = "1.1.2"
features = [
Expand Down
2 changes: 1 addition & 1 deletion core/bindings/ErrorKind.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export type ErrorKind = "NotFound" | "UnsupportedOperation" | "BadRequest" | "PermissionDenied" | "Unauthorized" | "Internal";
export type ErrorKind = "NotFound" | "UnsupportedOperation" | "BadRequest" | "PermissionDenied" | "Unauthorized" | "External" | "Internal";
2 changes: 1 addition & 1 deletion core/bindings/HandlerGameType.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export type HandlerGameType = "MinecraftJavaVanilla" | "MinecraftFabric" | "MinecraftForge" | "MinecraftPaper" | "MinecraftBedrock";
export type HandlerGameType = "MinecraftJavaVanilla" | "MinecraftFabric" | "MinecraftForge" | "MinecraftPaper" | "MinecraftBedrock" | "MinecraftNeoforge";
2 changes: 1 addition & 1 deletion core/bindings/MinecraftVariant.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export type MinecraftVariant = { "type": "Vanilla" } | { "type": "Forge" } | { "type": "Fabric" } | { "type": "Paper" } | { "type": "Spigot" } | { "type": "Other", name: string, };
export type MinecraftVariant = { "type": "Vanilla" } | { "type": "Forge" } | { "type": "Fabric" } | { "type": "Paper" } | { "type": "Spigot" } | { "type": "Neoforge" } | { "type": "Other", name: string, };
2 changes: 1 addition & 1 deletion core/bindings/UserPermission.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { InstanceUuid } from "./InstanceUuid";

export interface UserPermission { can_view_instance: Array<InstanceUuid>, can_start_instance: Array<InstanceUuid>, can_stop_instance: Array<InstanceUuid>, can_access_instance_console: Array<InstanceUuid>, can_access_instance_setting: Array<InstanceUuid>, can_read_instance_resource: Array<InstanceUuid>, can_write_instance_resource: Array<InstanceUuid>, can_access_instance_macro: Array<InstanceUuid>, can_read_instance_file: Array<InstanceUuid>, can_write_instance_file: Array<InstanceUuid>, can_create_instance: boolean, can_delete_instance: boolean, can_read_global_file: boolean, can_write_global_file: boolean, can_manage_permission: boolean, }
export interface UserPermission { can_view_instance: Array<InstanceUuid>, can_start_instance: Array<InstanceUuid>, can_stop_instance: Array<InstanceUuid>, can_access_instance_console: Array<InstanceUuid>, can_access_instance_setting: Array<InstanceUuid>, can_read_instance_resource: Array<InstanceUuid>, can_write_instance_resource: Array<InstanceUuid>, can_access_instance_macro: Array<InstanceUuid>, can_read_instance_file: Array<InstanceUuid>, can_write_instance_file: Array<InstanceUuid>, can_create_instance: boolean, can_delete_instance: boolean, can_read_global_file: boolean, can_write_global_file: boolean, can_manage_permission: boolean, can_install_extension: boolean, }
4 changes: 4 additions & 0 deletions core/src/handlers/instance_setup_configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub enum HandlerGameType {
MinecraftForge,
MinecraftPaper,
MinecraftBedrock,
MinecraftNeoforge,
}

impl From<HandlerGameType> for GameType {
Expand All @@ -35,6 +36,7 @@ impl From<HandlerGameType> for GameType {
HandlerGameType::MinecraftForge => Self::MinecraftJava,
HandlerGameType::MinecraftPaper => Self::MinecraftJava,
HandlerGameType::MinecraftBedrock => Self::MinecraftBedrock,
HandlerGameType::MinecraftNeoforge => Self::MinecraftJava,
}
}
}
Expand All @@ -48,6 +50,7 @@ impl TryFrom<HandlerGameType> for FlavourKind {
HandlerGameType::MinecraftFabric => Self::Fabric,
HandlerGameType::MinecraftForge => Self::Forge,
HandlerGameType::MinecraftPaper => Self::Paper,
HandlerGameType::MinecraftNeoforge => Self::Neoforge,
HandlerGameType::MinecraftBedrock => {
return Err(Error {
kind: ErrorKind::BadRequest,
Expand All @@ -64,6 +67,7 @@ pub async fn get_available_games() -> Json<Vec<HandlerGameType>> {
HandlerGameType::MinecraftFabric,
HandlerGameType::MinecraftForge,
HandlerGameType::MinecraftPaper,
HandlerGameType::MinecraftNeoforge,
])
}

Expand Down
6 changes: 6 additions & 0 deletions core/src/implementations/minecraft/configurable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ impl TConfigurable for MinecraftInstance {
source: eyre!("Changing versions is unsupported for forge servers"),
})
}
super::Flavour::Neoforge { .. } => {
return Err(Error {
kind: ErrorKind::UnsupportedOperation,
source: eyre!("Changing versions is unsupported for forge servers"), //TODO
});
}
};
let lodestone_tmp = path_to_tmp().clone();
let temp_dir = tempfile::tempdir_in(lodestone_tmp).context("Failed to create temp dir")?;
Expand Down
62 changes: 61 additions & 1 deletion core/src/implementations/minecraft/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub mod fabric;
mod forge;
mod line_parser;
pub mod r#macro;
mod neoforge;
mod paper;
pub mod player;
mod players_manager;
Expand Down Expand Up @@ -33,9 +34,14 @@ use tracing::error;
use tokio;
use ts_rs::TS;

use regex::Regex;

use crate::error::Error;
use crate::event_broadcaster::EventBroadcaster;
use crate::events::{Event, ProgressionEventID};
use crate::implementations::minecraft::neoforge::{
get_neoforge_minecraft_versions, NeoforgeVersion,
};
use crate::macro_executor::{MacroExecutor, MacroPID};
use crate::prelude::path_to_binaries;
use crate::traits::t_configurable::PathBuf;
Expand Down Expand Up @@ -92,6 +98,9 @@ pub enum Flavour {
Forge {
build_version: Option<ForgeBuildVersion>,
},
Neoforge {
build_version: Option<NeoforgeVersion>,
},
}

impl From<FlavourKind> for Flavour {
Expand All @@ -109,6 +118,9 @@ impl From<FlavourKind> for Flavour {
FlavourKind::Forge => Flavour::Forge {
build_version: None,
},
FlavourKind::Neoforge => Flavour::Neoforge {
build_version: None,
},
}
}
}
Expand All @@ -121,6 +133,7 @@ impl ToString for Flavour {
Flavour::Paper { .. } => "paper".to_string(),
Flavour::Spigot => "spigot".to_string(),
Flavour::Forge { .. } => "forge".to_string(),
Flavour::Neoforge { .. } => "neoforge".to_string(),
}
}
}
Expand All @@ -133,6 +146,7 @@ impl ToString for FlavourKind {
FlavourKind::Paper => "paper".to_string(),
FlavourKind::Spigot => "spigot".to_string(),
FlavourKind::Forge => "forge".to_string(),
FlavourKind::Neoforge => "neoforge".to_string(),
}
}
}
Expand Down Expand Up @@ -217,6 +231,7 @@ impl MinecraftInstance {
FlavourKind::Paper => get_paper_minecraft_versions().await,
FlavourKind::Spigot => todo!(),
FlavourKind::Forge => get_forge_minecraft_versions().await,
FlavourKind::Neoforge => get_neoforge_minecraft_versions().await,
}
.context("Failed to get minecraft versions")?;

Expand Down Expand Up @@ -463,8 +478,16 @@ impl MinecraftInstance {
e
})?;

let version_regex = Regex::new(r"^1\.\d+\.\d*0$").unwrap();

let version = if version_regex.is_match(config.version.as_str()) {
&config.version[..config.version.len() - 2]
} else {
config.version.as_str()
};

// Step 2: Download JRE
let (url, jre_major_version) = get_jre_url(config.version.as_str())
let (url, jre_major_version) = get_jre_url(version)
.await
.context("Could not get JRE URL")?;
if !path_to_runtimes
Expand Down Expand Up @@ -547,6 +570,7 @@ impl MinecraftInstance {
})?;
let jar_name = match flavour {
Flavour::Forge { .. } => "forge-installer.jar",
Flavour::Neoforge { .. } => "neoforge-installer.jar",
_ => "server.jar",
};

Expand Down Expand Up @@ -631,6 +655,42 @@ impl MinecraftInstance {
.context("Could not create user_jvm_args.txt")?;
}

if let Flavour::Neoforge { .. } = flavour.clone() {
event_broadcaster.send(Event::new_progression_event_update(
progression_event_id,
"3/4: Installing Neoforge Server",
1.0,
));

if !dont_spawn_terminal(
Command::new(&jre)
.arg("-jar")
.arg(&path_to_instance.join("neoforge-installer.jar"))
.arg("--installServer")
.arg(&path_to_instance)
.current_dir(&path_to_instance),
)
.stderr(Stdio::null())
.stdout(Stdio::null())
.stdin(Stdio::null())
.spawn()
.context("Failed to start neoforge-installer.jar")?
.wait()
.await
.context("neoforge-installer.jar failed")?
.success()
{
return Err(eyre!("Failed to install neoforge server").into());
}

tokio::fs::write(
&path_to_instance.join("user_jvm_args.txt"),
"# Generated by Lodestone\n# This file is ignored by Lodestone\n# Please set arguments using Lodestone",
)
.await
.context("Could not create user_jvm_args.txt")?;
}

// Step 4: Finishing Up
event_broadcaster.send(Event::new_progression_event_update(
progression_event_id,
Expand Down
Loading