From 0069196e3c4da7c351aed9c42e70d59ea3dc9061 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sat, 22 Mar 2025 19:17:01 -0400 Subject: [PATCH] Move some constants to common module --- src/common/custom_ipc.rs | 3 +-- src/common/mod.rs | 6 ++++++ src/lib.rs | 5 ----- src/lobby/ipc/character_action.rs | 2 +- src/lobby/ipc/character_list.rs | 2 +- src/world/chat_handler.rs | 3 +-- src/world/ipc/common_spawn.rs | 3 +-- src/world/ipc/player_setup.rs | 5 +---- src/world/ipc/social_list.rs | 5 +---- 9 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/common/custom_ipc.rs b/src/common/custom_ipc.rs index bb0afdc..89f9f2f 100644 --- a/src/common/custom_ipc.rs +++ b/src/common/custom_ipc.rs @@ -1,8 +1,7 @@ use binrw::binrw; use crate::{ - CHAR_NAME_MAX_LENGTH, - common::read_string, + common::{CHAR_NAME_MAX_LENGTH, read_string}, lobby::ipc::CharacterDetails, packet::{IpcSegment, ReadWriteIpcSegment}, }; diff --git a/src/common/mod.rs b/src/common/mod.rs index 5ab6aae..5fdc170 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -14,6 +14,12 @@ use crate::config::get_config; pub mod custom_ipc; +/// An invalid actor/object id. +pub const INVALID_OBJECT_ID: u32 = 0xE0000000; + +/// Maxmimum length of a character's name. +pub const CHAR_NAME_MAX_LENGTH: usize = 32; + pub(crate) fn read_string(byte_stream: Vec) -> String { let str = String::from_utf8(byte_stream).unwrap(); str.trim_matches(char::from(0)).to_string() // trim \0 from the end of strings diff --git a/src/lib.rs b/src/lib.rs index e8ad7fb..b2fa6ae 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,11 +26,6 @@ pub mod packet; /// Logic server-specific code. pub mod login; -pub const INVALID_OBJECT_ID: u32 = 0xE0000000; - -/// Maxmimum length of a character's name. -pub const CHAR_NAME_MAX_LENGTH: usize = 32; - pub fn setup_default_environment() -> Environment<'static> { let mut env = Environment::new(); env.add_template("admin.html", include_str!("../templates/admin.html")) diff --git a/src/lobby/ipc/character_action.rs b/src/lobby/ipc/character_action.rs index 0d0bf2e..95f482a 100644 --- a/src/lobby/ipc/character_action.rs +++ b/src/lobby/ipc/character_action.rs @@ -1,6 +1,6 @@ use binrw::binrw; -use crate::CHAR_NAME_MAX_LENGTH; +use crate::common::CHAR_NAME_MAX_LENGTH; use super::{read_string, write_string}; diff --git a/src/lobby/ipc/character_list.rs b/src/lobby/ipc/character_list.rs index 30cd378..8d1dc77 100644 --- a/src/lobby/ipc/character_list.rs +++ b/src/lobby/ipc/character_list.rs @@ -1,6 +1,6 @@ use binrw::binrw; -use crate::CHAR_NAME_MAX_LENGTH; +use crate::common::CHAR_NAME_MAX_LENGTH; use super::{read_string, write_string}; diff --git a/src/world/chat_handler.rs b/src/world/chat_handler.rs index 73e6cbe..266eb68 100644 --- a/src/world/chat_handler.rs +++ b/src/world/chat_handler.rs @@ -1,6 +1,5 @@ use crate::{ - INVALID_OBJECT_ID, - common::{CustomizeData, timestamp_secs}, + common::{CustomizeData, INVALID_OBJECT_ID, timestamp_secs}, config::get_config, packet::{PacketSegment, SegmentType}, world::ipc::{ diff --git a/src/world/ipc/common_spawn.rs b/src/world/ipc/common_spawn.rs index e9cb0b5..12b8127 100644 --- a/src/world/ipc/common_spawn.rs +++ b/src/world/ipc/common_spawn.rs @@ -1,7 +1,6 @@ use binrw::binrw; -use crate::CHAR_NAME_MAX_LENGTH; -use crate::common::{CustomizeData, read_string, write_string}; +use crate::common::{CHAR_NAME_MAX_LENGTH, CustomizeData, read_string, write_string}; use super::StatusEffect; use super::position::Position; diff --git a/src/world/ipc/player_setup.rs b/src/world/ipc/player_setup.rs index 2e04392..100d75b 100644 --- a/src/world/ipc/player_setup.rs +++ b/src/world/ipc/player_setup.rs @@ -1,9 +1,6 @@ use binrw::binrw; -use crate::{ - CHAR_NAME_MAX_LENGTH, - common::{read_string, write_string}, -}; +use crate::common::{CHAR_NAME_MAX_LENGTH, read_string, write_string}; #[binrw] #[derive(Debug, Clone, Default)] diff --git a/src/world/ipc/social_list.rs b/src/world/ipc/social_list.rs index 86bbf48..30eb568 100644 --- a/src/world/ipc/social_list.rs +++ b/src/world/ipc/social_list.rs @@ -1,9 +1,6 @@ use binrw::binrw; -use crate::{ - CHAR_NAME_MAX_LENGTH, - common::{read_string, write_string}, -}; +use crate::common::{CHAR_NAME_MAX_LENGTH, read_string, write_string}; #[binrw] #[brw(repr = u8)]