Skip to content

Commit

Permalink
Merge pull request #41 from Jupeyy/pr_vanilla_fixes
Browse files Browse the repository at this point in the history
Add rcon config variables to chain.
  • Loading branch information
Jupeyy authored Jan 7, 2025
2 parents c021626 + 13d66b7 commit f6d0192
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 109 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions game/game-base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ math = { path = "../../lib/math" }
base = { path = "../../lib/base" }
image = { path = "../../lib/image" }
graphics-types = { path = "../../lib/graphics-types" }
config = { path = "../../lib/config" }
command-parser = { path = "../../lib/command-parser" }
pool = { path = "../../lib/pool" }
hiarc = { path = "../../lib/hiarc", features = ["enable_time"] }

Expand Down
30 changes: 30 additions & 0 deletions game/game-base/src/config_helper.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use std::ops::Range;

use command_parser::parser::{self, Syn};

pub fn handle_config_variable_cmd(
cmd: &parser::Command,
config: &mut dyn config::traits::ConfigInterface,
) -> anyhow::Result<String> {
fn syn_vec_to_config_val(args: &[(Syn, Range<usize>)]) -> Option<String> {
args.first().map(|(arg, _)| match arg {
parser::Syn::Command(cmd) => cmd.cmd_text.clone(),
parser::Syn::Commands(cmds) => cmds
.first()
.map(|cmd| cmd.cmd_text.clone())
.unwrap_or_default(),
parser::Syn::Text(text) => text.clone(),
parser::Syn::Number(num) => num.clone(),
parser::Syn::Float(num) => num.clone(),
parser::Syn::JsonObjectLike(obj) => obj.clone(),
parser::Syn::JsonArrayLike(obj) => obj.clone(),
})
}
Ok(config.try_set_from_str(
cmd.cmd_text.clone(),
None,
syn_vec_to_config_val(&cmd.args),
None,
config::traits::ConfigFromStrOperation::Set,
)?)
}
1 change: 1 addition & 0 deletions game/game-base/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod assets_url;
pub mod browser_favorite_player;
pub mod config_helper;
pub mod datafile;
pub mod game_types;
pub mod indexmap_tests;
Expand Down
41 changes: 7 additions & 34 deletions game/game-server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::{
fmt::Debug,
net::IpAddr,
num::NonZeroUsize,
ops::Range,
path::PathBuf,
sync::{atomic::AtomicBool, Arc, Weak},
time::Duration,
Expand Down Expand Up @@ -83,6 +82,7 @@ use crate::{
};

use game_base::{
config_helper::handle_config_variable_cmd,
game_types::{is_next_tick, time_until_tick},
local_server_info::{LocalServerConnectInfo, LocalServerInfo, LocalServerState, ServerDbgGame},
network::{
Expand Down Expand Up @@ -527,7 +527,7 @@ impl Server {

match chain_cmd.cmd {
ServerRconCommand::ConfVariable => {
Self::handle_config_variable_cmd(&cmd, config).map(|msg| {
handle_config_variable_cmd(&cmd, config).map(|msg| {
format!("Updated value for {}: {}", cmd.cmd_text, msg)
})
}
Expand Down Expand Up @@ -557,8 +557,8 @@ impl Server {
};

if let ServerRconCommand::ConfVariable = chain_cmd.cmd {
Self::handle_config_variable_cmd(cmd, config)
.map(|msg| format!("Updated value for {}: {}", cmd.cmd_text, msg))
handle_config_variable_cmd(cmd, config)
.map(|msg| format!("Current value for {}: {}", cmd.cmd_text, msg))
} else {
Err(anyhow!("Failed to handle config variable: {cmd}"))
}
Expand Down Expand Up @@ -1701,33 +1701,6 @@ impl Server {
);
}

fn handle_config_variable_cmd(
cmd: &parser::Command,
config: &mut ConfigGame,
) -> anyhow::Result<String> {
fn syn_vec_to_config_val(args: &[(Syn, Range<usize>)]) -> Option<String> {
args.first().map(|(arg, _)| match arg {
parser::Syn::Command(cmd) => cmd.cmd_text.clone(),
parser::Syn::Commands(cmds) => cmds
.first()
.map(|cmd| cmd.cmd_text.clone())
.unwrap_or_default(),
parser::Syn::Text(text) => text.clone(),
parser::Syn::Number(num) => num.clone(),
parser::Syn::Float(num) => num.clone(),
parser::Syn::JsonObjectLike(obj) => obj.clone(),
parser::Syn::JsonArrayLike(obj) => obj.clone(),
})
}
Ok(config.try_set_from_str(
cmd.cmd_text.clone(),
None,
syn_vec_to_config_val(&cmd.args),
None,
config::traits::ConfigFromStrOperation::Set,
)?)
}

fn handle_cmd_full(
&mut self,
cmd: parser::Command,
Expand Down Expand Up @@ -1831,7 +1804,7 @@ impl Server {
Ok(res.join("\n"))
}
ServerRconCommand::ConfVariable => {
Self::handle_config_variable_cmd(&cmd, &mut self.config_game)
handle_config_variable_cmd(&cmd, &mut self.config_game)
.map(|msg| format!("Updated value for {}: {}", cmd.cmd_text, msg))
}
ServerRconCommand::Exec => {
Expand Down Expand Up @@ -1907,8 +1880,8 @@ impl Server {
};

if let ServerRconCommand::ConfVariable = chain_cmd.cmd {
Self::handle_config_variable_cmd(cmd, &mut self.config_game)
.map(|msg| format!("Updated value for {}: {}", cmd.cmd_text, msg))
handle_config_variable_cmd(cmd, &mut self.config_game)
.map(|msg| format!("Current value for {}: {}", cmd.cmd_text, msg))
} else {
Err(anyhow!("This command was invalid: {cmd}"))
}
Expand Down
7 changes: 7 additions & 0 deletions game/vanilla/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,11 @@ pub mod config {
/// this is false for vanilla
pub allow_player_vote_cam: bool,
}

/// Wraps vanilla config for the console chain
#[config_default]
#[derive(Debug, Clone, Serialize, Deserialize, ConfigInterface)]
pub struct ConfigVanillaWrapper {
pub vanilla: ConfigVanilla,
}
}
1 change: 1 addition & 0 deletions game/vanilla/src/entities/character.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ pub mod character {
self.weapons.copy_clone_from(&other.weapons);
self.buffs.copy_clone_from(&other.buffs);
self.debuffs.copy_clone_from(&other.debuffs);
self.queued_emoticon.clone_from(&other.queued_emoticon);
self.interactions.clone_from(&other.interactions);
}
}
Expand Down
Loading

0 comments on commit f6d0192

Please sign in to comment.