2 * Quoridor server and related libraries
3 * Copyright (C) 2009-2010 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://www.gnu.org/licenses/.
18 package cz.xelfi.quoridor.emailer
21 import java.util.ResourceBundle
22 import java.text.MessageFormat
23 import scala.collection.Map
24 import scala.collection.mutable.HashMap
26 abstract class Notify {
27 protected def allPlayers(): Map[String,List[Info]]
28 protected def emails(ids : Collection[String]): Map[String,String]
29 protected def sendEmail(address : String, subject : String, text : String) : Unit
30 protected def resignGame(id : Info): Unit
32 case class Info(lastMove : Long, gameId : String, toMove : String) {
36 val ret = allPlayers()
37 val name2Address = emails(ret.keySet)
39 for (val player <- ret.keySet) {
40 val address = name2Address.getOrElse(player, null)
42 val rb = ResourceBundle.getBundle("cz.xelfi.quoridor.emailer.Bundle")
43 val sb = new StringBuilder
44 sb.append(rb.getString("MSG_HEADER"))
45 var subject = rb.getString("MSG_SUBJECT")
46 val mf = new MessageFormat(rb.getString("MSG_GAME"))
47 val mfCancel = new MessageFormat(rb.getString("MSG_GAME_CANCEL"))
48 for (val info <- ret(player)) {
49 val delay : Long = (System.currentTimeMillis - info.lastMove) / (3600 * 1000 * 24)
50 val arr = new Array[Object](2);
51 arr(0) = "http://quoridor.xelfi.cz/games/" + info.gameId
52 arr(1) = java.lang.Long.valueOf(delay)
54 subject = rb.getString("MSG_SUBJECT_CANCEL")
55 sb.append(mfCancel.format(arr))
57 } else if (delay > 14) {
58 subject = rb.getString("MSG_SUBJECT_WARN")
59 sb.append(mf.format(arr))
62 if (address != null) {