Use Content::Plain explicitly

This commit is contained in:
coffee-compiler 2024-08-25 17:18:30 +00:00 committed by Marcel
parent 9971aa26a4
commit 5a69587c92
9 changed files with 225 additions and 136 deletions

View File

@ -40,16 +40,6 @@ pub enum Content {
},
}
// TODO: Remove impl and make use of `Plain(...)` explicit (to discourage it)
impl From<String> for Content {
fn from(text: String) -> Self { Self::Plain(text) }
}
// TODO: Remove impl and make use of `Plain(...)` explicit (to discourage it)
impl<'a> From<&'a str> for Content {
fn from(text: &'a str) -> Self { Self::Plain(text.to_string()) }
}
/// A localisation argument for localised content (see [`Content::Localized`]).
// TODO: Do we want it to be Enum or just wrapper around Content, to add
// additional `impl From<T>` for our arguments?

View File

@ -1,5 +1,5 @@
use crate::settings::Settings;
use common::comp::chat::ChatType;
use common::comp::{chat::ChatType, Content};
use common_net::msg::ServerGeneral;
use server::Server;
use std::{
@ -156,7 +156,10 @@ impl ShutdownCoordinator {
/// Logs and sends a message to all connected clients
fn send_msg(server: &mut Server, msg: String) {
info!("{}", &msg);
server.notify_players(ServerGeneral::server_msg(ChatType::CommandError, msg));
server.notify_players(ServerGeneral::server_msg(
ChatType::CommandError,
Content::Plain(msg),
));
}
/// Converts a `Duration` into text in the format XsXm for example 1 minute

View File

@ -592,7 +592,7 @@ fn handle_give_item(
target,
comp::InventoryUpdate::new(comp::InventoryUpdateEvent::Given),
)
.map_err(|_| "Entity target is dead!")?;
.map_err(|_| Content::Plain("Entity target is dead!".to_string()))?;
}
res
} else {
@ -834,12 +834,14 @@ fn handle_motd(
client,
ServerGeneral::server_msg(
ChatType::CommandInfo,
server
.editable_settings()
.server_description
.get(locale.as_deref())
.map_or("", |d| &d.motd)
.to_string(),
Content::Plain(
server
.editable_settings()
.server_description
.get(locale.as_deref())
.map_or("", |d| &d.motd)
.to_string(),
),
),
);
Ok(())
@ -953,7 +955,9 @@ fn handle_site(
_args: Vec<String>,
_action: &ServerChatCommand,
) -> CmdResult<()> {
Err("Unsupported without worldgen enabled".into())
Err(Content::Plain(
"Unsupported without worldgen enabled".into(),
))
}
/// TODO: Add autocompletion if possible (might require modifying enum to handle
@ -1223,7 +1227,7 @@ fn handle_time(
client,
ServerGeneral::server_msg(
ChatType::CommandInfo,
format!("Time changed to: {}", new_time.format("%H:%M")),
Content::Plain(format!("Time changed to: {}", new_time.format("%H:%M"))),
),
);
}
@ -1290,7 +1294,7 @@ fn handle_time_scale(
client,
ServerGeneral::server_msg(
ChatType::CommandError,
"Wrong parameter, expected f32.".to_string(),
Content::Plain("Wrong parameter, expected f32.".to_string()),
),
);
}
@ -1323,10 +1327,10 @@ fn handle_health(
health.change_by(change);
Ok(())
} else {
Err("You have no health".into())
Err(Content::Plain("You have no health".into()))
}
} else {
Err("You must specify health amount!".into())
Err(Content::Plain("You must specify health amount!".into()))
}
}
@ -1339,7 +1343,7 @@ fn handle_alias(
) -> CmdResult<()> {
if let Some(alias) = parse_cmd_args!(args, String) {
// Prevent silly aliases
comp::Player::alias_validate(&alias).map_err(|e| e.to_string())?;
comp::Player::alias_validate(&alias).map_err(|e| Content::Plain(e.to_string()))?;
let old_alias_optional = server
.state
@ -1365,7 +1369,7 @@ fn handle_alias(
if ecs.read_storage::<comp::Body>().get(target).is_some() {
server.state.notify_players(ServerGeneral::server_msg(
ChatType::CommandInfo,
format!("{} is now known as {}.", old_alias, player.alias),
Content::Plain(format!("{} is now known as {}.", old_alias, player.alias)),
));
}
}
@ -1373,7 +1377,10 @@ fn handle_alias(
// Notify target that an admin changed the alias due to /sudo
server.notify_client(
target,
ServerGeneral::server_msg(ChatType::CommandInfo, "An admin changed your alias."),
ServerGeneral::server_msg(
ChatType::CommandInfo,
Content::Plain("An admin changed your alias.".to_string()),
),
);
}
Ok(())
@ -1424,7 +1431,7 @@ fn handle_rtsim_tp(
.npcs
.values()
.find(|npc| npc.uid == id)
.ok_or_else(|| format!("No NPC has the id {id}"))?
.ok_or_else(|| Content::Plain(format!("No NPC has the id {id}")))?
.wpos
} else {
return Err(action.help_content());
@ -1451,7 +1458,7 @@ fn handle_rtsim_info(
.npcs
.iter()
.find(|(_, npc)| npc.uid == id)
.ok_or_else(|| format!("No NPC has the id {id}"))?;
.ok_or_else(|| Content::Plain(format!("No NPC has the id {id}")))?;
let mut info = String::new();
@ -1486,7 +1493,7 @@ fn handle_rtsim_info(
server.notify_client(
client,
ServerGeneral::server_msg(ChatType::CommandInfo, info),
ServerGeneral::server_msg(ChatType::CommandInfo, Content::Plain(info)),
);
Ok(())
@ -1558,7 +1565,7 @@ fn handle_rtsim_npc(
server.notify_client(
client,
ServerGeneral::server_msg(ChatType::CommandInfo, info),
ServerGeneral::server_msg(ChatType::CommandInfo, Content::Plain(info)),
);
Ok(())
@ -1592,10 +1599,10 @@ fn handle_rtsim_purge(
client,
ServerGeneral::server_msg(
ChatType::CommandInfo,
format!(
Content::Plain(format!(
"Rtsim data {} be purged on next startup",
if should_purge { "WILL" } else { "will NOT" },
),
)),
),
);
Ok(())
@ -1659,7 +1666,7 @@ fn handle_rtsim_chunk(
server.notify_client(
client,
ServerGeneral::server_msg(ChatType::CommandInfo, info),
ServerGeneral::server_msg(ChatType::CommandInfo, Content::Plain(info)),
);
Ok(())
@ -1691,7 +1698,9 @@ fn handle_spawn(
.read_storage::<comp::Anchor>()
.contains(target)
{
return Err("Spawning this pet would create an anchor chain".into());
return Err(Content::Plain(
"Spawning this pet would create an anchor chain".into(),
));
}
let amount = opt_amount.filter(|x| *x > 0).unwrap_or(1).min(50);
@ -1757,9 +1766,9 @@ fn handle_spawn(
follower,
tether_length: 4.0,
})
.map_err(|_| "Failed to tether entities")?;
.map_err(|_| Content::Plain("Failed to tether entities".to_string()))?;
} else {
return Err("Tether members don't have Uids.".into());
return Err(Content::Plain("Tether members don't have Uids.".into()));
}
}
@ -1787,7 +1796,7 @@ fn handle_spawn(
client,
ServerGeneral::server_msg(
ChatType::CommandInfo,
format!("Spawned {} entities", amount),
Content::Plain(format!("Spawned {} entities", amount)),
),
);
Ok(())
@ -1860,7 +1869,7 @@ fn handle_spawn_airship(
*comp::ship::ALL_AIRSHIPS
.iter()
.find(|body| format!("{body:?}") == body_name)
.ok_or_else(|| format!("No such airship '{body_name}'."))?
.ok_or_else(|| Content::Plain(format!("No such airship '{body_name}'.")))?
} else {
comp::ship::Body::random_airship_with(&mut thread_rng())
};
@ -1907,7 +1916,7 @@ fn handle_spawn_ship(
*comp::ship::ALL_SHIPS
.iter()
.find(|body| format!("{body:?}") == body_name)
.ok_or_else(|| format!("No such airship '{body_name}'."))?
.ok_or_else(|| Content::Plain(format!("No such airship '{body_name}'.")))?
} else {
comp::ship::Body::random_airship_with(&mut thread_rng())
};
@ -1961,15 +1970,18 @@ fn handle_spawn_ship(
follower,
tether_length,
})
.map_err(|_| "Failed to tether entities")?;
.map_err(|_| Content::Plain("Failed to tether entities".to_string()))?;
} else {
return Err("Tether members don't have Uids.".into());
return Err(Content::Plain("Tether members don't have Uids.".into()));
}
}
server.notify_client(
client,
ServerGeneral::server_msg(ChatType::CommandInfo, "Spawned a ship"),
ServerGeneral::server_msg(
ChatType::CommandInfo,
Content::Plain("Spawned a ship".to_string()),
),
);
Ok(())
}
@ -2132,7 +2144,7 @@ fn handle_permit_build(
let mut can_build = server.state.ecs().write_storage::<comp::CanBuild>();
let entry = can_build
.entry(target)
.map_err(|_| "Cannot find target entity!".to_string())?;
.map_err(|_| Content::Plain("Cannot find target entity!".to_string()))?;
let mut comp_can_build = entry.or_insert(comp::CanBuild {
enabled: false,
build_areas: HashSet::new(),
@ -2253,10 +2265,10 @@ fn handle_players(
client,
ServerGeneral::server_msg(
ChatType::CommandInfo,
entity_tuples.join().fold(
Content::Plain(entity_tuples.join().fold(
format!("{} online players:", entity_tuples.join().count()),
|s, (_, player, stat)| format!("{}\n[{}]{}", s, player.alias, stat.name,),
),
)),
),
);
Ok(())
@ -2287,7 +2299,10 @@ fn handle_spawn_portal(
server.notify_client(
client,
ServerGeneral::server_msg(ChatType::CommandInfo, "Spawned portal"),
ServerGeneral::server_msg(
ChatType::CommandInfo,
Content::Plain("Spawned portal".to_string()),
),
);
Ok(())
} else {
@ -2328,7 +2343,9 @@ fn handle_build(
server.notify_client(client, chat_msg);
Ok(())
} else {
Err("You do not have permission to build.".into())
Err(Content::Plain(
"You do not have permission to build.".into(),
))
}
}
@ -2340,7 +2357,7 @@ fn get_areas_mut<'l>(kind: &str, state: &'l mut State) -> CmdResult<&'l mut Area
Some(AreaKind::NoDurability) => state
.mut_resource::<AreasContainer<NoDurabilityArea>>()
.deref_mut(),
None => Err(format!("Invalid area type '{kind}'"))?,
None => Err(Content::Plain(format!("Invalid area type '{kind}'")))?,
})
}
@ -2365,14 +2382,16 @@ fn handle_area_add(
let special_areas = get_areas_mut(&kind, &mut server.state)?;
let msg = ServerGeneral::server_msg(
ChatType::CommandInfo,
format!("Created {kind} zone {}", area_name),
Content::Plain(format!("Created {kind} zone {}", area_name)),
);
special_areas
.insert(area_name, Aabb {
min: Vec3::new(xlo, ylo, zlo),
max: Vec3::new(xhi, yhi, zhi),
})
.map_err(|area_name| format!("{kind} zone {} already exists!", area_name))?;
.map_err(|area_name| {
Content::Plain(format!("{kind} zone {} already exists!", area_name))
})?;
server.notify_client(client, msg);
Ok(())
} else {
@ -2412,7 +2431,7 @@ fn handle_area_list(
let msg = ServerGeneral::server_msg(
ChatType::CommandInfo,
[build_message, no_dura_message].join("\n"),
Content::Plain([build_message, no_dura_message].join("\n")),
);
server.notify_client(client, msg);
@ -2430,17 +2449,19 @@ fn handle_area_remove(
let areas = get_areas_mut(&kind, &mut server.state)?;
areas.remove(&area_name).map_err(|err| match err {
SpecialAreaError::Reserved => format!(
SpecialAreaError::Reserved => Content::Plain(format!(
"Special area is reserved and cannot be removed: {}",
area_name
),
SpecialAreaError::NotFound => format!("No such build area {}", area_name),
)),
SpecialAreaError::NotFound => {
Content::Plain(format!("No such build area {}", area_name))
},
})?;
server.notify_client(
client,
ServerGeneral::server_msg(
ChatType::CommandInfo,
format!("Removed {kind} zone {area_name}"),
Content::Plain(format!("Removed {kind} zone {area_name}")),
),
);
Ok(())
@ -2576,7 +2597,7 @@ fn handle_kill_npcs(
server.notify_client(
client,
ServerGeneral::server_msg(ChatType::CommandInfo, text),
ServerGeneral::server_msg(ChatType::CommandInfo, Content::Plain(text)),
);
Ok(())
@ -2603,7 +2624,10 @@ fn handle_kit(
let notify = |server: &mut Server, kit_name: &str| {
server.notify_client(
client,
ServerGeneral::server_msg(ChatType::CommandInfo, format!("Gave kit: {}", kit_name)),
ServerGeneral::server_msg(
ChatType::CommandInfo,
Content::Plain(format!("Gave kit: {}", kit_name)),
),
);
};
let name = parse_cmd_args!(args, String).ok_or_else(|| action.help_content())?;
@ -2628,12 +2652,17 @@ fn handle_kit(
kit_name => {
let kits = KitManifest::load(KIT_MANIFEST_PATH)
.map(|kits| kits.read())
.map_err(|_| format!("Could not load manifest file {}", KIT_MANIFEST_PATH))?;
.map_err(|_| {
Content::Plain(format!(
"Could not load manifest file {}",
KIT_MANIFEST_PATH
))
})?;
let kit = kits
.0
.get(kit_name)
.ok_or(format!("Kit '{}' not found", kit_name))?;
.ok_or(Content::Plain(format!("Kit '{}' not found", kit_name)))?;
let res = push_kit(
kit.iter()
@ -2693,11 +2722,12 @@ fn push_item(
) -> CmdResult<()> {
let items = match item_id {
KitEntry::Spec(KitSpec::Item(item_id)) => vec![
Item::new_from_asset(&item_id).map_err(|_| format!("Unknown item: {:#?}", item_id))?,
Item::new_from_asset(&item_id)
.map_err(|_| Content::Plain(format!("Unknown item: {:#?}", item_id)))?,
],
KitEntry::Spec(KitSpec::ModularWeapon { tool, material }) => {
comp::item::modular::generate_weapons(tool, material, None)
.map_err(|err| format!("{:#?}", err))?
.map_err(|err| Content::Plain(format!("{:#?}", err)))?
},
KitEntry::Item(item) => vec![item],
};
@ -2749,7 +2779,7 @@ fn handle_object(
.read_storage::<comp::Ori>()
.get(target)
.copied()
.ok_or_else(|| "Cannot get orientation for target".to_string())?;
.ok_or_else(|| Content::Plain("Cannot get orientation for target".to_string()))?;
/*let builder = server.state
.create_object(pos, ori, obj_type)
.with(ori);*/
@ -2783,12 +2813,15 @@ fn handle_object(
client,
ServerGeneral::server_msg(
ChatType::CommandInfo,
format!("Spawned: {}", obj_str_res.unwrap_or("<Unknown object>")),
Content::Plain(format!(
"Spawned: {}",
obj_str_res.unwrap_or("<Unknown object>")
)),
),
);
Ok(())
} else {
Err("Object not found!".into())
Err(Content::Plain("Object not found!".into()))
}
}
@ -2807,7 +2840,9 @@ fn handle_light(
if let (Some(r), Some(g), Some(b)) = (opt_r, opt_g, opt_b) {
if r < 0.0 || g < 0.0 || b < 0.0 {
return Err("cr, cg and cb values mustn't be negative.".into());
return Err(Content::Plain(
"cr, cg and cb values mustn't be negative.".into(),
));
}
let r = r.clamp(0.0, 1.0);
@ -2841,7 +2876,10 @@ fn handle_light(
}
server.notify_client(
client,
ServerGeneral::server_msg(ChatType::CommandInfo, "Spawned object."),
ServerGeneral::server_msg(
ChatType::CommandInfo,
Content::Plain("Spawned object.".to_string()),
),
);
Ok(())
}
@ -2956,7 +2994,10 @@ fn handle_waypoint(
)?;
server.notify_client(
client,
ServerGeneral::server_msg(ChatType::CommandInfo, "Waypoint saved!"),
ServerGeneral::server_msg(
ChatType::CommandInfo,
Content::Plain("Waypoint saved!".to_string()),
),
);
server.notify_client(
target,
@ -3045,7 +3086,7 @@ fn handle_spawn_wiring(
server.notify_client(
client,
ServerGeneral::server_msg(ChatType::CommandInfo, "Wire"),
ServerGeneral::server_msg(ChatType::CommandInfo, Content::Plain("Wire".to_string())),
);
Ok(())
}
@ -3500,7 +3541,7 @@ fn handle_join_faction(
server.notify_client(target, ServerGeneral::ChatMode(mode));
Ok(())
} else {
Err("Could not find your player alias".into())
Err(Content::Plain("Could not find your player alias".into()))
}
}
@ -3512,7 +3553,9 @@ fn handle_debug_column(
_args: Vec<String>,
_action: &ServerChatCommand,
) -> CmdResult<()> {
Err("Unsupported without worldgen enabled".into())
Err(Content::Plain(
"Unsupported without worldgen enabled".into(),
))
}
#[cfg(feature = "worldgen")]
@ -3591,10 +3634,13 @@ cliff_height {:?} "#,
))
};
if let Some(s) = msg_generator(&calendar) {
server.notify_client(client, ServerGeneral::server_msg(ChatType::CommandInfo, s));
server.notify_client(
client,
ServerGeneral::server_msg(ChatType::CommandInfo, Content::Plain(s)),
);
Ok(())
} else {
Err("Not a pre-generated chunk.".into())
Err(Content::Plain("Not a pre-generated chunk.".into()))
}
}
@ -3606,7 +3652,9 @@ fn handle_debug_ways(
_args: Vec<String>,
_action: &ServerChatCommand,
) -> CmdResult<()> {
Err("Unsupported without worldgen enabled".into())
Err(Content::Plain(
"Unsupported without worldgen enabled".into(),
))
}
#[cfg(feature = "worldgen")]
@ -3636,10 +3684,13 @@ fn handle_debug_ways(
Some(ret)
};
if let Some(s) = msg_generator() {
server.notify_client(client, ServerGeneral::server_msg(ChatType::CommandInfo, s));
server.notify_client(
client,
ServerGeneral::server_msg(ChatType::CommandInfo, Content::Plain(s)),
);
Ok(())
} else {
Err("Not a pre-generated chunk.".into())
Err(Content::Plain("Not a pre-generated chunk.".into()))
}
}
@ -3707,7 +3758,7 @@ fn handle_skill_point(
skill_set.add_skill_points(skill_tree, sp);
Ok(())
} else {
Err("Entity has no stats!".into())
Err(Content::Plain("Entity has no stats!".into()))
}
} else {
Err(action.help_content())
@ -3829,7 +3880,10 @@ fn handle_remove_lights(
server.notify_client(
client,
ServerGeneral::server_msg(ChatType::CommandInfo, format!("Removed {} lights!", size)),
ServerGeneral::server_msg(
ChatType::CommandInfo,
Content::Plain(format!("Removed {} lights!", size)),
),
);
Ok(())
}
@ -4058,10 +4112,10 @@ fn handle_kick(
client,
ServerGeneral::server_msg(
ChatType::CommandInfo,
format!(
Content::Plain(format!(
"Kicked {} from the server with reason: {}",
target_alias, reason
),
)),
),
);
Ok(())
@ -4093,7 +4147,7 @@ fn handle_ban(
let end_date = parse_duration
.map(|duration| chrono::Duration::from_std(duration.into()))
.transpose()
.map_err(|err| format!("Error converting to duration: {}", err))?
.map_err(|err| Content::Plain(format!("Error converting to duration: {}", err)))?
// On overflow (someone adding some ridiculous time span), just make the ban infinite.
.and_then(|duration| now.checked_add_signed(duration));
@ -4303,7 +4357,7 @@ fn handle_battlemode(
let mut players = ecs.write_storage::<comp::Player>();
let mut player_info = players.get_mut(target).ok_or_else(|| {
error!("Can't get player component for player");
"Error!"
Content::Plain("Error!".to_string())
})?;
if let Some(Time(last_change)) = player_info.last_battlemode_change {
let Time(time) = *time;
@ -4340,7 +4394,7 @@ fn handle_battlemode(
let players = ecs.read_storage::<comp::Player>();
let player = players.get(target).ok_or_else(|| {
error!("Can't get player component for player");
"Error!"
Content::Plain("Error!".to_string())
})?;
let mut msg = format!("Current battle mode: {:?}.", player.battle_mode);
if settings.gameplay.battle_mode.allow_choosing() {
@ -4361,7 +4415,7 @@ fn handle_battlemode(
}
server.notify_client(
client,
ServerGeneral::server_msg(ChatType::CommandInfo, msg),
ServerGeneral::server_msg(ChatType::CommandInfo, Content::Plain(msg)),
);
Ok(())
}
@ -4386,9 +4440,9 @@ fn handle_battlemode_force(
_ => return Err(Content::localized("command-battlemode-available-modes")),
};
let mut players = ecs.write_storage::<comp::Player>();
let mut player_info = players
.get_mut(target)
.ok_or("Cannot get player component for target")?;
let mut player_info = players.get_mut(target).ok_or(Content::Plain(
"Cannot get player component for target".to_string(),
))?;
player_info.battle_mode = mode;
server.notify_client(
client,
@ -4476,10 +4530,10 @@ fn handle_server_physics(
client,
ServerGeneral::server_msg(
ChatType::CommandInfo,
format!(
Content::Plain(format!(
"Updated physics settings for {} ({}): {:?}",
username, uuid, entry
),
)),
),
);
Ok(())
@ -4663,7 +4717,7 @@ fn handle_skill_preset(
preset => set_skills(&mut skill_set, preset),
}
} else {
Err("Player has no stats!".into())
Err(Content::Plain("Player has no stats!".into()))
}
} else {
Err(action.help_content())
@ -4693,7 +4747,7 @@ fn set_skills(skill_set: &mut comp::SkillSet, preset: &str) -> CmdResult<()> {
skill_set.add_skill_points(group, cost);
match skill_set.unlock_skill(*skill) {
Ok(_) | Err(comp::skillset::SkillUnlockError::SkillAlreadyUnlocked) => Ok(()),
Err(err) => Err(format!("{:?}", err)),
Err(err) => Err(Content::Plain(format!("{:?}", err))),
}?;
}
}
@ -4804,7 +4858,9 @@ fn handle_weather_zone(
_args: Vec<String>,
_action: &ServerChatCommand,
) -> CmdResult<()> {
Err("Unsupported without worldgen enabled".into())
Err(Content::Plain(
"Unsupported without worldgen enabled".into(),
))
}
#[cfg(feature = "worldgen")]
@ -5042,9 +5098,9 @@ fn handle_tether(
follower,
tether_length,
})
.map_err(|_| "Failed to tether entities".into())
.map_err(|_| Content::Plain("Failed to tether entities".into()))
} else {
Err("Tether members don't have Uids.".into())
Err(Content::Plain("Tether members don't have Uids.".into()))
}
} else {
Err(action.help_content())
@ -5102,9 +5158,11 @@ fn handle_mount(
server
.state
.link(common::mounting::Mounting { mount, rider })
.map_err(|_| "Failed to mount entities".into())
.map_err(|_| Content::Plain("Failed to mount entities".into()))
} else {
Err("Mount and/or rider doesn't have an Uid component.".into())
Err(Content::Plain(
"Mount and/or rider doesn't have an Uid component.".into(),
))
}
} else {
Err(action.help_content())

View File

@ -4,7 +4,7 @@ use common::{
self,
group::{ChangeNotification, Group, GroupManager},
invite::{InviteKind, PendingInvites},
ChatType, GroupManip,
ChatType, Content, GroupManip,
},
event::GroupManipEvent,
uid::{IdMaps, Uid},
@ -39,7 +39,9 @@ pub fn can_invite(
if let Some(client) = clients.get(inviter) {
client.send_fallible(ServerGeneral::server_msg(
ChatType::Meta,
"Invite failed, can't invite someone already in your group",
Content::Plain(
"Invite failed, can't invite someone already in your group".to_string(),
),
));
}
return false;
@ -70,9 +72,11 @@ pub fn can_invite(
if let Some(client) = clients.get(inviter) {
client.send_fallible(ServerGeneral::server_msg(
ChatType::Meta,
"Invite failed, pending invites plus current group size have reached the group \
size limit"
.to_owned(),
Content::Plain(
"Invite failed, pending invites plus current group size have reached the \
group size limit"
.to_owned(),
),
));
}
return false;
@ -160,7 +164,9 @@ impl ServerEvent for GroupManipEvent {
if let Some(client) = clients.get(entity) {
client.send_fallible(ServerGeneral::server_msg(
ChatType::Meta,
"Kick failed, target does not exist.",
Content::Plain(
"Kick failed, target does not exist.".to_string(),
),
));
}
continue;
@ -173,7 +179,7 @@ impl ServerEvent for GroupManipEvent {
if let Some(general_stream) = clients.get(entity) {
general_stream.send_fallible(ServerGeneral::server_msg(
ChatType::Meta,
"Kick failed, you can't kick pets.",
Content::Plain("Kick failed, you can't kick pets.".to_string()),
));
}
continue;
@ -183,7 +189,7 @@ impl ServerEvent for GroupManipEvent {
if let Some(client) = clients.get(entity) {
client.send_fallible(ServerGeneral::server_msg(
ChatType::Meta,
"Kick failed, you can't kick yourself.",
Content::Plain("Kick failed, you can't kick yourself.".to_string()),
));
}
continue;
@ -226,14 +232,14 @@ impl ServerEvent for GroupManipEvent {
if let Some(client) = clients.get(target) {
client.send_fallible(ServerGeneral::server_msg(
ChatType::Meta,
"You were removed from the group.",
Content::Plain("You were removed from the group.".to_string()),
));
}
// Tell kicker that they were successful
if let Some(client) = clients.get(entity) {
client.send_fallible(ServerGeneral::server_msg(
ChatType::Meta,
"Player kicked.",
Content::Plain("Player kicked.".to_string()),
));
}
},
@ -242,7 +248,11 @@ impl ServerEvent for GroupManipEvent {
if let Some(client) = clients.get(entity) {
client.send_fallible(ServerGeneral::server_msg(
ChatType::Meta,
"Kick failed: You are not the leader of the target's group.",
Content::Plain(
"Kick failed: You are not the leader of the target's \
group."
.to_string(),
),
));
}
},
@ -251,7 +261,9 @@ impl ServerEvent for GroupManipEvent {
if let Some(client) = clients.get(entity) {
client.send_fallible(ServerGeneral::server_msg(
ChatType::Meta,
"Kick failed: Your target is not in a group.",
Content::Plain(
"Kick failed: Your target is not in a group.".to_string(),
),
));
}
},
@ -265,7 +277,10 @@ impl ServerEvent for GroupManipEvent {
if let Some(client) = clients.get(entity) {
client.send_fallible(ServerGeneral::server_msg(
ChatType::Meta,
"Leadership transfer failed, target does not exist",
Content::Plain(
"Leadership transfer failed, target does not exist"
.to_string(),
),
));
}
continue;
@ -307,14 +322,16 @@ impl ServerEvent for GroupManipEvent {
if let Some(client) = clients.get(target) {
client.send_fallible(ServerGeneral::server_msg(
ChatType::Meta,
"You are the group leader now.",
Content::Plain("You are the group leader now.".to_string()),
));
}
// Tell the old leader that the transfer was succesful
if let Some(client) = clients.get(entity) {
client.send_fallible(ServerGeneral::server_msg(
ChatType::Meta,
"You are no longer the group leader.",
Content::Plain(
"You are no longer the group leader.".to_string(),
),
));
}
},
@ -323,8 +340,11 @@ impl ServerEvent for GroupManipEvent {
if let Some(client) = clients.get(entity) {
client.send_fallible(ServerGeneral::server_msg(
ChatType::Meta,
"Transfer failed: You are not the leader of the target's \
group.",
Content::Plain(
"Transfer failed: You are not the leader of the target's \
group."
.to_string(),
),
));
}
},
@ -333,7 +353,10 @@ impl ServerEvent for GroupManipEvent {
if let Some(client) = clients.get(entity) {
client.send_fallible(ServerGeneral::server_msg(
ChatType::Meta,
"Transfer failed: Your target is not in a group.",
Content::Plain(
"Transfer failed: Your target is not in a group."
.to_string(),
),
));
}
},

View File

@ -10,7 +10,7 @@ use common::{
agent::{Agent, AgentEvent},
group::GroupManager,
invite::{Invite, InviteKind, InviteResponse, PendingInvites},
ChatType, Group, Health, Pos,
ChatType, Content, Group, Health, Pos,
},
consts::MAX_TRADE_RANGE,
event::{InitiateInviteEvent, InviteResponseEvent},
@ -80,7 +80,7 @@ impl ServerEvent for InitiateInviteEvent {
if let Some(client) = clients.get(inviter) {
client.send_fallible(ServerGeneral::server_msg(
ChatType::Meta,
"Invite failed, target does not exist.",
Content::Plain("Invite failed, target does not exist.".to_string()),
));
}
continue;
@ -146,7 +146,7 @@ impl ServerEvent for InitiateInviteEvent {
if let Some(client) = clients.get(inviter) {
client.send_fallible(ServerGeneral::server_msg(
ChatType::Meta,
"This player already has a pending invite.",
Content::Plain("This player already has a pending invite.".to_string()),
));
}
continue;
@ -206,7 +206,7 @@ impl ServerEvent for InitiateInviteEvent {
} else if let Some(client) = clients.get(inviter) {
client.send_fallible(ServerGeneral::server_msg(
ChatType::Meta,
"Can't invite, not a player or npc",
Content::Plain("Can't invite, not a player or npc".to_string()),
));
}
@ -301,8 +301,11 @@ pub fn handle_invite_accept(data: &mut InviteResponseData, entity: Entity) {
{
client.send_fallible(ServerGeneral::server_msg(
ChatType::Meta,
"Trade failed, inviter initiated new trade since sending trade \
request.",
Content::Plain(
"Trade failed, inviter initiated new trade since sending \
trade request."
.to_string(),
),
));
}
return;

View File

@ -4,8 +4,7 @@ use crate::{
state_ext::StateExt, BattleModeBuffer, Server,
};
use common::{
comp,
comp::{group, pet::is_tameable, Presence, PresenceKind},
comp::{self, group, pet::is_tameable, Content, Presence, PresenceKind},
event::{DeleteCharacterEvent, PossessEvent},
resources::Time,
uid::{IdMaps, Uid},
@ -223,7 +222,10 @@ pub fn handle_client_disconnect(
state.read_storage::<Uid>().get(entity),
state.read_storage::<comp::Player>().get(entity),
) {
state.notify_players(ServerGeneral::server_msg(comp::ChatType::Offline(*uid), ""));
state.notify_players(ServerGeneral::server_msg(
comp::ChatType::Offline(*uid),
Content::Plain("".to_string()),
));
state.notify_players(ServerGeneral::PlayerListUpdate(PlayerListUpdate::Remove(
*uid,

View File

@ -1384,7 +1384,9 @@ impl Server {
entity,
ServerGeneral::server_msg(
comp::ChatType::CommandError,
"Can't get player UUID (player may be disconnected?)",
common::comp::Content::Plain(
"Can't get player UUID (player may be disconnected?)".to_string(),
),
),
);
return;
@ -1395,10 +1397,10 @@ impl Server {
entity,
ServerGeneral::server_msg(
comp::ChatType::CommandError,
format!(
common::comp::Content::Plain(format!(
"Unknown command '/{name}'.\nType '/help' for available \
commands",
),
)),
),
),
Ok(value) => {
@ -1406,7 +1408,7 @@ impl Server {
entity,
ServerGeneral::server_msg(
comp::ChatType::CommandInfo,
value.join("\n"),
common::comp::Content::Plain(value.join("\n")),
),
);
},
@ -1415,7 +1417,9 @@ impl Server {
entity,
ServerGeneral::server_msg(
comp::ChatType::CommandError,
format!("Error occurred while executing command '/{name}'.\n{err}"),
common::comp::Content::Plain(format!(
"Error occurred while executing command '/{name}'.\n{err}"
)),
),
);
},
@ -1425,10 +1429,10 @@ impl Server {
entity,
ServerGeneral::server_msg(
comp::ChatType::CommandError,
format!(
common::comp::Content::Plain(format!(
"Internal error {err:?} while executing '/{name}'.\nContact \
the server administrator",
),
)),
),
);
},

View File

@ -754,7 +754,7 @@ impl StateExt for State {
if let Some(note) = note {
let _ = client.send(ServerGeneral::server_msg(
ChatType::CommandInfo,
format!("{}", note),
Content::Plain(format!("{}", note)),
));
}
true
@ -762,7 +762,7 @@ impl StateExt for State {
Err(err) => {
let _ = client.send(ServerGeneral::server_msg(
ChatType::CommandError,
format!("{}", err),
Content::Plain(format!("{}", err)),
));
false
},
@ -1167,7 +1167,9 @@ pub fn position_mut<T>(
.or_else(|| {
is_volume_riders.get(entity).and_then(|volume_rider| {
Some(match volume_rider.pos.kind {
common::mounting::Volume::Terrain => Err("Tried to move the world."),
common::mounting::Volume::Terrain => {
Err(Content::Plain("Tried to move the world.".to_string()))
},
common::mounting::Volume::Entity(uid) => Ok(id_maps.uid_entity(uid)?),
})
})

View File

@ -13,7 +13,7 @@ use crate::{
#[cfg(feature = "worldgen")]
use common::terrain::TerrainChunkSize;
use common::{
comp::{Admin, AdminRole, ChatType, Player, Presence, Waypoint},
comp::{Admin, AdminRole, ChatType, Content, Player, Presence, Waypoint},
event::{
ChatEvent, ClientDisconnectEvent, DeleteCharacterEvent, EmitExt, InitializeCharacterEvent,
InitializeSpectatorEvent,
@ -68,7 +68,9 @@ impl Sys {
if !localized_description.map_or(true, |d| d.motd.is_empty()) {
client.send(ServerGeneral::server_msg(
ChatType::CommandInfo,
localized_description.map_or("", |d| &d.motd),
localized_description.map_or(Content::Plain("".to_string()), |d| {
Content::Plain(d.motd.to_owned())
}),
))?;
}
@ -76,7 +78,9 @@ impl Sys {
if automod.enabled() {
client.send(ServerGeneral::server_msg(
ChatType::CommandInfo,
"Automatic moderation is enabled: play nice and have fun!",
Content::Plain(
"Automatic moderation is enabled: play nice and have fun!".to_string(),
),
))?;
}