tournament withdraw resigns current games

This commit is contained in:
Thibault Duplessis 2012-09-17 16:57:40 +02:00
parent 782e80643c
commit c76bcd5df0
8 changed files with 55 additions and 44 deletions

View file

@ -107,7 +107,7 @@ final class CoreEnv private (application: Application, val settings: Settings) {
flood = security.flood,
siteSocket = site.socket,
lobbyNotify = lobby.socket.reloadTournaments,
abortGame = round.forceAbort.apply,
roundMeddler = round.meddler,
mongodb = mongodb.apply _)
lazy val analyse = new lila.analyse.AnalyseEnv(

View file

@ -1,26 +0,0 @@
package lila
package round
import game.{ DbGame, GameRepo }
import scalaz.effects._
final class ForceAbort(
gameRepo: GameRepo,
finisher: Finisher,
socket: Socket) {
def apply(id: String): IO[Unit] = for {
gameOption gameRepo game id
_ gameOption.fold(
game (finisher forceAbort game).fold(
err putStrLn(err.shows),
ioEvents for {
events ioEvents
_ io { socket.send(game.id, events) }
} yield ()
),
putStrLn("Cannot abort missing game " + id)
)
} yield ()
}

40
app/round/Meddler.scala Normal file
View file

@ -0,0 +1,40 @@
package lila
package round
import game.{ DbGame, GameRepo, PovRef }
import scalaz.effects._
final class Meddler(
gameRepo: GameRepo,
finisher: Finisher,
socket: Socket) {
def forceAbort(id: String): IO[Unit] = for {
gameOption gameRepo game id
_ gameOption.fold(
game (finisher forceAbort game).fold(
err putStrLn(err.shows),
ioEvents for {
events ioEvents
_ io { socket.send(game.id, events) }
} yield ()
),
putStrLn("Cannot abort missing game " + id)
)
} yield ()
def resign(povRef: PovRef): IO[Unit] = for {
povOption gameRepo pov povRef
_ povOption.fold(
pov (finisher resign pov).fold(
err putStrLn(err.shows),
ioEvents for {
events ioEvents
_ io { socket.send(pov.game.id, events) }
} yield ()
),
putStrLn("Cannot resign missing game " + povRef)
)
} yield ()
}

View file

@ -93,7 +93,7 @@ final class RoundEnv(
lazy val watcherRoomRepo = new WatcherRoomRepo(
mongodb(RoundCollectionWatcherRoom))
lazy val forceAbort = new ForceAbort(
lazy val meddler = new Meddler(
gameRepo = gameRepo,
finisher = finisher,
socket = socket)

View file

@ -18,7 +18,7 @@ final class TournamentApi(
socket: Socket,
siteSocket: site.Socket,
lobbyNotify: String IO[Unit],
abortGame: String IO[Unit]) {
roundMeddler: round.Meddler) {
def makePairings(tour: Started, pairings: NonEmptyList[Pairing]): IO[Unit] =
(tour addPairings pairings) |> { tour2
@ -61,7 +61,7 @@ final class TournamentApi(
_ repo saveIO finished
_ socket reloadPage finished.id
_ reloadSiteSocket
_ (finished.playingPairings map (_.gameId) map abortGame).sequence
_ (finished.playingPairings map (_.gameId) map roundMeddler.forceAbort).sequence
} yield finished
}, io(started))
@ -87,14 +87,12 @@ final class TournamentApi(
)
case started: Started (started withdraw userId).fold(
err putStrLn(err.shows) inject tour,
tour2 tour2.readyToFinish.fold(
finish(tour2),
for {
_ repo saveIO tour2
_ socket reload tour2.id
_ reloadSiteSocket
} yield tour2
)
tour2 for {
_ repo saveIO tour2
_ (tour2 userCurrentPov userId).fold(roundMeddler.resign, io())
_ socket reload tour2.id
_ reloadSiteSocket
} yield tour2
)
case finished: Finished putStrLn("Cannot withdraw from finished tournament " + finished.id) inject tour
}
@ -115,7 +113,7 @@ final class TournamentApi(
)
} yield result
private def userIdWhoLostOnTimeWithoutMoving(game: DbGame): Option[String] =
private def userIdWhoLostOnTimeWithoutMoving(game: DbGame): Option[String] =
game.playerWhoDidNotMove
.flatMap(_.userId)
.filter(_ List(chess.Status.Timeout, chess.Status.Outoftime) contains game.status)

View file

@ -24,7 +24,7 @@ final class TournamentEnv(
flood: Flood,
siteSocket: site.Socket,
lobbyNotify: String IO[Unit],
abortGame: String IO[Unit],
roundMeddler: round.Meddler,
mongodb: String MongoCollection) {
implicit val ctx = app
@ -43,7 +43,7 @@ final class TournamentEnv(
socket = socket,
siteSocket = siteSocket,
lobbyNotify = lobbyNotify,
abortGame = abortGame)
roundMeddler = roundMeddler)
lazy val roomRepo = new RoomRepo(
collection = mongodb(TournamentCollectionRoom)

View file

@ -133,6 +133,8 @@
padding: 0.3em 0.2em;
display: block;
text-decoration: none;
white-space: nowrap;
overflow: hidden;
}
#tournament_side div.pairings a:hover {
text-decoration: underline;

3
todo
View file

@ -46,9 +46,6 @@ all hub members should use userIds rather than usernames
add opera to list of supported browsers (with websocket trick)
tournament ties
tournament detect leavers and withdraw them (started) (also use force resign)
^ game with no move = withdraw
tournament withdraw resigns playing games
tournament make pairings overflow hidden http://en.lichess.org/tournament/kswnkqr3
tournament warmup games
send lobby new forum posts html through websockets
un-ban IP mechanism (deleting cookies)