Admin controller draft
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
package controllers
|
||||
|
||||
import actors._
|
||||
import akka.NotUsed
|
||||
import akka.actor._
|
||||
import akka.event.Logging
|
||||
import akka.pattern.ask
|
||||
import akka.stream._
|
||||
import akka.stream.scaladsl._
|
||||
import akka.util.Timeout
|
||||
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}
|
||||
|
||||
/**
|
||||
* This class creates the actions and the websocket needed.
|
||||
*/
|
||||
@Singleton
|
||||
class AdminController @Inject()(cc: ControllerComponents) extends AbstractController(cc) {
|
||||
|
||||
implicit val actorSystem: ActorSystem = ActorSystem()
|
||||
implicit val ec: ExecutionContext = defaultExecutionContext
|
||||
|
||||
// Use a direct reference to SLF4J
|
||||
private val logger = org.slf4j.LoggerFactory.getLogger("controllers.HomeController")
|
||||
|
||||
val lobbiesActror: ActorRef = actorSystem.actorOf(Props[LobbiesActor]())
|
||||
val userParentActor: ActorRef = actorSystem.actorOf(Props(classOf[UserParentActor], actorSystem))
|
||||
|
||||
// Home page that renders template
|
||||
def viewAllLobbies() = Action { implicit request =>
|
||||
logger.info(s"Received request from: ${request.remoteAddress}")
|
||||
Ok(views.html.admin())
|
||||
}
|
||||
|
||||
def banLobby(lobbyActorName: String): Unit = {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the value of the Origin header contains an acceptable value.
|
||||
*/
|
||||
def originMatches(origin: String): Boolean = {
|
||||
origin.contains("139.59.210.74") || origin.contains("localhost") || origin.contains("localhost:9000") || origin.contains("localhost:19001")
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -28,11 +28,12 @@ class HomeController @Inject()(cc: ControllerComponents) extends AbstractControl
|
||||
// Use a direct reference to SLF4J
|
||||
private val logger = org.slf4j.LoggerFactory.getLogger("controllers.HomeController")
|
||||
|
||||
val lobbiesActror: ActorRef = actorSystem.actorOf(Props[LobbiesActor]())
|
||||
|
||||
val userParentActor: ActorRef = actorSystem.actorOf(Props(classOf[UserParentActor], actorSystem))
|
||||
|
||||
// Home page that renders template
|
||||
def index() = Action { implicit request =>
|
||||
logger.info(s"Received request from: ${request.remoteAddress}")
|
||||
Ok(views.html.index())
|
||||
}
|
||||
|
||||
@@ -161,7 +162,7 @@ class HomeController @Inject()(cc: ControllerComponents) extends AbstractControl
|
||||
val flowWatch: Flow[JsValue, JsValue, NotUsed] = flow.watchTermination() { (_, termination) =>
|
||||
termination.foreach { done =>
|
||||
logger.info(s"Terminating actor $userActor")
|
||||
lobbiesActror.tell(UnWatchAllLobbies, userActor)
|
||||
LobbiesActor.actor.tell(UnWatchAllLobbies, userActor)
|
||||
actorSystem.stop(userActor)
|
||||
}
|
||||
NotUsed
|
||||
@@ -181,7 +182,7 @@ class HomeController @Inject()(cc: ControllerComponents) extends AbstractControl
|
||||
// Use guice assisted injection to instantiate and configure the child actor.
|
||||
val userActorFuture = {
|
||||
implicit val timeout = Timeout(100.millis)
|
||||
(userParentActor ? UserParentActor.Create(name, webSocketOut, lobbiesActror)).mapTo[ActorRef]
|
||||
(userParentActor ? UserParentActor.Create(name, webSocketOut)).mapTo[ActorRef]
|
||||
}
|
||||
userActorFuture
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user