From 8c8823ebfe01da71090b3c7e7fbb4dbedc5dec42 Mon Sep 17 00:00:00 2001 From: skizzerz Date: Tue, 28 Feb 2017 21:17:51 -0600 Subject: [PATCH] Don't remove users if they're playing Instead mark them as a ghost, and remove them at end of game should they still be gone. --- src/users.py | 17 ++++++++++++++++- src/wolfgame.py | 5 +++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/users.py b/src/users.py index f35d4d4..3160a2d 100644 --- a/src/users.py +++ b/src/users.py @@ -10,6 +10,7 @@ import botconfig Bot = None # bot instance _users = set() +_ghosts = set() _arg_msg = "(nick={0!r}, ident={1!r}, host={2!r}, realname={3!r}, account={4!r}, allow_bot={5})" @@ -184,11 +185,25 @@ def parse_rawnick_as_dict(rawnick, *, default=None): def _cleanup_user(evt, var, user): """Removes a user from our global tracking set once it has left all channels.""" - _users.discard(user) + if var.PHASE not in var.GAME_PHASES or user not in var.ALL_PLAYERS: + _users.discard(user) + elif var.PHASE in var.GAME_PHASES and user in var.ALL_PLAYERS: + _ghosts.add(user) + +def _reset(evt, var): + """Cleans up users that left during game during game end.""" + for user in _ghosts: + if not user.channels: + _users.discard(user) + _ghosts.clear() # Can't use @event_listener decorator since src/decorators.py imports us # (meaning decorator isn't defined at the point in time we are run) events.add_listener("cleanup_user", _cleanup_user) +events.add_listener("reset", _reset) +# FIXME: when there is a swap_player event, we need a listener for that as well +# to remove the swapped player from _ghosts if they're in there (helps prevent +# duplicate user lookup bugs where the ghost and new player have the same nick) class User(IRCContext): diff --git a/src/wolfgame.py b/src/wolfgame.py index 820dd51..27ec33c 100644 --- a/src/wolfgame.py +++ b/src/wolfgame.py @@ -2969,8 +2969,9 @@ def return_to_village(var, chan, target, *, show_message): with var.GRAVEYARD_LOCK: temp = target.lower() if temp.nick in var.DISCONNECTED: - if (temp.account is not None and users.equals(temp.account, account) or - temp.userhost is not None and users.equals(temp.userhost, hostmask) and not var.ACCOUNTS_ONLY): + account, hostmask, when, what = var.DISCONNECTED[temp.nick] + if ((not var.DISABLE_ACCOUNTS and temp.account is not None and users.equals(temp.account, account)) or + (not var.ACCOUNTS_ONLY and temp.userhost is not None and users.equals(temp.userhost, hostmask))): del var.DISCONNECTED[temp.nick] var.LAST_SAID_TIME[temp.nick] = datetime.now()