mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'coffee-compiler/use_content_plain_explicitly' into 'master'
Use Content::Plain explicitly See merge request veloren/veloren!4565
This commit is contained in:
commit
e34ceeae5d
@ -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`]).
|
/// A localisation argument for localised content (see [`Content::Localized`]).
|
||||||
// TODO: Do we want it to be Enum or just wrapper around Content, to add
|
// TODO: Do we want it to be Enum or just wrapper around Content, to add
|
||||||
// additional `impl From<T>` for our arguments?
|
// additional `impl From<T>` for our arguments?
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::settings::Settings;
|
use crate::settings::Settings;
|
||||||
use common::comp::chat::ChatType;
|
use common::comp::{chat::ChatType, Content};
|
||||||
use common_net::msg::ServerGeneral;
|
use common_net::msg::ServerGeneral;
|
||||||
use server::Server;
|
use server::Server;
|
||||||
use std::{
|
use std::{
|
||||||
@ -156,7 +156,10 @@ impl ShutdownCoordinator {
|
|||||||
/// Logs and sends a message to all connected clients
|
/// Logs and sends a message to all connected clients
|
||||||
fn send_msg(server: &mut Server, msg: String) {
|
fn send_msg(server: &mut Server, msg: String) {
|
||||||
info!("{}", &msg);
|
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
|
/// Converts a `Duration` into text in the format XsXm for example 1 minute
|
||||||
|
@ -592,7 +592,7 @@ fn handle_give_item(
|
|||||||
target,
|
target,
|
||||||
comp::InventoryUpdate::new(comp::InventoryUpdateEvent::Given),
|
comp::InventoryUpdate::new(comp::InventoryUpdateEvent::Given),
|
||||||
)
|
)
|
||||||
.map_err(|_| "Entity target is dead!")?;
|
.map_err(|_| Content::Plain("Entity target is dead!".to_string()))?;
|
||||||
}
|
}
|
||||||
res
|
res
|
||||||
} else {
|
} else {
|
||||||
@ -834,6 +834,7 @@ fn handle_motd(
|
|||||||
client,
|
client,
|
||||||
ServerGeneral::server_msg(
|
ServerGeneral::server_msg(
|
||||||
ChatType::CommandInfo,
|
ChatType::CommandInfo,
|
||||||
|
Content::Plain(
|
||||||
server
|
server
|
||||||
.editable_settings()
|
.editable_settings()
|
||||||
.server_description
|
.server_description
|
||||||
@ -841,6 +842,7 @@ fn handle_motd(
|
|||||||
.map_or("", |d| &d.motd)
|
.map_or("", |d| &d.motd)
|
||||||
.to_string(),
|
.to_string(),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -953,7 +955,9 @@ fn handle_site(
|
|||||||
_args: Vec<String>,
|
_args: Vec<String>,
|
||||||
_action: &ServerChatCommand,
|
_action: &ServerChatCommand,
|
||||||
) -> CmdResult<()> {
|
) -> 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
|
/// TODO: Add autocompletion if possible (might require modifying enum to handle
|
||||||
@ -1223,7 +1227,7 @@ fn handle_time(
|
|||||||
client,
|
client,
|
||||||
ServerGeneral::server_msg(
|
ServerGeneral::server_msg(
|
||||||
ChatType::CommandInfo,
|
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,
|
client,
|
||||||
ServerGeneral::server_msg(
|
ServerGeneral::server_msg(
|
||||||
ChatType::CommandError,
|
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);
|
health.change_by(change);
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
Err("You have no health".into())
|
Err(Content::Plain("You have no health".into()))
|
||||||
}
|
}
|
||||||
} else {
|
} 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<()> {
|
) -> CmdResult<()> {
|
||||||
if let Some(alias) = parse_cmd_args!(args, String) {
|
if let Some(alias) = parse_cmd_args!(args, String) {
|
||||||
// Prevent silly aliases
|
// 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
|
let old_alias_optional = server
|
||||||
.state
|
.state
|
||||||
@ -1365,7 +1369,7 @@ 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_players(ServerGeneral::server_msg(
|
server.state.notify_players(ServerGeneral::server_msg(
|
||||||
ChatType::CommandInfo,
|
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
|
// Notify target that an admin changed the alias due to /sudo
|
||||||
server.notify_client(
|
server.notify_client(
|
||||||
target,
|
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(())
|
Ok(())
|
||||||
@ -1424,7 +1431,7 @@ fn handle_rtsim_tp(
|
|||||||
.npcs
|
.npcs
|
||||||
.values()
|
.values()
|
||||||
.find(|npc| npc.uid == id)
|
.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
|
.wpos
|
||||||
} else {
|
} else {
|
||||||
return Err(action.help_content());
|
return Err(action.help_content());
|
||||||
@ -1451,7 +1458,7 @@ fn handle_rtsim_info(
|
|||||||
.npcs
|
.npcs
|
||||||
.iter()
|
.iter()
|
||||||
.find(|(_, npc)| npc.uid == id)
|
.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();
|
let mut info = String::new();
|
||||||
|
|
||||||
@ -1486,7 +1493,7 @@ fn handle_rtsim_info(
|
|||||||
|
|
||||||
server.notify_client(
|
server.notify_client(
|
||||||
client,
|
client,
|
||||||
ServerGeneral::server_msg(ChatType::CommandInfo, info),
|
ServerGeneral::server_msg(ChatType::CommandInfo, Content::Plain(info)),
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -1558,7 +1565,7 @@ fn handle_rtsim_npc(
|
|||||||
|
|
||||||
server.notify_client(
|
server.notify_client(
|
||||||
client,
|
client,
|
||||||
ServerGeneral::server_msg(ChatType::CommandInfo, info),
|
ServerGeneral::server_msg(ChatType::CommandInfo, Content::Plain(info)),
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -1592,10 +1599,10 @@ fn handle_rtsim_purge(
|
|||||||
client,
|
client,
|
||||||
ServerGeneral::server_msg(
|
ServerGeneral::server_msg(
|
||||||
ChatType::CommandInfo,
|
ChatType::CommandInfo,
|
||||||
format!(
|
Content::Plain(format!(
|
||||||
"Rtsim data {} be purged on next startup",
|
"Rtsim data {} be purged on next startup",
|
||||||
if should_purge { "WILL" } else { "will NOT" },
|
if should_purge { "WILL" } else { "will NOT" },
|
||||||
),
|
)),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -1659,7 +1666,7 @@ fn handle_rtsim_chunk(
|
|||||||
|
|
||||||
server.notify_client(
|
server.notify_client(
|
||||||
client,
|
client,
|
||||||
ServerGeneral::server_msg(ChatType::CommandInfo, info),
|
ServerGeneral::server_msg(ChatType::CommandInfo, Content::Plain(info)),
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -1691,7 +1698,9 @@ fn handle_spawn(
|
|||||||
.read_storage::<comp::Anchor>()
|
.read_storage::<comp::Anchor>()
|
||||||
.contains(target)
|
.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);
|
let amount = opt_amount.filter(|x| *x > 0).unwrap_or(1).min(50);
|
||||||
@ -1757,9 +1766,9 @@ fn handle_spawn(
|
|||||||
follower,
|
follower,
|
||||||
tether_length: 4.0,
|
tether_length: 4.0,
|
||||||
})
|
})
|
||||||
.map_err(|_| "Failed to tether entities")?;
|
.map_err(|_| Content::Plain("Failed to tether entities".to_string()))?;
|
||||||
} else {
|
} 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,
|
client,
|
||||||
ServerGeneral::server_msg(
|
ServerGeneral::server_msg(
|
||||||
ChatType::CommandInfo,
|
ChatType::CommandInfo,
|
||||||
format!("Spawned {} entities", amount),
|
Content::Plain(format!("Spawned {} entities", amount)),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -1860,7 +1869,7 @@ fn handle_spawn_airship(
|
|||||||
*comp::ship::ALL_AIRSHIPS
|
*comp::ship::ALL_AIRSHIPS
|
||||||
.iter()
|
.iter()
|
||||||
.find(|body| format!("{body:?}") == body_name)
|
.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 {
|
} else {
|
||||||
comp::ship::Body::random_airship_with(&mut thread_rng())
|
comp::ship::Body::random_airship_with(&mut thread_rng())
|
||||||
};
|
};
|
||||||
@ -1907,7 +1916,7 @@ fn handle_spawn_ship(
|
|||||||
*comp::ship::ALL_SHIPS
|
*comp::ship::ALL_SHIPS
|
||||||
.iter()
|
.iter()
|
||||||
.find(|body| format!("{body:?}") == body_name)
|
.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 {
|
} else {
|
||||||
comp::ship::Body::random_airship_with(&mut thread_rng())
|
comp::ship::Body::random_airship_with(&mut thread_rng())
|
||||||
};
|
};
|
||||||
@ -1961,15 +1970,18 @@ fn handle_spawn_ship(
|
|||||||
follower,
|
follower,
|
||||||
tether_length,
|
tether_length,
|
||||||
})
|
})
|
||||||
.map_err(|_| "Failed to tether entities")?;
|
.map_err(|_| Content::Plain("Failed to tether entities".to_string()))?;
|
||||||
} else {
|
} else {
|
||||||
return Err("Tether members don't have Uids.".into());
|
return Err(Content::Plain("Tether members don't have Uids.".into()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
server.notify_client(
|
server.notify_client(
|
||||||
client,
|
client,
|
||||||
ServerGeneral::server_msg(ChatType::CommandInfo, "Spawned a ship"),
|
ServerGeneral::server_msg(
|
||||||
|
ChatType::CommandInfo,
|
||||||
|
Content::Plain("Spawned a ship".to_string()),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -2132,7 +2144,7 @@ fn handle_permit_build(
|
|||||||
let mut can_build = server.state.ecs().write_storage::<comp::CanBuild>();
|
let mut can_build = server.state.ecs().write_storage::<comp::CanBuild>();
|
||||||
let entry = can_build
|
let entry = can_build
|
||||||
.entry(target)
|
.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 {
|
let mut comp_can_build = entry.or_insert(comp::CanBuild {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
build_areas: HashSet::new(),
|
build_areas: HashSet::new(),
|
||||||
@ -2253,10 +2265,10 @@ fn handle_players(
|
|||||||
client,
|
client,
|
||||||
ServerGeneral::server_msg(
|
ServerGeneral::server_msg(
|
||||||
ChatType::CommandInfo,
|
ChatType::CommandInfo,
|
||||||
entity_tuples.join().fold(
|
Content::Plain(entity_tuples.join().fold(
|
||||||
format!("{} online players:", entity_tuples.join().count()),
|
format!("{} online players:", entity_tuples.join().count()),
|
||||||
|s, (_, player, stat)| format!("{}\n[{}]{}", s, player.alias, stat.name,),
|
|s, (_, player, stat)| format!("{}\n[{}]{}", s, player.alias, stat.name,),
|
||||||
),
|
)),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -2287,7 +2299,10 @@ fn handle_spawn_portal(
|
|||||||
|
|
||||||
server.notify_client(
|
server.notify_client(
|
||||||
client,
|
client,
|
||||||
ServerGeneral::server_msg(ChatType::CommandInfo, "Spawned portal"),
|
ServerGeneral::server_msg(
|
||||||
|
ChatType::CommandInfo,
|
||||||
|
Content::Plain("Spawned portal".to_string()),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
@ -2328,7 +2343,9 @@ fn handle_build(
|
|||||||
server.notify_client(client, chat_msg);
|
server.notify_client(client, chat_msg);
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} 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
|
Some(AreaKind::NoDurability) => state
|
||||||
.mut_resource::<AreasContainer<NoDurabilityArea>>()
|
.mut_resource::<AreasContainer<NoDurabilityArea>>()
|
||||||
.deref_mut(),
|
.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 special_areas = get_areas_mut(&kind, &mut server.state)?;
|
||||||
let msg = ServerGeneral::server_msg(
|
let msg = ServerGeneral::server_msg(
|
||||||
ChatType::CommandInfo,
|
ChatType::CommandInfo,
|
||||||
format!("Created {kind} zone {}", area_name),
|
Content::Plain(format!("Created {kind} zone {}", area_name)),
|
||||||
);
|
);
|
||||||
special_areas
|
special_areas
|
||||||
.insert(area_name, Aabb {
|
.insert(area_name, Aabb {
|
||||||
min: Vec3::new(xlo, ylo, zlo),
|
min: Vec3::new(xlo, ylo, zlo),
|
||||||
max: Vec3::new(xhi, yhi, zhi),
|
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);
|
server.notify_client(client, msg);
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
@ -2412,7 +2431,7 @@ fn handle_area_list(
|
|||||||
|
|
||||||
let msg = ServerGeneral::server_msg(
|
let msg = ServerGeneral::server_msg(
|
||||||
ChatType::CommandInfo,
|
ChatType::CommandInfo,
|
||||||
[build_message, no_dura_message].join("\n"),
|
Content::Plain([build_message, no_dura_message].join("\n")),
|
||||||
);
|
);
|
||||||
|
|
||||||
server.notify_client(client, msg);
|
server.notify_client(client, msg);
|
||||||
@ -2430,17 +2449,19 @@ fn handle_area_remove(
|
|||||||
let areas = get_areas_mut(&kind, &mut server.state)?;
|
let areas = get_areas_mut(&kind, &mut server.state)?;
|
||||||
|
|
||||||
areas.remove(&area_name).map_err(|err| match err {
|
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: {}",
|
"Special area is reserved and cannot be removed: {}",
|
||||||
area_name
|
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(
|
server.notify_client(
|
||||||
client,
|
client,
|
||||||
ServerGeneral::server_msg(
|
ServerGeneral::server_msg(
|
||||||
ChatType::CommandInfo,
|
ChatType::CommandInfo,
|
||||||
format!("Removed {kind} zone {area_name}"),
|
Content::Plain(format!("Removed {kind} zone {area_name}")),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -2576,7 +2597,7 @@ fn handle_kill_npcs(
|
|||||||
|
|
||||||
server.notify_client(
|
server.notify_client(
|
||||||
client,
|
client,
|
||||||
ServerGeneral::server_msg(ChatType::CommandInfo, text),
|
ServerGeneral::server_msg(ChatType::CommandInfo, Content::Plain(text)),
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -2603,7 +2624,10 @@ fn handle_kit(
|
|||||||
let notify = |server: &mut Server, kit_name: &str| {
|
let notify = |server: &mut Server, kit_name: &str| {
|
||||||
server.notify_client(
|
server.notify_client(
|
||||||
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())?;
|
let name = parse_cmd_args!(args, String).ok_or_else(|| action.help_content())?;
|
||||||
@ -2628,12 +2652,17 @@ fn handle_kit(
|
|||||||
kit_name => {
|
kit_name => {
|
||||||
let kits = KitManifest::load(KIT_MANIFEST_PATH)
|
let kits = KitManifest::load(KIT_MANIFEST_PATH)
|
||||||
.map(|kits| kits.read())
|
.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
|
let kit = kits
|
||||||
.0
|
.0
|
||||||
.get(kit_name)
|
.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(
|
let res = push_kit(
|
||||||
kit.iter()
|
kit.iter()
|
||||||
@ -2693,11 +2722,12 @@ fn push_item(
|
|||||||
) -> CmdResult<()> {
|
) -> CmdResult<()> {
|
||||||
let items = match item_id {
|
let items = match item_id {
|
||||||
KitEntry::Spec(KitSpec::Item(item_id)) => vec![
|
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 }) => {
|
KitEntry::Spec(KitSpec::ModularWeapon { tool, material }) => {
|
||||||
comp::item::modular::generate_weapons(tool, material, None)
|
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],
|
KitEntry::Item(item) => vec![item],
|
||||||
};
|
};
|
||||||
@ -2749,7 +2779,7 @@ fn handle_object(
|
|||||||
.read_storage::<comp::Ori>()
|
.read_storage::<comp::Ori>()
|
||||||
.get(target)
|
.get(target)
|
||||||
.copied()
|
.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
|
/*let builder = server.state
|
||||||
.create_object(pos, ori, obj_type)
|
.create_object(pos, ori, obj_type)
|
||||||
.with(ori);*/
|
.with(ori);*/
|
||||||
@ -2783,12 +2813,15 @@ fn handle_object(
|
|||||||
client,
|
client,
|
||||||
ServerGeneral::server_msg(
|
ServerGeneral::server_msg(
|
||||||
ChatType::CommandInfo,
|
ChatType::CommandInfo,
|
||||||
format!("Spawned: {}", obj_str_res.unwrap_or("<Unknown object>")),
|
Content::Plain(format!(
|
||||||
|
"Spawned: {}",
|
||||||
|
obj_str_res.unwrap_or("<Unknown object>")
|
||||||
|
)),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} 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 let (Some(r), Some(g), Some(b)) = (opt_r, opt_g, opt_b) {
|
||||||
if r < 0.0 || g < 0.0 || b < 0.0 {
|
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);
|
let r = r.clamp(0.0, 1.0);
|
||||||
@ -2841,7 +2876,10 @@ fn handle_light(
|
|||||||
}
|
}
|
||||||
server.notify_client(
|
server.notify_client(
|
||||||
client,
|
client,
|
||||||
ServerGeneral::server_msg(ChatType::CommandInfo, "Spawned object."),
|
ServerGeneral::server_msg(
|
||||||
|
ChatType::CommandInfo,
|
||||||
|
Content::Plain("Spawned object.".to_string()),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -2956,7 +2994,10 @@ fn handle_waypoint(
|
|||||||
)?;
|
)?;
|
||||||
server.notify_client(
|
server.notify_client(
|
||||||
client,
|
client,
|
||||||
ServerGeneral::server_msg(ChatType::CommandInfo, "Waypoint saved!"),
|
ServerGeneral::server_msg(
|
||||||
|
ChatType::CommandInfo,
|
||||||
|
Content::Plain("Waypoint saved!".to_string()),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
server.notify_client(
|
server.notify_client(
|
||||||
target,
|
target,
|
||||||
@ -3045,7 +3086,7 @@ fn handle_spawn_wiring(
|
|||||||
|
|
||||||
server.notify_client(
|
server.notify_client(
|
||||||
client,
|
client,
|
||||||
ServerGeneral::server_msg(ChatType::CommandInfo, "Wire"),
|
ServerGeneral::server_msg(ChatType::CommandInfo, Content::Plain("Wire".to_string())),
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -3500,7 +3541,7 @@ fn handle_join_faction(
|
|||||||
server.notify_client(target, ServerGeneral::ChatMode(mode));
|
server.notify_client(target, ServerGeneral::ChatMode(mode));
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} 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>,
|
_args: Vec<String>,
|
||||||
_action: &ServerChatCommand,
|
_action: &ServerChatCommand,
|
||||||
) -> CmdResult<()> {
|
) -> CmdResult<()> {
|
||||||
Err("Unsupported without worldgen enabled".into())
|
Err(Content::Plain(
|
||||||
|
"Unsupported without worldgen enabled".into(),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "worldgen")]
|
#[cfg(feature = "worldgen")]
|
||||||
@ -3591,10 +3634,13 @@ cliff_height {:?} "#,
|
|||||||
))
|
))
|
||||||
};
|
};
|
||||||
if let Some(s) = msg_generator(&calendar) {
|
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(())
|
Ok(())
|
||||||
} else {
|
} 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>,
|
_args: Vec<String>,
|
||||||
_action: &ServerChatCommand,
|
_action: &ServerChatCommand,
|
||||||
) -> CmdResult<()> {
|
) -> CmdResult<()> {
|
||||||
Err("Unsupported without worldgen enabled".into())
|
Err(Content::Plain(
|
||||||
|
"Unsupported without worldgen enabled".into(),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "worldgen")]
|
#[cfg(feature = "worldgen")]
|
||||||
@ -3636,10 +3684,13 @@ fn handle_debug_ways(
|
|||||||
Some(ret)
|
Some(ret)
|
||||||
};
|
};
|
||||||
if let Some(s) = msg_generator() {
|
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(())
|
Ok(())
|
||||||
} else {
|
} 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);
|
skill_set.add_skill_points(skill_tree, sp);
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
Err("Entity has no stats!".into())
|
Err(Content::Plain("Entity has no stats!".into()))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Err(action.help_content())
|
Err(action.help_content())
|
||||||
@ -3829,7 +3880,10 @@ fn handle_remove_lights(
|
|||||||
|
|
||||||
server.notify_client(
|
server.notify_client(
|
||||||
client,
|
client,
|
||||||
ServerGeneral::server_msg(ChatType::CommandInfo, format!("Removed {} lights!", size)),
|
ServerGeneral::server_msg(
|
||||||
|
ChatType::CommandInfo,
|
||||||
|
Content::Plain(format!("Removed {} lights!", size)),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -4058,10 +4112,10 @@ fn handle_kick(
|
|||||||
client,
|
client,
|
||||||
ServerGeneral::server_msg(
|
ServerGeneral::server_msg(
|
||||||
ChatType::CommandInfo,
|
ChatType::CommandInfo,
|
||||||
format!(
|
Content::Plain(format!(
|
||||||
"Kicked {} from the server with reason: {}",
|
"Kicked {} from the server with reason: {}",
|
||||||
target_alias, reason
|
target_alias, reason
|
||||||
),
|
)),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -4093,7 +4147,7 @@ fn handle_ban(
|
|||||||
let end_date = parse_duration
|
let end_date = parse_duration
|
||||||
.map(|duration| chrono::Duration::from_std(duration.into()))
|
.map(|duration| chrono::Duration::from_std(duration.into()))
|
||||||
.transpose()
|
.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.
|
// On overflow (someone adding some ridiculous time span), just make the ban infinite.
|
||||||
.and_then(|duration| now.checked_add_signed(duration));
|
.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 players = ecs.write_storage::<comp::Player>();
|
||||||
let mut player_info = players.get_mut(target).ok_or_else(|| {
|
let mut player_info = players.get_mut(target).ok_or_else(|| {
|
||||||
error!("Can't get player component for player");
|
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 {
|
if let Some(Time(last_change)) = player_info.last_battlemode_change {
|
||||||
let Time(time) = *time;
|
let Time(time) = *time;
|
||||||
@ -4340,7 +4394,7 @@ fn handle_battlemode(
|
|||||||
let players = ecs.read_storage::<comp::Player>();
|
let players = ecs.read_storage::<comp::Player>();
|
||||||
let player = players.get(target).ok_or_else(|| {
|
let player = players.get(target).ok_or_else(|| {
|
||||||
error!("Can't get player component for player");
|
error!("Can't get player component for player");
|
||||||
"Error!"
|
Content::Plain("Error!".to_string())
|
||||||
})?;
|
})?;
|
||||||
let mut msg = format!("Current battle mode: {:?}.", player.battle_mode);
|
let mut msg = format!("Current battle mode: {:?}.", player.battle_mode);
|
||||||
if settings.gameplay.battle_mode.allow_choosing() {
|
if settings.gameplay.battle_mode.allow_choosing() {
|
||||||
@ -4361,7 +4415,7 @@ fn handle_battlemode(
|
|||||||
}
|
}
|
||||||
server.notify_client(
|
server.notify_client(
|
||||||
client,
|
client,
|
||||||
ServerGeneral::server_msg(ChatType::CommandInfo, msg),
|
ServerGeneral::server_msg(ChatType::CommandInfo, Content::Plain(msg)),
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -4386,9 +4440,9 @@ fn handle_battlemode_force(
|
|||||||
_ => return Err(Content::localized("command-battlemode-available-modes")),
|
_ => return Err(Content::localized("command-battlemode-available-modes")),
|
||||||
};
|
};
|
||||||
let mut players = ecs.write_storage::<comp::Player>();
|
let mut players = ecs.write_storage::<comp::Player>();
|
||||||
let mut player_info = players
|
let mut player_info = players.get_mut(target).ok_or(Content::Plain(
|
||||||
.get_mut(target)
|
"Cannot get player component for target".to_string(),
|
||||||
.ok_or("Cannot get player component for target")?;
|
))?;
|
||||||
player_info.battle_mode = mode;
|
player_info.battle_mode = mode;
|
||||||
server.notify_client(
|
server.notify_client(
|
||||||
client,
|
client,
|
||||||
@ -4476,10 +4530,10 @@ fn handle_server_physics(
|
|||||||
client,
|
client,
|
||||||
ServerGeneral::server_msg(
|
ServerGeneral::server_msg(
|
||||||
ChatType::CommandInfo,
|
ChatType::CommandInfo,
|
||||||
format!(
|
Content::Plain(format!(
|
||||||
"Updated physics settings for {} ({}): {:?}",
|
"Updated physics settings for {} ({}): {:?}",
|
||||||
username, uuid, entry
|
username, uuid, entry
|
||||||
),
|
)),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -4663,7 +4717,7 @@ fn handle_skill_preset(
|
|||||||
preset => set_skills(&mut skill_set, preset),
|
preset => set_skills(&mut skill_set, preset),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Err("Player has no stats!".into())
|
Err(Content::Plain("Player has no stats!".into()))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Err(action.help_content())
|
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);
|
skill_set.add_skill_points(group, cost);
|
||||||
match skill_set.unlock_skill(*skill) {
|
match skill_set.unlock_skill(*skill) {
|
||||||
Ok(_) | Err(comp::skillset::SkillUnlockError::SkillAlreadyUnlocked) => Ok(()),
|
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>,
|
_args: Vec<String>,
|
||||||
_action: &ServerChatCommand,
|
_action: &ServerChatCommand,
|
||||||
) -> CmdResult<()> {
|
) -> CmdResult<()> {
|
||||||
Err("Unsupported without worldgen enabled".into())
|
Err(Content::Plain(
|
||||||
|
"Unsupported without worldgen enabled".into(),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "worldgen")]
|
#[cfg(feature = "worldgen")]
|
||||||
@ -5042,9 +5098,9 @@ fn handle_tether(
|
|||||||
follower,
|
follower,
|
||||||
tether_length,
|
tether_length,
|
||||||
})
|
})
|
||||||
.map_err(|_| "Failed to tether entities".into())
|
.map_err(|_| Content::Plain("Failed to tether entities".into()))
|
||||||
} else {
|
} else {
|
||||||
Err("Tether members don't have Uids.".into())
|
Err(Content::Plain("Tether members don't have Uids.".into()))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Err(action.help_content())
|
Err(action.help_content())
|
||||||
@ -5102,9 +5158,11 @@ fn handle_mount(
|
|||||||
server
|
server
|
||||||
.state
|
.state
|
||||||
.link(common::mounting::Mounting { mount, rider })
|
.link(common::mounting::Mounting { mount, rider })
|
||||||
.map_err(|_| "Failed to mount entities".into())
|
.map_err(|_| Content::Plain("Failed to mount entities".into()))
|
||||||
} else {
|
} 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 {
|
} else {
|
||||||
Err(action.help_content())
|
Err(action.help_content())
|
||||||
|
@ -4,7 +4,7 @@ use common::{
|
|||||||
self,
|
self,
|
||||||
group::{ChangeNotification, Group, GroupManager},
|
group::{ChangeNotification, Group, GroupManager},
|
||||||
invite::{InviteKind, PendingInvites},
|
invite::{InviteKind, PendingInvites},
|
||||||
ChatType, GroupManip,
|
ChatType, Content, GroupManip,
|
||||||
},
|
},
|
||||||
event::GroupManipEvent,
|
event::GroupManipEvent,
|
||||||
uid::{IdMaps, Uid},
|
uid::{IdMaps, Uid},
|
||||||
@ -39,7 +39,9 @@ pub fn can_invite(
|
|||||||
if let Some(client) = clients.get(inviter) {
|
if let Some(client) = clients.get(inviter) {
|
||||||
client.send_fallible(ServerGeneral::server_msg(
|
client.send_fallible(ServerGeneral::server_msg(
|
||||||
ChatType::Meta,
|
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;
|
return false;
|
||||||
@ -70,9 +72,11 @@ pub fn can_invite(
|
|||||||
if let Some(client) = clients.get(inviter) {
|
if let Some(client) = clients.get(inviter) {
|
||||||
client.send_fallible(ServerGeneral::server_msg(
|
client.send_fallible(ServerGeneral::server_msg(
|
||||||
ChatType::Meta,
|
ChatType::Meta,
|
||||||
"Invite failed, pending invites plus current group size have reached the group \
|
Content::Plain(
|
||||||
size limit"
|
"Invite failed, pending invites plus current group size have reached the \
|
||||||
|
group size limit"
|
||||||
.to_owned(),
|
.to_owned(),
|
||||||
|
),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -160,7 +164,9 @@ impl ServerEvent for GroupManipEvent {
|
|||||||
if let Some(client) = clients.get(entity) {
|
if let Some(client) = clients.get(entity) {
|
||||||
client.send_fallible(ServerGeneral::server_msg(
|
client.send_fallible(ServerGeneral::server_msg(
|
||||||
ChatType::Meta,
|
ChatType::Meta,
|
||||||
"Kick failed, target does not exist.",
|
Content::Plain(
|
||||||
|
"Kick failed, target does not exist.".to_string(),
|
||||||
|
),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
@ -173,7 +179,7 @@ impl ServerEvent for GroupManipEvent {
|
|||||||
if let Some(general_stream) = clients.get(entity) {
|
if let Some(general_stream) = clients.get(entity) {
|
||||||
general_stream.send_fallible(ServerGeneral::server_msg(
|
general_stream.send_fallible(ServerGeneral::server_msg(
|
||||||
ChatType::Meta,
|
ChatType::Meta,
|
||||||
"Kick failed, you can't kick pets.",
|
Content::Plain("Kick failed, you can't kick pets.".to_string()),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
@ -183,7 +189,7 @@ impl ServerEvent for GroupManipEvent {
|
|||||||
if let Some(client) = clients.get(entity) {
|
if let Some(client) = clients.get(entity) {
|
||||||
client.send_fallible(ServerGeneral::server_msg(
|
client.send_fallible(ServerGeneral::server_msg(
|
||||||
ChatType::Meta,
|
ChatType::Meta,
|
||||||
"Kick failed, you can't kick yourself.",
|
Content::Plain("Kick failed, you can't kick yourself.".to_string()),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
@ -226,14 +232,14 @@ impl ServerEvent for GroupManipEvent {
|
|||||||
if let Some(client) = clients.get(target) {
|
if let Some(client) = clients.get(target) {
|
||||||
client.send_fallible(ServerGeneral::server_msg(
|
client.send_fallible(ServerGeneral::server_msg(
|
||||||
ChatType::Meta,
|
ChatType::Meta,
|
||||||
"You were removed from the group.",
|
Content::Plain("You were removed from the group.".to_string()),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
// Tell kicker that they were successful
|
// Tell kicker that they were successful
|
||||||
if let Some(client) = clients.get(entity) {
|
if let Some(client) = clients.get(entity) {
|
||||||
client.send_fallible(ServerGeneral::server_msg(
|
client.send_fallible(ServerGeneral::server_msg(
|
||||||
ChatType::Meta,
|
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) {
|
if let Some(client) = clients.get(entity) {
|
||||||
client.send_fallible(ServerGeneral::server_msg(
|
client.send_fallible(ServerGeneral::server_msg(
|
||||||
ChatType::Meta,
|
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) {
|
if let Some(client) = clients.get(entity) {
|
||||||
client.send_fallible(ServerGeneral::server_msg(
|
client.send_fallible(ServerGeneral::server_msg(
|
||||||
ChatType::Meta,
|
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) {
|
if let Some(client) = clients.get(entity) {
|
||||||
client.send_fallible(ServerGeneral::server_msg(
|
client.send_fallible(ServerGeneral::server_msg(
|
||||||
ChatType::Meta,
|
ChatType::Meta,
|
||||||
"Leadership transfer failed, target does not exist",
|
Content::Plain(
|
||||||
|
"Leadership transfer failed, target does not exist"
|
||||||
|
.to_string(),
|
||||||
|
),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
@ -307,14 +322,16 @@ impl ServerEvent for GroupManipEvent {
|
|||||||
if let Some(client) = clients.get(target) {
|
if let Some(client) = clients.get(target) {
|
||||||
client.send_fallible(ServerGeneral::server_msg(
|
client.send_fallible(ServerGeneral::server_msg(
|
||||||
ChatType::Meta,
|
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
|
// Tell the old leader that the transfer was succesful
|
||||||
if let Some(client) = clients.get(entity) {
|
if let Some(client) = clients.get(entity) {
|
||||||
client.send_fallible(ServerGeneral::server_msg(
|
client.send_fallible(ServerGeneral::server_msg(
|
||||||
ChatType::Meta,
|
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) {
|
if let Some(client) = clients.get(entity) {
|
||||||
client.send_fallible(ServerGeneral::server_msg(
|
client.send_fallible(ServerGeneral::server_msg(
|
||||||
ChatType::Meta,
|
ChatType::Meta,
|
||||||
|
Content::Plain(
|
||||||
"Transfer failed: You are not the leader of the target's \
|
"Transfer failed: You are not the leader of the target's \
|
||||||
group.",
|
group."
|
||||||
|
.to_string(),
|
||||||
|
),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -333,7 +353,10 @@ impl ServerEvent for GroupManipEvent {
|
|||||||
if let Some(client) = clients.get(entity) {
|
if let Some(client) = clients.get(entity) {
|
||||||
client.send_fallible(ServerGeneral::server_msg(
|
client.send_fallible(ServerGeneral::server_msg(
|
||||||
ChatType::Meta,
|
ChatType::Meta,
|
||||||
"Transfer failed: Your target is not in a group.",
|
Content::Plain(
|
||||||
|
"Transfer failed: Your target is not in a group."
|
||||||
|
.to_string(),
|
||||||
|
),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -10,7 +10,7 @@ use common::{
|
|||||||
agent::{Agent, AgentEvent},
|
agent::{Agent, AgentEvent},
|
||||||
group::GroupManager,
|
group::GroupManager,
|
||||||
invite::{Invite, InviteKind, InviteResponse, PendingInvites},
|
invite::{Invite, InviteKind, InviteResponse, PendingInvites},
|
||||||
ChatType, Group, Health, Pos,
|
ChatType, Content, Group, Health, Pos,
|
||||||
},
|
},
|
||||||
consts::MAX_TRADE_RANGE,
|
consts::MAX_TRADE_RANGE,
|
||||||
event::{InitiateInviteEvent, InviteResponseEvent},
|
event::{InitiateInviteEvent, InviteResponseEvent},
|
||||||
@ -80,7 +80,7 @@ impl ServerEvent for InitiateInviteEvent {
|
|||||||
if let Some(client) = clients.get(inviter) {
|
if let Some(client) = clients.get(inviter) {
|
||||||
client.send_fallible(ServerGeneral::server_msg(
|
client.send_fallible(ServerGeneral::server_msg(
|
||||||
ChatType::Meta,
|
ChatType::Meta,
|
||||||
"Invite failed, target does not exist.",
|
Content::Plain("Invite failed, target does not exist.".to_string()),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
@ -146,7 +146,7 @@ impl ServerEvent for InitiateInviteEvent {
|
|||||||
if let Some(client) = clients.get(inviter) {
|
if let Some(client) = clients.get(inviter) {
|
||||||
client.send_fallible(ServerGeneral::server_msg(
|
client.send_fallible(ServerGeneral::server_msg(
|
||||||
ChatType::Meta,
|
ChatType::Meta,
|
||||||
"This player already has a pending invite.",
|
Content::Plain("This player already has a pending invite.".to_string()),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
@ -206,7 +206,7 @@ impl ServerEvent for InitiateInviteEvent {
|
|||||||
} else if let Some(client) = clients.get(inviter) {
|
} else if let Some(client) = clients.get(inviter) {
|
||||||
client.send_fallible(ServerGeneral::server_msg(
|
client.send_fallible(ServerGeneral::server_msg(
|
||||||
ChatType::Meta,
|
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(
|
client.send_fallible(ServerGeneral::server_msg(
|
||||||
ChatType::Meta,
|
ChatType::Meta,
|
||||||
"Trade failed, inviter initiated new trade since sending trade \
|
Content::Plain(
|
||||||
request.",
|
"Trade failed, inviter initiated new trade since sending \
|
||||||
|
trade request."
|
||||||
|
.to_string(),
|
||||||
|
),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -4,8 +4,7 @@ use crate::{
|
|||||||
state_ext::StateExt, BattleModeBuffer, Server,
|
state_ext::StateExt, BattleModeBuffer, Server,
|
||||||
};
|
};
|
||||||
use common::{
|
use common::{
|
||||||
comp,
|
comp::{self, group, pet::is_tameable, Content, Presence, PresenceKind},
|
||||||
comp::{group, pet::is_tameable, Presence, PresenceKind},
|
|
||||||
event::{DeleteCharacterEvent, PossessEvent},
|
event::{DeleteCharacterEvent, PossessEvent},
|
||||||
resources::Time,
|
resources::Time,
|
||||||
uid::{IdMaps, Uid},
|
uid::{IdMaps, Uid},
|
||||||
@ -223,7 +222,10 @@ pub fn handle_client_disconnect(
|
|||||||
state.read_storage::<Uid>().get(entity),
|
state.read_storage::<Uid>().get(entity),
|
||||||
state.read_storage::<comp::Player>().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(
|
state.notify_players(ServerGeneral::PlayerListUpdate(PlayerListUpdate::Remove(
|
||||||
*uid,
|
*uid,
|
||||||
|
@ -1384,7 +1384,9 @@ impl Server {
|
|||||||
entity,
|
entity,
|
||||||
ServerGeneral::server_msg(
|
ServerGeneral::server_msg(
|
||||||
comp::ChatType::CommandError,
|
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;
|
return;
|
||||||
@ -1395,10 +1397,10 @@ impl Server {
|
|||||||
entity,
|
entity,
|
||||||
ServerGeneral::server_msg(
|
ServerGeneral::server_msg(
|
||||||
comp::ChatType::CommandError,
|
comp::ChatType::CommandError,
|
||||||
format!(
|
common::comp::Content::Plain(format!(
|
||||||
"Unknown command '/{name}'.\nType '/help' for available \
|
"Unknown command '/{name}'.\nType '/help' for available \
|
||||||
commands",
|
commands",
|
||||||
),
|
)),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Ok(value) => {
|
Ok(value) => {
|
||||||
@ -1406,7 +1408,7 @@ impl Server {
|
|||||||
entity,
|
entity,
|
||||||
ServerGeneral::server_msg(
|
ServerGeneral::server_msg(
|
||||||
comp::ChatType::CommandInfo,
|
comp::ChatType::CommandInfo,
|
||||||
value.join("\n"),
|
common::comp::Content::Plain(value.join("\n")),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -1415,7 +1417,9 @@ impl Server {
|
|||||||
entity,
|
entity,
|
||||||
ServerGeneral::server_msg(
|
ServerGeneral::server_msg(
|
||||||
comp::ChatType::CommandError,
|
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,
|
entity,
|
||||||
ServerGeneral::server_msg(
|
ServerGeneral::server_msg(
|
||||||
comp::ChatType::CommandError,
|
comp::ChatType::CommandError,
|
||||||
format!(
|
common::comp::Content::Plain(format!(
|
||||||
"Internal error {err:?} while executing '/{name}'.\nContact \
|
"Internal error {err:?} while executing '/{name}'.\nContact \
|
||||||
the server administrator",
|
the server administrator",
|
||||||
),
|
)),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -754,7 +754,7 @@ impl StateExt for State {
|
|||||||
if let Some(note) = note {
|
if let Some(note) = note {
|
||||||
let _ = client.send(ServerGeneral::server_msg(
|
let _ = client.send(ServerGeneral::server_msg(
|
||||||
ChatType::CommandInfo,
|
ChatType::CommandInfo,
|
||||||
format!("{}", note),
|
Content::Plain(format!("{}", note)),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
@ -762,7 +762,7 @@ impl StateExt for State {
|
|||||||
Err(err) => {
|
Err(err) => {
|
||||||
let _ = client.send(ServerGeneral::server_msg(
|
let _ = client.send(ServerGeneral::server_msg(
|
||||||
ChatType::CommandError,
|
ChatType::CommandError,
|
||||||
format!("{}", err),
|
Content::Plain(format!("{}", err)),
|
||||||
));
|
));
|
||||||
false
|
false
|
||||||
},
|
},
|
||||||
@ -1167,7 +1167,9 @@ pub fn position_mut<T>(
|
|||||||
.or_else(|| {
|
.or_else(|| {
|
||||||
is_volume_riders.get(entity).and_then(|volume_rider| {
|
is_volume_riders.get(entity).and_then(|volume_rider| {
|
||||||
Some(match volume_rider.pos.kind {
|
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)?),
|
common::mounting::Volume::Entity(uid) => Ok(id_maps.uid_entity(uid)?),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -13,7 +13,7 @@ use crate::{
|
|||||||
#[cfg(feature = "worldgen")]
|
#[cfg(feature = "worldgen")]
|
||||||
use common::terrain::TerrainChunkSize;
|
use common::terrain::TerrainChunkSize;
|
||||||
use common::{
|
use common::{
|
||||||
comp::{Admin, AdminRole, ChatType, Player, Presence, Waypoint},
|
comp::{Admin, AdminRole, ChatType, Content, Player, Presence, Waypoint},
|
||||||
event::{
|
event::{
|
||||||
ChatEvent, ClientDisconnectEvent, DeleteCharacterEvent, EmitExt, InitializeCharacterEvent,
|
ChatEvent, ClientDisconnectEvent, DeleteCharacterEvent, EmitExt, InitializeCharacterEvent,
|
||||||
InitializeSpectatorEvent,
|
InitializeSpectatorEvent,
|
||||||
@ -68,7 +68,9 @@ impl Sys {
|
|||||||
if !localized_description.map_or(true, |d| d.motd.is_empty()) {
|
if !localized_description.map_or(true, |d| d.motd.is_empty()) {
|
||||||
client.send(ServerGeneral::server_msg(
|
client.send(ServerGeneral::server_msg(
|
||||||
ChatType::CommandInfo,
|
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() {
|
if automod.enabled() {
|
||||||
client.send(ServerGeneral::server_msg(
|
client.send(ServerGeneral::server_msg(
|
||||||
ChatType::CommandInfo,
|
ChatType::CommandInfo,
|
||||||
"Automatic moderation is enabled: play nice and have fun!",
|
Content::Plain(
|
||||||
|
"Automatic moderation is enabled: play nice and have fun!".to_string(),
|
||||||
|
),
|
||||||
))?;
|
))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user