2019-05-17 09:22:32 +00:00
|
|
|
//! # Implementing new commands.
|
2020-02-01 20:39:39 +00:00
|
|
|
//! To implement a new command, add an instance of `ChatCommand` to
|
|
|
|
//! `CHAT_COMMANDS` and provide a handler function.
|
2019-04-16 16:08:36 +00:00
|
|
|
|
2020-10-06 02:59:47 +00:00
|
|
|
use crate::{
|
|
|
|
settings::{BanRecord, EditableSetting},
|
2020-11-03 23:53:46 +00:00
|
|
|
Server, SpawnPoint, StateExt,
|
2020-10-06 02:59:47 +00:00
|
|
|
};
|
2019-07-26 14:38:31 +00:00
|
|
|
use chrono::{NaiveTime, Timelike};
|
2019-06-01 19:49:34 +00:00
|
|
|
use common::{
|
2020-06-05 18:12:18 +00:00
|
|
|
cmd::{ChatCommand, CHAT_COMMANDS, CHAT_SHORTCUTS},
|
2020-11-12 05:27:16 +00:00
|
|
|
comp::{self, ChatType, Item, LightEmitter, WaypointArea},
|
2020-11-01 17:15:46 +00:00
|
|
|
effect::Effect,
|
2019-08-25 16:48:12 +00:00
|
|
|
event::{EventBus, ServerEvent},
|
2020-10-12 08:18:28 +00:00
|
|
|
msg::{DisconnectReason, Notification, PlayerListUpdate, ServerGeneral},
|
2020-01-29 16:56:28 +00:00
|
|
|
npc::{self, get_npc_name},
|
2019-07-03 19:56:54 +00:00
|
|
|
state::TimeOfDay,
|
2019-12-23 06:02:00 +00:00
|
|
|
sync::{Uid, WorldSyncExt},
|
2020-09-21 15:39:20 +00:00
|
|
|
terrain::{Block, BlockKind, SpriteKind, TerrainChunkSize},
|
2020-03-28 01:31:22 +00:00
|
|
|
util::Dir,
|
2020-09-26 13:55:01 +00:00
|
|
|
vol::RectVolSize,
|
2020-11-05 01:21:42 +00:00
|
|
|
Damage, DamageSource, Explosion, LoadoutBuilder, RadiusEffect,
|
2019-06-01 19:49:34 +00:00
|
|
|
};
|
2019-07-21 18:22:13 +00:00
|
|
|
use rand::Rng;
|
2019-11-30 06:41:20 +00:00
|
|
|
use specs::{Builder, Entity as EcsEntity, Join, WorldExt};
|
2020-06-27 23:37:14 +00:00
|
|
|
use std::convert::TryFrom;
|
2019-04-16 15:38:01 +00:00
|
|
|
use vek::*;
|
2019-10-16 11:39:41 +00:00
|
|
|
use world::util::Sampler;
|
2019-04-16 15:38:01 +00:00
|
|
|
|
2020-11-02 18:30:56 +00:00
|
|
|
use crate::{client::Client, login_provider::LoginProvider};
|
2019-07-29 13:42:26 +00:00
|
|
|
use scan_fmt::{scan_fmt, scan_fmt_some};
|
2020-06-21 14:26:06 +00:00
|
|
|
use tracing::error;
|
2019-07-26 14:38:31 +00:00
|
|
|
|
2020-05-05 22:33:16 +00:00
|
|
|
pub trait ChatCommandExt {
|
|
|
|
fn execute(&self, server: &mut Server, entity: EcsEntity, args: String);
|
2019-04-16 15:38:01 +00:00
|
|
|
}
|
2020-05-05 22:33:16 +00:00
|
|
|
impl ChatCommandExt for ChatCommand {
|
2020-06-10 19:47:36 +00:00
|
|
|
#[allow(clippy::needless_return)] // TODO: Pending review in #587
|
2020-05-05 22:33:16 +00:00
|
|
|
fn execute(&self, server: &mut Server, entity: EcsEntity, args: String) {
|
2020-06-12 17:44:29 +00:00
|
|
|
if self.needs_admin() && !server.entity_is_admin(entity) {
|
2020-05-05 22:33:16 +00:00
|
|
|
server.notify_client(
|
|
|
|
entity,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg(format!(
|
2020-05-05 22:33:16 +00:00
|
|
|
"You don't have permission to use '/{}'.",
|
|
|
|
self.keyword()
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
return;
|
2019-08-15 14:33:00 +00:00
|
|
|
} else {
|
2020-05-05 22:33:16 +00:00
|
|
|
get_handler(self)(server, entity, entity, args, &self);
|
2019-08-15 14:33:00 +00:00
|
|
|
}
|
2019-04-16 15:38:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-11 22:02:21 +00:00
|
|
|
/// Handler function called when the command is executed.
|
|
|
|
/// # Arguments
|
|
|
|
/// * `&mut Server` - the `Server` instance executing the command.
|
|
|
|
/// * `EcsEntity` - an `Entity` corresponding to the player that invoked the
|
|
|
|
/// command.
|
|
|
|
/// * `EcsEntity` - an `Entity` for the player on whom the command is invoked.
|
|
|
|
/// This differs from the previous argument when using /sudo
|
|
|
|
/// * `String` - a `String` containing the part of the command after the
|
|
|
|
/// keyword.
|
|
|
|
/// * `&ChatCommand` - the command to execute with the above arguments.
|
|
|
|
/// Handler functions must parse arguments from the the given `String`
|
|
|
|
/// (`scan_fmt!` is included for this purpose).
|
2020-05-05 22:33:16 +00:00
|
|
|
type CommandHandler = fn(&mut Server, EcsEntity, EcsEntity, String, &ChatCommand);
|
|
|
|
fn get_handler(cmd: &ChatCommand) -> CommandHandler {
|
|
|
|
match cmd {
|
|
|
|
ChatCommand::Adminify => handle_adminify,
|
|
|
|
ChatCommand::Alias => handle_alias,
|
2020-07-16 00:48:37 +00:00
|
|
|
ChatCommand::Ban => handle_ban,
|
2020-05-05 22:33:16 +00:00
|
|
|
ChatCommand::Build => handle_build,
|
2020-07-31 09:34:26 +00:00
|
|
|
ChatCommand::Campfire => handle_spawn_campfire,
|
2020-05-05 22:33:16 +00:00
|
|
|
ChatCommand::Debug => handle_debug,
|
|
|
|
ChatCommand::DebugColumn => handle_debug_column,
|
2020-07-02 21:53:01 +00:00
|
|
|
ChatCommand::Dummy => handle_spawn_training_dummy,
|
2020-05-05 22:33:16 +00:00
|
|
|
ChatCommand::Explosion => handle_explosion,
|
2020-06-01 04:33:39 +00:00
|
|
|
ChatCommand::Faction => handle_faction,
|
2020-05-05 22:33:16 +00:00
|
|
|
ChatCommand::GiveExp => handle_give_exp,
|
|
|
|
ChatCommand::GiveItem => handle_give_item,
|
|
|
|
ChatCommand::Goto => handle_goto,
|
2020-06-01 04:33:39 +00:00
|
|
|
ChatCommand::Group => handle_group,
|
2020-05-05 22:33:16 +00:00
|
|
|
ChatCommand::Health => handle_health,
|
|
|
|
ChatCommand::Help => handle_help,
|
2020-11-03 23:53:46 +00:00
|
|
|
ChatCommand::Home => handle_home,
|
2020-06-04 09:40:05 +00:00
|
|
|
ChatCommand::JoinFaction => handle_join_faction,
|
2020-05-05 22:33:16 +00:00
|
|
|
ChatCommand::Jump => handle_jump,
|
2020-07-16 00:48:37 +00:00
|
|
|
ChatCommand::Kick => handle_kick,
|
2020-05-05 22:33:16 +00:00
|
|
|
ChatCommand::Kill => handle_kill,
|
|
|
|
ChatCommand::KillNpcs => handle_kill_npcs,
|
|
|
|
ChatCommand::Lantern => handle_lantern,
|
|
|
|
ChatCommand::Light => handle_light,
|
2020-06-27 18:39:16 +00:00
|
|
|
ChatCommand::MakeBlock => handle_make_block,
|
2020-09-21 15:39:20 +00:00
|
|
|
ChatCommand::MakeSprite => handle_make_sprite,
|
2020-06-25 12:07:01 +00:00
|
|
|
ChatCommand::Motd => handle_motd,
|
2020-05-05 22:33:16 +00:00
|
|
|
ChatCommand::Object => handle_object,
|
|
|
|
ChatCommand::Players => handle_players,
|
2020-06-01 04:33:39 +00:00
|
|
|
ChatCommand::Region => handle_region,
|
2020-05-05 22:33:16 +00:00
|
|
|
ChatCommand::RemoveLights => handle_remove_lights,
|
2020-06-01 04:33:39 +00:00
|
|
|
ChatCommand::Say => handle_say,
|
2020-05-05 22:33:16 +00:00
|
|
|
ChatCommand::SetLevel => handle_set_level,
|
2020-06-25 13:56:21 +00:00
|
|
|
ChatCommand::SetMotd => handle_set_motd,
|
2020-05-05 22:33:16 +00:00
|
|
|
ChatCommand::Spawn => handle_spawn,
|
|
|
|
ChatCommand::Sudo => handle_sudo,
|
|
|
|
ChatCommand::Tell => handle_tell,
|
|
|
|
ChatCommand::Time => handle_time,
|
|
|
|
ChatCommand::Tp => handle_tp,
|
2020-07-16 00:48:37 +00:00
|
|
|
ChatCommand::Unban => handle_unban,
|
2020-05-05 22:33:16 +00:00
|
|
|
ChatCommand::Version => handle_version,
|
|
|
|
ChatCommand::Waypoint => handle_waypoint,
|
2020-06-30 12:21:36 +00:00
|
|
|
ChatCommand::Whitelist => handle_whitelist,
|
2020-06-01 04:33:39 +00:00
|
|
|
ChatCommand::World => handle_world,
|
2020-05-05 22:33:16 +00:00
|
|
|
}
|
2019-04-16 15:38:01 +00:00
|
|
|
}
|
2020-05-09 02:42:51 +00:00
|
|
|
|
2020-06-23 06:52:04 +00:00
|
|
|
#[allow(clippy::useless_conversion)] // TODO: Pending review in #587
|
2020-05-05 22:33:16 +00:00
|
|
|
fn handle_give_item(
|
2020-04-24 02:36:19 +00:00
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
target: EcsEntity,
|
|
|
|
args: String,
|
2020-05-07 18:39:48 +00:00
|
|
|
action: &ChatCommand,
|
2020-04-24 02:36:19 +00:00
|
|
|
) {
|
2020-05-10 01:17:03 +00:00
|
|
|
if let (Some(item_name), give_amount_opt) =
|
|
|
|
scan_fmt_some!(&args, &action.arg_fmt(), String, u32)
|
|
|
|
{
|
2020-05-07 18:39:48 +00:00
|
|
|
let give_amount = give_amount_opt.unwrap_or(1);
|
2020-11-21 04:08:11 +00:00
|
|
|
if let Ok(item) = Item::new_from_asset(&item_name.replace('/', ".").replace("\\", ".")) {
|
2020-05-07 18:39:48 +00:00
|
|
|
let mut item: Item = item;
|
|
|
|
if let Ok(()) = item.set_amount(give_amount.min(2000)) {
|
|
|
|
server
|
|
|
|
.state
|
|
|
|
.ecs()
|
|
|
|
.write_storage::<comp::Inventory>()
|
|
|
|
.get_mut(target)
|
|
|
|
.map(|inv| {
|
|
|
|
if inv.push(item).is_some() {
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg(format!(
|
2020-05-07 18:39:48 +00:00
|
|
|
"Player inventory full. Gave 0 of {} items.",
|
|
|
|
give_amount
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// This item can't stack. Give each item in a loop.
|
|
|
|
server
|
|
|
|
.state
|
|
|
|
.ecs()
|
|
|
|
.write_storage::<comp::Inventory>()
|
|
|
|
.get_mut(target)
|
|
|
|
.map(|inv| {
|
|
|
|
for i in 0..give_amount {
|
2020-09-17 23:02:14 +00:00
|
|
|
if inv.push(item.duplicate()).is_some() {
|
2020-05-07 18:39:48 +00:00
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg(format!(
|
2020-05-07 18:39:48 +00:00
|
|
|
"Player inventory full. Gave {} of {} items.",
|
|
|
|
i, give_amount
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
let _ = server
|
|
|
|
.state
|
|
|
|
.ecs()
|
|
|
|
.write_storage::<comp::InventoryUpdate>()
|
|
|
|
.insert(
|
|
|
|
target,
|
|
|
|
comp::InventoryUpdate::new(comp::InventoryUpdateEvent::Given),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg(format!("Invalid item: {}", item_name)),
|
2020-03-04 10:09:48 +00:00
|
|
|
);
|
2020-05-07 18:39:48 +00:00
|
|
|
}
|
2019-10-24 21:05:10 +00:00
|
|
|
} else {
|
2020-06-12 17:44:29 +00:00
|
|
|
server.notify_client(
|
|
|
|
client,
|
|
|
|
ChatType::CommandError.server_msg(action.help_string()),
|
|
|
|
);
|
2019-10-24 21:05:10 +00:00
|
|
|
}
|
|
|
|
}
|
2019-10-31 04:48:57 +00:00
|
|
|
|
2020-06-27 18:39:16 +00:00
|
|
|
fn handle_make_block(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
target: EcsEntity,
|
|
|
|
args: String,
|
|
|
|
action: &ChatCommand,
|
|
|
|
) {
|
|
|
|
if let Some(block_name) = scan_fmt_some!(&args, &action.arg_fmt(), String) {
|
|
|
|
if let Ok(bk) = BlockKind::try_from(block_name.as_str()) {
|
2020-08-23 20:29:40 +00:00
|
|
|
match server.state.read_component_copied::<comp::Pos>(target) {
|
2020-06-27 18:39:16 +00:00
|
|
|
Some(pos) => server.state.set_block(
|
|
|
|
pos.0.map(|e| e.floor() as i32),
|
|
|
|
Block::new(bk, Rgb::broadcast(255)),
|
|
|
|
),
|
|
|
|
None => server.notify_client(
|
|
|
|
client,
|
|
|
|
ChatType::CommandError.server_msg(String::from("You have no position.")),
|
|
|
|
),
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
|
|
|
ChatType::CommandError.server_msg(format!("Invalid block kind: {}", block_name)),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-08-12 17:29:51 +00:00
|
|
|
ChatType::CommandError.server_msg(action.help_string()),
|
2020-06-27 18:39:16 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-21 15:39:20 +00:00
|
|
|
fn handle_make_sprite(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
target: EcsEntity,
|
|
|
|
args: String,
|
|
|
|
action: &ChatCommand,
|
|
|
|
) {
|
|
|
|
if let Some(sprite_name) = scan_fmt_some!(&args, &action.arg_fmt(), String) {
|
|
|
|
if let Ok(sk) = SpriteKind::try_from(sprite_name.as_str()) {
|
|
|
|
match server.state.read_component_copied::<comp::Pos>(target) {
|
|
|
|
Some(pos) => {
|
|
|
|
let pos = pos.0.map(|e| e.floor() as i32);
|
|
|
|
let new_block = server
|
|
|
|
.state
|
|
|
|
.get_block(pos)
|
2020-09-26 13:55:01 +00:00
|
|
|
// TODO: Make more principled.
|
|
|
|
.unwrap_or_else(|| Block::air(SpriteKind::Empty))
|
2020-09-21 15:39:20 +00:00
|
|
|
.with_sprite(sk);
|
|
|
|
server.state.set_block(pos, new_block);
|
|
|
|
},
|
|
|
|
None => server.notify_client(
|
|
|
|
client,
|
|
|
|
ChatType::CommandError.server_msg(String::from("You have no position.")),
|
|
|
|
),
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
|
|
|
ChatType::CommandError.server_msg(format!("Invalid sprite kind: {}", sprite_name)),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
|
|
|
ChatType::CommandError.server_msg(action.help_string()),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-25 12:07:01 +00:00
|
|
|
fn handle_motd(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
_target: EcsEntity,
|
2020-06-25 18:50:04 +00:00
|
|
|
_args: String,
|
|
|
|
_action: &ChatCommand,
|
2020-06-25 13:56:21 +00:00
|
|
|
) {
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-10-06 02:59:47 +00:00
|
|
|
ChatType::CommandError.server_msg((*server.editable_settings().server_description).clone()),
|
2020-06-25 13:56:21 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn handle_set_motd(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
_target: EcsEntity,
|
|
|
|
args: String,
|
|
|
|
action: &ChatCommand,
|
2020-06-25 12:07:01 +00:00
|
|
|
) {
|
2020-10-05 07:41:58 +00:00
|
|
|
let data_dir = server.data_dir();
|
2020-06-25 12:07:01 +00:00
|
|
|
match scan_fmt!(&args, &action.arg_fmt(), String) {
|
|
|
|
Ok(msg) => {
|
|
|
|
server
|
2020-10-06 02:59:47 +00:00
|
|
|
.editable_settings_mut()
|
|
|
|
.server_description
|
2020-10-05 07:41:58 +00:00
|
|
|
.edit(data_dir.as_ref(), |d| **d = msg.clone());
|
2020-06-25 12:07:01 +00:00
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-06-27 23:12:12 +00:00
|
|
|
ChatType::CommandError.server_msg(format!("Server description set to \"{}\"", msg)),
|
2020-06-25 12:07:01 +00:00
|
|
|
);
|
|
|
|
},
|
2020-06-25 13:56:21 +00:00
|
|
|
Err(_) => {
|
2020-10-05 07:41:58 +00:00
|
|
|
server
|
2020-10-06 02:59:47 +00:00
|
|
|
.editable_settings_mut()
|
|
|
|
.server_description
|
2020-10-05 07:41:58 +00:00
|
|
|
.edit(data_dir.as_ref(), |d| d.clear());
|
2020-06-25 13:56:21 +00:00
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-06-27 23:12:12 +00:00
|
|
|
ChatType::CommandError.server_msg("Removed server description".to_string()),
|
2020-06-25 13:56:21 +00:00
|
|
|
);
|
|
|
|
},
|
2020-06-25 12:07:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-24 02:36:19 +00:00
|
|
|
fn handle_jump(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
target: EcsEntity,
|
|
|
|
args: String,
|
|
|
|
action: &ChatCommand,
|
|
|
|
) {
|
2020-05-05 22:33:16 +00:00
|
|
|
if let Ok((x, y, z)) = scan_fmt!(&args, &action.arg_fmt(), f32, f32, f32) {
|
2020-08-23 20:29:40 +00:00
|
|
|
match server.state.read_component_copied::<comp::Pos>(target) {
|
2019-08-15 14:33:00 +00:00
|
|
|
Some(current_pos) => {
|
|
|
|
server
|
|
|
|
.state
|
2020-04-24 02:36:19 +00:00
|
|
|
.write_component(target, comp::Pos(current_pos.0 + Vec3::new(x, y, z)));
|
|
|
|
server.state.write_component(target, comp::ForceUpdate);
|
2020-02-01 20:39:39 +00:00
|
|
|
},
|
2019-10-15 04:06:14 +00:00
|
|
|
None => server.notify_client(
|
2020-04-24 02:36:19 +00:00
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg("You have no position."),
|
2019-08-15 14:33:00 +00:00
|
|
|
),
|
2019-04-16 15:38:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-24 02:36:19 +00:00
|
|
|
fn handle_goto(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
target: EcsEntity,
|
|
|
|
args: String,
|
|
|
|
action: &ChatCommand,
|
|
|
|
) {
|
2020-05-05 22:33:16 +00:00
|
|
|
if let Ok((x, y, z)) = scan_fmt!(&args, &action.arg_fmt(), f32, f32, f32) {
|
2019-08-15 14:33:00 +00:00
|
|
|
if server
|
|
|
|
.state
|
2020-08-23 20:29:40 +00:00
|
|
|
.read_component_copied::<comp::Pos>(target)
|
2019-08-15 14:33:00 +00:00
|
|
|
.is_some()
|
|
|
|
{
|
|
|
|
server
|
2019-07-30 08:10:58 +00:00
|
|
|
.state
|
2020-04-24 02:36:19 +00:00
|
|
|
.write_component(target, comp::Pos(Vec3::new(x, y, z)));
|
|
|
|
server.state.write_component(target, comp::ForceUpdate);
|
2019-07-30 08:10:58 +00:00
|
|
|
} else {
|
2019-10-15 04:06:14 +00:00
|
|
|
server.notify_client(
|
2020-04-24 02:36:19 +00:00
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg("You have no position."),
|
2019-08-15 14:33:00 +00:00
|
|
|
);
|
2019-04-29 20:37:19 +00:00
|
|
|
}
|
2019-08-15 14:33:00 +00:00
|
|
|
} else {
|
2020-06-12 17:44:29 +00:00
|
|
|
server.notify_client(
|
|
|
|
client,
|
|
|
|
ChatType::CommandError.server_msg(action.help_string()),
|
|
|
|
);
|
2019-04-16 15:38:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-03 23:53:46 +00:00
|
|
|
fn handle_home(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
target: EcsEntity,
|
|
|
|
_args: String,
|
|
|
|
_action: &ChatCommand,
|
|
|
|
) {
|
|
|
|
if server
|
|
|
|
.state
|
|
|
|
.read_component_copied::<comp::Pos>(target)
|
|
|
|
.is_some()
|
|
|
|
{
|
|
|
|
let home_pos = server.state.ecs().read_resource::<SpawnPoint>().0;
|
2020-11-15 01:06:27 +00:00
|
|
|
let time = *server.state.ecs().read_resource::<common::state::Time>();
|
|
|
|
|
2020-11-03 23:53:46 +00:00
|
|
|
server.state.write_component(target, comp::Pos(home_pos));
|
2020-11-15 01:06:27 +00:00
|
|
|
server
|
|
|
|
.state
|
2020-11-16 01:40:12 +00:00
|
|
|
.write_component(target, comp::Waypoint::temp_new(home_pos, time));
|
2020-11-03 23:53:46 +00:00
|
|
|
server.state.write_component(target, comp::ForceUpdate);
|
|
|
|
} else {
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
|
|
|
ChatType::CommandError.server_msg("You have no position."),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-24 02:36:19 +00:00
|
|
|
fn handle_kill(
|
|
|
|
server: &mut Server,
|
2020-04-24 16:17:56 +00:00
|
|
|
client: EcsEntity,
|
2020-04-24 02:36:19 +00:00
|
|
|
target: EcsEntity,
|
|
|
|
_args: String,
|
|
|
|
_action: &ChatCommand,
|
|
|
|
) {
|
2020-04-24 16:17:56 +00:00
|
|
|
let reason = if client == target {
|
|
|
|
comp::HealthSource::Suicide
|
2020-06-11 17:06:11 +00:00
|
|
|
} else if let Some(uid) = server.state.read_storage::<Uid>().get(client) {
|
2020-11-05 01:21:42 +00:00
|
|
|
comp::HealthSource::Damage {
|
|
|
|
kind: DamageSource::Other,
|
|
|
|
by: Some(*uid),
|
|
|
|
}
|
2020-04-24 16:17:56 +00:00
|
|
|
} else {
|
2020-06-11 17:06:11 +00:00
|
|
|
comp::HealthSource::Command
|
2020-04-24 16:17:56 +00:00
|
|
|
};
|
2019-05-19 21:54:09 +00:00
|
|
|
server
|
|
|
|
.state
|
2019-05-25 21:13:38 +00:00
|
|
|
.ecs_mut()
|
2020-10-31 22:34:08 +00:00
|
|
|
.write_storage::<comp::Health>()
|
2020-04-24 02:36:19 +00:00
|
|
|
.get_mut(target)
|
2020-10-31 22:34:08 +00:00
|
|
|
.map(|h| h.set_to(0, reason));
|
2019-05-19 21:54:09 +00:00
|
|
|
}
|
|
|
|
|
2020-04-24 02:36:19 +00:00
|
|
|
fn handle_time(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
_target: EcsEntity,
|
|
|
|
args: String,
|
|
|
|
action: &ChatCommand,
|
|
|
|
) {
|
2020-05-05 22:33:16 +00:00
|
|
|
let time = scan_fmt_some!(&args, &action.arg_fmt(), String);
|
2020-06-30 14:56:49 +00:00
|
|
|
let new_time = match time.as_deref() {
|
2020-11-16 22:46:31 +00:00
|
|
|
Some("midnight") => NaiveTime::from_hms(0, 0, 0).num_seconds_from_midnight() as f64,
|
|
|
|
Some("night") => NaiveTime::from_hms(20, 0, 0).num_seconds_from_midnight() as f64,
|
|
|
|
Some("dawn") => NaiveTime::from_hms(5, 0, 0).num_seconds_from_midnight() as f64,
|
|
|
|
Some("morning") => NaiveTime::from_hms(8, 0, 0).num_seconds_from_midnight() as f64,
|
|
|
|
Some("day") => NaiveTime::from_hms(10, 0, 0).num_seconds_from_midnight() as f64,
|
|
|
|
Some("noon") => NaiveTime::from_hms(12, 0, 0).num_seconds_from_midnight() as f64,
|
|
|
|
Some("dusk") => NaiveTime::from_hms(17, 0, 0).num_seconds_from_midnight() as f64,
|
2019-08-15 14:33:00 +00:00
|
|
|
Some(n) => match n.parse() {
|
|
|
|
Ok(n) => n,
|
|
|
|
Err(_) => match NaiveTime::parse_from_str(n, "%H:%M") {
|
2020-11-16 22:46:31 +00:00
|
|
|
Ok(time) => time.num_seconds_from_midnight() as f64,
|
|
|
|
// Accept `u12345`, seconds since midnight day 0`
|
|
|
|
Err(_) => match n
|
|
|
|
.get(1..)
|
|
|
|
.filter(|_| n.chars().next() == Some('u'))
|
|
|
|
.and_then(|n| n.trim_left_matches('u').parse::<u64>().ok())
|
|
|
|
{
|
|
|
|
Some(n) => n as f64,
|
|
|
|
None => {
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
|
|
|
ChatType::CommandError.server_msg(format!("'{}' is not a valid time.", n)),
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
},
|
2020-02-01 20:39:39 +00:00
|
|
|
},
|
2019-07-26 14:38:31 +00:00
|
|
|
},
|
2019-08-15 14:33:00 +00:00
|
|
|
},
|
|
|
|
None => {
|
|
|
|
let time_in_seconds = server.state.ecs_mut().read_resource::<TimeOfDay>().0;
|
|
|
|
|
|
|
|
let current_time = NaiveTime::from_num_seconds_from_midnight_opt(
|
|
|
|
// Wraps around back to 0s if it exceeds 24 hours (24 hours = 86400s)
|
|
|
|
(time_in_seconds as u64 % 86400) as u32,
|
|
|
|
0,
|
|
|
|
);
|
|
|
|
let msg = match current_time {
|
2019-08-18 18:07:21 +00:00
|
|
|
Some(time) => format!("It is {}", time.format("%H:%M").to_string()),
|
2019-08-15 14:33:00 +00:00
|
|
|
None => String::from("Unknown Time"),
|
|
|
|
};
|
2020-06-12 17:44:29 +00:00
|
|
|
server.notify_client(client, ChatType::CommandInfo.server_msg(msg));
|
2019-08-15 14:33:00 +00:00
|
|
|
return;
|
2020-02-01 20:39:39 +00:00
|
|
|
},
|
2019-08-15 14:33:00 +00:00
|
|
|
};
|
|
|
|
|
2020-11-16 22:46:31 +00:00
|
|
|
server.state.ecs_mut().write_resource::<TimeOfDay>().0 = new_time;
|
2019-08-15 14:33:00 +00:00
|
|
|
|
2020-11-16 22:46:31 +00:00
|
|
|
if let Some(new_time) = NaiveTime::from_num_seconds_from_midnight_opt(((new_time as u64) % 86400) as u32, 0) {
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
|
|
|
ChatType::CommandInfo.server_msg(format!(
|
|
|
|
"Time changed to: {}",
|
|
|
|
new_time
|
|
|
|
.format("%H:%M")
|
|
|
|
.to_string(),
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
}
|
2019-06-21 08:42:16 +00:00
|
|
|
}
|
|
|
|
|
2020-04-24 02:36:19 +00:00
|
|
|
fn handle_health(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
target: EcsEntity,
|
|
|
|
args: String,
|
|
|
|
action: &ChatCommand,
|
|
|
|
) {
|
2020-05-05 22:33:16 +00:00
|
|
|
if let Ok(hp) = scan_fmt!(&args, &action.arg_fmt(), u32) {
|
2020-10-31 22:34:08 +00:00
|
|
|
if let Some(health) = server
|
2019-08-15 14:33:00 +00:00
|
|
|
.state
|
2019-10-15 04:06:14 +00:00
|
|
|
.ecs()
|
2020-10-31 22:34:08 +00:00
|
|
|
.write_storage::<comp::Health>()
|
2020-04-24 02:36:19 +00:00
|
|
|
.get_mut(target)
|
2019-08-15 14:33:00 +00:00
|
|
|
{
|
2020-10-31 22:34:08 +00:00
|
|
|
health.set_to(hp * 10, comp::HealthSource::Command);
|
2019-07-30 08:10:58 +00:00
|
|
|
} else {
|
2019-10-15 04:06:14 +00:00
|
|
|
server.notify_client(
|
2020-04-24 02:36:19 +00:00
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg("You have no health."),
|
2019-07-30 08:10:58 +00:00
|
|
|
);
|
|
|
|
}
|
2019-08-15 14:33:00 +00:00
|
|
|
} else {
|
2019-10-15 04:06:14 +00:00
|
|
|
server.notify_client(
|
2020-04-24 02:36:19 +00:00
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg("You must specify health amount!"),
|
2019-08-15 14:33:00 +00:00
|
|
|
);
|
2019-07-01 20:07:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-24 02:36:19 +00:00
|
|
|
fn handle_alias(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
target: EcsEntity,
|
|
|
|
args: String,
|
|
|
|
action: &ChatCommand,
|
|
|
|
) {
|
2020-06-02 06:11:47 +00:00
|
|
|
if client != target {
|
2020-06-11 05:16:42 +00:00
|
|
|
// Notify target that an admin changed the alias due to /sudo
|
2020-06-02 06:11:47 +00:00
|
|
|
server.notify_client(
|
2020-06-11 05:16:42 +00:00
|
|
|
target,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandInfo.server_msg("An admin changed your alias."),
|
2020-06-02 06:11:47 +00:00
|
|
|
);
|
2020-06-12 07:43:20 +00:00
|
|
|
return;
|
2020-06-02 06:11:47 +00:00
|
|
|
}
|
2020-05-05 22:33:16 +00:00
|
|
|
if let Ok(alias) = scan_fmt!(&args, &action.arg_fmt(), String) {
|
2020-06-02 06:11:47 +00:00
|
|
|
if !comp::Player::alias_is_valid(&alias) {
|
|
|
|
// Prevent silly aliases
|
2020-06-12 17:44:29 +00:00
|
|
|
server.notify_client(client, ChatType::CommandError.server_msg("Invalid alias."));
|
2020-06-02 06:11:47 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-05-23 07:13:51 +00:00
|
|
|
let old_alias_optional = server
|
2019-07-30 08:10:58 +00:00
|
|
|
.state
|
|
|
|
.ecs_mut()
|
|
|
|
.write_storage::<comp::Player>()
|
2020-04-24 02:36:19 +00:00
|
|
|
.get_mut(target)
|
2020-05-23 07:13:51 +00:00
|
|
|
.map(|player| std::mem::replace(&mut player.alias, alias));
|
2019-12-23 06:02:00 +00:00
|
|
|
|
|
|
|
// Update name on client player lists
|
|
|
|
let ecs = server.state.ecs();
|
2020-05-23 07:13:51 +00:00
|
|
|
if let (Some(uid), Some(player), Some(old_alias)) = (
|
2020-04-24 02:36:19 +00:00
|
|
|
ecs.read_storage::<Uid>().get(target),
|
|
|
|
ecs.read_storage::<comp::Player>().get(target),
|
2020-05-23 07:13:51 +00:00
|
|
|
old_alias_optional,
|
2019-12-23 06:02:00 +00:00
|
|
|
) {
|
2020-10-07 10:31:49 +00:00
|
|
|
let msg = ServerGeneral::PlayerListUpdate(PlayerListUpdate::Alias(
|
2020-10-05 10:44:33 +00:00
|
|
|
*uid,
|
|
|
|
player.alias.clone(),
|
|
|
|
));
|
2020-10-30 16:39:53 +00:00
|
|
|
server.state.notify_players(msg);
|
2020-05-30 01:36:52 +00:00
|
|
|
|
|
|
|
// Announce alias change if target has a Body.
|
|
|
|
if ecs.read_storage::<comp::Body>().get(target).is_some() {
|
2020-10-30 16:39:53 +00:00
|
|
|
server.state.notify_players(
|
2020-06-12 07:43:20 +00:00
|
|
|
ChatType::CommandInfo
|
2020-06-12 17:44:29 +00:00
|
|
|
.server_msg(format!("{} is now known as {}.", old_alias, player.alias)),
|
2020-06-12 07:43:20 +00:00
|
|
|
);
|
2020-05-30 01:36:52 +00:00
|
|
|
}
|
2019-12-23 06:02:00 +00:00
|
|
|
}
|
2019-07-30 08:10:58 +00:00
|
|
|
} else {
|
2020-06-12 17:44:29 +00:00
|
|
|
server.notify_client(
|
|
|
|
client,
|
|
|
|
ChatType::CommandError.server_msg(action.help_string()),
|
|
|
|
);
|
2019-04-16 15:38:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-24 02:36:19 +00:00
|
|
|
fn handle_tp(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
target: EcsEntity,
|
|
|
|
args: String,
|
|
|
|
action: &ChatCommand,
|
|
|
|
) {
|
2020-05-10 01:17:03 +00:00
|
|
|
let opt_player = if let Some(alias) = scan_fmt_some!(&args, &action.arg_fmt(), String) {
|
2019-08-15 14:33:00 +00:00
|
|
|
let ecs = server.state.ecs();
|
2020-05-10 01:17:03 +00:00
|
|
|
(&ecs.entities(), &ecs.read_storage::<comp::Player>())
|
2019-08-15 14:33:00 +00:00
|
|
|
.join()
|
|
|
|
.find(|(_, player)| player.alias == alias)
|
2020-05-10 01:17:03 +00:00
|
|
|
.map(|(entity, _)| entity)
|
2020-06-11 17:06:11 +00:00
|
|
|
} else if client != target {
|
|
|
|
Some(client)
|
2020-05-10 01:17:03 +00:00
|
|
|
} else {
|
2020-06-24 05:46:29 +00:00
|
|
|
server.notify_client(
|
|
|
|
client,
|
|
|
|
ChatType::CommandError.server_msg("You must specify a player name"),
|
|
|
|
);
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
|
|
|
ChatType::CommandError.server_msg(action.help_string()),
|
|
|
|
);
|
|
|
|
return;
|
2020-05-10 01:17:03 +00:00
|
|
|
};
|
2020-08-23 20:29:40 +00:00
|
|
|
if let Some(_pos) = server.state.read_component_copied::<comp::Pos>(target) {
|
2020-05-10 01:17:03 +00:00
|
|
|
if let Some(player) = opt_player {
|
2020-08-23 20:29:40 +00:00
|
|
|
if let Some(pos) = server.state.read_component_copied::<comp::Pos>(player) {
|
2020-05-10 01:17:03 +00:00
|
|
|
server.state.write_component(target, pos);
|
|
|
|
server.state.write_component(target, comp::ForceUpdate);
|
|
|
|
} else {
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg("Unable to teleport to player!"),
|
2020-05-10 01:17:03 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg("Player not found!"),
|
|
|
|
);
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
|
|
|
ChatType::CommandError.server_msg(action.help_string()),
|
2020-05-10 01:17:03 +00:00
|
|
|
);
|
2019-04-16 15:38:01 +00:00
|
|
|
}
|
2019-08-15 14:33:00 +00:00
|
|
|
} else {
|
2020-06-12 07:43:20 +00:00
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg("You have no position!"),
|
2020-06-12 07:43:20 +00:00
|
|
|
);
|
2019-04-16 15:38:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-24 02:36:19 +00:00
|
|
|
fn handle_spawn(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
target: EcsEntity,
|
|
|
|
args: String,
|
|
|
|
action: &ChatCommand,
|
|
|
|
) {
|
2020-07-02 21:53:01 +00:00
|
|
|
match scan_fmt_some!(
|
|
|
|
&args,
|
|
|
|
&action.arg_fmt(),
|
|
|
|
String,
|
|
|
|
npc::NpcBody,
|
|
|
|
String,
|
|
|
|
String
|
|
|
|
) {
|
|
|
|
(Some(opt_align), Some(npc::NpcBody(id, mut body)), opt_amount, opt_ai) => {
|
2020-07-07 00:11:37 +00:00
|
|
|
let uid = server
|
|
|
|
.state
|
2020-08-23 20:29:40 +00:00
|
|
|
.read_component_copied(target)
|
2020-07-07 00:11:37 +00:00
|
|
|
.expect("Expected player to have a UID");
|
2020-07-07 00:01:39 +00:00
|
|
|
if let Some(alignment) = parse_alignment(uid, &opt_align) {
|
2019-08-15 14:33:00 +00:00
|
|
|
let amount = opt_amount
|
|
|
|
.and_then(|a| a.parse().ok())
|
|
|
|
.filter(|x| *x > 0)
|
|
|
|
.unwrap_or(1)
|
2020-10-21 10:23:34 +00:00
|
|
|
.min(50);
|
2019-08-15 14:33:00 +00:00
|
|
|
|
2020-07-02 22:13:21 +00:00
|
|
|
let ai = opt_ai.unwrap_or_else(|| "true".to_string());
|
2020-07-02 21:53:01 +00:00
|
|
|
|
2020-08-23 20:29:40 +00:00
|
|
|
match server.state.read_component_copied::<comp::Pos>(target) {
|
2019-08-15 14:33:00 +00:00
|
|
|
Some(pos) => {
|
2020-01-27 15:51:07 +00:00
|
|
|
let agent =
|
|
|
|
if let comp::Alignment::Owned(_) | comp::Alignment::Npc = alignment {
|
|
|
|
comp::Agent::default()
|
|
|
|
} else {
|
|
|
|
comp::Agent::default().with_patrol_origin(pos.0)
|
|
|
|
};
|
2020-01-25 18:49:47 +00:00
|
|
|
|
2019-08-15 14:33:00 +00:00
|
|
|
for _ in 0..amount {
|
|
|
|
let vel = Vec3::new(
|
|
|
|
rand::thread_rng().gen_range(-2.0, 3.0),
|
|
|
|
rand::thread_rng().gen_range(-2.0, 3.0),
|
|
|
|
10.0,
|
2019-07-29 13:42:26 +00:00
|
|
|
);
|
2019-08-15 14:33:00 +00:00
|
|
|
|
2020-01-29 16:56:28 +00:00
|
|
|
let body = body();
|
2020-01-13 22:49:46 +00:00
|
|
|
|
2020-11-12 05:27:16 +00:00
|
|
|
let map = server.state().ability_map();
|
2020-11-20 19:14:46 +00:00
|
|
|
let loadout = LoadoutBuilder::build_loadout(
|
|
|
|
body, alignment, None, false, &map, None,
|
|
|
|
)
|
|
|
|
.build();
|
2020-11-12 05:00:17 +00:00
|
|
|
drop(map);
|
|
|
|
|
2020-07-02 21:53:01 +00:00
|
|
|
let mut entity_base = server
|
2019-10-20 05:19:50 +00:00
|
|
|
.state
|
2020-01-13 22:49:46 +00:00
|
|
|
.create_npc(
|
|
|
|
pos,
|
2020-03-15 14:27:06 +00:00
|
|
|
comp::Stats::new(get_npc_name(id).into(), body),
|
2020-10-31 22:34:08 +00:00
|
|
|
comp::Health::new(body, 1),
|
2020-11-12 05:00:17 +00:00
|
|
|
loadout,
|
2020-01-13 22:49:46 +00:00
|
|
|
body,
|
|
|
|
)
|
2019-08-15 14:33:00 +00:00
|
|
|
.with(comp::Vel(vel))
|
2019-09-09 19:11:40 +00:00
|
|
|
.with(comp::MountState::Unmounted)
|
2020-07-02 21:53:01 +00:00
|
|
|
.with(alignment);
|
|
|
|
|
2020-07-02 22:13:21 +00:00
|
|
|
if ai == "true" {
|
2020-07-02 21:53:01 +00:00
|
|
|
entity_base = entity_base.with(agent.clone());
|
|
|
|
}
|
|
|
|
|
|
|
|
let new_entity = entity_base.build();
|
2019-12-11 05:28:45 +00:00
|
|
|
|
2020-04-26 17:03:19 +00:00
|
|
|
// Add to group system if a pet
|
|
|
|
if matches!(alignment, comp::Alignment::Owned { .. }) {
|
|
|
|
let state = server.state();
|
2020-11-02 18:30:56 +00:00
|
|
|
let clients = state.ecs().read_storage::<Client>();
|
2020-04-26 17:03:19 +00:00
|
|
|
let uids = state.ecs().read_storage::<Uid>();
|
|
|
|
let mut group_manager =
|
|
|
|
state.ecs().write_resource::<comp::group::GroupManager>();
|
|
|
|
group_manager.new_pet(
|
|
|
|
new_entity,
|
|
|
|
target,
|
|
|
|
&mut state.ecs().write_storage(),
|
|
|
|
&state.ecs().entities(),
|
2020-07-19 21:49:18 +00:00
|
|
|
&state.ecs().read_storage(),
|
|
|
|
&uids,
|
2020-04-26 17:03:19 +00:00
|
|
|
&mut |entity, group_change| {
|
2020-11-02 18:30:56 +00:00
|
|
|
clients
|
|
|
|
.get(entity)
|
|
|
|
.and_then(|c| {
|
2020-04-26 17:03:19 +00:00
|
|
|
group_change
|
|
|
|
.try_map(|e| uids.get(e).copied())
|
2020-11-02 18:30:56 +00:00
|
|
|
.map(|g| (g, c))
|
2020-04-26 17:03:19 +00:00
|
|
|
})
|
2020-11-02 18:30:56 +00:00
|
|
|
.map(|(g, c)| {
|
|
|
|
c.send_fallible(ServerGeneral::GroupUpdate(g));
|
2020-10-12 08:18:28 +00:00
|
|
|
});
|
2020-04-26 17:03:19 +00:00
|
|
|
},
|
|
|
|
);
|
|
|
|
} else if let Some(group) = match alignment {
|
|
|
|
comp::Alignment::Wild => None,
|
2020-08-21 20:37:08 +00:00
|
|
|
comp::Alignment::Passive => None,
|
2020-04-26 17:03:19 +00:00
|
|
|
comp::Alignment::Enemy => Some(comp::group::ENEMY),
|
|
|
|
comp::Alignment::Npc | comp::Alignment::Tame => {
|
|
|
|
Some(comp::group::NPC)
|
|
|
|
},
|
|
|
|
comp::Alignment::Owned(_) => unreachable!(),
|
|
|
|
} {
|
|
|
|
let _ =
|
|
|
|
server.state.ecs().write_storage().insert(new_entity, group);
|
|
|
|
}
|
|
|
|
|
2019-12-11 05:28:45 +00:00
|
|
|
if let Some(uid) = server.state.ecs().uid_from_entity(new_entity) {
|
|
|
|
server.notify_client(
|
2020-04-24 02:36:19 +00:00
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandInfo
|
|
|
|
.server_msg(format!("Spawned entity with ID: {}", uid)),
|
2019-12-11 05:28:45 +00:00
|
|
|
);
|
|
|
|
}
|
2019-07-29 13:42:26 +00:00
|
|
|
}
|
2019-10-15 04:06:14 +00:00
|
|
|
server.notify_client(
|
2020-04-24 02:36:19 +00:00
|
|
|
client,
|
2020-06-12 07:43:20 +00:00
|
|
|
ChatType::CommandInfo
|
2020-06-12 17:44:29 +00:00
|
|
|
.server_msg(format!("Spawned {} entities", amount)),
|
2019-08-15 14:33:00 +00:00
|
|
|
);
|
2020-02-01 20:39:39 +00:00
|
|
|
},
|
2019-10-15 04:06:14 +00:00
|
|
|
None => server.notify_client(
|
2020-04-24 02:36:19 +00:00
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg("You have no position!"),
|
2019-08-15 14:33:00 +00:00
|
|
|
),
|
2019-06-15 07:54:47 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-01 20:39:39 +00:00
|
|
|
},
|
2019-08-15 14:33:00 +00:00
|
|
|
_ => {
|
2020-06-12 17:44:29 +00:00
|
|
|
server.notify_client(
|
|
|
|
client,
|
|
|
|
ChatType::CommandError.server_msg(action.help_string()),
|
|
|
|
);
|
2020-02-01 20:39:39 +00:00
|
|
|
},
|
2019-05-11 12:43:19 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-31 03:01:52 +00:00
|
|
|
|
2020-07-02 21:53:01 +00:00
|
|
|
fn handle_spawn_training_dummy(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
target: EcsEntity,
|
|
|
|
_args: String,
|
|
|
|
_action: &ChatCommand,
|
|
|
|
) {
|
2020-08-23 20:29:40 +00:00
|
|
|
match server.state.read_component_copied::<comp::Pos>(target) {
|
2020-07-02 21:53:01 +00:00
|
|
|
Some(pos) => {
|
|
|
|
let vel = Vec3::new(
|
|
|
|
rand::thread_rng().gen_range(-2.0, 3.0),
|
|
|
|
rand::thread_rng().gen_range(-2.0, 3.0),
|
|
|
|
10.0,
|
|
|
|
);
|
|
|
|
|
2020-07-03 17:33:37 +00:00
|
|
|
let body = comp::Body::Object(comp::object::Body::TrainingDummy);
|
2020-07-02 21:53:01 +00:00
|
|
|
|
2020-07-03 16:16:55 +00:00
|
|
|
let mut stats = comp::Stats::new("Training Dummy".to_string(), body);
|
|
|
|
|
|
|
|
// Level 0 will prevent exp gain from kill
|
|
|
|
stats.level.set_level(0);
|
|
|
|
|
2020-10-31 22:34:08 +00:00
|
|
|
let health = comp::Health::new(body, 0);
|
|
|
|
|
2020-07-02 21:53:01 +00:00
|
|
|
server
|
|
|
|
.state
|
2020-10-31 22:34:08 +00:00
|
|
|
.create_npc(pos, stats, health, comp::Loadout::default(), body)
|
2020-07-02 21:53:01 +00:00
|
|
|
.with(comp::Vel(vel))
|
|
|
|
.with(comp::MountState::Unmounted)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-07-02 22:13:21 +00:00
|
|
|
ChatType::CommandInfo.server_msg("Spawned a training dummy"),
|
2020-07-02 21:53:01 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
None => server.notify_client(
|
|
|
|
client,
|
|
|
|
ChatType::CommandError.server_msg("You have no position!"),
|
|
|
|
),
|
2020-07-31 09:34:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn handle_spawn_campfire(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
target: EcsEntity,
|
|
|
|
_args: String,
|
|
|
|
_action: &ChatCommand,
|
|
|
|
) {
|
2020-08-23 20:29:40 +00:00
|
|
|
match server.state.read_component_copied::<comp::Pos>(target) {
|
2020-07-31 09:34:26 +00:00
|
|
|
Some(pos) => {
|
|
|
|
server
|
|
|
|
.state
|
2020-08-04 11:58:08 +00:00
|
|
|
.create_object(pos, comp::object::Body::CampfireLit)
|
|
|
|
.with(LightEmitter {
|
|
|
|
col: Rgb::new(1.0, 0.65, 0.2),
|
|
|
|
strength: 2.0,
|
|
|
|
flicker: 1.0,
|
|
|
|
animated: true,
|
|
|
|
})
|
|
|
|
.with(WaypointArea::default())
|
2020-07-31 09:34:26 +00:00
|
|
|
.build();
|
|
|
|
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
|
|
|
ChatType::CommandInfo.server_msg("Spawned a campfire"),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
None => server.notify_client(
|
|
|
|
client,
|
|
|
|
ChatType::CommandError.server_msg("You have no position!"),
|
|
|
|
),
|
2020-07-02 21:53:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-24 02:36:19 +00:00
|
|
|
fn handle_players(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
_target: EcsEntity,
|
|
|
|
_args: String,
|
|
|
|
_action: &ChatCommand,
|
|
|
|
) {
|
2019-06-11 04:24:35 +00:00
|
|
|
let ecs = server.state.ecs();
|
2019-06-29 22:16:16 +00:00
|
|
|
|
2020-06-01 13:01:10 +00:00
|
|
|
let entity_tuples = (
|
|
|
|
&ecs.entities(),
|
|
|
|
&ecs.read_storage::<comp::Player>(),
|
|
|
|
&ecs.read_storage::<comp::Stats>(),
|
|
|
|
);
|
|
|
|
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandInfo.server_msg(entity_tuples.join().fold(
|
2020-06-01 13:01:10 +00:00
|
|
|
format!("{} online players:", entity_tuples.join().count()),
|
|
|
|
|s, (_, player, stat)| {
|
|
|
|
format!(
|
|
|
|
"{}\n[{}]{} Lvl {}",
|
|
|
|
s,
|
|
|
|
player.alias,
|
|
|
|
stat.name,
|
|
|
|
stat.level.level()
|
|
|
|
)
|
|
|
|
},
|
|
|
|
)),
|
|
|
|
);
|
2019-06-11 04:24:35 +00:00
|
|
|
}
|
|
|
|
|
2020-04-24 02:36:19 +00:00
|
|
|
fn handle_build(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
target: EcsEntity,
|
|
|
|
_args: String,
|
|
|
|
_action: &ChatCommand,
|
|
|
|
) {
|
2019-08-15 14:33:00 +00:00
|
|
|
if server
|
|
|
|
.state
|
|
|
|
.read_storage::<comp::CanBuild>()
|
2020-04-24 02:36:19 +00:00
|
|
|
.get(target)
|
2019-08-15 14:33:00 +00:00
|
|
|
.is_some()
|
|
|
|
{
|
|
|
|
server
|
|
|
|
.state
|
|
|
|
.ecs()
|
|
|
|
.write_storage::<comp::CanBuild>()
|
2020-04-24 02:36:19 +00:00
|
|
|
.remove(target);
|
2019-10-15 04:06:14 +00:00
|
|
|
server.notify_client(
|
2020-04-24 02:36:19 +00:00
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandInfo.server_msg("Toggled off build mode!"),
|
2019-08-14 15:51:59 +00:00
|
|
|
);
|
|
|
|
} else {
|
2019-08-15 14:33:00 +00:00
|
|
|
let _ = server
|
2019-07-03 20:46:43 +00:00
|
|
|
.state
|
2019-08-15 14:33:00 +00:00
|
|
|
.ecs()
|
|
|
|
.write_storage::<comp::CanBuild>()
|
2020-04-24 02:36:19 +00:00
|
|
|
.insert(target, comp::CanBuild);
|
2019-10-15 04:06:14 +00:00
|
|
|
server.notify_client(
|
2020-04-24 02:36:19 +00:00
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandInfo.server_msg("Toggled on build mode!"),
|
2019-08-15 14:33:00 +00:00
|
|
|
);
|
2019-07-02 18:19:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-24 02:36:19 +00:00
|
|
|
fn handle_help(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
_target: EcsEntity,
|
2020-05-05 22:33:16 +00:00
|
|
|
args: String,
|
|
|
|
action: &ChatCommand,
|
2020-04-24 02:36:19 +00:00
|
|
|
) {
|
2020-05-05 22:33:16 +00:00
|
|
|
if let Some(cmd) = scan_fmt_some!(&args, &action.arg_fmt(), ChatCommand) {
|
2020-06-12 17:44:29 +00:00
|
|
|
server.notify_client(client, ChatType::CommandInfo.server_msg(cmd.help_string()));
|
2020-05-05 22:33:16 +00:00
|
|
|
} else {
|
2020-06-05 22:36:31 +00:00
|
|
|
let mut message = String::new();
|
2020-05-05 22:33:16 +00:00
|
|
|
for cmd in CHAT_COMMANDS.iter() {
|
|
|
|
if !cmd.needs_admin() || server.entity_is_admin(client) {
|
2020-06-05 22:36:31 +00:00
|
|
|
message += &cmd.help_string();
|
|
|
|
message += "\n";
|
2020-05-05 22:33:16 +00:00
|
|
|
}
|
2019-10-21 16:36:35 +00:00
|
|
|
}
|
2020-06-05 22:36:31 +00:00
|
|
|
message += "Additionally, you can use the following shortcuts:";
|
|
|
|
for (k, v) in CHAT_SHORTCUTS.iter() {
|
|
|
|
message += &format!(" /{} => /{}", k, v.keyword());
|
|
|
|
}
|
2020-06-12 17:44:29 +00:00
|
|
|
server.notify_client(client, ChatType::CommandInfo.server_msg(message));
|
2019-05-26 03:31:41 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-31 03:01:52 +00:00
|
|
|
|
2020-07-07 00:01:39 +00:00
|
|
|
fn parse_alignment(owner: Uid, alignment: &str) -> Option<comp::Alignment> {
|
2019-06-15 07:54:47 +00:00
|
|
|
match alignment {
|
2020-01-24 21:24:57 +00:00
|
|
|
"wild" => Some(comp::Alignment::Wild),
|
|
|
|
"enemy" => Some(comp::Alignment::Enemy),
|
|
|
|
"npc" => Some(comp::Alignment::Npc),
|
2020-01-27 15:51:07 +00:00
|
|
|
"pet" => Some(comp::Alignment::Owned(owner)),
|
2019-06-15 11:48:14 +00:00
|
|
|
_ => None,
|
2019-05-27 11:18:14 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-31 03:01:52 +00:00
|
|
|
|
2020-05-05 22:33:16 +00:00
|
|
|
fn handle_kill_npcs(
|
2020-04-24 02:36:19 +00:00
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
_target: EcsEntity,
|
|
|
|
_args: String,
|
|
|
|
_action: &ChatCommand,
|
|
|
|
) {
|
2019-08-15 14:33:00 +00:00
|
|
|
let ecs = server.state.ecs();
|
2020-10-31 22:34:08 +00:00
|
|
|
let mut healths = ecs.write_storage::<comp::Health>();
|
2019-08-15 14:33:00 +00:00
|
|
|
let players = ecs.read_storage::<comp::Player>();
|
|
|
|
let mut count = 0;
|
2020-10-31 22:34:08 +00:00
|
|
|
for (health, ()) in (&mut healths, !&players).join() {
|
2019-08-15 14:33:00 +00:00
|
|
|
count += 1;
|
2020-10-31 22:34:08 +00:00
|
|
|
health.set_to(0, comp::HealthSource::Command);
|
2019-07-12 21:16:07 +00:00
|
|
|
}
|
2019-08-15 14:33:00 +00:00
|
|
|
let text = if count > 0 {
|
|
|
|
format!("Destroyed {} NPCs.", count)
|
|
|
|
} else {
|
|
|
|
"No NPCs on server.".to_string()
|
|
|
|
};
|
2020-06-12 17:44:29 +00:00
|
|
|
server.notify_client(client, ChatType::CommandInfo.server_msg(text));
|
2019-07-12 21:16:07 +00:00
|
|
|
}
|
2019-07-17 17:53:10 +00:00
|
|
|
|
2020-06-10 19:47:36 +00:00
|
|
|
#[allow(clippy::float_cmp)] // TODO: Pending review in #587
|
|
|
|
#[allow(clippy::needless_return)] // TODO: Pending review in #587
|
|
|
|
#[allow(clippy::useless_format)] // TODO: Pending review in #587
|
2020-04-24 02:36:19 +00:00
|
|
|
fn handle_object(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
target: EcsEntity,
|
|
|
|
args: String,
|
2020-05-05 22:33:16 +00:00
|
|
|
action: &ChatCommand,
|
2020-04-24 02:36:19 +00:00
|
|
|
) {
|
2020-05-05 22:33:16 +00:00
|
|
|
let obj_type = scan_fmt!(&args, &action.arg_fmt(), String);
|
2019-07-28 09:21:17 +00:00
|
|
|
|
2019-08-15 14:33:00 +00:00
|
|
|
let pos = server
|
|
|
|
.state
|
|
|
|
.ecs()
|
|
|
|
.read_storage::<comp::Pos>()
|
2020-04-24 02:36:19 +00:00
|
|
|
.get(target)
|
2019-08-15 14:33:00 +00:00
|
|
|
.copied();
|
|
|
|
let ori = server
|
|
|
|
.state
|
|
|
|
.ecs()
|
|
|
|
.read_storage::<comp::Ori>()
|
2020-04-24 02:36:19 +00:00
|
|
|
.get(target)
|
2019-08-15 14:33:00 +00:00
|
|
|
.copied();
|
2020-03-10 02:27:32 +00:00
|
|
|
/*let builder = server.state
|
2019-08-15 14:33:00 +00:00
|
|
|
.create_object(pos, ori, obj_type)
|
|
|
|
.with(ori);*/
|
|
|
|
if let (Some(pos), Some(ori)) = (pos, ori) {
|
2019-07-28 12:58:18 +00:00
|
|
|
let obj_str_res = obj_type.as_ref().map(String::as_str);
|
2020-05-09 02:42:51 +00:00
|
|
|
if let Some(obj_type) = comp::object::ALL_OBJECTS
|
|
|
|
.iter()
|
|
|
|
.find(|o| Ok(o.to_string()) == obj_str_res)
|
|
|
|
{
|
|
|
|
server
|
|
|
|
.state
|
|
|
|
.create_object(pos, *obj_type)
|
|
|
|
.with(comp::Ori(
|
|
|
|
// converts player orientation into a 90° rotation for the object by using the
|
|
|
|
// axis with the highest value
|
|
|
|
Dir::from_unnormalized(ori.0.map(|e| {
|
|
|
|
if e.abs() == ori.0.map(|e| e.abs()).reduce_partial_max() {
|
|
|
|
e
|
|
|
|
} else {
|
|
|
|
0.0
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
.unwrap_or_default(),
|
|
|
|
))
|
|
|
|
.build();
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandInfo.server_msg(format!(
|
2020-05-09 02:42:51 +00:00
|
|
|
"Spawned: {}",
|
|
|
|
obj_str_res.unwrap_or("<Unknown object>")
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
} else {
|
2020-06-12 17:44:29 +00:00
|
|
|
return server.notify_client(
|
|
|
|
client,
|
|
|
|
ChatType::CommandError.server_msg("Object not found!"),
|
|
|
|
);
|
2020-05-09 02:42:51 +00:00
|
|
|
}
|
2019-08-15 14:33:00 +00:00
|
|
|
} else {
|
2020-06-12 07:43:20 +00:00
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg("You have no position!"),
|
2020-06-12 07:43:20 +00:00
|
|
|
);
|
2019-07-21 12:42:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-10 19:47:36 +00:00
|
|
|
#[allow(clippy::useless_format)] // TODO: Pending review in #587
|
2020-04-24 02:36:19 +00:00
|
|
|
fn handle_light(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
target: EcsEntity,
|
|
|
|
args: String,
|
|
|
|
action: &ChatCommand,
|
|
|
|
) {
|
2019-08-15 14:33:00 +00:00
|
|
|
let (opt_r, opt_g, opt_b, opt_x, opt_y, opt_z, opt_s) =
|
2020-05-05 22:33:16 +00:00
|
|
|
scan_fmt_some!(&args, &action.arg_fmt(), f32, f32, f32, f32, f32, f32, f32);
|
2019-08-15 14:33:00 +00:00
|
|
|
|
|
|
|
let mut light_emitter = comp::LightEmitter::default();
|
2020-05-04 15:15:31 +00:00
|
|
|
let mut light_offset_opt = None;
|
2019-08-15 14:33:00 +00:00
|
|
|
|
|
|
|
if let (Some(r), Some(g), Some(b)) = (opt_r, opt_g, opt_b) {
|
2020-05-04 09:50:58 +00:00
|
|
|
if r < 0.0 || g < 0.0 || b < 0.0 {
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg("cr, cg and cb values mustn't be negative."),
|
2020-05-04 09:50:58 +00:00
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-15 14:33:00 +00:00
|
|
|
let r = r.max(0.0).min(1.0);
|
|
|
|
let g = g.max(0.0).min(1.0);
|
|
|
|
let b = b.max(0.0).min(1.0);
|
|
|
|
light_emitter.col = Rgb::new(r, g, b)
|
|
|
|
};
|
|
|
|
if let (Some(x), Some(y), Some(z)) = (opt_x, opt_y, opt_z) {
|
2020-05-04 15:15:31 +00:00
|
|
|
light_offset_opt = Some(comp::LightAnimation {
|
|
|
|
offset: Vec3::new(x, y, z),
|
|
|
|
col: light_emitter.col,
|
|
|
|
strength: 0.0,
|
|
|
|
})
|
2019-08-15 14:33:00 +00:00
|
|
|
};
|
|
|
|
if let Some(s) = opt_s {
|
|
|
|
light_emitter.strength = s.max(0.0)
|
|
|
|
};
|
|
|
|
let pos = server
|
|
|
|
.state
|
|
|
|
.ecs()
|
|
|
|
.read_storage::<comp::Pos>()
|
2020-04-24 02:36:19 +00:00
|
|
|
.get(target)
|
2019-08-15 14:33:00 +00:00
|
|
|
.copied();
|
|
|
|
if let Some(pos) = pos {
|
2020-05-04 15:15:31 +00:00
|
|
|
let builder = server
|
2019-07-25 20:51:20 +00:00
|
|
|
.state
|
2019-08-15 14:33:00 +00:00
|
|
|
.ecs_mut()
|
|
|
|
.create_entity_synced()
|
|
|
|
.with(pos)
|
|
|
|
.with(comp::ForceUpdate)
|
2020-05-04 15:15:31 +00:00
|
|
|
.with(light_emitter);
|
|
|
|
if let Some(light_offset) = light_offset_opt {
|
|
|
|
builder.with(light_offset).build();
|
|
|
|
} else {
|
|
|
|
builder.build();
|
|
|
|
}
|
2020-06-12 17:44:29 +00:00
|
|
|
server.notify_client(client, ChatType::CommandInfo.server_msg("Spawned object."));
|
2019-08-15 14:33:00 +00:00
|
|
|
} else {
|
2020-06-12 07:43:20 +00:00
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg("You have no position!"),
|
2020-06-12 07:43:20 +00:00
|
|
|
);
|
2019-07-25 20:51:20 +00:00
|
|
|
}
|
|
|
|
}
|
2019-07-26 14:38:31 +00:00
|
|
|
|
2020-06-23 06:52:04 +00:00
|
|
|
#[allow(clippy::useless_conversion)] // TODO: Pending review in #587
|
2020-04-24 02:36:19 +00:00
|
|
|
fn handle_lantern(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
target: EcsEntity,
|
|
|
|
args: String,
|
|
|
|
action: &ChatCommand,
|
|
|
|
) {
|
2020-05-05 22:33:16 +00:00
|
|
|
if let (Some(s), r, g, b) = scan_fmt_some!(&args, &action.arg_fmt(), f32, f32, f32, f32) {
|
2020-05-04 15:15:31 +00:00
|
|
|
if let Some(light) = server
|
|
|
|
.state
|
|
|
|
.ecs()
|
|
|
|
.write_storage::<comp::LightEmitter>()
|
|
|
|
.get_mut(target)
|
|
|
|
{
|
|
|
|
light.strength = s.max(0.1).min(10.0);
|
|
|
|
if let (Some(r), Some(g), Some(b)) = (r, g, b) {
|
|
|
|
light.col = (
|
|
|
|
r.max(0.0).min(1.0),
|
|
|
|
g.max(0.0).min(1.0),
|
|
|
|
b.max(0.0).min(1.0),
|
|
|
|
)
|
|
|
|
.into();
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandInfo.server_msg("You adjusted flame strength and color."),
|
2020-05-04 15:15:31 +00:00
|
|
|
);
|
|
|
|
} else {
|
2019-10-15 04:06:14 +00:00
|
|
|
server.notify_client(
|
2020-04-24 02:36:19 +00:00
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandInfo.server_msg("You adjusted flame strength."),
|
2019-07-28 11:36:35 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
2019-10-15 04:06:14 +00:00
|
|
|
server.notify_client(
|
2020-04-24 02:36:19 +00:00
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg("Please equip a lantern first"),
|
2019-07-28 11:36:35 +00:00
|
|
|
);
|
|
|
|
}
|
2019-08-12 14:05:58 +00:00
|
|
|
} else {
|
2020-06-12 17:44:29 +00:00
|
|
|
server.notify_client(
|
|
|
|
client,
|
|
|
|
ChatType::CommandError.server_msg(action.help_string()),
|
|
|
|
);
|
2019-08-12 14:05:58 +00:00
|
|
|
}
|
2019-07-25 20:51:20 +00:00
|
|
|
}
|
2019-07-26 14:38:31 +00:00
|
|
|
|
2020-04-24 02:36:19 +00:00
|
|
|
fn handle_explosion(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
target: EcsEntity,
|
|
|
|
args: String,
|
|
|
|
action: &ChatCommand,
|
|
|
|
) {
|
2020-05-05 22:33:16 +00:00
|
|
|
let power = scan_fmt!(&args, &action.arg_fmt(), f32).unwrap_or(8.0);
|
2020-05-04 09:50:58 +00:00
|
|
|
|
|
|
|
if power > 512.0 {
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg("Explosion power mustn't be more than 512."),
|
2020-05-04 09:50:58 +00:00
|
|
|
);
|
|
|
|
return;
|
|
|
|
} else if power <= 0.0 {
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg("Explosion power must be more than 0."),
|
2020-05-04 09:50:58 +00:00
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-22 19:39:50 +00:00
|
|
|
let ecs = server.state.ecs();
|
2019-08-07 17:18:32 +00:00
|
|
|
|
2020-08-23 20:29:40 +00:00
|
|
|
match server.state.read_component_copied::<comp::Pos>(target) {
|
2020-03-22 19:39:50 +00:00
|
|
|
Some(pos) => {
|
|
|
|
ecs.read_resource::<EventBus<ServerEvent>>()
|
|
|
|
.emit_now(ServerEvent::Explosion {
|
|
|
|
pos: pos.0,
|
2020-10-15 00:43:53 +00:00
|
|
|
explosion: Explosion {
|
2020-10-30 20:41:21 +00:00
|
|
|
effects: vec![
|
2020-11-02 00:26:01 +00:00
|
|
|
RadiusEffect::Entity(
|
|
|
|
None,
|
2020-11-05 01:21:42 +00:00
|
|
|
Effect::Damage(Damage {
|
|
|
|
source: DamageSource::Explosion,
|
|
|
|
value: 100.0 * power,
|
2020-11-02 00:26:01 +00:00
|
|
|
}),
|
|
|
|
),
|
2020-10-30 20:41:21 +00:00
|
|
|
RadiusEffect::TerrainDestruction(power),
|
|
|
|
],
|
2020-10-06 02:19:41 +00:00
|
|
|
radius: 3.0 * power,
|
2020-10-08 00:32:30 +00:00
|
|
|
energy_regen: 0,
|
2020-10-06 02:19:41 +00:00
|
|
|
},
|
2020-04-24 02:36:19 +00:00
|
|
|
owner: ecs.read_storage::<Uid>().get(target).copied(),
|
2020-08-11 14:05:34 +00:00
|
|
|
reagent: None,
|
2020-03-22 19:39:50 +00:00
|
|
|
})
|
|
|
|
},
|
2019-10-15 04:06:14 +00:00
|
|
|
None => server.notify_client(
|
2020-04-24 02:36:19 +00:00
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg("You have no position!"),
|
2019-08-07 17:18:32 +00:00
|
|
|
),
|
2019-08-07 17:17:04 +00:00
|
|
|
}
|
2019-09-25 20:22:39 +00:00
|
|
|
}
|
|
|
|
|
2020-04-24 02:36:19 +00:00
|
|
|
fn handle_waypoint(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
target: EcsEntity,
|
|
|
|
_args: String,
|
|
|
|
_action: &ChatCommand,
|
|
|
|
) {
|
2020-08-23 20:29:40 +00:00
|
|
|
match server.state.read_component_copied::<comp::Pos>(target) {
|
2019-09-25 20:22:39 +00:00
|
|
|
Some(pos) => {
|
2020-05-24 04:10:08 +00:00
|
|
|
let time = server.state.ecs().read_resource();
|
2019-09-25 20:22:39 +00:00
|
|
|
let _ = server
|
|
|
|
.state
|
|
|
|
.ecs()
|
|
|
|
.write_storage::<comp::Waypoint>()
|
2020-11-16 01:40:12 +00:00
|
|
|
.insert(target, comp::Waypoint::temp_new(pos.0, *time));
|
2020-06-12 17:44:29 +00:00
|
|
|
server.notify_client(client, ChatType::CommandInfo.server_msg("Waypoint saved!"));
|
2020-10-05 10:44:33 +00:00
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-10-07 10:31:49 +00:00
|
|
|
ServerGeneral::Notification(Notification::WaypointSaved),
|
2020-10-05 10:44:33 +00:00
|
|
|
);
|
2020-02-01 20:39:39 +00:00
|
|
|
},
|
2019-10-15 04:06:14 +00:00
|
|
|
None => server.notify_client(
|
2020-04-24 02:36:19 +00:00
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg("You have no position!"),
|
2019-09-25 20:22:39 +00:00
|
|
|
),
|
|
|
|
}
|
2019-08-07 17:17:04 +00:00
|
|
|
}
|
|
|
|
|
2020-06-23 06:52:04 +00:00
|
|
|
#[allow(clippy::useless_conversion)] // TODO: Pending review in #587
|
2020-04-24 02:36:19 +00:00
|
|
|
fn handle_adminify(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
_target: EcsEntity,
|
|
|
|
args: String,
|
|
|
|
action: &ChatCommand,
|
|
|
|
) {
|
2020-05-05 22:33:16 +00:00
|
|
|
if let Ok(alias) = scan_fmt!(&args, &action.arg_fmt(), String) {
|
2019-08-17 18:16:58 +00:00
|
|
|
let ecs = server.state.ecs();
|
|
|
|
let opt_player = (&ecs.entities(), &ecs.read_storage::<comp::Player>())
|
|
|
|
.join()
|
2020-06-02 06:11:47 +00:00
|
|
|
.find(|(_, player)| alias == player.alias)
|
2019-08-17 18:16:58 +00:00
|
|
|
.map(|(entity, _)| entity);
|
|
|
|
match opt_player {
|
2020-06-02 06:11:47 +00:00
|
|
|
Some(player) => {
|
2020-06-06 07:32:09 +00:00
|
|
|
let is_admin = if server
|
|
|
|
.state
|
2020-08-23 20:29:40 +00:00
|
|
|
.read_component_copied::<comp::Admin>(player)
|
2020-06-06 07:32:09 +00:00
|
|
|
.is_some()
|
|
|
|
{
|
2019-08-17 18:16:58 +00:00
|
|
|
ecs.write_storage::<comp::Admin>().remove(player);
|
2020-06-02 06:11:47 +00:00
|
|
|
false
|
|
|
|
} else {
|
|
|
|
ecs.write_storage().insert(player, comp::Admin).is_ok()
|
|
|
|
};
|
|
|
|
// Update player list so the player shows up as admin in client chat.
|
2020-10-07 10:31:49 +00:00
|
|
|
let msg = ServerGeneral::PlayerListUpdate(PlayerListUpdate::Admin(
|
2020-06-02 06:11:47 +00:00
|
|
|
*ecs.read_storage::<Uid>()
|
|
|
|
.get(player)
|
|
|
|
.expect("Player should have uid"),
|
|
|
|
is_admin,
|
|
|
|
));
|
2020-10-30 16:39:53 +00:00
|
|
|
server.state.notify_players(msg);
|
2019-08-17 18:16:58 +00:00
|
|
|
},
|
|
|
|
None => {
|
2019-10-15 04:06:14 +00:00
|
|
|
server.notify_client(
|
2020-04-24 02:36:19 +00:00
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg(format!("Player '{}' not found!", alias)),
|
2019-08-17 18:16:58 +00:00
|
|
|
);
|
2020-02-01 20:39:39 +00:00
|
|
|
},
|
2019-08-17 18:16:58 +00:00
|
|
|
}
|
|
|
|
} else {
|
2020-06-12 17:44:29 +00:00
|
|
|
server.notify_client(
|
|
|
|
client,
|
|
|
|
ChatType::CommandError.server_msg(action.help_string()),
|
|
|
|
);
|
2019-08-17 18:16:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-23 06:52:04 +00:00
|
|
|
#[allow(clippy::useless_conversion)] // TODO: Pending review in #587
|
2020-06-10 19:47:36 +00:00
|
|
|
#[allow(clippy::useless_format)] // TODO: Pending review in #587
|
2020-04-24 02:36:19 +00:00
|
|
|
fn handle_tell(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
target: EcsEntity,
|
|
|
|
args: String,
|
|
|
|
action: &ChatCommand,
|
|
|
|
) {
|
|
|
|
if client != target {
|
2020-06-01 04:33:39 +00:00
|
|
|
// This happens when [ab]using /sudo
|
2020-04-24 02:36:19 +00:00
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg("It's rude to impersonate people"),
|
2020-04-24 02:36:19 +00:00
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
2020-06-12 07:43:20 +00:00
|
|
|
if let (Some(alias), message_opt) = scan_fmt_some!(&args, &action.arg_fmt(), String, String) {
|
2019-07-30 08:10:58 +00:00
|
|
|
let ecs = server.state.ecs();
|
|
|
|
if let Some(player) = (&ecs.entities(), &ecs.read_storage::<comp::Player>())
|
|
|
|
.join()
|
|
|
|
.find(|(_, player)| player.alias == alias)
|
|
|
|
.map(|(entity, _)| entity)
|
|
|
|
{
|
2020-06-01 04:33:39 +00:00
|
|
|
if player == client {
|
2019-10-15 04:06:14 +00:00
|
|
|
server.notify_client(
|
2020-04-24 02:36:19 +00:00
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg("You can't /tell yourself."),
|
2019-07-30 08:10:58 +00:00
|
|
|
);
|
2020-06-01 04:33:39 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-06-02 02:42:26 +00:00
|
|
|
let client_uid = *ecs
|
|
|
|
.read_storage()
|
2020-06-01 04:33:39 +00:00
|
|
|
.get(client)
|
2020-06-02 02:42:26 +00:00
|
|
|
.expect("Player must have uid");
|
|
|
|
let player_uid = *ecs
|
|
|
|
.read_storage()
|
|
|
|
.get(player)
|
|
|
|
.expect("Player must have uid");
|
|
|
|
let mode = comp::ChatMode::Tell(player_uid);
|
2020-06-04 09:40:05 +00:00
|
|
|
let _ = server
|
|
|
|
.state
|
|
|
|
.ecs()
|
|
|
|
.write_storage()
|
|
|
|
.insert(client, mode.clone());
|
2020-06-12 07:43:20 +00:00
|
|
|
let msg = message_opt.unwrap_or_else(|| format!("{} wants to talk to you.", alias));
|
2020-06-05 01:48:26 +00:00
|
|
|
server.state.send_chat(mode.new_message(client_uid, msg));
|
2019-07-30 08:10:58 +00:00
|
|
|
} else {
|
2019-10-15 04:06:14 +00:00
|
|
|
server.notify_client(
|
2020-04-24 02:36:19 +00:00
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg(format!("Player '{}' not found!", alias)),
|
2019-07-30 08:10:58 +00:00
|
|
|
);
|
2019-07-13 04:25:44 +00:00
|
|
|
}
|
2019-07-30 08:10:58 +00:00
|
|
|
} else {
|
2020-06-12 17:44:29 +00:00
|
|
|
server.notify_client(
|
|
|
|
client,
|
|
|
|
ChatType::CommandError.server_msg(action.help_string()),
|
|
|
|
);
|
2019-07-13 04:25:44 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-26 09:49:14 +00:00
|
|
|
|
2020-06-01 04:33:39 +00:00
|
|
|
fn handle_faction(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
target: EcsEntity,
|
|
|
|
msg: String,
|
|
|
|
_action: &ChatCommand,
|
|
|
|
) {
|
|
|
|
if client != target {
|
|
|
|
// This happens when [ab]using /sudo
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg("It's rude to impersonate people"),
|
2020-06-01 04:33:39 +00:00
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
2020-06-04 09:40:05 +00:00
|
|
|
let ecs = server.state.ecs();
|
|
|
|
if let Some(comp::Faction(faction)) = ecs.read_storage().get(client) {
|
|
|
|
let mode = comp::ChatMode::Faction(faction.to_string());
|
|
|
|
let _ = ecs.write_storage().insert(client, mode.clone());
|
|
|
|
if !msg.is_empty() {
|
|
|
|
if let Some(uid) = ecs.read_storage().get(client) {
|
2020-06-24 06:29:39 +00:00
|
|
|
server.state.send_chat(mode.new_message(*uid, msg));
|
2020-06-04 09:40:05 +00:00
|
|
|
}
|
2020-06-02 02:42:26 +00:00
|
|
|
}
|
2020-06-04 09:40:05 +00:00
|
|
|
} else {
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg("Please join a faction with /join_faction"),
|
2020-06-04 09:40:05 +00:00
|
|
|
);
|
2020-06-01 04:33:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn handle_group(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
target: EcsEntity,
|
|
|
|
msg: String,
|
|
|
|
_action: &ChatCommand,
|
|
|
|
) {
|
|
|
|
if client != target {
|
|
|
|
// This happens when [ab]using /sudo
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg("It's rude to impersonate people"),
|
2020-06-01 04:33:39 +00:00
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
2020-06-04 09:40:05 +00:00
|
|
|
let ecs = server.state.ecs();
|
2020-07-12 20:18:57 +00:00
|
|
|
if let Some(group) = ecs.read_storage::<comp::Group>().get(client) {
|
|
|
|
let mode = comp::ChatMode::Group(*group);
|
2020-06-04 09:40:05 +00:00
|
|
|
let _ = ecs.write_storage().insert(client, mode.clone());
|
|
|
|
if !msg.is_empty() {
|
|
|
|
if let Some(uid) = ecs.read_storage().get(client) {
|
2020-06-24 06:29:39 +00:00
|
|
|
server.state.send_chat(mode.new_message(*uid, msg));
|
2020-06-04 09:40:05 +00:00
|
|
|
}
|
2020-06-02 02:42:26 +00:00
|
|
|
}
|
2020-06-04 09:40:05 +00:00
|
|
|
} else {
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-07-12 20:18:57 +00:00
|
|
|
ChatType::CommandError.server_msg("Please create a group first"),
|
2020-06-04 09:40:05 +00:00
|
|
|
);
|
2020-06-01 04:33:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn handle_region(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
target: EcsEntity,
|
|
|
|
msg: String,
|
|
|
|
_action: &ChatCommand,
|
|
|
|
) {
|
|
|
|
if client != target {
|
|
|
|
// This happens when [ab]using /sudo
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg("It's rude to impersonate people"),
|
2020-06-01 04:33:39 +00:00
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
2020-06-02 02:42:26 +00:00
|
|
|
let mode = comp::ChatMode::Region;
|
2020-06-04 09:40:05 +00:00
|
|
|
let _ = server
|
|
|
|
.state
|
|
|
|
.ecs()
|
|
|
|
.write_storage()
|
|
|
|
.insert(client, mode.clone());
|
2020-06-01 04:33:39 +00:00
|
|
|
if !msg.is_empty() {
|
2020-06-02 02:42:26 +00:00
|
|
|
if let Some(uid) = server.state.ecs().read_storage().get(client) {
|
2020-06-24 06:29:39 +00:00
|
|
|
server.state.send_chat(mode.new_message(*uid, msg));
|
2020-06-02 02:42:26 +00:00
|
|
|
}
|
2020-06-01 04:33:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn handle_say(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
target: EcsEntity,
|
|
|
|
msg: String,
|
|
|
|
_action: &ChatCommand,
|
|
|
|
) {
|
|
|
|
if client != target {
|
|
|
|
// This happens when [ab]using /sudo
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg("It's rude to impersonate people"),
|
2020-06-01 04:33:39 +00:00
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
2020-06-02 02:42:26 +00:00
|
|
|
let mode = comp::ChatMode::Say;
|
2020-06-04 09:40:05 +00:00
|
|
|
let _ = server
|
|
|
|
.state
|
|
|
|
.ecs()
|
|
|
|
.write_storage()
|
|
|
|
.insert(client, mode.clone());
|
2020-06-01 04:33:39 +00:00
|
|
|
if !msg.is_empty() {
|
2020-06-02 02:42:26 +00:00
|
|
|
if let Some(uid) = server.state.ecs().read_storage().get(client) {
|
2020-06-24 06:29:39 +00:00
|
|
|
server.state.send_chat(mode.new_message(*uid, msg));
|
2020-06-02 02:42:26 +00:00
|
|
|
}
|
2020-06-01 04:33:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn handle_world(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
target: EcsEntity,
|
|
|
|
msg: String,
|
|
|
|
_action: &ChatCommand,
|
|
|
|
) {
|
|
|
|
if client != target {
|
|
|
|
// This happens when [ab]using /sudo
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg("It's rude to impersonate people"),
|
2020-06-01 04:33:39 +00:00
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
2020-06-02 02:42:26 +00:00
|
|
|
let mode = comp::ChatMode::World;
|
2020-06-04 09:40:05 +00:00
|
|
|
let _ = server
|
|
|
|
.state
|
|
|
|
.ecs()
|
|
|
|
.write_storage()
|
|
|
|
.insert(client, mode.clone());
|
2020-06-01 04:33:39 +00:00
|
|
|
if !msg.is_empty() {
|
2020-06-02 02:42:26 +00:00
|
|
|
if let Some(uid) = server.state.ecs().read_storage().get(client) {
|
2020-06-24 06:29:39 +00:00
|
|
|
server.state.send_chat(mode.new_message(*uid, msg));
|
2020-06-02 02:42:26 +00:00
|
|
|
}
|
2020-06-01 04:33:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-04 09:40:05 +00:00
|
|
|
fn handle_join_faction(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
target: EcsEntity,
|
|
|
|
args: String,
|
|
|
|
action: &ChatCommand,
|
|
|
|
) {
|
|
|
|
if client != target {
|
|
|
|
// This happens when [ab]using /sudo
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg("It's rude to impersonate people"),
|
2020-06-04 09:40:05 +00:00
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
2020-06-12 07:43:20 +00:00
|
|
|
if let Some(alias) = server
|
|
|
|
.state
|
|
|
|
.ecs()
|
|
|
|
.read_storage::<comp::Player>()
|
|
|
|
.get(target)
|
|
|
|
.map(|player| player.alias.clone())
|
|
|
|
{
|
2020-06-12 22:37:15 +00:00
|
|
|
let faction_leave = if let Ok(faction) = scan_fmt!(&args, &action.arg_fmt(), String) {
|
2020-06-12 07:43:20 +00:00
|
|
|
let mode = comp::ChatMode::Faction(faction.clone());
|
|
|
|
let _ = server.state.ecs().write_storage().insert(client, mode);
|
2020-06-12 22:37:15 +00:00
|
|
|
let faction_leave = server
|
2020-06-12 07:43:20 +00:00
|
|
|
.state
|
|
|
|
.ecs()
|
|
|
|
.write_storage()
|
2020-06-12 22:37:15 +00:00
|
|
|
.insert(client, comp::Faction(faction.clone()))
|
|
|
|
.ok()
|
|
|
|
.flatten()
|
|
|
|
.map(|f| f.0);
|
2020-06-12 17:44:29 +00:00
|
|
|
server.state.send_chat(
|
|
|
|
ChatType::FactionMeta(faction.clone())
|
|
|
|
.chat_msg(format!("[{}] joined faction ({})", alias, faction)),
|
2020-06-04 09:40:05 +00:00
|
|
|
);
|
2020-06-12 22:37:15 +00:00
|
|
|
faction_leave
|
2020-06-12 07:43:20 +00:00
|
|
|
} else {
|
|
|
|
let mode = comp::ChatMode::default();
|
|
|
|
let _ = server.state.ecs().write_storage().insert(client, mode);
|
2020-06-12 22:37:15 +00:00
|
|
|
server
|
|
|
|
.state
|
|
|
|
.ecs()
|
|
|
|
.write_storage()
|
|
|
|
.remove(client)
|
|
|
|
.map(|comp::Faction(f)| f)
|
|
|
|
};
|
|
|
|
if let Some(faction) = faction_leave {
|
|
|
|
server.state.send_chat(
|
|
|
|
ChatType::FactionMeta(faction.clone())
|
|
|
|
.chat_msg(format!("[{}] left faction ({})", alias, faction)),
|
|
|
|
);
|
2020-06-04 09:40:05 +00:00
|
|
|
}
|
2020-06-12 07:43:20 +00:00
|
|
|
} else {
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg("Could not find your player alias"),
|
2020-06-12 07:43:20 +00:00
|
|
|
);
|
2020-06-04 09:40:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-22 03:12:17 +00:00
|
|
|
#[cfg(not(feature = "worldgen"))]
|
|
|
|
fn handle_debug_column(
|
|
|
|
server: &mut Server,
|
2020-04-24 02:36:19 +00:00
|
|
|
client: EcsEntity,
|
|
|
|
target: EcsEntity,
|
2020-01-22 03:12:17 +00:00
|
|
|
_args: String,
|
|
|
|
_action: &ChatCommand,
|
|
|
|
) {
|
|
|
|
server.notify_client(
|
2020-04-24 02:36:19 +00:00
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg("Unsupported without worldgen enabled"),
|
2020-01-22 03:12:17 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "worldgen")]
|
2020-04-24 02:36:19 +00:00
|
|
|
fn handle_debug_column(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
2020-10-14 21:02:58 +00:00
|
|
|
target: EcsEntity,
|
2020-04-24 02:36:19 +00:00
|
|
|
args: String,
|
|
|
|
action: &ChatCommand,
|
|
|
|
) {
|
2019-08-26 09:49:14 +00:00
|
|
|
let sim = server.world.sim();
|
2019-10-16 11:39:41 +00:00
|
|
|
let sampler = server.world.sample_columns();
|
2020-10-14 21:02:58 +00:00
|
|
|
let mut wpos = Vec2::new(0, 0);
|
2020-05-05 22:33:16 +00:00
|
|
|
if let Ok((x, y)) = scan_fmt!(&args, &action.arg_fmt(), i32, i32) {
|
2020-10-14 21:02:58 +00:00
|
|
|
wpos = Vec2::new(x, y);
|
2020-11-21 12:33:52 +00:00
|
|
|
} else {
|
2020-10-14 21:02:58 +00:00
|
|
|
match server.state.read_component_copied::<comp::Pos>(target) {
|
|
|
|
Some(pos) => wpos = pos.0.xy().map(|x| x as i32),
|
|
|
|
None => server.notify_client(
|
|
|
|
client,
|
|
|
|
ChatType::CommandError.server_msg(String::from("You have no position.")),
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let msg_generator = || {
|
|
|
|
let alt = sim.get_interpolated(wpos, |chunk| chunk.alt)?;
|
|
|
|
let basement = sim.get_interpolated(wpos, |chunk| chunk.basement)?;
|
|
|
|
let water_alt = sim.get_interpolated(wpos, |chunk| chunk.water_alt)?;
|
|
|
|
let chaos = sim.get_interpolated(wpos, |chunk| chunk.chaos)?;
|
|
|
|
let temp = sim.get_interpolated(wpos, |chunk| chunk.temp)?;
|
|
|
|
let humidity = sim.get_interpolated(wpos, |chunk| chunk.humidity)?;
|
|
|
|
let rockiness = sim.get_interpolated(wpos, |chunk| chunk.rockiness)?;
|
|
|
|
let tree_density = sim.get_interpolated(wpos, |chunk| chunk.tree_density)?;
|
|
|
|
let spawn_rate = sim.get_interpolated(wpos, |chunk| chunk.spawn_rate)?;
|
|
|
|
let chunk_pos = wpos.map2(TerrainChunkSize::RECT_SIZE, |e, sz: u32| e / sz as i32);
|
|
|
|
let chunk = sim.get(chunk_pos)?;
|
|
|
|
let col = sampler.get((wpos, server.index.as_index_ref()))?;
|
2020-10-24 17:57:46 +00:00
|
|
|
let gradient = sim.get_gradient_approx(chunk_pos)?;
|
2020-10-14 21:02:58 +00:00
|
|
|
let downhill = chunk.downhill;
|
|
|
|
let river = &chunk.river;
|
|
|
|
let flux = chunk.flux;
|
|
|
|
|
|
|
|
Some(format!(
|
|
|
|
r#"wpos: {:?}
|
2019-10-16 11:39:41 +00:00
|
|
|
alt {:?} ({:?})
|
|
|
|
water_alt {:?} ({:?})
|
2019-11-19 18:34:52 +00:00
|
|
|
basement {:?}
|
2019-10-16 11:39:41 +00:00
|
|
|
river {:?}
|
2020-10-24 17:57:46 +00:00
|
|
|
gradient {:?}
|
2019-10-16 11:39:41 +00:00
|
|
|
downhill {:?}
|
2019-08-26 09:49:14 +00:00
|
|
|
chaos {:?}
|
2019-10-16 11:39:41 +00:00
|
|
|
flux {:?}
|
2019-08-26 09:49:14 +00:00
|
|
|
temp {:?}
|
|
|
|
humidity {:?}
|
|
|
|
rockiness {:?}
|
|
|
|
tree_density {:?}
|
|
|
|
spawn_rate {:?} "#,
|
2020-10-14 21:02:58 +00:00
|
|
|
wpos,
|
|
|
|
alt,
|
|
|
|
col.alt,
|
|
|
|
water_alt,
|
|
|
|
col.water_level,
|
|
|
|
basement,
|
|
|
|
river,
|
2020-10-24 17:57:46 +00:00
|
|
|
gradient,
|
2020-10-14 21:02:58 +00:00
|
|
|
downhill,
|
|
|
|
chaos,
|
|
|
|
flux,
|
|
|
|
temp,
|
|
|
|
humidity,
|
|
|
|
rockiness,
|
|
|
|
tree_density,
|
|
|
|
spawn_rate
|
|
|
|
))
|
|
|
|
};
|
|
|
|
if let Some(s) = msg_generator() {
|
|
|
|
server.notify_client(client, ChatType::CommandInfo.server_msg(s));
|
2019-08-26 09:49:14 +00:00
|
|
|
} else {
|
2020-06-12 17:44:29 +00:00
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-10-14 21:02:58 +00:00
|
|
|
ChatType::CommandError.server_msg("Not a pregenerated chunk."),
|
2020-06-12 17:44:29 +00:00
|
|
|
);
|
2019-08-26 09:49:14 +00:00
|
|
|
}
|
|
|
|
}
|
2019-10-04 15:48:14 +00:00
|
|
|
|
2020-02-13 20:32:24 +00:00
|
|
|
fn find_target(
|
|
|
|
ecs: &specs::World,
|
|
|
|
opt_alias: Option<String>,
|
|
|
|
fallback: EcsEntity,
|
2020-10-07 10:31:49 +00:00
|
|
|
) -> Result<EcsEntity, ServerGeneral> {
|
2020-02-13 20:32:24 +00:00
|
|
|
if let Some(alias) = opt_alias {
|
|
|
|
(&ecs.entities(), &ecs.read_storage::<comp::Player>())
|
2019-10-04 15:48:14 +00:00
|
|
|
.join()
|
|
|
|
.find(|(_, player)| player.alias == alias)
|
2020-02-13 20:32:24 +00:00
|
|
|
.map(|(entity, _)| entity)
|
2020-06-30 14:56:49 +00:00
|
|
|
.ok_or_else(|| {
|
|
|
|
ChatType::CommandError.server_msg(format!("Player '{}' not found!", alias))
|
|
|
|
})
|
2020-02-13 20:32:24 +00:00
|
|
|
} else {
|
|
|
|
Ok(fallback)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-05 22:33:16 +00:00
|
|
|
fn handle_give_exp(
|
2020-04-24 02:36:19 +00:00
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
target: EcsEntity,
|
|
|
|
args: String,
|
|
|
|
action: &ChatCommand,
|
|
|
|
) {
|
2020-05-05 22:33:16 +00:00
|
|
|
let (a_exp, a_alias) = scan_fmt_some!(&args, &action.arg_fmt(), i64, String);
|
2020-02-13 20:32:24 +00:00
|
|
|
|
|
|
|
if let Some(exp) = a_exp {
|
|
|
|
let ecs = server.state.ecs_mut();
|
2020-04-24 02:36:19 +00:00
|
|
|
let target = find_target(&ecs, a_alias, target);
|
2019-10-04 15:48:14 +00:00
|
|
|
|
2019-10-15 04:06:14 +00:00
|
|
|
let mut error_msg = None;
|
|
|
|
|
2020-02-13 20:32:24 +00:00
|
|
|
match target {
|
|
|
|
Ok(player) => {
|
2020-02-10 09:38:45 +00:00
|
|
|
if let Some(stats) = ecs.write_storage::<comp::Stats>().get_mut(player) {
|
2019-10-04 15:48:14 +00:00
|
|
|
stats.exp.change_by(exp);
|
|
|
|
} else {
|
2020-06-12 17:44:29 +00:00
|
|
|
error_msg = Some(ChatType::CommandError.server_msg("Player has no stats!"));
|
2019-10-04 15:48:14 +00:00
|
|
|
}
|
2020-02-01 20:39:39 +00:00
|
|
|
},
|
2020-02-13 20:32:24 +00:00
|
|
|
Err(e) => {
|
|
|
|
error_msg = Some(e);
|
2020-02-01 20:39:39 +00:00
|
|
|
},
|
2019-10-04 15:48:14 +00:00
|
|
|
}
|
2019-10-15 04:06:14 +00:00
|
|
|
|
|
|
|
if let Some(msg) = error_msg {
|
2020-04-24 02:36:19 +00:00
|
|
|
server.notify_client(client, msg);
|
2019-10-15 04:06:14 +00:00
|
|
|
}
|
2019-10-04 15:48:14 +00:00
|
|
|
}
|
|
|
|
}
|
2019-10-07 03:19:46 +00:00
|
|
|
|
2020-05-05 22:33:16 +00:00
|
|
|
fn handle_set_level(
|
2020-04-24 02:36:19 +00:00
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
target: EcsEntity,
|
|
|
|
args: String,
|
|
|
|
action: &ChatCommand,
|
|
|
|
) {
|
2020-05-05 22:33:16 +00:00
|
|
|
let (a_lvl, a_alias) = scan_fmt_some!(&args, &action.arg_fmt(), u32, String);
|
2020-02-13 21:15:54 +00:00
|
|
|
|
|
|
|
if let Some(lvl) = a_lvl {
|
2020-06-01 10:06:30 +00:00
|
|
|
let target = find_target(&server.state.ecs(), a_alias, target);
|
2020-02-13 21:15:54 +00:00
|
|
|
|
|
|
|
let mut error_msg = None;
|
|
|
|
|
|
|
|
match target {
|
|
|
|
Ok(player) => {
|
2020-06-02 06:11:47 +00:00
|
|
|
let uid = *server
|
2020-06-01 10:06:30 +00:00
|
|
|
.state
|
|
|
|
.ecs()
|
|
|
|
.read_storage::<Uid>()
|
|
|
|
.get(player)
|
2020-06-02 06:11:47 +00:00
|
|
|
.expect("Failed to get uid for player");
|
2020-10-30 16:39:53 +00:00
|
|
|
server.state.notify_players(ServerGeneral::PlayerListUpdate(
|
|
|
|
PlayerListUpdate::LevelChange(uid, lvl),
|
|
|
|
));
|
2020-06-01 10:06:30 +00:00
|
|
|
|
2020-10-31 22:34:08 +00:00
|
|
|
let body_type: Option<comp::Body>;
|
|
|
|
|
2020-06-01 10:06:30 +00:00
|
|
|
if let Some(stats) = server
|
|
|
|
.state
|
|
|
|
.ecs_mut()
|
|
|
|
.write_storage::<comp::Stats>()
|
|
|
|
.get_mut(player)
|
|
|
|
{
|
2020-02-13 21:15:54 +00:00
|
|
|
stats.level.set_level(lvl);
|
2020-10-31 22:34:08 +00:00
|
|
|
body_type = Some(stats.body_type);
|
2020-02-13 21:15:54 +00:00
|
|
|
} else {
|
2020-06-12 17:44:29 +00:00
|
|
|
error_msg = Some(ChatType::CommandError.server_msg("Player has no stats!"));
|
2020-10-31 22:34:08 +00:00
|
|
|
body_type = None;
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(health) = server
|
|
|
|
.state
|
|
|
|
.ecs_mut()
|
|
|
|
.write_storage::<comp::Health>()
|
|
|
|
.get_mut(player)
|
|
|
|
{
|
|
|
|
health.update_max_hp(body_type, lvl);
|
|
|
|
health.set_to(health.maximum(), comp::HealthSource::LevelUp);
|
2020-02-13 21:15:54 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
Err(e) => {
|
|
|
|
error_msg = Some(e);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(msg) = error_msg {
|
2020-04-24 02:36:19 +00:00
|
|
|
server.notify_client(client, msg);
|
2020-02-13 21:15:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-24 02:36:19 +00:00
|
|
|
fn handle_debug(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
target: EcsEntity,
|
|
|
|
_args: String,
|
|
|
|
_action: &ChatCommand,
|
|
|
|
) {
|
2020-09-17 23:02:14 +00:00
|
|
|
if let Ok(items) = comp::Item::new_from_asset_glob("common.items.debug.*") {
|
2019-10-31 14:26:25 +00:00
|
|
|
server
|
|
|
|
.state()
|
|
|
|
.ecs()
|
|
|
|
.write_storage::<comp::Inventory>()
|
2020-04-24 02:36:19 +00:00
|
|
|
.get_mut(target)
|
2020-09-17 23:02:14 +00:00
|
|
|
.map(|inv| inv.push_all_unique(items.into_iter()));
|
2019-10-31 04:48:57 +00:00
|
|
|
let _ = server
|
|
|
|
.state
|
|
|
|
.ecs()
|
|
|
|
.write_storage::<comp::InventoryUpdate>()
|
2020-03-04 10:09:48 +00:00
|
|
|
.insert(
|
2020-04-24 02:36:19 +00:00
|
|
|
target,
|
2020-03-04 10:09:48 +00:00
|
|
|
comp::InventoryUpdate::new(comp::InventoryUpdateEvent::Debug),
|
|
|
|
);
|
2019-10-31 04:48:57 +00:00
|
|
|
} else {
|
|
|
|
server.notify_client(
|
2020-04-24 02:36:19 +00:00
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg("Debug items not found? Something is very broken."),
|
2019-10-31 04:48:57 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-07 04:38:28 +00:00
|
|
|
fn handle_remove_lights(
|
|
|
|
server: &mut Server,
|
2020-04-24 02:36:19 +00:00
|
|
|
client: EcsEntity,
|
|
|
|
target: EcsEntity,
|
2019-10-07 04:38:28 +00:00
|
|
|
args: String,
|
|
|
|
action: &ChatCommand,
|
|
|
|
) {
|
2020-05-05 22:33:16 +00:00
|
|
|
let opt_radius = scan_fmt_some!(&args, &action.arg_fmt(), f32);
|
2020-08-23 20:29:40 +00:00
|
|
|
let opt_player_pos = server.state.read_component_copied::<comp::Pos>(target);
|
2019-10-07 03:19:46 +00:00
|
|
|
let mut to_delete = vec![];
|
|
|
|
|
|
|
|
match opt_player_pos {
|
|
|
|
Some(player_pos) => {
|
|
|
|
let ecs = server.state.ecs();
|
2020-01-26 12:47:41 +00:00
|
|
|
for (entity, pos, _, _, _) in (
|
2019-10-07 04:03:53 +00:00
|
|
|
&ecs.entities(),
|
|
|
|
&ecs.read_storage::<comp::Pos>(),
|
|
|
|
&ecs.read_storage::<comp::LightEmitter>(),
|
2020-01-26 12:47:41 +00:00
|
|
|
!&ecs.read_storage::<comp::WaypointArea>(),
|
2019-10-07 04:38:28 +00:00
|
|
|
!&ecs.read_storage::<comp::Player>(),
|
|
|
|
)
|
|
|
|
.join()
|
|
|
|
{
|
|
|
|
if opt_radius
|
|
|
|
.map(|r| pos.0.distance(player_pos.0) < r)
|
|
|
|
.unwrap_or(true)
|
|
|
|
{
|
2019-10-07 04:03:53 +00:00
|
|
|
to_delete.push(entity);
|
2019-10-07 03:19:46 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-01 20:39:39 +00:00
|
|
|
},
|
2019-10-15 04:06:14 +00:00
|
|
|
None => server.notify_client(
|
2020-04-24 02:36:19 +00:00
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg("You have no position."),
|
2019-10-07 03:19:46 +00:00
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
let size = to_delete.len();
|
|
|
|
|
2019-10-07 04:49:56 +00:00
|
|
|
for entity in to_delete {
|
2020-06-21 21:47:49 +00:00
|
|
|
if let Err(e) = server.state.delete_entity_recorded(entity) {
|
|
|
|
error!(?e, "Failed to delete light: {:?}", e);
|
2019-11-29 06:04:37 +00:00
|
|
|
}
|
2019-10-07 03:19:46 +00:00
|
|
|
}
|
|
|
|
|
2019-10-15 04:06:14 +00:00
|
|
|
server.notify_client(
|
2020-04-24 02:36:19 +00:00
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg(format!("Removed {} lights!", size)),
|
2019-10-07 03:19:46 +00:00
|
|
|
);
|
|
|
|
}
|
2020-04-24 02:36:19 +00:00
|
|
|
|
|
|
|
fn handle_sudo(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
_target: EcsEntity,
|
|
|
|
args: String,
|
|
|
|
action: &ChatCommand,
|
|
|
|
) {
|
2020-04-25 17:18:29 +00:00
|
|
|
if let (Some(player_alias), Some(cmd), cmd_args) =
|
2020-05-05 22:33:16 +00:00
|
|
|
scan_fmt_some!(&args, &action.arg_fmt(), String, String, String)
|
2020-04-24 02:36:19 +00:00
|
|
|
{
|
2020-06-30 14:56:49 +00:00
|
|
|
let cmd_args = cmd_args.unwrap_or_else(|| String::from(""));
|
2020-06-05 18:12:18 +00:00
|
|
|
if let Ok(action) = cmd.parse() {
|
2020-04-24 02:36:19 +00:00
|
|
|
let ecs = server.state.ecs();
|
2020-04-25 17:18:29 +00:00
|
|
|
let entity_opt = (&ecs.entities(), &ecs.read_storage::<comp::Player>())
|
|
|
|
.join()
|
|
|
|
.find(|(_, player)| player.alias == player_alias)
|
|
|
|
.map(|(entity, _)| entity);
|
2020-04-24 02:36:19 +00:00
|
|
|
if let Some(entity) = entity_opt {
|
2020-06-05 18:12:18 +00:00
|
|
|
get_handler(&action)(server, client, entity, cmd_args, &action);
|
2020-04-24 02:36:19 +00:00
|
|
|
} else {
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg("Could not find that player"),
|
2020-04-24 02:36:19 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandError.server_msg(format!("Unknown command: /{}", cmd)),
|
2020-04-24 02:36:19 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
2020-06-12 17:44:29 +00:00
|
|
|
server.notify_client(
|
|
|
|
client,
|
|
|
|
ChatType::CommandError.server_msg(action.help_string()),
|
|
|
|
);
|
2020-04-24 02:36:19 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-04 15:59:53 +00:00
|
|
|
|
|
|
|
fn handle_version(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
_target: EcsEntity,
|
|
|
|
_args: String,
|
|
|
|
_action: &ChatCommand,
|
|
|
|
) {
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-06-12 17:44:29 +00:00
|
|
|
ChatType::CommandInfo.server_msg(format!(
|
2020-05-04 15:59:53 +00:00
|
|
|
"Server is running {}[{}]",
|
|
|
|
common::util::GIT_HASH.to_string(),
|
|
|
|
common::util::GIT_DATE.to_string(),
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
}
|
2020-06-30 12:21:36 +00:00
|
|
|
|
|
|
|
fn handle_whitelist(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
_target: EcsEntity,
|
|
|
|
args: String,
|
|
|
|
action: &ChatCommand,
|
|
|
|
) {
|
|
|
|
if let Ok((whitelist_action, username)) = scan_fmt!(&args, &action.arg_fmt(), String, String) {
|
2020-10-06 02:59:47 +00:00
|
|
|
let lookup_uuid = || {
|
2020-06-30 12:21:36 +00:00
|
|
|
server
|
2020-10-06 02:59:47 +00:00
|
|
|
.state
|
|
|
|
.ecs()
|
|
|
|
.read_resource::<LoginProvider>()
|
|
|
|
.username_to_uuid(&username)
|
|
|
|
.map_err(|_| {
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
|
|
|
ChatType::CommandError.server_msg(format!(
|
|
|
|
"Unable to determine UUID for username \"{}\"",
|
|
|
|
&username
|
|
|
|
)),
|
|
|
|
)
|
|
|
|
})
|
|
|
|
.ok()
|
|
|
|
};
|
|
|
|
|
|
|
|
if whitelist_action.eq_ignore_ascii_case("add") {
|
|
|
|
if let Some(uuid) = lookup_uuid() {
|
|
|
|
server
|
|
|
|
.editable_settings_mut()
|
|
|
|
.whitelist
|
2020-10-06 03:42:09 +00:00
|
|
|
.edit(server.data_dir().as_ref(), |w| w.insert(uuid));
|
2020-10-06 02:59:47 +00:00
|
|
|
server.notify_client(
|
|
|
|
client,
|
|
|
|
ChatType::CommandInfo
|
|
|
|
.server_msg(format!("\"{}\" added to whitelist", username)),
|
|
|
|
);
|
|
|
|
}
|
2020-06-30 12:21:36 +00:00
|
|
|
} else if whitelist_action.eq_ignore_ascii_case("remove") {
|
2020-10-06 02:59:47 +00:00
|
|
|
if let Some(uuid) = lookup_uuid() {
|
|
|
|
server
|
|
|
|
.editable_settings_mut()
|
|
|
|
.whitelist
|
2020-10-06 03:42:09 +00:00
|
|
|
.edit(server.data_dir().as_ref(), |w| w.remove(&uuid));
|
2020-10-06 02:59:47 +00:00
|
|
|
server.notify_client(
|
|
|
|
client,
|
|
|
|
ChatType::CommandInfo
|
|
|
|
.server_msg(format!("\"{}\" removed from whitelist", username)),
|
|
|
|
);
|
|
|
|
}
|
2020-06-30 12:21:36 +00:00
|
|
|
} else {
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
|
|
|
ChatType::CommandError.server_msg(action.help_string()),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
|
|
|
ChatType::CommandError.server_msg(action.help_string()),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-07-16 00:48:37 +00:00
|
|
|
|
2020-08-09 15:14:44 +00:00
|
|
|
fn kick_player(server: &mut Server, target_player: EcsEntity, reason: &str) {
|
2020-08-11 17:02:21 +00:00
|
|
|
server
|
|
|
|
.state
|
|
|
|
.ecs()
|
|
|
|
.read_resource::<EventBus<ServerEvent>>()
|
|
|
|
.emit_now(ServerEvent::ClientDisconnect(target_player));
|
2020-09-14 06:16:09 +00:00
|
|
|
server.notify_client(
|
|
|
|
target_player,
|
2020-10-07 10:31:49 +00:00
|
|
|
ServerGeneral::Disconnect(DisconnectReason::Kicked(reason.to_string())),
|
2020-09-14 06:16:09 +00:00
|
|
|
);
|
2020-08-09 15:14:44 +00:00
|
|
|
}
|
|
|
|
|
2020-07-16 00:48:37 +00:00
|
|
|
fn handle_kick(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
_target: EcsEntity,
|
|
|
|
args: String,
|
|
|
|
action: &ChatCommand,
|
|
|
|
) {
|
2020-08-09 15:14:44 +00:00
|
|
|
if let (Some(target_alias), reason_opt) =
|
|
|
|
scan_fmt_some!(&args, &action.arg_fmt(), String, String)
|
|
|
|
{
|
|
|
|
let reason = reason_opt.unwrap_or_default();
|
2020-07-16 00:48:37 +00:00
|
|
|
let ecs = server.state.ecs();
|
|
|
|
let target_player_opt = (&ecs.entities(), &ecs.read_storage::<comp::Player>())
|
|
|
|
.join()
|
|
|
|
.find(|(_, player)| player.alias == target_alias)
|
|
|
|
.map(|(entity, _)| entity);
|
|
|
|
|
|
|
|
if let Some(target_player) = target_player_opt {
|
2020-08-09 15:14:44 +00:00
|
|
|
kick_player(server, target_player, &reason);
|
2020-07-16 00:48:37 +00:00
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-08-09 15:14:44 +00:00
|
|
|
ChatType::CommandInfo.server_msg(format!(
|
|
|
|
"Kicked {} from the server with reason: {}",
|
|
|
|
target_alias, reason
|
|
|
|
)),
|
2020-07-16 00:48:37 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-08-09 15:14:44 +00:00
|
|
|
ChatType::CommandError
|
|
|
|
.server_msg(format!("Player with alias {} not found", target_alias)),
|
2020-07-16 00:48:37 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
server.notify_client(
|
2020-08-09 15:14:44 +00:00
|
|
|
client,
|
|
|
|
ChatType::CommandError.server_msg(action.help_string()),
|
2020-07-16 00:48:37 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn handle_ban(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
2020-08-09 15:14:44 +00:00
|
|
|
_target: EcsEntity,
|
2020-07-16 20:56:11 +00:00
|
|
|
args: String,
|
|
|
|
action: &ChatCommand,
|
2020-07-16 00:48:37 +00:00
|
|
|
) {
|
2020-08-09 15:14:44 +00:00
|
|
|
if let (Some(target_alias), reason_opt) =
|
|
|
|
scan_fmt_some!(&args, &action.arg_fmt(), String, String)
|
|
|
|
{
|
|
|
|
let reason = reason_opt.unwrap_or_default();
|
2020-08-11 17:02:21 +00:00
|
|
|
let uuid_result = server
|
|
|
|
.state
|
|
|
|
.ecs()
|
|
|
|
.read_resource::<LoginProvider>()
|
|
|
|
.username_to_uuid(&target_alias);
|
2020-07-16 20:56:11 +00:00
|
|
|
|
2020-08-11 16:44:30 +00:00
|
|
|
if let Ok(uuid) = uuid_result {
|
2020-10-06 02:59:47 +00:00
|
|
|
if server.editable_settings().banlist.contains_key(&uuid) {
|
2020-08-11 16:44:30 +00:00
|
|
|
server.notify_client(
|
|
|
|
client,
|
|
|
|
ChatType::CommandError
|
|
|
|
.server_msg(format!("{} is already on the banlist", target_alias)),
|
|
|
|
)
|
|
|
|
} else {
|
2020-10-06 02:59:47 +00:00
|
|
|
server
|
|
|
|
.editable_settings_mut()
|
|
|
|
.banlist
|
|
|
|
.edit(server.data_dir().as_ref(), |b| {
|
|
|
|
b.insert(uuid, BanRecord {
|
|
|
|
username_when_banned: target_alias.clone(),
|
|
|
|
reason: reason.clone(),
|
|
|
|
});
|
|
|
|
});
|
2020-08-11 16:44:30 +00:00
|
|
|
server.notify_client(
|
|
|
|
client,
|
|
|
|
ChatType::CommandInfo.server_msg(format!(
|
|
|
|
"Added {} to the banlist with reason: {}",
|
|
|
|
target_alias, reason
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
|
|
|
|
// If the player is online kick them
|
|
|
|
let ecs = server.state.ecs();
|
|
|
|
let target_player_opt = (&ecs.entities(), &ecs.read_storage::<comp::Player>())
|
|
|
|
.join()
|
|
|
|
.find(|(_, player)| player.alias == target_alias)
|
|
|
|
.map(|(entity, _)| entity);
|
|
|
|
if let Some(target_player) = target_player_opt {
|
|
|
|
kick_player(server, target_player, &reason);
|
|
|
|
}
|
|
|
|
}
|
2020-07-16 21:34:54 +00:00
|
|
|
} else {
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-08-11 17:02:21 +00:00
|
|
|
ChatType::CommandError.server_msg(format!(
|
|
|
|
"Unable to determine UUID for username \"{}\"",
|
|
|
|
target_alias
|
|
|
|
)),
|
2020-08-11 16:44:30 +00:00
|
|
|
)
|
2020-07-16 21:34:54 +00:00
|
|
|
}
|
2020-07-16 20:56:11 +00:00
|
|
|
} else {
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-08-09 15:14:44 +00:00
|
|
|
ChatType::CommandError.server_msg(action.help_string()),
|
2020-07-16 20:56:11 +00:00
|
|
|
);
|
|
|
|
}
|
2020-07-16 00:48:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn handle_unban(
|
|
|
|
server: &mut Server,
|
|
|
|
client: EcsEntity,
|
|
|
|
_target: EcsEntity,
|
2020-07-16 22:27:04 +00:00
|
|
|
args: String,
|
|
|
|
action: &ChatCommand,
|
2020-07-16 00:48:37 +00:00
|
|
|
) {
|
2020-07-16 22:27:04 +00:00
|
|
|
if let Ok(username) = scan_fmt!(&args, &action.arg_fmt(), String) {
|
2020-08-11 17:02:21 +00:00
|
|
|
let uuid_result = server
|
|
|
|
.state
|
|
|
|
.ecs()
|
|
|
|
.read_resource::<LoginProvider>()
|
|
|
|
.username_to_uuid(&username);
|
2020-08-11 16:44:30 +00:00
|
|
|
|
|
|
|
if let Ok(uuid) = uuid_result {
|
2020-10-06 02:59:47 +00:00
|
|
|
server
|
|
|
|
.editable_settings_mut()
|
|
|
|
.banlist
|
|
|
|
.edit(server.data_dir().as_ref(), |b| {
|
|
|
|
b.remove(&uuid);
|
|
|
|
});
|
2020-08-11 16:44:30 +00:00
|
|
|
server.notify_client(
|
|
|
|
client,
|
|
|
|
ChatType::CommandInfo.server_msg(format!("{} was successfully unbanned", username)),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-08-11 17:02:21 +00:00
|
|
|
ChatType::CommandError.server_msg(format!(
|
|
|
|
"Unable to determine UUID for username \"{}\"",
|
|
|
|
username
|
|
|
|
)),
|
2020-08-11 16:44:30 +00:00
|
|
|
)
|
|
|
|
}
|
2020-07-16 22:27:04 +00:00
|
|
|
} else {
|
|
|
|
server.notify_client(
|
|
|
|
client,
|
2020-08-09 15:14:44 +00:00
|
|
|
ChatType::CommandError.server_msg(action.help_string()),
|
2020-07-16 22:27:04 +00:00
|
|
|
);
|
|
|
|
}
|
2020-07-16 00:48:37 +00:00
|
|
|
}
|