veloren/common/src/msg/mod.rs
Nicolas 6e4d556073 Add max chat message length
Fixes #115
Credit to @scorpion9979 for the previous implementation (https://gitlab.com/veloren/veloren/merge_requests/215)
2019-10-04 16:14:54 +02:00

34 lines
778 B
Rust

pub mod client;
pub mod ecs_packet;
pub mod server;
// Reexports
pub use self::client::ClientMsg;
pub use self::ecs_packet::{EcsCompPacket, EcsResPacket};
pub use self::server::{RequestStateError, ServerError, ServerInfo, ServerMsg};
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
pub enum ClientState {
Pending,
Connected,
Registered,
Spectator,
Dead,
Character,
}
pub const MAX_BYTES_CHAT_MSG: usize = 80;
pub enum ChatMsgValidationError {
TooLong,
}
pub fn validate_chat_msg(msg: &str) -> Result<(), ChatMsgValidationError> {
// TODO: Consider using grapheme cluster count instead of size in bytes
if msg.len() <= MAX_BYTES_CHAT_MSG {
Ok(())
} else {
Err(ChatMsgValidationError::TooLong)
}
}