diff --git a/app/round/Finisher.scala b/app/round/Finisher.scala index 4e8ad3482a..8c95316d10 100644 --- a/app/round/Finisher.scala +++ b/app/round/Finisher.scala @@ -10,6 +10,8 @@ import Status._ import Color._ import scalaz.effects._ +import play.api.Play.current +import play.api.libs.concurrent.Akka final class Finisher( userRepo: UserRepo, @@ -18,10 +20,14 @@ final class Finisher( eloUpdater: EloUpdater, eloCalculator: EloCalculator, finisherLock: FinisherLock, - indexGame: DbGame ⇒ IO[Unit]) { + indexGame: DbGame ⇒ IO[Unit], + tournamentOrganizerActorName: String) { type ValidIOEvents = Valid[IO[List[Event]]] + private lazy val tournamentOrganizerActor = + Akka.system.actorFor("/user/" + tournamentOrganizerActorName) + def abort(pov: Pov): ValidIOEvents = if (pov.game.abortable) finish(pov.game, Aborted) else !!("game is not abortable") @@ -87,6 +93,7 @@ final class Finisher( _ ← incNbGames(g, White) doIf (g.status >= Status.Mate) _ ← incNbGames(g, Black) doIf (g.status >= Status.Mate) _ ← indexGame(g) + _ ← io { tournamentOrganizerActor ! FinishGame(g.id) } } yield p2.events) private def incNbGames(game: DbGame, color: Color): IO[Unit] = diff --git a/app/round/Hub.scala b/app/round/Hub.scala index 668fbaaf44..045c52274d 100644 --- a/app/round/Hub.scala +++ b/app/round/Hub.scala @@ -18,8 +18,7 @@ final class Hub( history: History, uidTimeout: Int, hubTimeout: Int, - playerTimeout: Int, - tournamentOrganizerActorName: String) extends HubActor[Member](uidTimeout) { + playerTimeout: Int) extends HubActor[Member](uidTimeout) { var lastPingTime = nowMillis @@ -27,9 +26,6 @@ final class Hub( var whiteTime = nowMillis var blackTime = nowMillis - lazy val tournamentOrganizerActor = - Akka.system.actorFor("/user/" + tournamentOrganizerActorName) - def receiveSpecific = { case PingVersion(uid, v) ⇒ { @@ -111,7 +107,6 @@ final class Hub( def notify(events: List[Event]) { val vevents = events map history.+= members.values foreach { m ⇒ batch(m, vevents) } - if (events contains Event.End()) notifyEnd } def batch(member: Member, vevents: List[VersionedEvent]) { @@ -130,10 +125,6 @@ final class Hub( notifyOwner(!color, "gone", JsBoolean(gone)) } - def notifyEnd { - tournamentOrganizerActor ! FinishGame(gameId) - } - def makeEvent(t: String, data: JsValue): JsObject = JsObject(Seq("t" -> JsString(t), "d" -> data)) diff --git a/app/round/HubMaster.scala b/app/round/HubMaster.scala index 1bc0e7308f..b48b2c4fbb 100644 --- a/app/round/HubMaster.scala +++ b/app/round/HubMaster.scala @@ -17,8 +17,7 @@ final class HubMaster( makeHistory: () ⇒ History, uidTimeout: Int, hubTimeout: Int, - playerTimeout: Int, - tournamentOrganizerActorName: String) extends Actor { + playerTimeout: Int) extends Actor { implicit val timeout = Timeout(1 second) implicit val executor = Akka.system.dispatcher @@ -76,7 +75,6 @@ final class HubMaster( history = makeHistory(), uidTimeout = uidTimeout, hubTimeout = hubTimeout, - playerTimeout = playerTimeout, - tournamentOrganizerActorName = tournamentOrganizerActorName + playerTimeout = playerTimeout )), name = "game_hub_" + gameId) } diff --git a/app/round/RoundEnv.scala b/app/round/RoundEnv.scala index b17230d6ec..f7203ba10d 100644 --- a/app/round/RoundEnv.scala +++ b/app/round/RoundEnv.scala @@ -37,8 +37,7 @@ final class RoundEnv( makeHistory = history, uidTimeout = RoundUidTimeout, hubTimeout = RoundHubTimeout, - playerTimeout = RoundPlayerTimeout, - tournamentOrganizerActorName = ActorTournamentOrganizer + playerTimeout = RoundPlayerTimeout )), name = ActorRoundHubMaster) lazy val moveNotifier = new MoveNotifier( @@ -72,7 +71,8 @@ final class RoundEnv( eloUpdater = eloUpdater, eloCalculator = eloCalculator, finisherLock = finisherLock, - indexGame = indexGame) + indexGame = indexGame, + tournamentOrganizerActorName = ActorTournamentOrganizer) lazy val eloCalculator = new chess.EloCalculator(false) diff --git a/todo b/todo index 5e0be0b33a..84be96adde 100644 --- a/todo +++ b/todo @@ -48,3 +48,5 @@ all hub members should use userIds rather than usernames tournament miniboards are not updating finish games when tournament is over tournament players are winning one point just by having a game in progress! +add opera to list of supported browsers (with websocket trick) +finish pairing on resign