diff options
-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]) |