clean up warnings
authorGeoffrey Allott <geoffrey@allott.email>
Tue, 2 Mar 2021 18:18:51 +0000 (18:18 +0000)
committerGeoffrey Allott <geoffrey@allott.email>
Tue, 2 Mar 2021 18:18:51 +0000 (18:18 +0000)
src/api.rs
src/client.rs
src/dealer.rs
src/game/mod.rs
src/game/poker/classify.rs
src/game/poker/holdem.rs
src/main.rs
src/rng.rs
src/server.rs

index b45f21b0f8b23dbaf56a912b819885623128bcd8..36d3ee3cd4cb18d22aaacf5430beaa1ae3be53f0 100644 (file)
@@ -52,11 +52,9 @@ pub enum ServerMessage {
     NewAction { action: UserAction },
     TakeActionSuccess { action: UserAction },
     TakeActionFailure { action: UserAction, reason: String },
-    NewMessage { username: Username, message: String },
     LeaveGameSuccess,
     LeaveGameFailure { reason: String },
     LeaveLobbySuccess,
     LeaveLobbyFailure { reason: String },
-    HandHistory { games: Vec<(GameSummary, Vec<UserAction>)> }, // TODO
     ProtocolError { reason: String },
 }
index 0722c1f218c49330f5be349fe58919d82caba1e3..a32af50dc7dab4b35a622c53369b2f6372a5066d 100644 (file)
@@ -206,13 +206,16 @@ impl ConnectionState {
                 self.client = ClientState::LoggedIn{username, state: LoggedInState::Idle};
                 ServerMessage::LeaveLobbySuccess
             }
