Admin controller draft

This commit is contained in:
Viktor Kholodov
2021-01-09 02:09:00 +03:00
parent 23f566af51
commit e702bd61b4
13 changed files with 119 additions and 37 deletions
+8 -9
View File
@@ -13,8 +13,7 @@ import scala.concurrent.duration.DurationInt
import scala.util.{Failure, Success}
class UserActor(out: ActorRef,
userParentActor: ActorRef,
lobbiesActor: ActorRef) extends Actor with LazyLogging {
userParentActor: ActorRef) extends Actor with LazyLogging {
implicit val timeout: Timeout = 3.seconds
@@ -138,7 +137,7 @@ class UserActor(out: ActorRef,
})
case Some("createDecider") =>
lobbiesActor ! CreateLobby(name)
LobbiesActor.actor ! CreateLobby(name)
case Some("leaveDecider") =>
lobbieActor.foreach(lobby => lobby ! LeaveLobby)
@@ -163,12 +162,12 @@ class UserActor(out: ActorRef,
case Some("joinDecider") =>
val lobbyActorName = (json \ "lobbyActorName").as[String]
logger.info(s"Player ${self.path.name} join lobby $lobbyActorName")
lobbiesActor ! JoinLobbyByActorName(lobbyActorName, name)
LobbiesActor.actor ! JoinLobbyByActorName(lobbyActorName, name)
case Some("observerDecider") =>
val lobbyActorName = (json \ "lobbyActorName").as[String]
logger.info(s"Player ${self.path.name} observe lobby $lobbyActorName")
lobbiesActor ! ObserveLobbyByActorName(lobbyActorName)
LobbiesActor.actor ! ObserveLobbyByActorName(lobbyActorName)
case Some("banMap") =>
val map = (json \ "map").as[String]
@@ -176,7 +175,7 @@ class UserActor(out: ActorRef,
case Some("getLobbies") =>
logger.debug("Get all lobby request")
(lobbiesActor ? GetAllLobbies).mapTo[List[RefreshLobbyInfo]] onComplete {
(LobbiesActor.actor ? GetAllLobbies).mapTo[List[RefreshLobbyInfo]] onComplete {
case Success(lobbies) => {
logger.info(s"Received lobbies: $lobbies")
out ! Json.obj("type" -> "lobbies", "lobbies" -> lobbies.map(res => res.lobbyInfo))
@@ -198,8 +197,8 @@ class UserParentActor(actorSystem: ActorSystem) extends Actor with ActorLogging
import UserParentActor._
override def receive: Receive = LoggingReceive {
case Create(id, out, lobbiesActor) =>
val child: ActorRef = actorSystem.actorOf(Props(classOf[UserActor], out, self, lobbiesActor), s"userActor-$id")
case Create(id, out) =>
val child: ActorRef = actorSystem.actorOf(Props(classOf[UserActor], out, self), s"userActor-$id")
sender() ! child
case GetAllUsers =>
sender() ! context.children
@@ -209,7 +208,7 @@ class UserParentActor(actorSystem: ActorSystem) extends Actor with ActorLogging
object UserParentActor {
case class Create(id: String, out: ActorRef, lobbiesActor: ActorRef)
case class Create(id: String, out: ActorRef)
case object GetAllUsers