aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-06-02 20:26:50 +0000
committerFuwn <[email protected]>2021-06-02 20:26:50 +0000
commit2974c0d619db1eb28f16a2b7f59c462f06ea574d (patch)
tree06b6bf709760e4b5f3198b2a97a67edb41ba8e45
parentrefactor(server): use enum for command types (diff)
downloadwhirl-2974c0d619db1eb28f16a2b7f59c462f06ea574d.tar.xz
whirl-2974c0d619db1eb28f16a2b7f59c462f06ea574d.zip
refactor(server): replace more matches with enums
-rw-r--r--crates/whirl_server/src/hub.rs34
1 files changed, 12 insertions, 22 deletions
diff --git a/crates/whirl_server/src/hub.rs b/crates/whirl_server/src/hub.rs
index b2e2dfb..7ccd247 100644
--- a/crates/whirl_server/src/hub.rs
+++ b/crates/whirl_server/src/hub.rs
@@ -30,17 +30,7 @@ use crate::{
teleport::Teleport,
text::Text,
},
- constants::{
- BUDDYLISTUPDATE,
- PROPREQ,
- PROPSET,
- SESSEXIT,
- SESSINIT,
- SUBSCRIB,
- SUB_DIST,
- TELEPORT,
- TEXT,
- },
+ constants::Command,
extendable::{Creatable, Parsable, ParsableWithArguments},
},
interaction::{peer::Peer, shared::Shared},
@@ -74,15 +64,15 @@ impl Server for Hub {
Some(Ok(msg)) => {
// trace!("got some bytes: {:?}", &msg);
for msg in parse_commands_from_packet(msg) {
- match msg.get(2).unwrap().to_owned().as_(): i32 {
- PROPREQ => {
+ match num_traits::FromPrimitive::from_i32(msg.get(2).unwrap().to_owned().as_(): i32) {
+ Some(Command::PropReq) => {
debug!("received property request from client");
peer.bytes.get_mut()
.write_all(&property_update_as_hub()).await?;
trace!("sent property update to client");
}
- SESSINIT => {
+ Some(Command::SessInit) => {
username = (&*find_property_in_property_list(
&parse_network_property(msg[3..].to_vec()),
VAR_USERNAME,
@@ -94,7 +84,7 @@ impl Server for Hub {
.write_all(&property_request_as_hub()).await?;
trace!("sent property request to {}", username);
}
- PROPSET => {
+ Some(Command::PropSet) => {
debug!("received property set from {}", username);
peer.bytes.get_mut()
@@ -106,22 +96,22 @@ impl Server for Hub {
.write_all(&create()).await?;
trace!("sent text to {}", username);
}
- BUDDYLISTUPDATE => {
+ Some(Command::BuddyListUpdate) => {
let buddy = BuddyList::parse(msg.to_vec());
debug!("received buddy list update from {}: {}", username, buddy.buddy);
peer.bytes.get_mut().write_all(&buddy.create()).await?;
trace!("sent buddy list notify to {}: {}", username, buddy.buddy);
}
// TODO: Figure out if this is actually even needed.
- // ROOMIDRQ => {
+ // Some(Command::RoomIdRq) => {
// let room = RoomIdRequest::parse(msg.to_vec());
// debug!("received room id request from {}: {}", username, room.room_name);
// trace!("{:?}", create_room_id_request(&room.room_name, 0x00));
// }
- SESSEXIT => {
+ Some(Command::SessExit) => {
debug!("received session exit from {}", username); break;
}
- TEXT => {
+ Some(Command::Text) => {
let text = Text::parse(msg.to_vec(), &[&username]);
debug!("received text from {}:{}", username, text.content);
@@ -133,17 +123,17 @@ impl Server for Hub {
}
debug!("broadcasted text to hub");
}
- SUBSCRIB => {
+ Some(Command::Subscrib) => {
let subscribe_room = SubscribeRoom::parse(msg[3..].to_vec());
debug!("received subscribe room from {}: {:?}",
username, subscribe_room);
}
- SUB_DIST => {
+ Some(Command::SubDist) => {
let subscribe_distance = SubscribeDistance::parse(msg[3..].to_vec());
debug!("received subscribe distance from {}: {:?}",
username, subscribe_distance);
}
- TELEPORT => {
+ Some(Command::Teleport) => {
let teleport = Teleport::parse(msg[3..].to_vec());
debug!("received teleport from {}: {:?}",
username, teleport);