Don't adjust colorIt when aborting fixed color lobby games
parent
abbab60ecf
commit
f34edfd1de
|
@ -1,5 +1,7 @@
|
||||||
package lila.game
|
package lila.game
|
||||||
|
|
||||||
|
import scala.concurrent.duration._
|
||||||
|
|
||||||
import chess.format.{ FEN, Forsyth }
|
import chess.format.{ FEN, Forsyth }
|
||||||
import chess.{ Color, Status }
|
import chess.{ Color, Status }
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
|
@ -19,6 +21,8 @@ final class GameRepo(val coll: Coll)(implicit ec: scala.concurrent.ExecutionCont
|
||||||
import Game.{ ID, BSONFields => F }
|
import Game.{ ID, BSONFields => F }
|
||||||
import Player.holdAlertBSONHandler
|
import Player.holdAlertBSONHandler
|
||||||
|
|
||||||
|
val fixedColorLobbyCache = new lila.memo.ExpireSetMemo(2 hours)
|
||||||
|
|
||||||
def game(gameId: ID): Fu[Option[Game]] = coll.byId[Game](gameId)
|
def game(gameId: ID): Fu[Option[Game]] = coll.byId[Game](gameId)
|
||||||
def gameFromSecondary(gameId: ID): Fu[Option[Game]] = coll.secondaryPreferred.byId[Game](gameId)
|
def gameFromSecondary(gameId: ID): Fu[Option[Game]] = coll.secondaryPreferred.byId[Game](gameId)
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import lila.game.{ Pov, Source }
|
||||||
|
|
||||||
final private class AbortListener(
|
final private class AbortListener(
|
||||||
userRepo: lila.user.UserRepo,
|
userRepo: lila.user.UserRepo,
|
||||||
|
gameRepo: lila.game.GameRepo,
|
||||||
seekApi: SeekApi,
|
seekApi: SeekApi,
|
||||||
lobbyActor: LobbySyncActor
|
lobbyActor: LobbySyncActor
|
||||||
)(implicit ec: scala.concurrent.ExecutionContext) {
|
)(implicit ec: scala.concurrent.ExecutionContext) {
|
||||||
|
@ -14,7 +15,10 @@ final private class AbortListener(
|
||||||
lobbyActor.registerAbortedGame(pov.game)
|
lobbyActor.registerAbortedGame(pov.game)
|
||||||
|
|
||||||
private def cancelColorIncrement(pov: Pov): Unit =
|
private def cancelColorIncrement(pov: Pov): Unit =
|
||||||
if (pov.game.source.exists(s => s == Source.Lobby || s == Source.Pool)) pov.game.userIds match {
|
if (
|
||||||
|
pov.game.source
|
||||||
|
.exists(s => s == Source.Lobby || s == Source.Pool) && !gameRepo.fixedColorLobbyCache.get(pov.game.id)
|
||||||
|
) pov.game.userIds match {
|
||||||
case List(u1, u2) =>
|
case List(u1, u2) =>
|
||||||
userRepo.incColor(u1, -1)
|
userRepo.incColor(u1, -1)
|
||||||
userRepo.incColor(u2, 1)
|
userRepo.incColor(u2, 1)
|
||||||
|
|
|
@ -36,6 +36,7 @@ final private class Biter(
|
||||||
_ <- gameRepo insertDenormalized game
|
_ <- gameRepo insertDenormalized game
|
||||||
} yield {
|
} yield {
|
||||||
lila.mon.lobby.hook.join.increment()
|
lila.mon.lobby.hook.join.increment()
|
||||||
|
rememberIfFixedColor(hook.realColor, game)
|
||||||
JoinHook(sri, hook, game, creatorColor)
|
JoinHook(sri, hook, game, creatorColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +51,14 @@ final private class Biter(
|
||||||
blackUser = creatorColor.fold(user.some, owner.some)
|
blackUser = creatorColor.fold(user.some, owner.some)
|
||||||
).withUniqueId
|
).withUniqueId
|
||||||
_ <- gameRepo insertDenormalized game
|
_ <- gameRepo insertDenormalized game
|
||||||
} yield JoinSeek(user.id, seek, game, creatorColor)
|
} yield {
|
||||||
|
rememberIfFixedColor(seek.realColor, game)
|
||||||
|
JoinSeek(user.id, seek, game, creatorColor)
|
||||||
|
}
|
||||||
|
|
||||||
|
private def rememberIfFixedColor(color: Color, game: Game) =
|
||||||
|
if (color != Color.Random)
|
||||||
|
gameRepo.fixedColorLobbyCache put game.id
|
||||||
|
|
||||||
private def assignCreatorColor(
|
private def assignCreatorColor(
|
||||||
creatorUser: Option[User],
|
creatorUser: Option[User],
|
||||||
|
|
|
@ -173,7 +173,7 @@ final class UserRepo(val coll: Coll)(implicit ec: scala.concurrent.ExecutionCont
|
||||||
coll
|
coll
|
||||||
.update(ordered = false, WriteConcern.Unacknowledged)
|
.update(ordered = false, WriteConcern.Unacknowledged)
|
||||||
.one(
|
.one(
|
||||||
$id(userId) ++ (value < 0).??($doc(F.colorIt $gt -3)),
|
$id(userId) ++ (if (value < 0) $doc(F.colorIt $gt -3) else $doc(F.colorIt $lt 5)),
|
||||||
$inc(F.colorIt -> value)
|
$inc(F.colorIt -> value)
|
||||||
)
|
)
|
||||||
.unit
|
.unit
|
||||||
|
|
Loading…
Reference in New Issue