-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Remove all the code except models - Clean sbt settings - Add new dependencies
- Loading branch information
1 parent
6cb86aa
commit 32cdf61
Showing
11 changed files
with
172 additions
and
477 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,49 @@ | ||
version = "2.6.3" | ||
align.preset = more | ||
version = 3.7.15 | ||
runner.dialect = scala3 | ||
maxColumn = 110 | ||
spaces.inImportCurlyBraces = true | ||
rewrite.rules = [SortImports, RedundantParens, SortModifiers] | ||
rewrite.redundantBraces.stringInterpolation = true | ||
|
||
newlines.source = keep | ||
|
||
trailingCommas = "multiple" | ||
|
||
rewrite { | ||
rules = [Imports] | ||
imports.sort = ascii | ||
} | ||
|
||
rewrite.scala3 { | ||
convertToNewSyntax = yes | ||
removeOptionalBraces = yes | ||
} | ||
|
||
align { | ||
allowOverflow = true | ||
preset = more | ||
openParenCallSite = false | ||
stripMargin = true | ||
} | ||
|
||
continuationIndent { | ||
callSite = 2 | ||
defnSite = 4 | ||
} | ||
|
||
docstrings { | ||
style = Asterisk | ||
oneline = keep | ||
wrap = no | ||
} | ||
|
||
spaces { | ||
beforeContextBoundColon = Never | ||
inImportCurlyBraces = true | ||
} | ||
|
||
fileOverride { | ||
"glob:**/build.sbt" { | ||
runner.dialect = scala213 | ||
} | ||
"glob:**/project/**" { | ||
runner.dialect = scala213 | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,22 @@ | ||
package lila.fishnet | ||
|
||
import chess.format.{ FEN, Uci } | ||
import io.lettuce.core._ | ||
import io.lettuce.core.pubsub._ | ||
import chess.format.{ Fen, Uci } | ||
import org.joda.time.DateTime | ||
import play.api.Configuration | ||
import play.api.Logger | ||
|
||
final class Lila( | ||
moveDb: MoveDb, | ||
config: Configuration | ||
) { | ||
object Lila: | ||
|
||
private val logger = Logger(getClass) | ||
private val redis = RedisClient create config.get[String]("redis.uri") | ||
|
||
def pubsub(chanIn: String, chanOut: String): Lila.Move => Unit = { | ||
|
||
val connIn = redis.connectPubSub() | ||
val connOut = redis.connectPubSub() | ||
|
||
def send(move: Lila.Move): Unit = connIn.async.publish(chanIn, move.write) | ||
|
||
connOut.addListener(new RedisPubSubAdapter[String, String] { | ||
override def message(chan: String, msg: String): Unit = | ||
Lila.readMoveReq(msg) match { | ||
case None => logger warn s"LilaOut invalid move $msg" | ||
case Some(req) => moveDb add req | ||
} | ||
}) | ||
|
||
connOut.async.subscribe(chanOut) thenRun { () => connIn.async.publish(chanIn, "start") } | ||
|
||
send | ||
} | ||
} | ||
|
||
object Lila { | ||
|
||
case class Move(game: Work.Game, uci: Uci) { | ||
case class Move(game: Work.Game, uci: Uci): | ||
def sign = game.moves.takeRight(20).replace(" ", "") | ||
def write = s"${game.id} $sign ${uci.uci}" | ||
} | ||
|
||
def readMoveReq(msg: String): Option[Work.Move] = | ||
msg.split(";", 6) match { | ||
case Array(gameId, levelS, clockS, variantS, initialFenS, moves) => | ||
for { | ||
level <- levelS.toIntOption | ||
variant = chess.variant.Variant.orDefault(variantS) | ||
initialFen = if (initialFenS.isEmpty) None else Some(FEN(initialFenS)) | ||
clock = readClock(clockS) | ||
} yield Work.Move( | ||
_id = Work.makeId, | ||
game = Work.Game( | ||
id = gameId, | ||
initialFen = initialFen, | ||
variant = variant, | ||
moves = moves | ||
), | ||
level = level, | ||
clock = clock, | ||
tries = 0, | ||
lastTryByKey = None, | ||
acquired = None, | ||
createdAt = DateTime.now | ||
) | ||
case _ => None | ||
} | ||
def readMoveReq(msg: String): Option[Work.Move] = ??? | ||
|
||
def readClock(s: String) = | ||
s split ' ' match { | ||
s split ' ' match | ||
case Array(ws, bs, incs) => | ||
for { | ||
wtime <- ws.toIntOption | ||
btime <- bs.toIntOption | ||
inc <- incs.toIntOption | ||
} yield Work.Clock(wtime, btime, inc) | ||
case _ => None | ||
} | ||
} |
Oops, something went wrong.