From 4e0bdd3f093f345dcdf49e46a2bd7e8bfaf4dfff Mon Sep 17 00:00:00 2001 From: stale Date: Tue, 12 Jul 2022 23:34:58 -0300 Subject: rework old, dumb code --- src/conn.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/conn.rs') diff --git a/src/conn.rs b/src/conn.rs index a0ba899..2b6ee80 100644 --- a/src/conn.rs +++ b/src/conn.rs @@ -77,9 +77,9 @@ pub async fn drive_conn(conn: (Conn, SplitStream), rinfo: (RoomId, Ar }; let mut fields = cmd.split(" "); - let parse_pos = |mut fields: std::str::Split<&str>| -> Option<(usize, usize)> { - let x = fields.next().and_then(|xstr| xstr.parse::().ok()); - let y = fields.next().and_then(|ystr| ystr.parse::().ok()); + let parse_pos = |mut fields: std::str::Split<&str>| -> Option<(u32, u32)> { + let x = fields.next().and_then(|xstr| xstr.parse::().ok()); + let y = fields.next().and_then(|ystr| ystr.parse::().ok()); x.zip(y) }; if let Some(cmd_name) = fields.next() { @@ -100,7 +100,9 @@ pub async fn drive_conn(conn: (Conn, SplitStream), rinfo: (RoomId, Ar "reveal" => { match parse_pos(fields) { Some(pos) => { - if let Err(e) = cmd_tx.send(MetaMove::Move(Move { t: MoveType::Reveal, pos }, conn.addr)) { + if let Err(e) = cmd_tx.send(MetaMove::Move( + Move {t: MoveType::Reveal, pos: pos.try_into().unwrap() }, conn.addr)) + { println!("{room_id} E: couldn't process {me}'s reveal command: {e}"); }; }, @@ -112,7 +114,9 @@ pub async fn drive_conn(conn: (Conn, SplitStream), rinfo: (RoomId, Ar "flag" => { match parse_pos(fields) { Some(pos) => { - if let Err(e) = cmd_tx.send(MetaMove::Move(Move { t: MoveType::ToggleFlag, pos }, conn.addr)) { + if let Err(e) = cmd_tx.send(MetaMove::Move( + Move { t: MoveType::ToggleFlag, pos: pos.try_into().unwrap() }, conn.addr)) + { println!("{room_id} E: couldn't process {me}'s flag command: {e}"); }; }, -- cgit v1.2.3