diff options
| author | Fuwn <[email protected]> | 2021-06-02 20:47:21 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-06-02 20:47:21 +0000 |
| commit | f0c01f1478844f2c7d2928883daac1d89bc54ba9 (patch) | |
| tree | 611ecf101166921c4ef8e928ea6d457ba0a09490 /crates/whirl_server/src/cmd/commands | |
| parent | refactor(server): replace more matches with enums (diff) | |
| download | whirl-f0c01f1478844f2c7d2928883daac1d89bc54ba9.tar.xz whirl-f0c01f1478844f2c7d2928883daac1d89bc54ba9.zip | |
refactor(server): final refactoring of replacing command type constants with enum values
Diffstat (limited to 'crates/whirl_server/src/cmd/commands')
4 files changed, 14 insertions, 14 deletions
diff --git a/crates/whirl_server/src/cmd/commands/buddy_list.rs b/crates/whirl_server/src/cmd/commands/buddy_list.rs index f80c86d..9b53ac2 100644 --- a/crates/whirl_server/src/cmd/commands/buddy_list.rs +++ b/crates/whirl_server/src/cmd/commands/buddy_list.rs @@ -6,10 +6,7 @@ use std::str::from_utf8; use bytes::{BufMut, BytesMut}; use num_traits::AsPrimitive; -use crate::cmd::{ - constants::BUDDYLISTNOTIFY, - extendable::{Creatable, Parsable}, -}; +use crate::cmd::extendable::{Creatable, Parsable}; pub struct BuddyList { pub buddy: String, @@ -33,7 +30,8 @@ impl Creatable for BuddyList { // Header command.put_u8(0x01); // ObjId - command.put_i8(BUDDYLISTNOTIFY.as_(): i8); // Type + #[allow(clippy::cast_possible_truncation)] + command.put_i8(crate::cmd::constants::Command::BuddyListNotify as i32 as i8); // Type // Content command.put_u8(self.buddy.len().as_(): u8); // Buddy (name) length diff --git a/crates/whirl_server/src/cmd/commands/property/create.rs b/crates/whirl_server/src/cmd/commands/property/create.rs index 94cf75b..d689857 100644 --- a/crates/whirl_server/src/cmd/commands/property/create.rs +++ b/crates/whirl_server/src/cmd/commands/property/create.rs @@ -6,7 +6,7 @@ use whirl_config::Config; use crate::{ - cmd::constants::{PROPUPD, SESSINIT}, + cmd::constants::Command, net::{ constants::{ VAR_APPNAME, @@ -29,7 +29,7 @@ use crate::{ pub fn property_update_as_distributor() -> Vec<u8> { property_list_to_bytes( - PROPUPD, + Command::PropUpd as i32, 0xFF, vec![ NetworkProperty { @@ -66,7 +66,7 @@ pub fn property_update_as_distributor() -> Vec<u8> { pub fn property_update_as_hub() -> Vec<u8> { property_list_to_bytes( - PROPUPD, + Command::PropUpd as i32, 0xFF, vec![ NetworkProperty { @@ -107,7 +107,7 @@ pub fn property_update_as_hub() -> Vec<u8> { pub fn property_request_as_distributor() -> Vec<u8> { property_list_to_bytes( - SESSINIT as i32, + Command::SessInit as i32, 0x01, vec![ NetworkProperty { @@ -144,7 +144,7 @@ pub fn property_request_as_distributor() -> Vec<u8> { pub fn property_request_as_hub() -> Vec<u8> { property_list_to_bytes( - SESSINIT as i32, + Command::SessInit as i32, 0x01, vec![ NetworkProperty { diff --git a/crates/whirl_server/src/cmd/commands/redirect_id.rs b/crates/whirl_server/src/cmd/commands/redirect_id.rs index 9727107..3a7bb83 100644 --- a/crates/whirl_server/src/cmd/commands/redirect_id.rs +++ b/crates/whirl_server/src/cmd/commands/redirect_id.rs @@ -5,7 +5,7 @@ use bytes::{BufMut, BytesMut}; use num_traits::AsPrimitive; use whirl_config::Config; -use crate::cmd::{constants::REDIRID, extendable::Creatable}; +use crate::cmd::{constants::Command, extendable::Creatable}; #[derive(Debug)] pub struct RedirectId { @@ -18,7 +18,8 @@ impl Creatable for RedirectId { // Header command.put_u8(0x01); // ObjId - command.put_u8(REDIRID.as_(): u8); // Type + #[allow(clippy::cast_possible_truncation)] + command.put_i8(Command::RedirId as i32 as i8); // Type // Content command.put_u8(self.room_name.len().as_(): u8); // Room name length diff --git a/crates/whirl_server/src/cmd/commands/text.rs b/crates/whirl_server/src/cmd/commands/text.rs index 414dc64..d2fddf6 100644 --- a/crates/whirl_server/src/cmd/commands/text.rs +++ b/crates/whirl_server/src/cmd/commands/text.rs @@ -7,7 +7,7 @@ use bytes::{BufMut, BytesMut}; use num_traits::AsPrimitive; use crate::cmd::{ - constants::TEXT, + constants::Command, extendable::{Creatable, ParsableWithArguments}, }; @@ -21,7 +21,8 @@ impl Creatable for Text { // Header command.put_u8(0x01); - command.put_i8(TEXT.as_(): i8); + #[allow(clippy::cast_possible_truncation)] + command.put_i8(Command::Text as i32 as i8); // Content // TODO: Find a way to parse ObjIds. |