mirror of
https://github.com/zyllian/classics.git
synced 2025-01-18 11:47:14 -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 std::net::SocketAddr;
|
||||||
|
|
||||||
use half::f16;
|
use half::f16;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::packet::server::ServerPacket;
|
use crate::packet::server::ServerPacket;
|
||||||
|
|
||||||
|
@ -31,7 +32,7 @@ pub struct Player {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// enum describing types of players
|
/// 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)]
|
#[repr(u8)]
|
||||||
pub enum PlayerType {
|
pub enum PlayerType {
|
||||||
/// a normal player
|
/// a normal player
|
||||||
|
|
|
@ -3,7 +3,7 @@ use std::collections::BTreeMap;
|
||||||
use optional_struct::optional_struct;
|
use optional_struct::optional_struct;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::level::generation::LevelGeneration;
|
use crate::{level::generation::LevelGeneration, player::PlayerType};
|
||||||
|
|
||||||
/// configuration for the server
|
/// configuration for the server
|
||||||
#[optional_struct]
|
#[optional_struct]
|
||||||
|
@ -16,6 +16,8 @@ pub struct ServerConfig {
|
||||||
/// the server's protection mode
|
/// the server's protection mode
|
||||||
#[serde(rename = "password")]
|
#[serde(rename = "password")]
|
||||||
pub protection_mode: ServerProtectionMode,
|
pub protection_mode: ServerProtectionMode,
|
||||||
|
/// map of user permissions
|
||||||
|
pub player_perms: BTreeMap<String, PlayerType>,
|
||||||
/// the level's size
|
/// the level's size
|
||||||
pub level_size: ConfigCoordinates,
|
pub level_size: ConfigCoordinates,
|
||||||
/// the level's spawn point
|
/// the level's spawn point
|
||||||
|
@ -37,6 +39,7 @@ impl Default for ServerConfig {
|
||||||
name: "classic server wowie".to_string(),
|
name: "classic server wowie".to_string(),
|
||||||
motd: "here's the default server motd".to_string(),
|
motd: "here's the default server motd".to_string(),
|
||||||
protection_mode: ServerProtectionMode::None,
|
protection_mode: ServerProtectionMode::None,
|
||||||
|
player_perms: Default::default(),
|
||||||
level_size: ConfigCoordinates {
|
level_size: ConfigCoordinates {
|
||||||
x: 256,
|
x: 256,
|
||||||
y: 64,
|
y: 64,
|
||||||
|
|
|
@ -141,6 +141,13 @@ async fn handle_stream_inner(
|
||||||
.pop()
|
.pop()
|
||||||
.unwrap_or_else(|| data.players.len() as i8);
|
.unwrap_or_else(|| data.players.len() as i8);
|
||||||
|
|
||||||
|
let player_type = data
|
||||||
|
.config
|
||||||
|
.player_perms
|
||||||
|
.get(&username)
|
||||||
|
.copied()
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
let player = Player {
|
let player = Player {
|
||||||
_addr: addr,
|
_addr: addr,
|
||||||
id: *own_id, // TODO: actually assign user ids
|
id: *own_id, // TODO: actually assign user ids
|
||||||
|
@ -151,7 +158,7 @@ async fn handle_stream_inner(
|
||||||
z: zero,
|
z: zero,
|
||||||
yaw: 0,
|
yaw: 0,
|
||||||
pitch: 0,
|
pitch: 0,
|
||||||
player_type: PlayerType::Normal,
|
player_type,
|
||||||
packets_to_send: Vec::new(),
|
packets_to_send: Vec::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -159,7 +166,7 @@ async fn handle_stream_inner(
|
||||||
protocol_version: 0x07,
|
protocol_version: 0x07,
|
||||||
server_name: data.config.name.clone(),
|
server_name: data.config.name.clone(),
|
||||||
server_motd: data.config.motd.clone(),
|
server_motd: data.config.motd.clone(),
|
||||||
user_type: PlayerType::Normal,
|
user_type: player_type,
|
||||||
});
|
});
|
||||||
|
|
||||||
println!("generating level packets");
|
println!("generating level packets");
|
||||||
|
|
Loading…
Add table
Reference in a new issue