mirror of
https://github.com/zyllian/classics.git
synced 2025-01-18 03:32:41 -08:00
implement making players operators in config
This commit is contained in:
parent
c1eb4e1a8b
commit
990777e5b4
3 changed files with 15 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -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<String, PlayerType>,
|
||||
/// 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,
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Add table
Reference in a new issue