diff --git a/src/player.rs b/src/player.rs index 6269e74..5f24fce 100644 --- a/src/player.rs +++ b/src/player.rs @@ -1,6 +1,7 @@ use std::net::SocketAddr; use half::f16; +use serde::{Deserialize, Serialize}; use crate::packet::server::ServerPacket; @@ -31,7 +32,7 @@ pub struct Player { } /// enum describing types of players -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] #[repr(u8)] pub enum PlayerType { /// a normal player diff --git a/src/server/config.rs b/src/server/config.rs index 2022840..401be62 100644 --- a/src/server/config.rs +++ b/src/server/config.rs @@ -3,7 +3,7 @@ use std::collections::BTreeMap; use optional_struct::optional_struct; use serde::{Deserialize, Serialize}; -use crate::level::generation::LevelGeneration; +use crate::{level::generation::LevelGeneration, player::PlayerType}; /// configuration for the server #[optional_struct] @@ -16,6 +16,8 @@ pub struct ServerConfig { /// the server's protection mode #[serde(rename = "password")] pub protection_mode: ServerProtectionMode, + /// map of user permissions + pub player_perms: BTreeMap, /// the level's size pub level_size: ConfigCoordinates, /// the level's spawn point @@ -37,6 +39,7 @@ impl Default for ServerConfig { name: "classic server wowie".to_string(), motd: "here's the default server motd".to_string(), protection_mode: ServerProtectionMode::None, + player_perms: Default::default(), level_size: ConfigCoordinates { x: 256, y: 64, diff --git a/src/server/network.rs b/src/server/network.rs index 8fb8ec4..5e5df30 100644 --- a/src/server/network.rs +++ b/src/server/network.rs @@ -141,6 +141,13 @@ async fn handle_stream_inner( .pop() .unwrap_or_else(|| data.players.len() as i8); + let player_type = data + .config + .player_perms + .get(&username) + .copied() + .unwrap_or_default(); + let player = Player { _addr: addr, id: *own_id, // TODO: actually assign user ids @@ -151,7 +158,7 @@ async fn handle_stream_inner( z: zero, yaw: 0, pitch: 0, - player_type: PlayerType::Normal, + player_type, packets_to_send: Vec::new(), }; @@ -159,7 +166,7 @@ async fn handle_stream_inner( protocol_version: 0x07, server_name: data.config.name.clone(), server_motd: data.config.motd.clone(), - user_type: PlayerType::Normal, + user_type: player_type, }); println!("generating level packets");