From 799e20f0535e0126aa06dd9833dc066cd8aa7de3 Mon Sep 17 00:00:00 2001 From: Geoffrey Allott Date: Sun, 21 Mar 2021 16:47:51 +0000 Subject: [PATCH] allow chat messages in whist and holdem --- site/modules/poker.js | 2 ++ site/modules/whist.js | 2 ++ src/game/poker/holdem.rs | 4 ++++ src/game/whist.rs | 4 ++++ 4 files changed, 12 insertions(+) diff --git a/site/modules/poker.js b/site/modules/poker.js index 812d051..fedc9a0 100644 --- a/site/modules/poker.js +++ b/site/modules/poker.js @@ -462,6 +462,8 @@ export class TexasHoldEm { take_action(user_action) { this.chatroom.take_action(user_action); switch (user_action.action.action) { + case "Message": + break; case "Join": this.seats.set(user_action.username, user_action.action.seat); this.stacks.set(user_action.username, user_action.action.chips); diff --git a/site/modules/whist.js b/site/modules/whist.js index 543821c..6a38b99 100644 --- a/site/modules/whist.js +++ b/site/modules/whist.js @@ -301,6 +301,8 @@ export class KnockOutWhist { take_action(user_action) { this.chatroom.take_action(user_action); switch (user_action.action.action) { + case "Message": + break; case "Join": this.seats.set(user_action.username, user_action.action.seat); this.hands.set(user_action.username, []); diff --git a/src/game/poker/holdem.rs b/src/game/poker/holdem.rs index 64ef9ac..ed64bff 100644 --- a/src/game/poker/holdem.rs +++ b/src/game/poker/holdem.rs @@ -269,6 +269,7 @@ impl Game for TexasHoldEm { fn validate_action(&self, UserAction { timestamp, username, action }: UserAction) -> Result { match (self.state, action) { (_, Action::PlayCard { .. }) | (_, Action::ChooseTrumps { .. }) => Err(ActionError::InvalidActionForGameType), + (_, Action::Message {message}) => Ok(ValidatedUserAction(UserAction { timestamp, username, action: Action::Message {message}})), (State::NotStarted, Action::Join { seat, chips }) => { if self.seats.contains_player(username) { Err(ActionError::AlreadyJoined) @@ -315,6 +316,9 @@ impl Game for TexasHoldEm { fn take_action(&mut self, ValidatedUserAction(UserAction { timestamp, username, action }): ValidatedUserAction) -> Result<(), ActionError> { self.actions_len += 1; + if matches!(action, Action::Message {..}) { + return Ok(()); + } self.last_action_time = Some(timestamp); self.rng.advance(); match (self.state, action) { diff --git a/src/game/whist.rs b/src/game/whist.rs index 7773a7c..a817941 100644 --- a/src/game/whist.rs +++ b/src/game/whist.rs @@ -125,6 +125,7 @@ impl Game for KnockOutWhist { (_, Action::AddOn { .. }) | (_, Action::RevealCard { .. }) | (_, Action::Fold) | (_, Action::TimeoutFold) | (_, Action::Bet { .. }) => { Err(ActionError::InvalidActionForGameType) } + (_, Action::Message {message}) => Ok(ValidatedUserAction(UserAction { timestamp, username, action: Action::Message {message}})), (State::NotStarted, Action::Join { seat, .. }) => { if self.seats.contains_player(username) { Err(ActionError::AlreadyJoined) @@ -171,6 +172,9 @@ impl Game for KnockOutWhist { fn take_action(&mut self, ValidatedUserAction(UserAction { username, action, .. }): ValidatedUserAction) -> Result<(), ActionError> { self.actions_len += 1; + if matches!(action, Action::Message {..}) { + return Ok(()); + } self.rng.advance(); match (self.state, action) { (_, Action::AddOn { .. }) | (_, Action::Fold) | (_, Action::TimeoutFold) | (_, Action::Bet { .. }) => Err(ActionError::InvalidActionForGameType), -- 2.34.1