-            (&mut ClientState::LoggedIn{username, ..}, ClientMessage::LeaveLobby) => {
+            (&mut ClientState::LoggedIn{..}, ClientMessage::LeaveLobby) => {
                 ServerMessage::LeaveLobbyFailure{reason: "Not in lobby".to_string()}
             }
             (&mut ClientState::LoggedIn{username, state: LoggedInState::InGame{..}}, ClientMessage::LeaveGame) => {
                 self.client = ClientState::LoggedIn{username, state: LoggedInState::Idle};
                 ServerMessage::LeaveGameSuccess
             }
+            (&mut ClientState::LoggedIn{..}, ClientMessage::LeaveGame) => {
+                ServerMessage::LeaveGameFailure{reason: "Not in game".to_string()}
+            }
             (&mut ClientState::LoggedIn{..}, ClientMessage::Logout) => {
                 self.client = ClientState::Connected;
                 ServerMessage::LogoutSuccess
index 3aa9644016b2f9fa812eeeaa8b1260f4a58e1c76..ba661f29338188d5100bcd211589ec822b49bfc9 100644 (file)
@@ -1,12 +1,11 @@
-use std::collections::{HashMap, HashSet};
+use std::collections::HashSet;
 
 use async_std::stream::StreamExt;
 use futures::channel::mpsc::Receiver;
-use rand::prelude::*;
 use redis::{ErrorKind, RedisError, RedisResult};
 
 use crate::client::ClientInterest;
-use crate::game::{Action, Game, ValidatedUserAction};
+use crate::game::{Game, ValidatedUserAction};
 use crate::server::{ActionStatus, ServerState};
 
 pub struct Dealer {
@@ -26,7 +25,7 @@ impl Dealer {
         server.register_interests(interests).await;
         let summary = server.game_summary(id).await?;
         let seed = server.game_seed(id).await?;
-        let mut game = Game::new(summary, seed);
+        let game = Game::new(summary, seed);
         let mut dealer = Dealer{server, dealer: DealerState{game}};
         dealer.retrieve_updates().await?;
         Ok(dealer)
index 2ab9e1c14386cd284ea358c165130c85e3316c91..6c73c3b1c0a12f3e77b76115ea10f95532d08974 100644 (file)
@@ -4,7 +4,7 @@ mod poker;
 mod whist;
 
 use std::collections::HashSet;
-use std::fmt::{Debug, Display, Formatter};
+use std::fmt::Debug;
 
 use crate::rng::Seed;
 use crate::username::Username;
@@ -15,7 +15,7 @@ use self::poker::{TexasHoldEm, TexasHoldEmSettings};
 
 pub use self::action::{Action, ActionError, UserAction, ValidatedUserAction};
 
-pub trait Game : Debug + CloneBox + Send + Sync {
+pub trait Game : Debug + CloneBoxGame + Send + Sync {
     fn id(&self) -> i64;
     fn players(&self) -> HashSet<Username>;
     fn actions_len(&self) -> usize;
@@ -24,11 +24,11 @@ pub trait Game : Debug + CloneBox + Send + Sync {
     fn next_dealer_action(&self) -> Option<ValidatedUserAction>;
 }
 
-trait CloneBox {
+pub trait CloneBoxGame {
     fn clone_box(&self) -> Box<dyn Game>;
 }
 
-impl<T: Clone + Game + 'static> CloneBox for T {
+impl<T: Clone + Game + 'static> CloneBoxGame for T {
     fn clone_box(&self) -> Box<dyn Game> {
         Box::new(self.clone())
     }
index cad9402179a08841d13300bb37a475a088e51edf..99124bc47a211bf9555a4a0796d0ba4c4cc831bd 100644 (file)
@@ -474,6 +474,7 @@ impl Odds {
         self.draws as f64 / (self.player1_wins + self.player2_wins + self.draws) as f64
     }
 
+    #[allow(unused)] // FIXME
     pub fn favourite(&self) -> Player {
         match self.player1_wins.cmp(&self.player2_wins) {
             Ordering::Greater => Player::Player1,
index b2536a64215628d2fec6675f3074b9edda3539de..33a81ea070d816d56e5bed3cfdd01c8bb7743fe9 100644 (file)
@@ -2,10 +2,8 @@ use std::collections::{HashMap, HashSet};
 use std::convert::TryInto;
 
 use itertools::Itertools;
-use rand::seq::IteratorRandom;
-use rand::Rng;
 
-use crate::card::{Card, Suit, FIFTY_TWO_CARD_DECK};
+use crate::card::{Card, FIFTY_TWO_CARD_DECK};
 use crate::seats::Seats;
 use crate::username::Username;
 use crate::util::max::IteratorMaxItems;
@@ -170,9 +168,6 @@ impl Game for TexasHoldEm {
                 Ok(ValidatedUserAction(UserAction{username, action: Action::Leave}))
             }
             (_, _) if !self.seats.contains_player(username) => Err(ActionError::NotAuthorised),
-            (State::NotStarted, Action::Leave) => {
-                Ok(ValidatedUserAction(UserAction{username, action: Action::Leave}))
-            }
             (State::Completed, _) => Err(ActionError::GameHasEnded),
             (_, Action::Leave) => Err(ActionError::GameHasStarted),
             (State::Dealing, _) | (State::DealingFlop, _) | (State::DealingTurn, _) | (State::DealingRiver, _) => {
index 4b3773c1217979375320167b6958d4b2ff8a28d9..1cd378b0536246c710d5fc6543bfebaf4e90b661 100644 (file)
@@ -12,7 +12,7 @@ use signal_hook::consts::signal::*;
 use signal_hook_async_std::Signals;
 use tide::{Body, Request, Error, Response, StatusCode};
 use tide::utils::After;
-use tide_rustls::TlsListener;
+//use tide_rustls::TlsListener;
 use tide_websockets::{Message, WebSocket, WebSocketConnection};
 
 mod api;
index dfe297a2759856d1a6fe78e7891262c4f7efebe0..45f7ecc19e8ee507de11bdfbfe6e894e73e876a4 100644 (file)
@@ -2,7 +2,7 @@ use std::cmp::{Ord, Eq};
 
 use getrandom::getrandom;
 use itertools::Itertools;
-use rand::{SeedableRng, CryptoRng, RngCore, Rng, Error, seq::IteratorRandom};
+use rand::{SeedableRng, CryptoRng, Rng, RngCore, Error, seq::IteratorRandom};
 use rand_chacha::ChaCha20Rng;
 
 #[derive(Copy, Clone, Debug, Serialize, Deserialize)]
@@ -81,8 +81,6 @@ mod tests {
 
     use std::collections::HashSet;
 
-    use rand::Rng;
-
     #[test]
     fn chacha_true_values() {
         let seed_json = r#"{"rng":"ChaCha20","seed":"0000000000000000000000000000000000000000000000000000000000000000"}"#;
index 7ff323485aa5e50d33ec0465bbb5ce029458f53d..12a4b36c74ea50c3b5cb3324b512063d6b99eac3 100644 (file)
@@ -1,13 +1,13 @@
 use std::collections::HashSet;
 use std::convert::TryFrom;
 
-use futures::{channel::mpsc::{Receiver, Sender, channel}, SinkExt, future::try_join_all};
+use futures::{channel::mpsc::{Receiver, Sender, channel}, SinkExt};
 use redis::{AsyncCommands, ErrorKind, FromRedisValue, Msg, RedisError, RedisResult, RedisWrite, Script, ToRedisArgs, Value, aio::MultiplexedConnection};
 use serde::{Serialize, Deserialize};
 
 use crate::auth::Auth;
 use crate::client::ClientInterest;
-use crate::game::{GameList, GameSettings, GameSummary, UserAction, ValidatedUserAction};
+use crate::game::{GameSettings, GameSummary, ValidatedUserAction};
 use crate::rng::Seed;
 use crate::username::Username;
 
@@ -172,7 +172,7 @@ impl ServerState {
         for id in games {
             match self.game_summary(id).await {
                 Ok(summary) => summaries.push(summary),
-                Err(err) => error!("Could not find summary for game {}", id),
+                Err(err) => error!("Could not find summary for game {}: {}", id, err),
             }
         }
         Ok(summaries)