diff --git a/app/actors/LobbieActor.scala b/app/actors/LobbieActor.scala index 55805cb..3a8d22a 100644 --- a/app/actors/LobbieActor.scala +++ b/app/actors/LobbieActor.scala @@ -163,15 +163,6 @@ class LobbieActor(hostUser: LobbyUser, deciderName: String) extends Actor with L } users.foreach(_ ! RefreshLobbyInfo(getLobbyInfoResponse)) - case ChangeIsNecronSelected(isSelected) => - isNecrons = isSelected - if (isSelected) { - mapsLobby.foreach(map => if (map.map == "2p_meeting_of_minds" || map.map == "2p_shrine_of_excellion_[Rem]") map.isBanned = true) - } else { - mapsLobby.foreach(map => map.isBanned = false) - } - users.foreach(_ ! RefreshLobbyInfo(getLobbyInfoResponse)) - case KickSecondPlayer => if (sender() == host.actorRef) { secondPlayer.foreach(player => player.actorRef ! LobbyFatal("You were kicked from lobby!")) diff --git a/app/actors/UserActor.scala b/app/actors/UserActor.scala index 8b8c5df..fc2bfe9 100644 --- a/app/actors/UserActor.scala +++ b/app/actors/UserActor.scala @@ -13,10 +13,13 @@ import scala.concurrent.duration.DurationInt import scala.util.{Failure, Success} class UserActor(out: ActorRef, - userParentActor: ActorRef) extends Actor with LazyLogging { + userParentActor: ActorRef, + ip: String) extends Actor with LazyLogging { implicit val timeout: Timeout = 3.seconds + val ipAddress: String = ip + var lobbieActor: Option[ActorRef] = None implicit val mapJson: Writes[DeciderMap] = new Writes[DeciderMap] { @@ -42,7 +45,6 @@ class UserActor(out: ActorRef, "status" -> lobby.status, "playerTurn" -> lobby.playerTurn, "selectedType" -> lobby.selectedType, - "isNecrons" -> lobby.isNecrons, "maps" -> Json.toJson(lobby.maps) ) } @@ -62,7 +64,6 @@ class UserActor(out: ActorRef, "status" -> lobby.status, "playerTurn" -> lobby.playerTurn, "selectedType" -> lobby.selectedType, - "isNecrons" -> lobby.isNecrons, "maps" -> Json.toJson(lobby.maps) ))) } @@ -154,10 +155,6 @@ class UserActor(out: ActorRef, val lobbyType = (json \ "lobbyType").as[String] lobbieActor.foreach(lobby => lobby ! ChangeLobbyType(lobbyType)) - case Some("changeIsNecronSelected") => - val isNecronSelected = (json \ "isNecronSelected").as[Boolean] - lobbieActor.foreach(lobby => lobby ! ChangeIsNecronSelected(isNecronSelected)) - case Some("kickSecondPlayer") => lobbieActor.foreach(lobby => lobby ! KickSecondPlayer) @@ -210,10 +207,11 @@ class UserParentActor(actorSystem: ActorSystem) extends Actor with ActorLogging import UserParentActor._ override def receive: Receive = LoggingReceive { - case Create(id, out) => - val child: ActorRef = actorSystem.actorOf(Props(classOf[UserActor], out, self), s"userActor-$id") + case Create(id, ipAddress, out) => + val child: ActorRef = actorSystem.actorOf(Props(classOf[UserActor], out, self, ipAddress), s"userActor-$id") sender() ! child case GetAllUsers => + System.out.print("12123" + context.children) sender() ! context.children } } @@ -221,7 +219,7 @@ class UserParentActor(actorSystem: ActorSystem) extends Actor with ActorLogging object UserParentActor { - case class Create(id: String, out: ActorRef) + case class Create(id: String, ipAddress: String, out: ActorRef) case object GetAllUsers diff --git a/app/assets/images/maps/4p_chaos_platenau.jpg b/app/assets/images/maps/4p_chaos_platenau.jpg new file mode 100644 index 0000000..9fe119a Binary files /dev/null and b/app/assets/images/maps/4p_chaos_platenau.jpg differ diff --git a/app/assets/images/maps/4p_snowblind.jpg b/app/assets/images/maps/4p_snowblind.jpg new file mode 100644 index 0000000..90eeae8 Binary files /dev/null and b/app/assets/images/maps/4p_snowblind.jpg differ diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index 8b0a817..065b436 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -272,7 +272,7 @@ function renderRaces() { } if(raceCount >= 3){ - resHtml += "

Ban race

"; + resHtml += "

Third race

"; for(var i = 1; i <= 9; i++){ var selected = "raceNotSelected"; var banned = ""; @@ -281,7 +281,7 @@ function renderRaces() { banned = "bannedRace"; selectedThirdRace = i; } - resHtml += ' '; + resHtml += ' '; } resHtml += "
"; } @@ -327,12 +327,10 @@ function selectThirdRace(button, race){ $.cookie("race3", race, { expires: 1 }); _.each($(".thirdRaceIcon"), function (el){ $(el).removeClass("raceSelected"); - $(el).children('img').removeClass("bannedRace"); $(el).addClass("raceNotSelected"); }); $(button).removeClass("raceNotSelected"); $(button).addClass("raceSelected"); - $(button).children("img").addClass("bannedRace"); checkRaceSelectFinish(); } @@ -520,7 +518,7 @@ function renderPlayersAndStats(lobby) { "" + "" + "" + - /*"" +*/ + "" + ""; if(lobby.user1Info.name !== userName && lobby.user2Info.name !== userName){ diff --git a/app/controllers/AdminController.scala b/app/controllers/AdminController.scala index 50cbec3..60ef02b 100644 --- a/app/controllers/AdminController.scala +++ b/app/controllers/AdminController.scala @@ -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 = { diff --git a/app/controllers/HomeController.scala b/app/controllers/HomeController.scala index 512e092..300c67f 100644 --- a/app/controllers/HomeController.scala +++ b/app/controllers/HomeController.scala @@ -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 } diff --git a/app/views/index.scala.html b/app/views/index.scala.html index f2d0092..2e357a1 100644 --- a/app/views/index.scala.html +++ b/app/views/index.scala.html @@ -20,7 +20,7 @@ - +