misc chat mode changes

This commit is contained in:
CapsizeGlimmer 2020-06-12 13:44:29 -04:00 committed by Forest Anderson
parent 5ad212b7ed
commit b04810cae5
10 changed files with 165 additions and 174 deletions

View File

@ -1044,8 +1044,8 @@ impl Client {
comp::ChatType::Offline => message.to_string(), comp::ChatType::Offline => message.to_string(),
comp::ChatType::CommandError => message.to_string(), comp::ChatType::CommandError => message.to_string(),
comp::ChatType::CommandInfo => message.to_string(), comp::ChatType::CommandInfo => message.to_string(),
comp::ChatType::FactionMeta => message.to_string(), comp::ChatType::FactionMeta(_) => message.to_string(),
comp::ChatType::GroupMeta => message.to_string(), comp::ChatType::GroupMeta(_) => message.to_string(),
comp::ChatType::Kill => message.to_string(), comp::ChatType::Kill => message.to_string(),
comp::ChatType::Tell(from, to) => { comp::ChatType::Tell(from, to) => {
let from_alias = alias_of_uid(from); let from_alias = alias_of_uid(from);

View File

@ -4,7 +4,6 @@ use tracing::warn;
use std::{ use std::{
collections::HashMap, collections::HashMap,
fmt::{self, Display}, fmt::{self, Display},
ops::Deref,
path::Path, path::Path,
str::FromStr, str::FromStr,
}; };
@ -404,7 +403,7 @@ impl ChatCommand {
/// A boolean that is used to check whether the command requires /// A boolean that is used to check whether the command requires
/// administrator permissions or not. /// administrator permissions or not.
pub fn needs_admin(&self) -> bool { *self.data().needs_admin } pub fn needs_admin(&self) -> bool { IsAdminOnly::Admin == self.data().needs_admin }
/// Returns a format string for parsing arguments with scan_fmt /// Returns a format string for parsing arguments with scan_fmt
pub fn arg_fmt(&self) -> String { pub fn arg_fmt(&self) -> String {
@ -461,34 +460,17 @@ impl FromStr for ChatCommand {
} }
} }
#[derive(Eq, PartialEq, Debug)]
pub enum IsAdminOnly { pub enum IsAdminOnly {
Admin, Admin,
NoAdmin, NoAdmin,
} }
impl Deref for IsAdminOnly {
type Target = bool;
fn deref(&self) -> &bool { #[derive(Eq, PartialEq, Debug)]
match self {
IsAdminOnly::Admin => &true,
IsAdminOnly::NoAdmin => &false,
}
}
}
pub enum Requirement { pub enum Requirement {
Required, Required,
Optional, Optional,
} }
impl Deref for Requirement {
type Target = bool;
fn deref(&self) -> &bool {
match self {
Requirement::Required => &true,
Requirement::Optional => &false,
}
}
}
/// Representation for chat command arguments /// Representation for chat command arguments
pub enum ArgumentSpec { pub enum ArgumentSpec {
@ -524,50 +506,50 @@ impl ArgumentSpec {
pub fn usage_string(&self) -> String { pub fn usage_string(&self) -> String {
match self { match self {
ArgumentSpec::PlayerName(req) => { ArgumentSpec::PlayerName(req) => {
if **req { if &Requirement::Required == req {
"<player>".to_string() "<player>".to_string()
} else { } else {
"[player]".to_string() "[player]".to_string()
} }
}, },
ArgumentSpec::Float(label, _, req) => { ArgumentSpec::Float(label, _, req) => {
if **req { if &Requirement::Required == req {
format!("<{}>", label) format!("<{}>", label)
} else { } else {
format!("[{}]", label) format!("[{}]", label)
} }
}, },
ArgumentSpec::Integer(label, _, req) => { ArgumentSpec::Integer(label, _, req) => {
if **req { if &Requirement::Required == req {
format!("<{}>", label) format!("<{}>", label)
} else { } else {
format!("[{}]", label) format!("[{}]", label)
} }
}, },
ArgumentSpec::Any(label, req) => { ArgumentSpec::Any(label, req) => {
if **req { if &Requirement::Required == req {
format!("<{}>", label) format!("<{}>", label)
} else { } else {
format!("[{}]", label) format!("[{}]", label)
} }
}, },
ArgumentSpec::Command(req) => { ArgumentSpec::Command(req) => {
if **req { if &Requirement::Required == req {
"<[/]command>".to_string() "<[/]command>".to_string()
} else { } else {
"[[/]command]".to_string() "[[/]command]".to_string()
} }
}, },
ArgumentSpec::Message(req) => { ArgumentSpec::Message(req) => {
if **req { if &Requirement::Required == req {
"<message>".to_string() "<message>".to_string()
} else { } else {
"<message>".to_string() "[message]".to_string()
} }
}, },
ArgumentSpec::SubCommand => "<[/]command> [args...]".to_string(), ArgumentSpec::SubCommand => "<[/]command> [args...]".to_string(),
ArgumentSpec::Enum(label, _, req) => { ArgumentSpec::Enum(label, _, req) => {
if **req { if &Requirement::Required == req {
format! {"<{}>", label} format! {"<{}>", label}
} else { } else {
format! {"[{}]", label} format! {"[{}]", label}

View File

@ -60,9 +60,9 @@ pub enum ChatType {
/// Inform players that someone died /// Inform players that someone died
Kill, Kill,
/// Server notifications to a group, such as player join/leave /// Server notifications to a group, such as player join/leave
GroupMeta, GroupMeta(String),
/// Server notifications to a faction, such as player join/leave /// Server notifications to a faction, such as player join/leave
FactionMeta, FactionMeta(String),
/// One-on-one chat (from, to) /// One-on-one chat (from, to)
Tell(Uid, Uid), Tell(Uid, Uid),
/// Chat with nearby players /// Chat with nearby players
@ -82,15 +82,21 @@ pub enum ChatType {
} }
impl ChatType { impl ChatType {
pub fn message<S>(self, msg: S) -> ServerMsg pub fn chat_msg<S>(self, msg: S) -> ChatMsg
where where
S: Into<String>, S: Into<String>,
{ {
let msg = ChatMsg { ChatMsg {
chat_type: self, chat_type: self,
message: msg.into(), message: msg.into(),
}; }
ServerMsg::ChatMsg(msg) }
pub fn server_msg<S>(self, msg: S) -> ServerMsg
where
S: Into<String>,
{
ServerMsg::ChatMsg(self.chat_msg(msg))
} }
} }
@ -126,8 +132,8 @@ impl ChatMsg {
ChatType::Offline => SpeechBubbleType::None, ChatType::Offline => SpeechBubbleType::None,
ChatType::CommandInfo => SpeechBubbleType::None, ChatType::CommandInfo => SpeechBubbleType::None,
ChatType::CommandError => SpeechBubbleType::None, ChatType::CommandError => SpeechBubbleType::None,
ChatType::FactionMeta => SpeechBubbleType::None, ChatType::FactionMeta(_) => SpeechBubbleType::None,
ChatType::GroupMeta => SpeechBubbleType::None, ChatType::GroupMeta(_) => SpeechBubbleType::None,
ChatType::Kill => SpeechBubbleType::None, ChatType::Kill => SpeechBubbleType::None,
ChatType::Tell(_u, _) => SpeechBubbleType::Tell, ChatType::Tell(_u, _) => SpeechBubbleType::Tell,
ChatType::Say(_u) => SpeechBubbleType::Say, ChatType::Say(_u) => SpeechBubbleType::Say,
@ -145,8 +151,8 @@ impl ChatMsg {
ChatType::Offline => None, ChatType::Offline => None,
ChatType::CommandInfo => None, ChatType::CommandInfo => None,
ChatType::CommandError => None, ChatType::CommandError => None,
ChatType::FactionMeta => None, ChatType::FactionMeta(_) => None,
ChatType::GroupMeta => None, ChatType::GroupMeta(_) => None,
ChatType::Kill => None, ChatType::Kill => None,
ChatType::Tell(u, _t) => Some(*u), ChatType::Tell(u, _t) => Some(*u),
ChatType::Say(u) => Some(*u), ChatType::Say(u) => Some(*u),

View File

@ -119,27 +119,3 @@ impl From<AuthClientError> for RegisterError {
impl From<comp::ChatMsg> for ServerMsg { impl From<comp::ChatMsg> for ServerMsg {
fn from(v: comp::ChatMsg) -> Self { ServerMsg::ChatMsg(v) } fn from(v: comp::ChatMsg) -> Self { ServerMsg::ChatMsg(v) }
} }
impl ServerMsg {
// TODO remove unneeded
// pub fn broadcast(message: String) -> ServerMsg {
// ServerMsg::ChatMsg(comp::ChatMsg {
// chat_type: comp::ChatType::Broadcast,
// message,
// })
// }
// pub fn private(message: String) -> ServerMsg {
// ServerMsg::ChatMsg(comp::ChatMsg {
// chat_type: comp::ChatType::Private,
// message,
// })
// }
// pub fn kill(message: String) -> ServerMsg {
// ServerMsg::ChatMsg(comp::ChatMsg {
// chat_type: comp::ChatType::Kill,
// message,
// })
// }
}

View File

@ -31,11 +31,10 @@ pub trait ChatCommandExt {
impl ChatCommandExt for ChatCommand { impl ChatCommandExt for ChatCommand {
#[allow(clippy::needless_return)] // TODO: Pending review in #587 #[allow(clippy::needless_return)] // TODO: Pending review in #587
fn execute(&self, server: &mut Server, entity: EcsEntity, args: String) { fn execute(&self, server: &mut Server, entity: EcsEntity, args: String) {
let cmd_data = self.data(); if self.needs_admin() && !server.entity_is_admin(entity) {
if *cmd_data.needs_admin && !server.entity_is_admin(entity) {
server.notify_client( server.notify_client(
entity, entity,
ChatType::CommandError.message(format!( ChatType::CommandError.server_msg(format!(
"You don't have permission to use '/{}'.", "You don't have permission to use '/{}'.",
self.keyword() self.keyword()
)), )),
@ -125,7 +124,7 @@ fn handle_give_item(
if inv.push(item).is_some() { if inv.push(item).is_some() {
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message(format!( ChatType::CommandError.server_msg(format!(
"Player inventory full. Gave 0 of {} items.", "Player inventory full. Gave 0 of {} items.",
give_amount give_amount
)), )),
@ -144,7 +143,7 @@ fn handle_give_item(
if inv.push(item.clone()).is_some() { if inv.push(item.clone()).is_some() {
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message(format!( ChatType::CommandError.server_msg(format!(
"Player inventory full. Gave {} of {} items.", "Player inventory full. Gave {} of {} items.",
i, give_amount i, give_amount
)), )),
@ -166,11 +165,14 @@ fn handle_give_item(
} else { } else {
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message(format!("Invalid item: {}", item_name)), ChatType::CommandError.server_msg(format!("Invalid item: {}", item_name)),
); );
} }
} else { } else {
server.notify_client(client, ChatType::CommandError.message(action.help_string())); server.notify_client(
client,
ChatType::CommandError.server_msg(action.help_string()),
);
} }
} }
@ -231,7 +233,7 @@ fn handle_jump(
}, },
None => server.notify_client( None => server.notify_client(
client, client,
ChatType::CommandError.message("You have no position."), ChatType::CommandError.server_msg("You have no position."),
), ),
} }
} }
@ -258,11 +260,14 @@ fn handle_goto(
} else { } else {
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message("You have no position."), ChatType::CommandError.server_msg("You have no position."),
); );
} }
} else { } else {
server.notify_client(client, ChatType::CommandError.message(action.help_string())); server.notify_client(
client,
ChatType::CommandError.server_msg(action.help_string()),
);
} }
} }
@ -312,7 +317,7 @@ fn handle_time(
Err(_) => { Err(_) => {
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message(format!("'{}' is not a valid time.", n)), ChatType::CommandError.server_msg(format!("'{}' is not a valid time.", n)),
); );
return; return;
}, },
@ -330,7 +335,7 @@ fn handle_time(
Some(time) => format!("It is {}", time.format("%H:%M").to_string()), Some(time) => format!("It is {}", time.format("%H:%M").to_string()),
None => String::from("Unknown Time"), None => String::from("Unknown Time"),
}; };
server.notify_client(client, ChatType::CommandInfo.message(msg)); server.notify_client(client, ChatType::CommandInfo.server_msg(msg));
return; return;
}, },
}; };
@ -340,7 +345,7 @@ fn handle_time(
server.notify_client( server.notify_client(
client, client,
ChatType::CommandInfo.message(format!( ChatType::CommandInfo.server_msg(format!(
"Time changed to: {}", "Time changed to: {}",
new_time.format("%H:%M").to_string() new_time.format("%H:%M").to_string()
)), )),
@ -365,13 +370,13 @@ fn handle_health(
} else { } else {
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message("You have no health."), ChatType::CommandError.server_msg("You have no health."),
); );
} }
} else { } else {
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message("You must specify health amount!"), ChatType::CommandError.server_msg("You must specify health amount!"),
); );
} }
} }
@ -388,14 +393,14 @@ fn handle_alias(
// Notify target that an admin changed the alias due to /sudo // Notify target that an admin changed the alias due to /sudo
server.notify_client( server.notify_client(
target, target,
ChatType::CommandInfo.message("An admin changed your alias."), ChatType::CommandInfo.server_msg("An admin changed your alias."),
); );
return; return;
} }
if let Ok(alias) = scan_fmt!(&args, &action.arg_fmt(), String) { if let Ok(alias) = scan_fmt!(&args, &action.arg_fmt(), String) {
if !comp::Player::alias_is_valid(&alias) { if !comp::Player::alias_is_valid(&alias) {
// Prevent silly aliases // Prevent silly aliases
server.notify_client(client, ChatType::CommandError.message("Invalid alias.")); server.notify_client(client, ChatType::CommandError.server_msg("Invalid alias."));
return; return;
} }
let old_alias_optional = server let old_alias_optional = server
@ -422,12 +427,15 @@ fn handle_alias(
if ecs.read_storage::<comp::Body>().get(target).is_some() { if ecs.read_storage::<comp::Body>().get(target).is_some() {
server.state.notify_registered_clients( server.state.notify_registered_clients(
ChatType::CommandInfo ChatType::CommandInfo
.message(format!("{} is now known as {}.", old_alias, player.alias)), .server_msg(format!("{} is now known as {}.", old_alias, player.alias)),
); );
} }
} }
} else { } else {
server.notify_client(client, ChatType::CommandError.message(action.help_string())); server.notify_client(
client,
ChatType::CommandError.server_msg(action.help_string()),
);
} }
} }
@ -454,9 +462,12 @@ fn handle_tp(
} else { } else {
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message("You must specify a player name".to_string()), ChatType::CommandError.server_msg("You must specify a player name"),
);
server.notify_client(
client,
ChatType::CommandError.server_msg(action.help_string()),
); );
server.notify_client(client, ChatType::CommandError.message(action.help_string()));
return; return;
} }
}; };
@ -468,20 +479,23 @@ fn handle_tp(
} else { } else {
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message(format!("Unable to teleport to player!")), ChatType::CommandError.server_msg("Unable to teleport to player!"),
); );
} }
} else { } else {
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message(format!("Player not found!")), ChatType::CommandError.server_msg("Player not found!"),
);
server.notify_client(
client,
ChatType::CommandError.server_msg(action.help_string()),
); );
server.notify_client(client, ChatType::CommandError.message(action.help_string()));
} }
} else { } else {
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message(format!("You have no position!")), ChatType::CommandError.server_msg("You have no position!"),
); );
} }
} }
@ -539,27 +553,29 @@ fn handle_spawn(
if let Some(uid) = server.state.ecs().uid_from_entity(new_entity) { if let Some(uid) = server.state.ecs().uid_from_entity(new_entity) {
server.notify_client( server.notify_client(
client, client,
ChatType::CommandInfo.message( ChatType::CommandInfo
format!("Spawned entity with ID: {}", uid).to_owned(), .server_msg(format!("Spawned entity with ID: {}", uid)),
),
); );
} }
} }
server.notify_client( server.notify_client(
client, client,
ChatType::CommandInfo ChatType::CommandInfo
.message(format!("Spawned {} entities", amount).to_owned()), .server_msg(format!("Spawned {} entities", amount)),
); );
}, },
None => server.notify_client( None => server.notify_client(
client, client,
ChatType::CommandError.message("You have no position!".to_owned()), ChatType::CommandError.server_msg("You have no position!"),
), ),
} }
} }
}, },
_ => { _ => {
server.notify_client(client, ChatType::CommandError.message(action.help_string())); server.notify_client(
client,
ChatType::CommandError.server_msg(action.help_string()),
);
}, },
} }
} }
@ -581,7 +597,7 @@ fn handle_players(
server.notify_client( server.notify_client(
client, client,
ChatType::CommandInfo.message(entity_tuples.join().fold( ChatType::CommandInfo.server_msg(entity_tuples.join().fold(
format!("{} online players:", entity_tuples.join().count()), format!("{} online players:", entity_tuples.join().count()),
|s, (_, player, stat)| { |s, (_, player, stat)| {
format!( format!(
@ -616,7 +632,7 @@ fn handle_build(
.remove(target); .remove(target);
server.notify_client( server.notify_client(
client, client,
ChatType::CommandInfo.message("Toggled off build mode!"), ChatType::CommandInfo.server_msg("Toggled off build mode!"),
); );
} else { } else {
let _ = server let _ = server
@ -626,7 +642,7 @@ fn handle_build(
.insert(target, comp::CanBuild); .insert(target, comp::CanBuild);
server.notify_client( server.notify_client(
client, client,
ChatType::CommandInfo.message("Toggled on build mode!"), ChatType::CommandInfo.server_msg("Toggled on build mode!"),
); );
} }
} }
@ -640,7 +656,7 @@ fn handle_help(
action: &ChatCommand, action: &ChatCommand,
) { ) {
if let Some(cmd) = scan_fmt_some!(&args, &action.arg_fmt(), ChatCommand) { if let Some(cmd) = scan_fmt_some!(&args, &action.arg_fmt(), ChatCommand) {
server.notify_client(client, ChatType::CommandInfo.message(cmd.help_string())); server.notify_client(client, ChatType::CommandInfo.server_msg(cmd.help_string()));
} else { } else {
let mut message = String::new(); let mut message = String::new();
for cmd in CHAT_COMMANDS.iter() { for cmd in CHAT_COMMANDS.iter() {
@ -653,7 +669,7 @@ fn handle_help(
for (k, v) in CHAT_SHORTCUTS.iter() { for (k, v) in CHAT_SHORTCUTS.iter() {
message += &format!(" /{} => /{}", k, v.keyword()); message += &format!(" /{} => /{}", k, v.keyword());
} }
server.notify_client(client, ChatType::CommandInfo.message(message)); server.notify_client(client, ChatType::CommandInfo.server_msg(message));
} }
} }
@ -687,7 +703,7 @@ fn handle_kill_npcs(
} else { } else {
"No NPCs on server.".to_string() "No NPCs on server.".to_string()
}; };
server.notify_client(client, ChatType::CommandInfo.message(text)); server.notify_client(client, ChatType::CommandInfo.server_msg(text));
} }
#[allow(clippy::float_cmp)] // TODO: Pending review in #587 #[allow(clippy::float_cmp)] // TODO: Pending review in #587
@ -741,19 +757,21 @@ fn handle_object(
.build(); .build();
server.notify_client( server.notify_client(
client, client,
ChatType::CommandInfo.message(format!( ChatType::CommandInfo.server_msg(format!(
"Spawned: {}", "Spawned: {}",
obj_str_res.unwrap_or("<Unknown object>") obj_str_res.unwrap_or("<Unknown object>")
)), )),
); );
} else { } else {
return server return server.notify_client(
.notify_client(client, ChatType::CommandError.message("Object not found!")); client,
ChatType::CommandError.server_msg("Object not found!"),
);
} }
} else { } else {
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message(format!("You have no position!")), ChatType::CommandError.server_msg("You have no position!"),
); );
} }
} }
@ -776,7 +794,7 @@ fn handle_light(
if r < 0.0 || g < 0.0 || b < 0.0 { if r < 0.0 || g < 0.0 || b < 0.0 {
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message("cr, cg and cb values mustn't be negative."), ChatType::CommandError.server_msg("cr, cg and cb values mustn't be negative."),
); );
return; return;
} }
@ -815,14 +833,11 @@ fn handle_light(
} else { } else {
builder.build(); builder.build();
} }
server.notify_client( server.notify_client(client, ChatType::CommandInfo.server_msg("Spawned object."));
client,
ChatType::CommandInfo.message(format!("Spawned object.")),
);
} else { } else {
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message(format!("You have no position!")), ChatType::CommandError.server_msg("You have no position!"),
); );
} }
} }
@ -852,22 +867,25 @@ fn handle_lantern(
.into(); .into();
server.notify_client( server.notify_client(
client, client,
ChatType::CommandInfo.message("You adjusted flame strength and color."), ChatType::CommandInfo.server_msg("You adjusted flame strength and color."),
); );
} else { } else {
server.notify_client( server.notify_client(
client, client,
ChatType::CommandInfo.message("You adjusted flame strength."), ChatType::CommandInfo.server_msg("You adjusted flame strength."),
); );
} }
} else { } else {
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message("Please equip a lantern first"), ChatType::CommandError.server_msg("Please equip a lantern first"),
); );
} }
} else { } else {
server.notify_client(client, ChatType::CommandError.message(action.help_string())); server.notify_client(
client,
ChatType::CommandError.server_msg(action.help_string()),
);
} }
} }
@ -883,13 +901,13 @@ fn handle_explosion(
if power > 512.0 { if power > 512.0 {
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message("Explosion power mustn't be more than 512."), ChatType::CommandError.server_msg("Explosion power mustn't be more than 512."),
); );
return; return;
} else if power <= 0.0 { } else if power <= 0.0 {
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message("Explosion power must be more than 0."), ChatType::CommandError.server_msg("Explosion power must be more than 0."),
); );
return; return;
} }
@ -907,7 +925,7 @@ fn handle_explosion(
}, },
None => server.notify_client( None => server.notify_client(
client, client,
ChatType::CommandError.message("You have no position!"), ChatType::CommandError.server_msg("You have no position!"),
), ),
} }
} }
@ -927,12 +945,12 @@ fn handle_waypoint(
.ecs() .ecs()
.write_storage::<comp::Waypoint>() .write_storage::<comp::Waypoint>()
.insert(target, comp::Waypoint::new(pos.0, *time)); .insert(target, comp::Waypoint::new(pos.0, *time));
server.notify_client(client, ChatType::CommandInfo.message("Waypoint saved!")); server.notify_client(client, ChatType::CommandInfo.server_msg("Waypoint saved!"));
server.notify_client(client, ServerMsg::Notification(Notification::WaypointSaved)); server.notify_client(client, ServerMsg::Notification(Notification::WaypointSaved));
}, },
None => server.notify_client( None => server.notify_client(
client, client,
ChatType::CommandError.message("You have no position!"), ChatType::CommandError.server_msg("You have no position!"),
), ),
} }
} }
@ -975,12 +993,15 @@ fn handle_adminify(
None => { None => {
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message(format!("Player '{}' not found!", alias)), ChatType::CommandError.server_msg(format!("Player '{}' not found!", alias)),
); );
}, },
} }
} else { } else {
server.notify_client(client, ChatType::CommandError.message(action.help_string())); server.notify_client(
client,
ChatType::CommandError.server_msg(action.help_string()),
);
} }
} }
@ -997,7 +1018,7 @@ fn handle_tell(
// This happens when [ab]using /sudo // This happens when [ab]using /sudo
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message("It's rude to impersonate people"), ChatType::CommandError.server_msg("It's rude to impersonate people"),
); );
return; return;
} }
@ -1011,7 +1032,7 @@ fn handle_tell(
if player == client { if player == client {
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message(format!("You can't /tell yourself.")), ChatType::CommandError.server_msg("You can't /tell yourself."),
); );
return; return;
} }
@ -1034,11 +1055,14 @@ fn handle_tell(
} else { } else {
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message(format!("Player '{}' not found!", alias)), ChatType::CommandError.server_msg(format!("Player '{}' not found!", alias)),
); );
} }
} else { } else {
server.notify_client(client, ChatType::CommandError.message(action.help_string())); server.notify_client(
client,
ChatType::CommandError.server_msg(action.help_string()),
);
} }
} }
@ -1053,7 +1077,7 @@ fn handle_faction(
// This happens when [ab]using /sudo // This happens when [ab]using /sudo
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message("It's rude to impersonate people"), ChatType::CommandError.server_msg("It's rude to impersonate people"),
); );
return; return;
} }
@ -1071,7 +1095,7 @@ fn handle_faction(
} else { } else {
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message("Please join a faction with /join_faction"), ChatType::CommandError.server_msg("Please join a faction with /join_faction"),
); );
} }
} }
@ -1087,7 +1111,7 @@ fn handle_group(
// This happens when [ab]using /sudo // This happens when [ab]using /sudo
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message("It's rude to impersonate people"), ChatType::CommandError.server_msg("It's rude to impersonate people"),
); );
return; return;
} }
@ -1105,7 +1129,7 @@ fn handle_group(
} else { } else {
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message("Please join a group with /join_group"), ChatType::CommandError.server_msg("Please join a group with /join_group"),
); );
} }
} }
@ -1121,7 +1145,7 @@ fn handle_region(
// This happens when [ab]using /sudo // This happens when [ab]using /sudo
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message("It's rude to impersonate people"), ChatType::CommandError.server_msg("It's rude to impersonate people"),
); );
return; return;
} }
@ -1151,7 +1175,7 @@ fn handle_say(
// This happens when [ab]using /sudo // This happens when [ab]using /sudo
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message("It's rude to impersonate people"), ChatType::CommandError.server_msg("It's rude to impersonate people"),
); );
return; return;
} }
@ -1181,7 +1205,7 @@ fn handle_world(
// This happens when [ab]using /sudo // This happens when [ab]using /sudo
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message("It's rude to impersonate people"), ChatType::CommandError.server_msg("It's rude to impersonate people"),
); );
return; return;
} }
@ -1211,7 +1235,7 @@ fn handle_join_faction(
// This happens when [ab]using /sudo // This happens when [ab]using /sudo
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message("It's rude to impersonate people"), ChatType::CommandError.server_msg("It's rude to impersonate people"),
); );
return; return;
} }
@ -1230,26 +1254,25 @@ fn handle_join_faction(
.ecs() .ecs()
.write_storage() .write_storage()
.insert(client, comp::Faction(faction.clone())); .insert(client, comp::Faction(faction.clone()));
server.notify_client( server.state.send_chat(
client, ChatType::FactionMeta(faction.clone())
ChatType::FactionMeta.message(format!("[{}] joined faction ({})", alias, faction)), .chat_msg(format!("[{}] joined faction ({})", alias, faction)),
); );
} else { } else {
let mode = comp::ChatMode::default(); let mode = comp::ChatMode::default();
let _ = server.state.ecs().write_storage().insert(client, mode); let _ = server.state.ecs().write_storage().insert(client, mode);
if let Some(comp::Faction(faction)) = server.state.ecs().write_storage().remove(client) if let Some(comp::Faction(faction)) = server.state.ecs().write_storage().remove(client)
{ {
server.notify_client( server.state.send_chat(
client, ChatType::FactionMeta(faction.clone())
ChatType::FactionMeta .chat_msg(format!("[{}] left faction ({})", alias, faction)),
.message(format!("[{}] left faction ({})", alias, faction)),
); );
} }
} }
} else { } else {
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message("Could not find your player alias"), ChatType::CommandError.server_msg("Could not find your player alias"),
); );
} }
} }
@ -1265,7 +1288,7 @@ fn handle_join_group(
// This happens when [ab]using /sudo // This happens when [ab]using /sudo
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message("It's rude to impersonate people"), ChatType::CommandError.server_msg("It's rude to impersonate people"),
); );
return; return;
} }
@ -1284,24 +1307,24 @@ fn handle_join_group(
.ecs() .ecs()
.write_storage() .write_storage()
.insert(client, comp::Group(group.clone())); .insert(client, comp::Group(group.clone()));
server.notify_client( server.state.send_chat(
client, ChatType::GroupMeta(group.clone())
ChatType::GroupMeta.message(format!("[{}] joined group ({})", alias, group)), .chat_msg(format!("[{}] joined group ({})", alias, group)),
); );
} else { } else {
let mode = comp::ChatMode::default(); let mode = comp::ChatMode::default();
let _ = server.state.ecs().write_storage().insert(client, mode); let _ = server.state.ecs().write_storage().insert(client, mode);
if let Some(comp::Group(group)) = server.state.ecs().write_storage().remove(client) { if let Some(comp::Group(group)) = server.state.ecs().write_storage().remove(client) {
server.notify_client( server.state.send_chat(
client, ChatType::GroupMeta(group.clone())
ChatType::GroupMeta.message(format!("[{}] left group ({})", alias, group)), .chat_msg(format!("[{}] left group ({})", alias, group)),
); );
} }
} }
} else { } else {
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message("Could not find your player alias"), ChatType::CommandError.server_msg("Could not find your player alias"),
); );
} }
} }
@ -1316,7 +1339,7 @@ fn handle_debug_column(
) { ) {
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message("Unsupported without worldgen enabled"), ChatType::CommandError.server_msg("Unsupported without worldgen enabled"),
); );
} }
@ -1388,15 +1411,18 @@ spawn_rate {:?} "#,
)) ))
}; };
if let Some(s) = foo() { if let Some(s) = foo() {
server.notify_client(client, ChatType::CommandInfo.message(s)); server.notify_client(client, ChatType::CommandInfo.server_msg(s));
} else { } else {
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message("Not a pregenerated chunk."), ChatType::CommandError.server_msg("Not a pregenerated chunk."),
); );
} }
} else { } else {
server.notify_client(client, ChatType::CommandError.message(action.help_string())); server.notify_client(
client,
ChatType::CommandError.server_msg(action.help_string()),
);
} }
} }
@ -1411,7 +1437,7 @@ fn find_target(
.join() .join()
.find(|(_, player)| player.alias == alias) .find(|(_, player)| player.alias == alias)
.map(|(entity, _)| entity) .map(|(entity, _)| entity)
.ok_or(ChatType::CommandError.message(format!("Player '{}' not found!", alias))) .ok_or(ChatType::CommandError.server_msg(format!("Player '{}' not found!", alias)))
} else { } else {
Ok(fallback) Ok(fallback)
} }
@ -1437,7 +1463,7 @@ fn handle_give_exp(
if let Some(stats) = ecs.write_storage::<comp::Stats>().get_mut(player) { if let Some(stats) = ecs.write_storage::<comp::Stats>().get_mut(player) {
stats.exp.change_by(exp); stats.exp.change_by(exp);
} else { } else {
error_msg = Some(ChatType::CommandError.message("Player has no stats!")); error_msg = Some(ChatType::CommandError.server_msg("Player has no stats!"));
} }
}, },
Err(e) => { Err(e) => {
@ -1492,7 +1518,7 @@ fn handle_set_level(
.health .health
.set_to(stats.health.maximum(), comp::HealthSource::LevelUp); .set_to(stats.health.maximum(), comp::HealthSource::LevelUp);
} else { } else {
error_msg = Some(ChatType::CommandError.message("Player has no stats!")); error_msg = Some(ChatType::CommandError.server_msg("Player has no stats!"));
} }
}, },
Err(e) => { Err(e) => {
@ -1532,7 +1558,7 @@ fn handle_debug(
} else { } else {
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message("Debug items not found? Something is very broken."), ChatType::CommandError.server_msg("Debug items not found? Something is very broken."),
); );
} }
} }
@ -1571,7 +1597,7 @@ fn handle_remove_lights(
}, },
None => server.notify_client( None => server.notify_client(
client, client,
ChatType::CommandError.message("You have no position."), ChatType::CommandError.server_msg("You have no position."),
), ),
} }
@ -1585,7 +1611,7 @@ fn handle_remove_lights(
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message(format!("Removed {} lights!", size)), ChatType::CommandError.server_msg(format!("Removed {} lights!", size)),
); );
} }
@ -1615,17 +1641,20 @@ fn handle_sudo(
} else { } else {
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message(format!("Could not find that player")), ChatType::CommandError.server_msg("Could not find that player"),
); );
} }
} else { } else {
server.notify_client( server.notify_client(
client, client,
ChatType::CommandError.message(format!("Unknown command: /{}", cmd)), ChatType::CommandError.server_msg(format!("Unknown command: /{}", cmd)),
); );
} }
} else { } else {
server.notify_client(client, ChatType::CommandError.message(action.help_string())); server.notify_client(
client,
ChatType::CommandError.server_msg(action.help_string()),
);
} }
} }
@ -1638,7 +1667,7 @@ fn handle_version(
) { ) {
server.notify_client( server.notify_client(
client, client,
ChatType::CommandInfo.message(format!( ChatType::CommandInfo.server_msg(format!(
"Server is running {}[{}]", "Server is running {}[{}]",
common::util::GIT_HASH.to_string(), common::util::GIT_HASH.to_string(),
common::util::GIT_DATE.to_string(), common::util::GIT_DATE.to_string(),

View File

@ -46,7 +46,7 @@ pub fn handle_destroy(server: &mut Server, entity: EcsEntity, cause: HealthSourc
} }
.unwrap_or(format!("{} died", &player.alias)); .unwrap_or(format!("{} died", &player.alias));
state.notify_registered_clients(comp::ChatType::Kill.message(msg)); state.notify_registered_clients(comp::ChatType::Kill.server_msg(msg));
} }
{ {

View File

@ -64,7 +64,7 @@ pub fn handle_client_disconnect(server: &mut Server, entity: EcsEntity) -> Event
let mut accounts = state.ecs().write_resource::<AuthProvider>(); let mut accounts = state.ecs().write_resource::<AuthProvider>();
accounts.logout(player.uuid()); accounts.logout(player.uuid());
let msg = comp::ChatType::Online.message(format!("{} went offline.", &player.alias)); let msg = comp::ChatType::Offline.server_msg(format!("{} went offline.", &player.alias));
state.notify_registered_clients(msg); state.notify_registered_clients(msg);
} }

View File

@ -652,7 +652,7 @@ impl Server {
} else { } else {
self.notify_client( self.notify_client(
entity, entity,
ChatType::CommandError.message(format!( ChatType::CommandError.server_msg(format!(
"Unknown command '/{}'.\nType '/help' for available commands", "Unknown command '/{}'.\nType '/help' for available commands",
kwd kwd
)), )),

View File

@ -252,8 +252,6 @@ impl StateExt for State {
| comp::ChatType::CommandInfo | comp::ChatType::CommandInfo
| comp::ChatType::CommandError | comp::ChatType::CommandError
| comp::ChatType::Kill | comp::ChatType::Kill
| comp::ChatType::GroupMeta
| comp::ChatType::FactionMeta
| comp::ChatType::World(_) => { | comp::ChatType::World(_) => {
self.notify_registered_clients(ServerMsg::ChatMsg(msg.clone())) self.notify_registered_clients(ServerMsg::ChatMsg(msg.clone()))
}, },
@ -307,7 +305,7 @@ impl StateExt for State {
} }
}, },
comp::ChatType::Faction(_u, s) => { comp::ChatType::FactionMeta(s) | comp::ChatType::Faction(_, s) => {
for (client, faction) in ( for (client, faction) in (
&mut ecs.write_storage::<Client>(), &mut ecs.write_storage::<Client>(),
&ecs.read_storage::<comp::Faction>(), &ecs.read_storage::<comp::Faction>(),
@ -319,7 +317,7 @@ impl StateExt for State {
} }
} }
}, },
comp::ChatType::Group(_u, s) => { comp::ChatType::GroupMeta(s) | comp::ChatType::Group(_, s) => {
for (client, group) in ( for (client, group) in (
&mut ecs.write_storage::<Client>(), &mut ecs.write_storage::<Client>(),
&ecs.read_storage::<comp::Group>(), &ecs.read_storage::<comp::Group>(),

View File

@ -478,8 +478,8 @@ fn render_chat_line(chat_type: &ChatType, imgs: &Imgs) -> (Color, conrod_core::i
ChatType::Offline => (OFFLINE_COLOR, imgs.chat_offline_small), ChatType::Offline => (OFFLINE_COLOR, imgs.chat_offline_small),
ChatType::CommandError => (ERROR_COLOR, imgs.chat_command_error_small), ChatType::CommandError => (ERROR_COLOR, imgs.chat_command_error_small),
ChatType::CommandInfo => (INFO_COLOR, imgs.chat_command_info_small), ChatType::CommandInfo => (INFO_COLOR, imgs.chat_command_info_small),
ChatType::GroupMeta => (GROUP_COLOR, imgs.chat_group_small), ChatType::GroupMeta(_) => (GROUP_COLOR, imgs.chat_group_small),
ChatType::FactionMeta => (FACTION_COLOR, imgs.chat_faction_small), ChatType::FactionMeta(_) => (FACTION_COLOR, imgs.chat_faction_small),
ChatType::Kill => (KILL_COLOR, imgs.chat_kill_small), ChatType::Kill => (KILL_COLOR, imgs.chat_kill_small),
ChatType::Tell(_from, _to) => (TELL_COLOR, imgs.chat_tell_small), ChatType::Tell(_from, _to) => (TELL_COLOR, imgs.chat_tell_small),
ChatType::Say(_uid) => (SAY_COLOR, imgs.chat_say_small), ChatType::Say(_uid) => (SAY_COLOR, imgs.chat_say_small),