Browse Source

add a player record on join in the database

master
jcao219 13 years ago
parent
commit
345b597dc9
  1. 5
      var.py
  2. 11
      wolfgame.py

5
var.py

@ -209,6 +209,11 @@ def add_away(clk):
c.execute('INSERT into away VALUES (?)', (clk,)) c.execute('INSERT into away VALUES (?)', (clk,))
def add_player_record(nick, cloak):
with conn:
c.execute('INSERT OR IGNORE INTO players (nick, cloak) VALUES (?,?)', (nick, cloak))
def record_nick_change(from_nick, to_nick, cloak): def record_nick_change(from_nick, to_nick, cloak):
with conn: with conn:
c.execute('SELECT id FROM players WHERE nick=? AND cloak=?', (from_nick, cloak)) c.execute('SELECT id FROM players WHERE nick=? AND cloak=?', (from_nick, cloak))

11
wolfgame.py

@ -314,11 +314,17 @@ def fpinger(cli, nick, chan, rest):
@cmd("join") @cmd("join", raw_nick=True)
def join(cli, nick, chan, rest): def join(cli, nick, chan, rest):
"""Either starts a new game of Werewolf or joins an existing game that has not started yet.""" """Either starts a new game of Werewolf or joins an existing game that has not started yet."""
pl = var.list_players() pl = var.list_players()
nick, _, __, cloak = parse_nick(nick)
if var.PHASE == "none": if var.PHASE == "none":
if cloak:
var.add_player_record(nick, cloak)
cli.mode(chan, "+v", nick, nick+"!*@*") cli.mode(chan, "+v", nick, nick+"!*@*")
var.ROLES["person"].append(nick) var.ROLES["person"].append(nick)
var.PHASE = "join" var.PHASE = "join"
@ -335,6 +341,9 @@ def join(cli, nick, chan, rest):
elif var.PHASE != "join": elif var.PHASE != "join":
cli.notice(nick, "Sorry but the game is already running. Try again next time.") cli.notice(nick, "Sorry but the game is already running. Try again next time.")
else: else:
if cloak:
var.add_player_record(nick, cloak)
cli.mode(chan, "+v", nick, nick+"!*@*") cli.mode(chan, "+v", nick, nick+"!*@*")
var.ROLES["person"].append(nick) var.ROLES["person"].append(nick)
cli.msg(chan, '\u0002{0}\u0002 has joined the game.'.format(nick)) cli.msg(chan, '\u0002{0}\u0002 has joined the game.'.format(nick))

Loading…
Cancel
Save