summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/controls.rs2
-rw-r--r--src/gameserver.rs7
2 files changed, 7 insertions, 2 deletions
diff --git a/src/controls.rs b/src/controls.rs
index 101b401..1f96180 100644
--- a/src/controls.rs
+++ b/src/controls.rs
@@ -47,7 +47,7 @@ pub enum Control {
impl Control {
- pub fn from_json(val: Value) -> Option<Control>{
+ pub fn from_json(val: &Value) -> Option<Control>{
if let Value::String(control_type) = &val[0] {
match control_type.as_str() {
"move" => match Direction::from_json(&val[1]) {
diff --git a/src/gameserver.rs b/src/gameserver.rs
index ce4a1e5..c7c5062 100644
--- a/src/gameserver.rs
+++ b/src/gameserver.rs
@@ -134,7 +134,12 @@ impl GameServer {
Message::Input(inp) => {
if let Some(nameref) = self.players.get(&id) {
let name = nameref.clone();
- Some(Action::Input(name, Control::from_json(inp).unwrap()))
+ if let Some(control) = Control::from_json(&inp) {
+ Some(Action::Input(name, control))
+ } else {
+ let _ = self.send_error(id, "invalidaction", &format!("unknown action: {}", inp));
+ None
+ }
} else {
let _ = self.send_error(id, "invalidaction", &format!("Set a name before you send other messages"));
None