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