diff options
author | Tor Andersson <tor@ccxvii.net> | 2022-05-22 15:22:57 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2022-05-23 02:48:44 +0200 |
commit | 7c1756320916352d100ac8724d032ab937978832 (patch) | |
tree | c3c10dc782090d2db6afcba96b874ce228ef4584 /server.js | |
parent | 10dde19c9de34715910a0c9197c693e78644d41c (diff) | |
download | server-7c1756320916352d100ac8724d032ab937978832.tar.gz |
Send "game over" mail notifications.
Diffstat (limited to 'server.js')
-rw-r--r-- | server.js | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -1520,6 +1520,19 @@ function mail_new_message(user, msg_id, msg_from) { } } +function mail_game_over_notification(user, game_id, result, victory) { + if (mailer) { + let game = SQL_SELECT_GAME_FULL_VIEW.get(game_id); + let subject = `${game.title_name} #${game_id} (${user.role}) - Finished!`; + let body = mail_game_info(game) + + victory + "\n\n" + + mail_game_link(game_id, user) + + MAIL_FOOTER; + console.log("SENT MAIL:", mail_addr(user), subject); + mailer.sendMail({ from: MAIL_FROM, to: mail_addr(user), subject: subject, text: body }, mail_callback); + } +} + function mail_your_turn_notification(user, game_id, interval) { if (mailer) { let too_soon = SQL_SELECT_NOTIFIED.get(interval, game_id, user.user_id); @@ -1581,6 +1594,13 @@ function mail_your_turn_notification_to_offline_users(game_id, old_active, activ } } +function mail_game_over_notification_to_offline_users(game_id, result, victory) { + let players = SQL_SELECT_PLAYERS.all(game_id); + for (let p of players) + if (p.notify && !is_online(game_id, p.user_id)) + mail_game_over_notification(p, game_id, result, victory); +} + function notify_your_turn_reminder() { for (let item of QUERY_LIST_YOUR_TURN.all()) { mail_your_turn_notification(item, item.game_id, '+25 hours'); @@ -1661,6 +1681,7 @@ function get_game_state(game_id) { function put_game_state(game_id, state, old_active) { if (state.state === 'game_over') { SQL_UPDATE_GAME_RESULT.run(2, state.result, game_id); + mail_game_over_notification_to_offline_users(game_id, state.result, state.victory); } SQL_UPDATE_GAME_STATE.run(game_id, JSON.stringify(state), state.active); for (let other of clients[game_id]) |