From 62f716093a40e9c48ea154da4bf4b77fbebd361b Mon Sep 17 00:00:00 2001 From: jacob1 Date: Sat, 21 Jan 2017 18:29:11 -0500 Subject: [PATCH] fix !swap and nick changing errors var.ALL_PLAYERS update (for !swap) needs to happen before checking if the new user is in var.ALL_PLAYERS pl is inaccurate during nick changes because the user's nick in var.ALL_PLAYERS is updated automatically but in var.ROLES isn't, therefore a user that changes nicks would never be returned in list_players() one instance of prefix incorrectly changed to user.nick --- src/wolfgame.py | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/wolfgame.py b/src/wolfgame.py index 0056988..8239dda 100644 --- a/src/wolfgame.py +++ b/src/wolfgame.py @@ -542,7 +542,7 @@ def replace(var, wrapper, message): wrapper.pm(messages["already_playing"].format("You")) return - if temp.account is None: + if wrapper.source.account is None: wrapper.pm(messages["not_logged_in"]) return @@ -3103,24 +3103,22 @@ def rename_player(var, user, prefix): event = Event("rename_player", {}) event.dispatch(user.client, var, prefix, nick) # FIXME: Need to update all the callbacks - if user in var.ALL_PLAYERS: - pl = list_players() - if user.nick in pl: - r = var.ROLES[get_role(user.nick)] - r.add(user.nick) - r.remove(prefix) - tpls = get_templates(prefix) - for t in tpls: - var.ROLES[t].add(user.nick) - var.ROLES[t].remove(prefix) + try: + temp = users._get(prefix) # FIXME + except KeyError: # dirty hack; this isn't a swap + pass + else: + # ALL_PLAYERS needs to keep its ordering for purposes of mad scientist + var.ALL_PLAYERS[var.ALL_PLAYERS.index(temp)] = user - try: - temp = users._get(prefix) # FIXME - except KeyError: # dirty hack; this isn't a swap - pass - else: - # ALL_PLAYERS needs to keep its ordering for purposes of mad scientist - var.ALL_PLAYERS[var.ALL_PLAYERS.index(temp)] = user + if user in var.ALL_PLAYERS: + r = var.ROLES[get_role(prefix)] + r.add(user.nick) + r.remove(prefix) + tpls = get_templates(prefix) + for t in tpls: + var.ROLES[t].add(user.nick) + var.ROLES[t].remove(prefix) if var.PHASE in var.GAME_PHASES: for k,v in var.ORIGINAL_ROLES.items():