euchre-live

Euchre web-app for the socially distant family
git clone git://git.alexkarle.com/euchre-live.git
Log | Files | Refs | README | LICENSE

commit 1b45c2cd0f65d0dd0eeda184b55d7e10b076dfc8 (patch)
parent 1f0af442eceba8f385689fc495a2751f39c0ad85
Author: Alex Karle <alex@karle.co>
Date:   Mon, 30 Mar 2020 00:04:55 -0400

Euchre::Dealer: Prevent players from entering full game

This was always the intent, but a logic bug crept in.

Note to self: send_error doesn't abort the current method!

Diffstat:
Mlib/Euchre/Dealer.pm | 26+++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/lib/Euchre/Dealer.pm b/lib/Euchre/Dealer.pm @@ -129,19 +129,18 @@ sub join_game { } # Handle full game case - my $num_players = scalar grep { defined } @{$GAMES{$id}->{players}}; - if ($num_players >= 4) { + if (num_players($GAMES{$id}) >= 4) { send_error($cid, 'Already 4 players'); + } else { + # Add player to Game and cross-link in %PLAYERS for handle_msg + # All players start as spectators and have to take a seat explicitly + $PLAYERS{$cid}->{name} = $msg->{player_name}; + $PLAYERS{$cid}->{game_id} = $id; + push @{$GAMES{$id}->{spectators}}, $cid; + + # XXX: for fast prototyping we just broadcast gamestate + broadcast_gamestate($GAMES{$id}); } - - # Add player to Game and cross-link in %PLAYERS for handle_msg - # All players start as spectators and have to take a seat explicitly - $PLAYERS{$cid}->{name} = $msg->{player_name}; - $PLAYERS{$cid}->{game_id} = $id; - push @{$GAMES{$id}->{spectators}}, $cid; - - # XXX: for fast prototyping we just broadcast gamestate - broadcast_gamestate($GAMES{$id}); } # seat @@ -184,6 +183,11 @@ sub stand_up { } +sub num_players { + my ($gid) = @_; + return scalar grep { defined } @{$GAMES{$gid}->{players}} +} + # XXX: The most simplest (bulkiest) message we can send is to just # broadcast the gamestate to all clients. This will be our temporary # debugging method / MVP. We can trim down the communication later