From 28f11e74c598b8a0df3c3868d1f6e25f7c31b9c3 Mon Sep 17 00:00:00 2001 From: _ <> Date: Mon, 25 Oct 2021 01:06:09 +0000 Subject: [PATCH] ah, that's good enough. Now to run it un-protected on my server. --- game/src/lib.rs | 7 ++++++- telnet/src/main.rs | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/game/src/lib.rs b/game/src/lib.rs index eacce2b..55ca729 100644 --- a/game/src/lib.rs +++ b/game/src/lib.rs @@ -64,7 +64,7 @@ fn parse_input (s: &str) -> PlayerAction { use PlayerAction::*; use PlayerActionRoomSpecific::*; - let s = s.to_lowercase (); + let s = s.trim ().to_lowercase (); let look = |rest| RoomSpecific (Look (parse_item_name (rest))); let activate = |rest| RoomSpecific (Use (parse_item_name (rest))); @@ -185,6 +185,9 @@ pub enum Response { JokeEnding, FailedDetectionCheck, PlayerVictory, + + // These are hints for spam detection on the Telnet frontend + Nonsense, } #[derive (Clone, Copy)] @@ -254,6 +257,7 @@ impl State { PlayerAction::Nonsense => vec! [ line_response ("I couldn't understand that. Try `help` or `hint`."), line_response ("`hint` may contain spoilers. `help` will not."), + Response::Nonsense, ], PlayerAction::RoomSpecific (x) => self.room_1 (x), } @@ -414,6 +418,7 @@ mod test { ("look table", RoomSpecific (Look (ItemName::Table))), ("look note ", RoomSpecific (Look (ItemName::Note))), ("LOOK TABLE", RoomSpecific (Look (ItemName::Table))), + ("look ", RoomSpecific (LookAround)), ("wait", RoomSpecific (Wait)), ("hint", RoomSpecific (Hint)), ].into_iter () { diff --git a/telnet/src/main.rs b/telnet/src/main.rs index 2b6838d..1ce5978 100644 --- a/telnet/src/main.rs +++ b/telnet/src/main.rs @@ -71,6 +71,10 @@ async fn process_socket (socket: TcpStream, id: &str) { use kajam_10_game::Response; + let mut interval = tokio::time::interval (tokio::time::Duration::from_millis (500)); + interval.set_missed_tick_behavior (tokio::time::MissedTickBehavior::Delay); + interval.tick ().await; + let mut seq = 0; let (mut read, mut write) = socket.into_split (); @@ -91,6 +95,7 @@ async fn process_socket (socket: TcpStream, id: &str) } 'main_loop: loop { + interval.tick ().await; let input = read_input (&mut read, &mut write).await.context ("couldn't get player input")?; tracing::debug! ("Processing input {} from connection {}", seq, id); seq += 1;