Admin controller draft
This commit is contained in:
parent
23f566af51
commit
e702bd61b4
@ -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
|
||||
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 46 KiB |
@ -54,6 +54,7 @@
|
||||
"2p_velvet_duress": "Velvet Duress (2)",
|
||||
"2p_fraziersdemise": "Fraziers Demise (2)",
|
||||
"2p_vortex_plateau": "Vortex Plateau (2)",
|
||||
"2p_chaos_gate": "Chaos gate (2)",
|
||||
"2p_valley_of_khorne": "Valley of Khorne (2)",
|
||||
"2p_tiboraxx":"Tiboraxx (2)",
|
||||
"3p_fortress": "Fortress (3)",
|
||||
|
||||
@ -45,8 +45,8 @@ window.onload = function() {
|
||||
'</button>';
|
||||
|
||||
return memo + '<tr>\n' +
|
||||
' <td>'+ lobby.user1Info.name +'</td>\n' +
|
||||
' <td>'+ lobby.user2Info.name +'</td>\n' +
|
||||
' <td>'+ lobby.user1Info.name.substring(0, 20) +'</td>\n' +
|
||||
' <td>'+ lobby.user2Info.name.substring(0, 20) +'</td>\n' +
|
||||
' <td>'+ lobby.status +'</td>\n' +
|
||||
' <td>' + joinButton + ' ' + observerButton +
|
||||
' </td>' +
|
||||
@ -81,13 +81,6 @@ window.onload = function() {
|
||||
}));
|
||||
});
|
||||
|
||||
$("#updateDecider").click(function(event) {
|
||||
event.preventDefault();
|
||||
ws.send(JSON.stringify({
|
||||
type: "updateDecider"
|
||||
}));
|
||||
});
|
||||
|
||||
$("#submitmsg").click(function(event) {
|
||||
sendMessage();
|
||||
});
|
||||
@ -105,6 +98,7 @@ window.onload = function() {
|
||||
}));
|
||||
$("#decider").hide();
|
||||
$("#lobbies").show();
|
||||
$(".navbar").show();
|
||||
});
|
||||
|
||||
if($.cookie('user')=== undefined){
|
||||
@ -157,9 +151,12 @@ window.onload = function() {
|
||||
type: "userName",
|
||||
name: $.cookie('user')
|
||||
}));
|
||||
ws.send(JSON.stringify({
|
||||
type: "getLobbies"
|
||||
}));
|
||||
}
|
||||
|
||||
let timerId = setInterval(() =>
|
||||
var timerId = setInterval(() =>
|
||||
ws.send(JSON.stringify({
|
||||
type: "getLobbies"
|
||||
})), 2000);
|
||||
@ -168,6 +165,7 @@ window.onload = function() {
|
||||
function changeNick() {
|
||||
result = prompt("Введите ник", $.cookie('user'));
|
||||
if(result == null) return;
|
||||
result = result.substr(0, 20);
|
||||
$.cookie('user', result, { expires: 7 });
|
||||
ws.send(JSON.stringify({
|
||||
type: "userName",
|
||||
@ -195,6 +193,9 @@ function disconnectLobby(error) {
|
||||
$("#decider").hide();
|
||||
$(".navbar").show();
|
||||
$("#lobbies").show();
|
||||
ws.send(JSON.stringify({
|
||||
type: "getLobbies"
|
||||
}));
|
||||
alert(error);
|
||||
}
|
||||
|
||||
|
||||
54
app/controllers/AdminController.scala
Normal file
54
app/controllers/AdminController.scala
Normal file
@ -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
|
||||
}
|
||||
|
||||
6
app/views/admin.scala.html
Normal file
6
app/views/admin.scala.html
Normal file
@ -0,0 +1,6 @@
|
||||
@()(implicit r: Request[_])
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
|
||||
</html>
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Second Autumn Cup decider</title>
|
||||
<title>Soulstorm tournament decider</title>
|
||||
<link rel='stylesheet' href='@routes.Assets.at("lib/bootstrap/css/bootstrap.min.css")'>
|
||||
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")">
|
||||
<link rel="shortcut icon" type="image/png" href="@routes.Assets.at("images/favicon.png")">
|
||||
@ -13,7 +13,7 @@
|
||||
<script type='text/javascript' src='@routes.Assets.at("lib/backbonejs/backbone.js")'></script>
|
||||
<script type="text/javascript" src="@routes.Assets.at("lib/jquery-cookie/jquery.cookie.js")"></script>
|
||||
|
||||
<script type='text/javascript' src='@routes.Assets.at("javascripts/index.js")'></script>
|
||||
<script type='text/javascript' src='@routes.Assets.at("javascripts/index.js?020121")'></script>
|
||||
</head>
|
||||
<body data-ws-url="@routes.HomeController.ws.webSocketURL()">
|
||||
<div class="navbar navbar-inverse navbar-fixed-top">
|
||||
|
||||
@ -5,5 +5,5 @@ play.filters.hosts {
|
||||
allowed = ["localhost:9000", "localhost", "139.59.210.74"]
|
||||
}
|
||||
|
||||
maps = ["2p_battle_marshes", "2p_fallen_city", "2p_fata_morgana_[Rem]", "2p_meeting_of_minds", "2p_outer_reaches", "2p_quests_triumph", "2p_shrine_of_excellion_[Rem]", "2p_titan_fall_[Rem]", "2p_tranquilitys_end_[rem]", "2p_blood_river_[Rem]", "2p_emerald_river", "2p_deadly_fun_archeology", "2p_fraziersdemise"]
|
||||
maps = ["2p_battle_marshes", "2p_fallen_city", "2p_fata_morgana_[Rem]", "2p_meeting_of_minds", "2p_deadly_fun_archeology", "2p_quests_triumph", "2p_shrine_of_excellion_[Rem]", "2p_titan_fall_[Rem]", "2p_tranquilitys_end_[rem]", "2p_blood_river_[Rem]", "2p_sugaroasis", "2p_emerald_river", "2p_fraziersdemise", "2p_vortex_plateau", "2p_chaos_gate"]
|
||||
|
||||
|
||||
@ -2,10 +2,18 @@
|
||||
|
||||
<conversionRule conversionWord="coloredLevel" converterClass="play.api.libs.logback.ColoredLevel"/>
|
||||
|
||||
<property name="LOG_FILE" value="logs\decider-log" />
|
||||
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
|
||||
<file>logs/application.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<!-- daily rollover -->
|
||||
<fileNamePattern>${LOG_FILE}.%d{yyyy-MM-dd}.gz</fileNamePattern>
|
||||
|
||||
<!-- keep 30 days' worth of history capped at 3GB total size -->
|
||||
<maxHistory>30</maxHistory>
|
||||
<totalSizeCap>3GB</totalSizeCap>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>%date [%level] from %logger in %thread - %message%n%xException</pattern>
|
||||
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
|
||||
@ -2,8 +2,10 @@
|
||||
# This file defines all application routes (Higher priority routes first)
|
||||
# ~~~~
|
||||
|
||||
GET / controllers.HomeController.index
|
||||
GET /ws controllers.HomeController.ws
|
||||
GET / controllers.HomeController.index
|
||||
GET /ws controllers.HomeController.ws
|
||||
|
||||
GET /lobbyadmin controllers.AdminController.viewAllLobbies
|
||||
|
||||
# Map static resources from the /public folder to the /assets URL path
|
||||
GET /assets/*file controllers.Assets.at(path="/public", file)
|
||||
GET /assets/*file controllers.Assets.at(path="/public", file)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user