Admin controller draft
This commit is contained in:
@@ -172,9 +172,14 @@ class LobbieActor(hostUser: LobbyUser) extends Actor with LazyLogging {
|
||||
users.foreach(_ ! HostLeaveLobby)
|
||||
context.stop(self)
|
||||
}else if(secondPlayer.exists(_.actorRef == sender())){
|
||||
users.foreach(_ ! SecondPlayerLeaveLobby)
|
||||
secondPlayerReady = false
|
||||
secondPlayer = None
|
||||
context.stop(self)
|
||||
if(status == Draft()){
|
||||
users.foreach(_ ! SecondPlayerLeaveLobby)
|
||||
context.stop(self)
|
||||
}else {
|
||||
users.foreach(_ ! RefreshLobbyInfo(getLobbyInfoResponse))
|
||||
}
|
||||
}
|
||||
if (users.isEmpty) {
|
||||
logger.info(s"Stop lobby ${self.path.name}")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package actors
|
||||
|
||||
import akka.actor.{Actor, ActorLogging, Props}
|
||||
import akka.actor.{Actor, ActorLogging, ActorRef, ActorSystem, Props}
|
||||
import akka.event.LoggingReceive
|
||||
import akka.pattern.ask
|
||||
import akka.util.Timeout
|
||||
@@ -20,8 +20,8 @@ class LobbiesActor extends Actor with LazyLogging {
|
||||
case CreateLobby(hostName) =>
|
||||
val hostActorRef = sender
|
||||
logger.info(s"Player ${hostActorRef.path.name} create lobby.")
|
||||
val lobbyActor = context.actorOf(Props(new LobbieActor(LobbyUser(hostName,hostActorRef))),
|
||||
s"lobbyActor-${(math.random*100000000L).toLong}")
|
||||
val lobbyActor = context.actorOf(Props(new LobbieActor(LobbyUser(hostName, hostActorRef))),
|
||||
s"lobbyActor-${(math.random * 100000000L).toLong}")
|
||||
lobbyActor.tell(WatchLobby("watchIt"), hostActorRef)
|
||||
case JoinLobbyByActorName(lobbyName, userName) =>
|
||||
// get or create the StockActor for the symbol and forward this message
|
||||
@@ -44,7 +44,7 @@ class LobbiesActor extends Actor with LazyLogging {
|
||||
case None => logger.error(s"Can't watch lobby $lobbyName - lobby not exists")
|
||||
}
|
||||
case UnWatchAllLobbies =>
|
||||
context.children.foreach( _.tell(LeaveLobby, sender))
|
||||
context.children.foreach(_.tell(LeaveLobby, sender))
|
||||
case GetAllLobbies =>
|
||||
sender ! context.children.toList.map(lobbyActor =>
|
||||
Await.result(lobbyActor ? InfoQuery, 1.second))
|
||||
@@ -59,4 +59,9 @@ case class JoinLobbyByActorName(actorName: String, userName: String)
|
||||
|
||||
case class ObserveLobbyByActorName(actorName: String)
|
||||
|
||||
case object UnWatchAllLobbies
|
||||
case object UnWatchAllLobbies
|
||||
|
||||
object LobbiesActor {
|
||||
implicit val actorSystem: ActorSystem = ActorSystem()
|
||||
val actor: ActorRef = actorSystem.actorOf(Props[LobbiesActor]())
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user