Browse Source

hopefully fix the elusive nick-change bug, prevent DC'd users from rejoining after a game ends

master
jcao219 13 years ago
parent
commit
d808d748ef
  1. 59
      wolfgame.py

59
wolfgame.py

@ -49,8 +49,7 @@ def connect_callback(cli):
cli.nickname = user cli.nickname = user
cli.ident = ident cli.ident = ident
cli.hostmask = cloak cli.hostmask = cloak
var.USERS.append(user) var.USERS[user] = cloak
var.CLOAKS.append(cloak)
@hook("endofwho", id=294) @hook("endofwho", id=294)
def afterwho(*args): def afterwho(*args):
@ -81,8 +80,7 @@ def connect_callback(cli):
var.LAST_VOTES = None var.LAST_VOTES = None
var.LAST_ADMINS = None var.LAST_ADMINS = None
var.USERS = [] var.USERS = {}
var.CLOAKS = []
var.PINGING = False var.PINGING = False
var.ADMIN_PINGING = False var.ADMIN_PINGING = False
@ -173,6 +171,7 @@ def reset(cli):
dict.clear(var.LAST_SAID_TIME) dict.clear(var.LAST_SAID_TIME)
dict.clear(var.DEAD_USERS) dict.clear(var.DEAD_USERS)
dict.clear(var.DISCONNECTED)
@pmcmd("fdie", "fbye", admin_only=True) @pmcmd("fdie", "fbye", admin_only=True)
@ -353,7 +352,8 @@ def fjoin(cli, nick, chan, rest):
a = a.strip() a = a.strip()
if not a: if not a:
continue continue
ull = [u.lower() for u in var.USERS] ul = list(var.USERS.keys())
ull = [u.lower() for u in ul]
if a.lower() not in ull: if a.lower() not in ull:
if not is_fake_nick(a) or not botconfig.DEBUG_MODE: if not is_fake_nick(a) or not botconfig.DEBUG_MODE:
if not noticed: # important if not noticed: # important
@ -362,7 +362,7 @@ def fjoin(cli, nick, chan, rest):
noticed = True noticed = True
continue continue
if not is_fake_nick(a): if not is_fake_nick(a):
a = var.USERS[ull.index(a.lower())] a = ul[ull.index(a.lower())]
if a != botconfig.NICK: if a != botconfig.NICK:
join(cli, a.strip(), chan, "") join(cli, a.strip(), chan, "")
else: else:
@ -685,13 +685,13 @@ def stop_game(cli, winner = ""):
var.LOGGER.saveToFile() var.LOGGER.saveToFile()
for plr, rol in plrl: for plr, rol in plrl:
if plr not in var.USERS: # he died TODO: when a player leaves, count the game as lost for him if plr not in var.USERS.keys(): # he died TODO: when a player leaves, count the game as lost for him
if plr in var.DEAD_USERS.keys(): if plr in var.DEAD_USERS.keys():
clk = var.DEAD_USERS[plr] clk = var.DEAD_USERS[plr]
else: else:
continue # something wrong happened continue # something wrong happened
else: else:
clk = var.CLOAKS[var.USERS.index(plr)] clk = var.USERS[plr]
# determine if this player's team won # determine if this player's team won
if plr in (var.ORIGINAL_ROLES["wolf"] + var.ORIGINAL_ROLES["traitor"] + if plr in (var.ORIGINAL_ROLES["wolf"] + var.ORIGINAL_ROLES["traitor"] +
@ -931,9 +931,8 @@ def update_last_said(cli, nick, chan, rest):
@hook("join") @hook("join")
def on_join(cli, raw_nick, chan): def on_join(cli, raw_nick, chan):
nick,m,u,cloak = parse_nick(raw_nick) nick,m,u,cloak = parse_nick(raw_nick)
if nick not in var.USERS and nick != botconfig.NICK: if nick not in var.USERS.keys() and nick != botconfig.NICK:
var.USERS.append(nick) var.USERS[nick] = cloak
var.CLOAKS.append(cloak)
with var.GRAVEYARD_LOCK: with var.GRAVEYARD_LOCK:
if nick in var.DISCONNECTED.keys(): if nick in var.DISCONNECTED.keys():
clk = var.DISCONNECTED[nick][0] clk = var.DISCONNECTED[nick][0]
@ -961,7 +960,8 @@ def goat(cli, nick, chan, rest):
if var.GOATED: if var.GOATED:
cli.notice(nick, "You can only do that once per day.") cli.notice(nick, "You can only do that once per day.")
return return
ull = [x.lower() for x in var.USERS] ul = list(var.USERS.keys())
ull = [x.lower() for x in ul]
rest = re.split(" +",rest)[0].strip().lower() rest = re.split(" +",rest)[0].strip().lower()
if not rest: if not rest:
cli.notice(nick, "Not enough parameters.") cli.notice(nick, "Not enough parameters.")
@ -978,7 +978,7 @@ def goat(cli, nick, chan, rest):
if matches != 1: if matches != 1:
cli.msg(nick,"\u0002{0}\u0002 is not in this channel.".format(rest)) cli.msg(nick,"\u0002{0}\u0002 is not in this channel.".format(rest))
return return
victim = var.USERS[ull.index(victim)] victim = ul[ull.index(victim)]
cli.msg(chan, ("\u0002{0}\u0002's goat walks by "+ cli.msg(chan, ("\u0002{0}\u0002's goat walks by "+
"and kicks \u0002{1}\u0002.").format(nick, "and kicks \u0002{1}\u0002.").format(nick,
victim)) victim))
@ -993,10 +993,7 @@ def on_nick(cli, prefix, nick):
chan = botconfig.CHANNEL chan = botconfig.CHANNEL
if prefix in var.USERS: if prefix in var.USERS:
var.USERS.remove(prefix) var.USERS[nick] = var.USERS.pop(prefix)
var.CLOAKS.remove(cloak)
var.USERS.append(nick)
var.CLOAKS.append(cloak)
if prefix == var.ADMIN_TO_PING: if prefix == var.ADMIN_TO_PING:
var.ADMIN_TO_PING = nick var.ADMIN_TO_PING = nick
@ -1078,9 +1075,7 @@ def leave(cli, what, nick, why=""):
nick, _, _, cloak = parse_nick(nick) nick, _, _, cloak = parse_nick(nick)
if nick in var.USERS: if nick in var.USERS:
i = var.USERS.index(nick) del var.USERS[nick]
var.USERS.remove(nick)
var.CLOAKS.pop(i)
if why and why == botconfig.CHANGING_HOST_QUIT_MESSAGE: if why and why == botconfig.CHANGING_HOST_QUIT_MESSAGE:
return return
if var.PHASE == "none": if var.PHASE == "none":
@ -1091,7 +1086,7 @@ def leave(cli, what, nick, why=""):
# the player who just quit was in the game # the player who just quit was in the game
if nick in var.USERS: if nick in var.USERS:
var.DEAD_USERS[nick] = var.CLOAKS[var.USERS.index(nick)] var.DEAD_USERS[nick] = var.USERS[nick]
# for gstats, just in case # for gstats, just in case
killhim = True killhim = True
@ -1130,7 +1125,7 @@ def leave_game(cli, nick, chan, rest):
cli.notice(nick, "You're not currently playing.") cli.notice(nick, "You're not currently playing.")
return return
if nick in var.USERS: if nick in var.USERS:
var.DEAD_USERS[nick] = var.CLOAKS[var.USERS.index(nick)] var.DEAD_USERS[nick] = var.USERS[nick]
cli.msg(chan, ("\02{0}\02 died of an unknown disease. "+ cli.msg(chan, ("\02{0}\02 died of an unknown disease. "+
"S/He was a \02{1}\02.").format(nick, var.get_role(nick))) "S/He was a \02{1}\02.").format(nick, var.get_role(nick)))
var.LOGGER.logMessage(("{0} died of an unknown disease. "+ var.LOGGER.logMessage(("{0} died of an unknown disease. "+
@ -2174,8 +2169,6 @@ def start(cli, nick, chan, rest):
var.DAY_START_TIME = None var.DAY_START_TIME = None
var.NIGHT_START_TIME = None var.NIGHT_START_TIME = None
dict.clear(var.DISCONNECTED)
var.LOGGER.log("Game Start") var.LOGGER.log("Game Start")
var.LOGGER.logBare("GAME", "BEGIN", nick) var.LOGGER.logBare("GAME", "BEGIN", nick)
var.LOGGER.logBare(str(len(pl)), "PLAYERCOUNT") var.LOGGER.logBare(str(len(pl)), "PLAYERCOUNT")
@ -2579,17 +2572,18 @@ if botconfig.DEBUG_MODE:
cli.msg(chan, "That won't work.") cli.msg(chan, "That won't work.")
return return
if not is_fake_nick(who): if not is_fake_nick(who):
pll = [pl.lower() for pl in var.USERS] ul = list(var.USERS.keys())
ull = [u.lower() for u in ul]
if who.lower() not in pll: if who.lower() not in pll:
cli.msg(chan, "This can only be done on fake nicks.") cli.msg(chan, "This can only be done on fake nicks.")
return return
else: else:
who = var.USERS[pll.index(who.lower())] who = ul[ull.index(who.lower())]
cmd = rst.pop(0).lower().replace(botconfig.CMD_CHAR, "", 1) cmd = rst.pop(0).lower().replace(botconfig.CMD_CHAR, "", 1)
did = False did = False
if PM_COMMANDS.get(cmd) and not PM_COMMANDS[cmd][0].owner_only: if PM_COMMANDS.get(cmd) and not PM_COMMANDS[cmd][0].owner_only:
if (PM_COMMANDS[cmd][0].admin_only and nick in var.USERS and if (PM_COMMANDS[cmd][0].admin_only and nick in var.USERS and
not is_admin(var.CLOAKS[var.USERS.index(nick)])): not is_admin(var.USERS[nick])):
# Not a full admin # Not a full admin
cli.notice(nick, "Only full admins can force an admin-only command.") cli.notice(nick, "Only full admins can force an admin-only command.")
return return
@ -2607,7 +2601,7 @@ if botconfig.DEBUG_MODE:
# chk_nightdone(cli) # chk_nightdone(cli)
elif COMMANDS.get(cmd) and not COMMANDS[cmd][0].owner_only: elif COMMANDS.get(cmd) and not COMMANDS[cmd][0].owner_only:
if (COMMANDS[cmd][0].admin_only and nick in var.USERS and if (COMMANDS[cmd][0].admin_only and nick in var.USERS and
not is_admin(var.CLOAKS[var.USERS.index(nick)])): not is_admin(var.USERS[nick])):
# Not a full admin # Not a full admin
cli.notice(nick, "Only full admins can force an admin-only command.") cli.notice(nick, "Only full admins can force an admin-only command.")
return return
@ -2646,7 +2640,7 @@ if botconfig.DEBUG_MODE:
cmd = rst.pop(0).lower().replace(botconfig.CMD_CHAR, "", 1) cmd = rst.pop(0).lower().replace(botconfig.CMD_CHAR, "", 1)
if PM_COMMANDS.get(cmd) and not PM_COMMANDS[cmd][0].owner_only: if PM_COMMANDS.get(cmd) and not PM_COMMANDS[cmd][0].owner_only:
if (PM_COMMANDS[cmd][0].admin_only and nick in var.USERS and if (PM_COMMANDS[cmd][0].admin_only and nick in var.USERS and
not is_admin(var.CLOAKS[var.USERS.index(nick)])): not is_admin(var.USERS[nick])):
# Not a full admin # Not a full admin
cli.notice(nick, "Only full admins can force an admin-only command.") cli.notice(nick, "Only full admins can force an admin-only command.")
return return
@ -2659,7 +2653,7 @@ if botconfig.DEBUG_MODE:
# chk_nightdone(cli) # chk_nightdone(cli)
elif cmd.lower() in COMMANDS.keys() and not COMMANDS[cmd][0].owner_only: elif cmd.lower() in COMMANDS.keys() and not COMMANDS[cmd][0].owner_only:
if (COMMANDS[cmd][0].admin_only and nick in var.USERS and if (COMMANDS[cmd][0].admin_only and nick in var.USERS and
not is_admin(var.CLOAKS[var.USERS.index(nick)])): not is_admin(var.USERS[nick])):
# Not a full admin # Not a full admin
cli.notice(nick, "Only full admins can force an admin-only command.") cli.notice(nick, "Only full admins can force an admin-only command.")
return return
@ -2681,14 +2675,15 @@ if botconfig.DEBUG_MODE:
return return
who = rst.pop(0).strip() who = rst.pop(0).strip()
rol = " ".join(rst).strip() rol = " ".join(rst).strip()
ull = [u.lower() for u in var.USERS] ul = list(var.USERS.keys())
ull = [u.lower() for u in ul]
if who.lower() not in ull: if who.lower() not in ull:
if not is_fake_nick(who): if not is_fake_nick(who):
cli.msg(chan, "Could not be done.") cli.msg(chan, "Could not be done.")
cli.msg(chan, "The target needs to be in this channel or a fake name.") cli.msg(chan, "The target needs to be in this channel or a fake name.")
return return
if not is_fake_nick(who): if not is_fake_nick(who):
who = var.USERS[ull.index(who.lower())] who = ul[ull.index(who.lower())]
if who == botconfig.NICK or not who: if who == botconfig.NICK or not who:
cli.msg(chan, "No.") cli.msg(chan, "No.")
return return

Loading…
Cancel
Save