2 new map, fix map name 4+ players

This commit is contained in:
v.holodov
2022-10-05 23:22:08 +03:00
parent d3e90fb01e
commit 750ea483b6
10 changed files with 146 additions and 68 deletions
+12 -4
View File
@@ -1,5 +1,6 @@
package controllers
import actors.UserParentActor.GetAllUsers
import actors._
import akka.NotUsed
import akka.actor._
@@ -9,30 +10,37 @@ import akka.stream._
import akka.stream.scaladsl._
import akka.util.Timeout
import com.typesafe.config.ConfigFactory
import javax.inject._
import org.reactivestreams.Publisher
import play.api.libs.json._
import play.api.mvc._
import scala.concurrent.duration._
import scala.concurrent.{ExecutionContext, Future}
import scala.concurrent.{Await, ExecutionContext, Future}
/**
* This class creates the actions and the websocket needed.
*/
@Singleton
class AdminController @Inject()(cc: ControllerComponents) extends AbstractController(cc) {
class AdminController @Inject()(cc: ControllerComponents, homeController: HomeController) extends AbstractController(cc) {
implicit val actorSystem: ActorSystem = ActorSystem()
implicit val ec: ExecutionContext = defaultExecutionContext
implicit val timeout = Timeout(100.millis)
// Use a direct reference to SLF4J
private val logger = org.slf4j.LoggerFactory.getLogger("controllers.HomeController")
val userParentActor: ActorRef = homeController.userParentActor
// Home page that renders template
def viewAllLobbies() = Action { implicit request =>
def viewAllUsers() = Action { implicit request =>
logger.info(s"Received request from: ${request.remoteAddress}")
Ok(views.html.admin())
val allUsers = userParentActor ? GetAllUsers
val res = Await.result(allUsers, Duration.Inf)
Ok(res.toString)
}
def banLobby(lobbyActorName: String): Unit = {
+3 -3
View File
@@ -112,7 +112,7 @@ class HomeController @Inject()(cc: ControllerComponents) extends AbstractControl
val (webSocketOut: ActorRef, webSocketIn: Publisher[JsValue]) = createWebSocketConnections()
// Create a user actor off the request id and attach it to the source
val userActorFuture = createUserActor(request.id.toString, webSocketOut)
val userActorFuture = createUserActor(request.id.toString, request.remoteAddress, webSocketOut)
// Once we have an actor available, create a flow...
userActorFuture.map { userActor =>
@@ -190,11 +190,11 @@ class HomeController @Inject()(cc: ControllerComponents) extends AbstractControl
* @param webSocketOut the "write" side of the websocket, that the user actor sends JsValue to.
* @return a user actor for this ws connection.
*/
private def createUserActor(name: String, webSocketOut: ActorRef): Future[ActorRef] = {
private def createUserActor(name: String, remoteAddress: String, webSocketOut: ActorRef): Future[ActorRef] = {
// Use guice assisted injection to instantiate and configure the child actor.
val userActorFuture = {
implicit val timeout = Timeout(100.millis)
(userParentActor ? UserParentActor.Create(name, webSocketOut)).mapTo[ActorRef]
(userParentActor ? UserParentActor.Create(name, remoteAddress, webSocketOut)).mapTo[ActorRef]
}
userActorFuture
}