From 0521a36bb5f7bae19dffb3d67279e97bd277f28e Mon Sep 17 00:00:00 2001 From: Alex Karle Date: Thu, 7 May 2020 00:24:15 -0400 Subject: [PATCH] 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. --- lib/Euchre/Host.pm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/Euchre/Host.pm b/lib/Euchre/Host.pm index 42d7843..0ffc0ad 100644 --- 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}}; } } -- libgit2 1.1.1