private def processUserCommand order JsValue order command validate St

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
private def processUserCommand(order: JsValue) = {
(order \ "command").validate[String].map(_ match {
case "I want to play" => checkedAction(Idle, "You are already in search or in game."){
userStatus = Waiting
board ! Subscribe
}
case "I don't want to play" => checkedAction(Waiting, "You are not in search."){
userStatus = Idle
board ! Unsubscribe
}
case "make move" => checkedAction(InGame, "Keep calm and search opponent first."){
currentChallenge.get !
NewMove(user.main.userId, (order \ "cell").as[String])
}
case cmd: String => sendErrorCmdMsg(cmd, order.toString())
}) recover {
case err => sendErrorCmdMsg(err.toString, order.toString())
}
def checkedAction(status: UserStatus, err: String)(p: => Unit) =
if (userStatus == status) p
else out ! Error(err).json
}