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 0521a36bb5f7bae19dffb3d67279e97bd277f28e (patch)
parent 416c1730613d2a21b1fe3622406a1b3a5b1db7ff
Author: Alex Karle <alex@karle.co>
Date:   Thu,  7 May 2020 00:24:15 -0400

Euchre::Host: Delete finished games on last leave_game

When a Player exits (either via leave_game themselves or by closing a
tab and killing the connection), we check if the Table they were at has
a game that is finished. If they're the last Player at the Table to
leave, AND if the game was over (i.e. no progress), we kill the table.

Diffstat:
Mlib/Euchre/Host.pm | 7+++++++
1 file changed, 7 insertions(+), 0 deletions(-)

diff --git a/lib/Euchre/Host.pm b/lib/Euchre/Host.pm @@ -157,6 +157,13 @@ sub leave_table { if (my $errno = $d->remove_player($p)) { $p->error($errno); } else { + # Success! Was removed properly, delete PINDEX + # Also delete the Dealer itself if that was the last player + # to leave and the game looks finished + if (!$d->is_active && $d->game->phase eq 'end') { + printf "Deleting Table %s that appears to have finished\n", $d->id; + delete $DEALERS{$PINDEX{$p->{id}}}; + } delete $PINDEX{$p->{id}}; } }