Prevent text clients from gaining position

This commit is contained in:
Piotr Korgól 2019-06-28 16:22:25 +02:00
parent 947a473435
commit 888faadfab
2 changed files with 39 additions and 23 deletions

View File

@ -15,7 +15,7 @@ fn read_input() -> String {
.read_line(&mut buffer)
.expect("Failed to read input");
buffer
buffer.trim().to_string()
}
fn main() {

View File

@ -128,16 +128,24 @@ fn handle_jump(server: &mut Server, entity: EcsEntity, args: String, action: &Ch
fn handle_goto(server: &mut Server, entity: EcsEntity, args: String, action: &ChatCommand) {
let (opt_x, opt_y, opt_z) = scan_fmt!(&args, action.arg_fmt, f32, f32, f32);
match (opt_x, opt_y, opt_z) {
(Some(x), Some(y), Some(z)) => {
server
.state
.write_component(entity, comp::Pos(Vec3::new(x, y, z)));
server.state.write_component(entity, comp::ForceUpdate);
match server.state.read_component_cloned::<comp::Pos>(entity) {
Some(mut pos) => match (opt_x, opt_y, opt_z) {
(Some(x), Some(y), Some(z)) => {
server
.state
.write_component(entity, comp::Pos(Vec3::new(x, y, z)));
server.state.write_component(entity, comp::ForceUpdate);
}
_ => server
.clients
.notify(entity, ServerMsg::Chat(String::from(action.help_string))),
},
None => {
server.clients.notify(
entity,
ServerMsg::Chat(String::from("You don't have any position!")),
);
}
_ => server
.clients
.notify(entity, ServerMsg::Chat(String::from(action.help_string))),
}
}
@ -203,25 +211,33 @@ fn handle_tp(server: &mut Server, entity: EcsEntity, args: String, action: &Chat
.join()
.find(|(_, player)| player.alias == alias)
.map(|(entity, _)| entity);
match opt_player {
Some(player) => match server.state.read_component_cloned::<comp::Pos>(player) {
Some(pos) => {
server.state.write_component(entity, pos);
server.state.write_component(entity, comp::ForceUpdate);
match server.state.read_component_cloned::<comp::Pos>(entity) {
Some(mut pos) => match opt_player {
Some(player) => match server.state.read_component_cloned::<comp::Pos>(player) {
Some(pos) => {
server.state.write_component(entity, pos);
server.state.write_component(entity, comp::ForceUpdate);
}
None => server.clients.notify(
entity,
ServerMsg::Chat(format!("Unable to teleport to player '{}'!", alias)),
),
},
None => {
server.clients.notify(
entity,
ServerMsg::Chat(format!("Player '{}' not found!", alias)),
);
server
.clients
.notify(entity, ServerMsg::Chat(String::from(action.help_string)));
}
None => server.clients.notify(
entity,
ServerMsg::Chat(format!("Unable to teleport to player '{}'!", alias)),
),
},
None => {
server.clients.notify(
entity,
ServerMsg::Chat(format!("Player '{}' not found!", alias)),
ServerMsg::Chat(format!("You don't have any position!")),
);
server
.clients
.notify(entity, ServerMsg::Chat(String::from(action.help_string)));
}
}
}