commit 416c1730613d2a21b1fe3622406a1b3a5b1db7ff (patch)
parent 5853216c1b9c070a90ec695453707c7c49b093c4
Author: Alex Karle <alex@karle.co>
Date: Thu, 7 May 2020 00:16:05 -0400
Euchre::Host: Call leave_table on join_table
As noted in the comment, we really depend on there being a 0/1-1 between
Table-Player. Not having this could mean strange messages, uncleanable
state (memory leaks), etc.
It's just cleanest to make sure that we leave any existing table on
joining a new one!
Diffstat:
1 file changed, 9 insertions(+), 0 deletions(-)
diff --git a/lib/Euchre/Host.pm b/lib/Euchre/Host.pm
@@ -117,6 +117,15 @@ sub join_table {
require_keys(@_, qw(table player_name)) or return;
+ # If currently at a table, leave it (safe to call if not at a table) This
+ # is important because some clients may not have implemented the
+ # leave_table in all cases, and we need to prevent one Player from having
+ # multiple Tables for a whole lot of reasons (messages from multiple
+ # tables, failure to detect and cleanup state, etc)
+ if (exists $PINDEX{$p->{id}}) {
+ leave_table($p);
+ }
+
my $tid = $msg->{table};
$p->name($msg->{player_name});