mirror of https://github.com/zyllian/classics.git synced 2025-05-11 14:26:40 -07:00

implement commands system

This commit is contained in:
Zoey 2024-04-22 22:02:06 -07:00
parent 37c82d8755
commit 19116ee308
No known key found for this signature in database
GPG key ID: 8611B896D1AAFAF2
5 changed files with 248 additions and 57 deletions

View file

@ -33,12 +33,13 @@ pub struct Player {
/// enum describing types of players
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
#[repr(u8)]
pub enum PlayerType {
/// a normal player
Normal = 0x00,
Normal,
/// moderator of the server
Moderator,
/// a player who's an operator
Operator = 0x64,
Operator,
}
impl Default for PlayerType {
@ -47,16 +48,25 @@ impl Default for PlayerType {
}
}
impl TryFrom<u8> for PlayerType {
type Error = ();
fn try_from(value: u8) -> Result<Self, Self::Error> {
if value == Self::Normal as u8 {
Ok(Self::Normal)
} else if value == Self::Operator as u8 {
Ok(Self::Operator)
} else {
Err(())
impl From<&PlayerType> for u8 {
fn from(val: &PlayerType) -> Self {
match val {
PlayerType::Normal => 0,
PlayerType::Moderator => 0x64,
PlayerType::Operator => 0x64,
}
}
}
impl TryFrom<&str> for PlayerType {
type Error = String;
fn try_from(value: &str) -> Result<Self, Self::Error> {
Ok(match value.to_lowercase().as_str() {
"normal" => Self::Normal,
"moderator" => Self::Moderator,
"operator" => Self::Operator,
value => return Err(format!("Unknown permissions type: {value}")),
})
}
}