mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'coffee-compiler/restrict_chat_msg_len_client' into 'master'
Restrict chat message length on client side See merge request veloren/veloren!4557
This commit is contained in:
commit
b598f38eca
@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- Localization support for prompt dialogs, diary sections, trade and group invitations, command descriptions.
|
||||
- Added Freezing Potion
|
||||
- Clear command to delete chat messages.
|
||||
- Chat message capping to prevent too long messages before sending.
|
||||
|
||||
### Changed
|
||||
|
||||
|
@ -197,6 +197,7 @@ pub type ChatMsg = GenericChatMsg<String>;
|
||||
pub type UnresolvedChatMsg = GenericChatMsg<Group>;
|
||||
|
||||
impl<G> GenericChatMsg<G> {
|
||||
pub const MAX_BYTES_PLAYER_CHAT_MSG: usize = 256;
|
||||
pub const NPC_DISTANCE: f32 = 100.0;
|
||||
pub const NPC_SAY_DISTANCE: f32 = 30.0;
|
||||
pub const REGION_DISTANCE: f32 = 1000.0;
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::settings::ModerationSettings;
|
||||
use authc::Uuid;
|
||||
use censor::Censor;
|
||||
use common::comp::{AdminRole, ChatType, Group};
|
||||
use common::comp::{AdminRole, ChatMsg, ChatType, Group};
|
||||
use hashbrown::HashMap;
|
||||
use std::{
|
||||
fmt,
|
||||
@ -10,8 +10,6 @@ use std::{
|
||||
};
|
||||
use tracing::info;
|
||||
|
||||
pub const MAX_BYTES_CHAT_MSG: usize = 256;
|
||||
|
||||
pub enum ActionNote {
|
||||
SpamWarn,
|
||||
}
|
||||
@ -45,7 +43,7 @@ impl fmt::Display for ActionErr {
|
||||
ActionErr::TooLong => write!(
|
||||
f,
|
||||
"Your message was too long, no more than {} characters are permitted.",
|
||||
MAX_BYTES_CHAT_MSG
|
||||
ChatMsg::MAX_BYTES_PLAYER_CHAT_MSG
|
||||
),
|
||||
ActionErr::SpamMuted(dur) => write!(
|
||||
f,
|
||||
@ -99,7 +97,7 @@ impl AutoMod {
|
||||
msg: &str,
|
||||
) -> Result<Option<ActionNote>, ActionErr> {
|
||||
// TODO: Consider using grapheme cluster count instead of size in bytes
|
||||
if msg.len() > MAX_BYTES_CHAT_MSG {
|
||||
if msg.len() > ChatMsg::MAX_BYTES_PLAYER_CHAT_MSG {
|
||||
Err(ActionErr::TooLong)
|
||||
} else if !self.settings.automod
|
||||
// Is this a private chat message?
|
||||
|
@ -504,7 +504,10 @@ impl<'a> Widget for Chat<'a> {
|
||||
.set(state.ids.chat_input, ui)
|
||||
{
|
||||
input.retain(|c| c != '\n');
|
||||
state.update(|s| s.input.message = input);
|
||||
|
||||
if input.len() <= ChatMsg::MAX_BYTES_PLAYER_CHAT_MSG {
|
||||
state.update(|s| s.input.message = input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user