Add logic for communicating end games to users

This commit is contained in:
sloumdrone 2019-04-29 22:43:38 -07:00
parent 286e591ee0
commit 21443189ac
1 changed files with 7 additions and 0 deletions

7
oberon
View File

@ -95,6 +95,13 @@ def play_game(gid):
q2 = "UPDATE games SET game_board = ?, turn = ?, winner = ? WHERE rowid = ?"
v2 = (json.dumps(play['board']), state['turn_number'] + 1, play['winner'], gid)
res2 = db_do(q2, v2, True)
if play['winner']:
msg_path = '/home/{}/.oberon'.format(enemy)
enemy = state['p1'] if state['p1'] != username else state['p2']
writemode = 'a' if fileexists(msg_path) else 'w'
with open(msg_path, writemode) as f:
f.write('{} defeated you in {} game {}\n'.format(username, state['game_type'], gid))
if not res2:
print('Error updating database, sorry.\nTry again later?\n...or contact the sysadmin.')
return False