diff options
| author | Fuwn <[email protected]> | 2021-07-04 04:02:23 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-07-04 04:02:23 -0700 |
| commit | c31442b473fd465e1b78eb3041bcc5d847ba4944 (patch) | |
| tree | 44085e3b32d4e8dc588cb5acaceec2e1456c02ac | |
| parent | test(make): add `checkall` task which performs a suite of checks (diff) | |
| download | whirl-c31442b473fd465e1b78eb3041bcc5d847ba4944.tar.xz whirl-c31442b473fd465e1b78eb3041bcc5d847ba4944.zip | |
feat(whirl_server): create REGOBJID and APPRACTR commands
| -rw-r--r-- | crates/whirl_server/src/cmd/commands/appear_actor.rs | 42 | ||||
| -rw-r--r-- | crates/whirl_server/src/cmd/commands/mod.rs | 2 | ||||
| -rw-r--r-- | crates/whirl_server/src/cmd/commands/register_object_id.rs | 35 |
3 files changed, 79 insertions, 0 deletions
diff --git a/crates/whirl_server/src/cmd/commands/appear_actor.rs b/crates/whirl_server/src/cmd/commands/appear_actor.rs new file mode 100644 index 0000000..89f0022 --- /dev/null +++ b/crates/whirl_server/src/cmd/commands/appear_actor.rs @@ -0,0 +1,42 @@ +// Copyright (C) 2021-2021 The Whirlsplash Collective +// SPDX-License-Identifier: GPL-3.0-only + +use bytes::{BufMut, BytesMut}; +use num_traits::AsPrimitive; + +use crate::cmd::{constants::Command, extendable::Creatable}; + +#[derive(Debug)] +pub struct AppearActor { + pub short_object_id: i8, + pub room_id: u16, + pub x: i16, + pub y: i16, + pub z: i16, + pub direction: i16, +} +impl Creatable for AppearActor { + fn create(&self) -> Vec<u8> { + let mut command = BytesMut::new(); + + // Header + command.put_u8(0xFE); // ObjId + #[allow(clippy::cast_possible_truncation)] + command.put_i8(Command::ApprActr as i32 as i8); // Type + + // Content + command.put_i8(self.short_object_id.as_(): i8); // ObjId, why is it here? Worlds... + command.put_u16(self.room_id.as_(): u16); // Room ID + command.put_u16(self.x.as_(): u16); // X + command.put_u16(self.y.as_(): u16); // Y + command.put_u16(self.z.as_(): u16); // Z + command.put_u16(self.direction.as_(): u16); // Direction + + // Length + let mut command_as_vec = command.to_vec(); + command_as_vec.insert(0, command.len().as_(): u8 + 1); + + // Return + command_as_vec + } +} diff --git a/crates/whirl_server/src/cmd/commands/mod.rs b/crates/whirl_server/src/cmd/commands/mod.rs index 7f8bb4a..0129d47 100644 --- a/crates/whirl_server/src/cmd/commands/mod.rs +++ b/crates/whirl_server/src/cmd/commands/mod.rs @@ -2,9 +2,11 @@ // SPDX-License-Identifier: GPL-3.0-only pub mod action; +pub mod appear_actor; pub mod buddy_list; pub mod property; pub mod redirect_id; +pub mod register_object_id; pub mod room_id_request; pub mod session_exit; pub mod subscribe_distance; diff --git a/crates/whirl_server/src/cmd/commands/register_object_id.rs b/crates/whirl_server/src/cmd/commands/register_object_id.rs new file mode 100644 index 0000000..61e15a5 --- /dev/null +++ b/crates/whirl_server/src/cmd/commands/register_object_id.rs @@ -0,0 +1,35 @@ +// Copyright (C) 2021-2021 The Whirlsplash Collective +// SPDX-License-Identifier: GPL-3.0-only + +use bytes::{BufMut, BytesMut}; +use num_traits::AsPrimitive; + +use crate::cmd::{constants::Command, extendable::Creatable}; + +#[derive(Debug)] +pub struct RegisterObjectId { + pub long_object_id: String, + pub short_object_id: i8, +} +impl Creatable for RegisterObjectId { + fn create(&self) -> Vec<u8> { + let mut command = BytesMut::new(); + + // Header + command.put_u8(0xFF); // ObjId + #[allow(clippy::cast_possible_truncation)] + command.put_i8(Command::RegObjId as i32 as i8); // Type + + // Content + command.put_u8(self.long_object_id.len().as_(): u8); // Long object ID length + command.put_slice(self.long_object_id.as_bytes()); // Long object ID + command.put_i8(self.short_object_id.as_(): i8); // Short object ID + + // Length + let mut command_as_vec = command.to_vec(); + command_as_vec.insert(0, command.len().as_(): u8 + 1); + + // Return + command_as_vec + } +} |