prevent challenge nastyness
by opening several challenge setups before the opponent blocks, one could send a few challenges even after having been blocked
This commit is contained in:
parent
79eb255151
commit
6c0a9e27af
|
@ -41,7 +41,7 @@ object Setup extends LilaController with TheftPrevention {
|
|||
}
|
||||
|
||||
def friendForm(userId: Option[String]) = Open { implicit ctx =>
|
||||
if (HTTPRequest isXhr ctx.req) {
|
||||
if (HTTPRequest isXhr ctx.req)
|
||||
env.forms friendFilled get("fen") flatMap { form =>
|
||||
val validFen = form("fen").value flatMap ValidFen(false)
|
||||
userId ?? UserRepo.named flatMap {
|
||||
|
@ -51,7 +51,6 @@ object Setup extends LilaController with TheftPrevention {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else fuccess {
|
||||
Redirect(routes.Lobby.home + "#friend")
|
||||
}
|
||||
|
@ -67,28 +66,33 @@ object Setup extends LilaController with TheftPrevention {
|
|||
api = _ => fuccess(BadRequest(errorsAsJson(f)))
|
||||
), {
|
||||
case config => userId ?? UserRepo.byId flatMap { destUser =>
|
||||
import lila.challenge.Challenge._
|
||||
val challenge = lila.challenge.Challenge.make(
|
||||
variant = config.variant,
|
||||
initialFen = config.fen,
|
||||
timeControl = config.makeClock map { c =>
|
||||
TimeControl.Clock(c.limit, c.increment)
|
||||
} orElse config.makeDaysPerTurn.map {
|
||||
TimeControl.Correspondence.apply
|
||||
} getOrElse TimeControl.Unlimited,
|
||||
mode = config.mode,
|
||||
color = config.color.name,
|
||||
challenger = (ctx.me, HTTPRequest sid req) match {
|
||||
case (Some(user), _) => Right(user)
|
||||
case (_, Some(sid)) => Left(sid)
|
||||
case _ => Left("no_sid")
|
||||
},
|
||||
destUser = destUser,
|
||||
rematchOf = none)
|
||||
env.processor.saveFriendConfig(config) >>
|
||||
(Env.challenge.api create challenge) >> negotiate(
|
||||
html = fuccess(Redirect(routes.Round.watcher(challenge.id, "white"))),
|
||||
api = _ => Challenge showChallenge challenge)
|
||||
destUser ?? Challenge.restriction flatMap {
|
||||
case Some(_) =>
|
||||
Redirect(routes.Lobby.home + s"?user=${~userId}#friend").fuccess
|
||||
case None =>
|
||||
import lila.challenge.Challenge._
|
||||
val challenge = lila.challenge.Challenge.make(
|
||||
variant = config.variant,
|
||||
initialFen = config.fen,
|
||||
timeControl = config.makeClock map { c =>
|
||||
TimeControl.Clock(c.limit, c.increment)
|
||||
} orElse config.makeDaysPerTurn.map {
|
||||
TimeControl.Correspondence.apply
|
||||
} getOrElse TimeControl.Unlimited,
|
||||
mode = config.mode,
|
||||
color = config.color.name,
|
||||
challenger = (ctx.me, HTTPRequest sid req) match {
|
||||
case (Some(user), _) => Right(user)
|
||||
case (_, Some(sid)) => Left(sid)
|
||||
case _ => Left("no_sid")
|
||||
},
|
||||
destUser = destUser,
|
||||
rematchOf = none)
|
||||
env.processor.saveFriendConfig(config) >>
|
||||
(Env.challenge.api create challenge) >> negotiate(
|
||||
html = fuccess(Redirect(routes.Round.watcher(challenge.id, "white"))),
|
||||
api = _ => Challenge showChallenge challenge)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue