send tournament finish messages from the finisher rather than round hub

pull/83/head
Thibault Duplessis 2012-09-16 12:52:54 +02:00
parent b29ff34fb9
commit 10d2d4ce67
5 changed files with 16 additions and 18 deletions

View File

@ -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] =

View File

@ -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))

View File

@ -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)
}

View File

@ -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)

2
todo
View File

@ -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