Skip to content

Commit

Permalink
Add exec & load for command line parsing in server.
Browse files Browse the repository at this point in the history
Rename server-bin to server.
  • Loading branch information
Jupeyy committed Jan 6, 2025
1 parent de2478c commit 40c2d21
Show file tree
Hide file tree
Showing 26 changed files with 592 additions and 418 deletions.
111 changes: 56 additions & 55 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ members = [
"examples/wasm-modules/graphics",
"examples/wasm-modules/mainmenu",
"examples/wasm-modules/ingame_menu",
"src/server-bin",
"src/server",
"src/emoticon-convert",
"src/game-convert",
"src/hud-convert",
Expand All @@ -67,7 +67,7 @@ members = [
"game/client-types",
"game/client-containers",
"game/client-ui",
"game/server",
"game/game-server",
"lib/game-database",
"game/game-base",
"game/vanilla",
Expand Down Expand Up @@ -166,7 +166,7 @@ client-demo = { path = "game/client-demo" }
client-replay = { path = "game/client-replay" }
ghost = { path = "game/ghost" }
client-ghost = { path = "game/client-ghost" }
server = { path = "game/server", default-features = false }
game-server = { path = "game/game-server", default-features = false }
game-base = { path = "game/game-base" }
game-interface = { path = "game/game-interface" }
game-network = { path = "game/game-network" }
Expand Down Expand Up @@ -231,7 +231,7 @@ opt-level = 3

[features]
bundled_data_dir = ["base-fs/bundled_data_dir"]
legacy = ["server/legacy", "editor-wasm/legacy", "editor/legacy"]
legacy = ["game-server/legacy", "editor-wasm/legacy", "editor/legacy"]
enable_steam = ["steam/runtime"]
microphone = ["microphone/cpal_opus"]
ffmpeg = ["client-demo/ffmpeg"]
Expand Down
3 changes: 3 additions & 0 deletions game/game-config-fs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ edition = "2021"

[dependencies]
base-io = { path = "../../lib/base-io" }

game-config = { path = "../game-config" }

anyhow = { version = "1.0.95", features = ["backtrace"] }
14 changes: 5 additions & 9 deletions game/game-config-fs/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,16 @@ pub fn save(config: &ConfigGame, io: &Io) {
}
}

pub fn load_in(io: &IoFileSys, path: &Path) -> ConfigGame {
pub fn load_in(io: &IoFileSys, path: &Path) -> anyhow::Result<ConfigGame> {
let fs = io.fs.clone();
let path = path.to_path_buf();
let config_file = io
.rt
.spawn(async move { Ok(fs.read_file(path.as_ref()).await) });
let res = config_file.get_storage().unwrap();
match res {
Ok(file) => ConfigGame::from_json_string(String::from_utf8(file).unwrap().as_str())
.unwrap_or_default(),
Err(_) => ConfigGame::new(),
}
.spawn(async move { Ok(fs.read_file(path.as_ref()).await?) });
let res = config_file.get_storage()?;
ConfigGame::from_json_slice(&res)
}

pub fn load(io: &IoFileSys) -> ConfigGame {
pub fn load(io: &IoFileSys) -> anyhow::Result<ConfigGame> {
load_in(io, "cfg_game.json".as_ref())
}
10 changes: 6 additions & 4 deletions game/game-config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -755,13 +755,15 @@ impl ConfigGame {
}

pub fn to_json_string(&self) -> anyhow::Result<String> {
let res = serde_json::to_string_pretty(self)?;
Ok(res)
Ok(serde_json::to_string_pretty(self)?)
}

pub fn from_json_string(json_str: &str) -> anyhow::Result<Self> {
let res = serde_json::from_str(json_str)?;
Ok(res)
Ok(serde_json::from_str(json_str)?)
}

pub fn from_json_slice(json: &[u8]) -> anyhow::Result<Self> {
Ok(serde_json::from_slice(json)?)
}
}

Expand Down
2 changes: 1 addition & 1 deletion game/server/Cargo.toml → game/game-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "server"
name = "game-server"
version = "0.1.0"
edition = "2021"

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use std::sync::{atomic::AtomicBool, Arc};

use base::{join_thread::JoinThread, system::System};
use config::config::ConfigEngine;
use game_base::local_server_info::{LocalServerInfo, LocalServerState, LocalServerThread};
use game_config::config::ConfigGame;
use network::network::utils::create_certifified_keys;
use game_base::local_server_info::{LocalServerInfo, LocalServerState, LocalServerThread};

use crate::server::ddnet_server_main;

Expand Down Expand Up @@ -37,7 +37,7 @@ pub fn start_local_server(
(cert, private_key),
server_is_open_clone,
shared_info_thread,
None,
Default::default(),
Some((config_engine, config_game)),
)
})
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions game/server/src/rcon.rs → game/game-server/src/rcon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,10 @@ pub enum ServerRconCommand {
KickId,
Status,
ConfVariable,
/// Executes a command line like file
/// and parses it in the command chain.
Exec,
/// Loads server config from a specific path
Load,
RecordDemo,
}
Loading

0 comments on commit 40c2d21

Please sign in to comment.