add a player record on join in the database

This commit is contained in:
Jimmy Cao 2011-08-21 00:39:06 -05:00
parent 290bb9da1e
commit 446f62f6b8
2 changed files with 15 additions and 1 deletions

5
var.py
View File

@ -209,6 +209,11 @@ def add_away(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):
with conn:
c.execute('SELECT id FROM players WHERE nick=? AND cloak=?', (from_nick, cloak))

View File

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