allow chat messages in whist and holdem
authorGeoffrey Allott <geoffrey@allott.email>
Sun, 21 Mar 2021 16:47:51 +0000 (16:47 +0000)
committerGeoffrey Allott <geoffrey@allott.email>
Sun, 21 Mar 2021 16:47:51 +0000 (16:47 +0000)
site/modules/poker.js
site/modules/whist.js
src/game/poker/holdem.rs
src/game/whist.rs

index 812d051a995c6bb83c347b7eeb12247ab992533e..fedc9a0d62be2015db31e6cc0fb80398f3730075 100644 (file)
@@ -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);
index 543821ca10230851661243c214fe108d96c59239..6a38b99ea4abdacf5ed44587efd54a789dac7bad 100644 (file)
@@ -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, []);
index 64ef9acd8a9c9dad97fc7fdca2562bb2608f4eb7..ed64bff622986805bdddcde3d475da07bdb93e87 100644 (file)
@@ -269,6 +269,7 @@ impl Game for TexasHoldEm {
     fn validate_action(&self, UserAction { timestamp, username, action }: UserAction) -> Result<ValidatedUserAction, ActionError> {
         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) {
index 7773a7c2fcfba96a7926d96f1b37ede6961ede85..a817941842a0bfff8364abfb93e7c1238c7f1a4c 100644 (file)
@@ -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),