From 416c1730613d2a21b1fe3622406a1b3a5b1db7ff Mon Sep 17 00:00:00 2001 From: Alex Karle Date: Thu, 7 May 2020 00:16:05 -0400 Subject: [PATCH] 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! --- lib/Euchre/Host.pm | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/Euchre/Host.pm b/lib/Euchre/Host.pm index 292bf4c..42d7843 100644 --- 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}); -- libgit2 1.1.1