Blame users on ai games
This commit is contained in:
parent
b988e6e774
commit
3788c1e292
|
@ -38,7 +38,8 @@ final class CoreEnv private (application: Application, val settings: Settings) {
|
|||
mongodb = mongodb.apply _,
|
||||
gameRepo = game.gameRepo,
|
||||
timelinePush = timeline.push.apply,
|
||||
ai = ai.ai)
|
||||
ai = ai.ai,
|
||||
dbRef = user.userRepo.dbRef)
|
||||
|
||||
lazy val timeline = new lila.timeline.TimelineEnv(
|
||||
settings = settings,
|
||||
|
|
|
@ -47,6 +47,10 @@ case class DbPlayer(
|
|||
|
||||
def isUser(u: User) = user.fold(_.getId == u.id, false)
|
||||
|
||||
def withUser(u: User, ref: DBRef) = copy(
|
||||
elo = u.elo.some,
|
||||
user = ref.some)
|
||||
|
||||
def wins = isWinner getOrElse false
|
||||
|
||||
def hasMoveTimes = moveTimes.size > 10
|
||||
|
|
|
@ -3,16 +3,19 @@ package setup
|
|||
|
||||
import http.Context
|
||||
import game.{ DbGame, GameRepo, Pov }
|
||||
import user.User
|
||||
import chess.{ Game, Board }
|
||||
import ai.Ai
|
||||
|
||||
import com.mongodb.DBRef
|
||||
import scalaz.effects._
|
||||
|
||||
final class Processor(
|
||||
configRepo: UserConfigRepo,
|
||||
gameRepo: GameRepo,
|
||||
timelinePush: DbGame ⇒ IO[Unit],
|
||||
ai: () ⇒ Ai) {
|
||||
ai: () ⇒ Ai,
|
||||
dbRef: User ⇒ DBRef) {
|
||||
|
||||
def ai(config: AiConfig)(implicit ctx: Context): IO[Pov] = for {
|
||||
_ ← ctx.me.fold(
|
||||
|
@ -20,7 +23,9 @@ final class Processor(
|
|||
io()
|
||||
)
|
||||
pov = config.pov
|
||||
game = pov.game
|
||||
game = ctx.me.fold(
|
||||
user ⇒ pov.game.updatePlayer(pov.color, _.withUser(user, dbRef(user))),
|
||||
pov.game)
|
||||
_ ← gameRepo insert game
|
||||
_ ← game.variant.standard.fold(io(), gameRepo saveInitialFen game)
|
||||
_ ← timelinePush(game)
|
||||
|
|
|
@ -1,19 +1,22 @@
|
|||
package lila
|
||||
package setup
|
||||
|
||||
import com.mongodb.casbah.MongoCollection
|
||||
import scalaz.effects._
|
||||
|
||||
import core.Settings
|
||||
import game.{ DbGame, GameRepo }
|
||||
import ai.Ai
|
||||
import user.User
|
||||
|
||||
import com.mongodb.casbah.MongoCollection
|
||||
import scalaz.effects._
|
||||
import com.mongodb.DBRef
|
||||
|
||||
final class SetupEnv(
|
||||
settings: Settings,
|
||||
mongodb: String ⇒ MongoCollection,
|
||||
gameRepo: GameRepo,
|
||||
timelinePush: DbGame ⇒ IO[Unit],
|
||||
ai: () ⇒ Ai) {
|
||||
ai: () ⇒ Ai,
|
||||
dbRef: User ⇒ DBRef) {
|
||||
|
||||
import settings._
|
||||
|
||||
|
@ -26,5 +29,6 @@ final class SetupEnv(
|
|||
configRepo = configRepo,
|
||||
gameRepo = gameRepo,
|
||||
timelinePush = timelinePush,
|
||||
ai = ai)
|
||||
ai = ai,
|
||||
dbRef = dbRef)
|
||||
}
|
||||
|
|
|
@ -10,8 +10,8 @@ import scalaz.effects._
|
|||
import com.roundeights.hasher.Implicits._
|
||||
|
||||
class UserRepo(
|
||||
collection: MongoCollection,
|
||||
val dbRef: User => DBRef) extends SalatDAO[User, ObjectId](collection) {
|
||||
collection: MongoCollection,
|
||||
val dbRef: User ⇒ DBRef) extends SalatDAO[User, ObjectId](collection) {
|
||||
|
||||
def user(userId: String): IO[Option[User]] = user(new ObjectId(userId))
|
||||
|
||||
|
|
2
todo
2
todo
|
@ -15,7 +15,7 @@ prevent cheaters from joining the game
|
|||
translate "view rematch"
|
||||
translate clock name
|
||||
start chess960 after both player move http://fr.lichess.org/forum/lichess-feedback/clock-fairness-in-chess960-games
|
||||
|
||||
elo floor 800
|
||||
|
||||
next deploy:
|
||||
db.user.update({},{$unset:{isOnline: true}}, false, true)
|
||||
|
|
Loading…
Reference in a new issue