Skip to content

Commit 1753640

Browse files
committed
Update configuration system
1 parent b5d8141 commit 1753640

5 files changed

Lines changed: 42 additions & 32 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/target
22
**/*.rs.bk
33
.idea
4+
feather.toml

server/config/feather.toml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
[io]
22
# Packets with a size more than or equal to this value will be sent compressed.
33
# Compressing packets reduces bandwidth usage but increases CPU activity.
4-
compression-threshold = 256
4+
compression_threshold = 256
55
# The number of worker threads used for asynchronous IO.
66
# Set to the number of cores on your CPU for optimal performance.
7-
io-worker-threads = 8
7+
io_worker_threads = 8
88

99
[proxy]
1010
# IP forwarding using either "bungee" (BungeeCord/Waterfall/Travertine) or "velocity" (Velocity)
11-
proxy-mode = "none"
11+
proxy_mode = "none"
1212

1313
[server]
14-
online-mode = true
14+
online_mode = true
1515
motd = "&lMesa called Jar Jar Binks!\n Mesa your humble servant!"
16-
max-players = 16
17-
default-gamemode = "survival"
18-
difficulty = "normal"
19-
view-distance = 6
16+
max_players = 16
17+
default_gamemode = "survival"
18+
difficulty = "none"
19+
view_distance = 6
2020
address = "127.0.0.1"
2121
port = 25565
2222

2323
[gameplay]
24-
monster-spawning = true
25-
animal-spawning = true
24+
monster_spawning = true
25+
animal_spawning = true
2626
pvp = true
27-
nerf-spawner-mobs = false
28-
# Either "1.8" or "1.9"
29-
pvp-style = "1.8"
27+
nerf_spawner_mobs = false
28+
# Either "classic" for 1.8 PvP or "new" for 1.9
29+
pvp_style = "classic"
3030

3131
[log]
3232
level = "trace"

server/src/config.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use feather_core::prelude::*;
2+
use serde::Deserializer;
3+
use serde::Serializer;
4+
use serde::{Deserialize, Serialize};
25
use std::fs::read_to_string;
3-
use serde::{Serialize, Deserialize};
46

5-
#[derive(Serialize, Deserialize, Debug)]
7+
#[derive(Deserialize, Debug)]
68
pub struct Config {
79
pub io: IO,
810
pub proxy: Proxy,
@@ -11,45 +13,40 @@ pub struct Config {
1113
pub log: Log,
1214
}
1315

14-
#[derive(Serialize, Deserialize, Debug)]
16+
#[derive(Deserialize, Debug)]
1517
pub struct IO {
1618
pub compression_threshold: i32,
1719
pub io_worker_threads: u16,
1820
}
1921

20-
#[derive(Serialize, Deserialize, Debug)]
21-
pub struct Proxy {
22-
pub proxy_mode: ProxyMode,
23-
}
22+
#[derive(Deserialize, Debug)]
23+
pub struct Proxy {}
2424

25-
#[derive(Serialize, Deserialize, Debug)]
25+
#[derive(Deserialize, Debug)]
2626
pub struct Server {
2727
pub online_mode: bool,
2828
pub motd: String,
2929
pub max_players: i32,
30-
pub default_gamemode: Gamemode,
31-
pub difficulty: Difficulty,
3230
pub view_distance: u8,
3331
pub address: String,
3432
pub port: u16,
3533
}
3634

37-
#[derive(Serialize, Deserialize, Debug)]
35+
#[derive(Deserialize, Debug)]
3836
pub struct Gameplay {
3937
pub monster_spawning: bool,
4038
pub animal_spawning: bool,
4139
pub pvp: bool,
4240
pub nerf_spawner_mobs: bool,
43-
pub pvp_style: PvpStyle,
4441
}
4542

46-
#[derive(Serialize, Deserialize, Debug)]
43+
#[derive(Deserialize, Debug)]
4744
pub struct Log {
48-
pub log_level: String,
45+
pub level: String,
4946
}
5047

5148
pub fn load() -> Result<Config, ()> {
52-
let config_content = read_to_string("config.toml").expect("Could not load configuration file");
49+
let config_content = read_to_string("feather.toml").expect("Could not load configuration file");
5350

5451
let config: Config = toml::from_str(&config_content).expect("Invalid configuration file");
5552

server/src/initialhandler.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ use crate::io::NewClientInfo;
22
use feather_core::network::packet::Packet;
33

44
pub struct InitialHandler {
5-
packets_to_send: Vec<Box<Packet>>,
65
state: State,
76
finished: bool,
87
}
98

109
impl InitialHandler {
1110
pub fn new() -> Self {
1211
Self {
13-
packets_to_send: vec![],
1412
state: State::Handshake,
1513
finished: false,
1614
}

server/src/main.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,28 @@ pub mod config;
1111
pub mod initialhandler;
1212
pub mod io;
1313

14+
pub use config::Config;
15+
1416
pub struct Server {}
1517

1618
fn main() {
1719
let config = config::load()
1820
.expect("Failed to load configuration. Please ensure that the file feather.toml exists and is correct.");
1921

20-
21-
simple_logger::init_with_level(log::Level::Trace).unwrap();
22+
init_log(&config);
2223

2324
info!("Starting Feather; please wait...");
2425
}
26+
27+
fn init_log(config: &Config) {
28+
let level = match config.log.level.as_str() {
29+
"trace" => log::Level::Trace,
30+
"debug" => log::Level::Debug,
31+
"info" => log::Level::Info,
32+
"warn" => log::Level::Warn,
33+
"error" => log::Level::Error,
34+
_ => panic!("Unknown log level {}", config.log.level),
35+
};
36+
37+
simple_logger::init_with_level(level);
38+
}

0 commit comments

Comments
 (0)