diff --git a/app/actors/LobbieActor.scala b/app/actors/LobbieActor.scala
index 564fd5f..004024b 100644
--- a/app/actors/LobbieActor.scala
+++ b/app/actors/LobbieActor.scala
@@ -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}")
diff --git a/app/actors/LobbiesActor.scala b/app/actors/LobbiesActor.scala
index 388ba75..327083d 100644
--- a/app/actors/LobbiesActor.scala
+++ b/app/actors/LobbiesActor.scala
@@ -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
\ No newline at end of file
+case object UnWatchAllLobbies
+
+object LobbiesActor {
+ implicit val actorSystem: ActorSystem = ActorSystem()
+ val actor: ActorRef = actorSystem.actorOf(Props[LobbiesActor]())
+}
diff --git a/app/actors/UserActor.scala b/app/actors/UserActor.scala
index 1b0916a..dd2cf8f 100644
--- a/app/actors/UserActor.scala
+++ b/app/actors/UserActor.scala
@@ -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
diff --git a/app/assets/images/maps/2p_faceoff.jpg b/app/assets/images/maps/2p_faceoff.jpg
index 3ade6f4..3d86069 100644
Binary files a/app/assets/images/maps/2p_faceoff.jpg and b/app/assets/images/maps/2p_faceoff.jpg differ
diff --git a/app/assets/images/maps/allMaps.json b/app/assets/images/maps/allMaps.json
index 87a57f7..474a7cd 100644
--- a/app/assets/images/maps/allMaps.json
+++ b/app/assets/images/maps/allMaps.json
@@ -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)",
diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js
index 98850bc..51bfdf2 100644
--- a/app/assets/javascripts/index.js
+++ b/app/assets/javascripts/index.js
@@ -45,8 +45,8 @@ window.onload = function() {
'';
return memo + '
\n' +
- ' | '+ lobby.user1Info.name +' | \n' +
- ' '+ lobby.user2Info.name +' | \n' +
+ ' '+ lobby.user1Info.name.substring(0, 20) +' | \n' +
+ ' '+ lobby.user2Info.name.substring(0, 20) +' | \n' +
' '+ lobby.status +' | \n' +
' ' + joinButton + ' ' + observerButton +
' | ' +
@@ -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);
}
diff --git a/app/controllers/AdminController.scala b/app/controllers/AdminController.scala
new file mode 100644
index 0000000..e8d39ce
--- /dev/null
+++ b/app/controllers/AdminController.scala
@@ -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")
+ }
+
+
+
+}
diff --git a/app/controllers/HomeController.scala b/app/controllers/HomeController.scala
index fef46c3..16bdb8c 100644
--- a/app/controllers/HomeController.scala
+++ b/app/controllers/HomeController.scala
@@ -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
}
diff --git a/app/views/admin.scala.html b/app/views/admin.scala.html
new file mode 100644
index 0000000..f681e07
--- /dev/null
+++ b/app/views/admin.scala.html
@@ -0,0 +1,6 @@
+@()(implicit r: Request[_])
+
+
+
+
+
diff --git a/app/views/index.scala.html b/app/views/index.scala.html
index 1e82942..4fe3f7b 100644
--- a/app/views/index.scala.html
+++ b/app/views/index.scala.html
@@ -3,7 +3,7 @@
- Second Autumn Cup decider
+ Soulstorm tournament decider
@@ -13,7 +13,7 @@
-
+
diff --git a/conf/application.conf b/conf/application.conf
index 7f4eaa7..9ee6c66 100644
--- a/conf/application.conf
+++ b/conf/application.conf
@@ -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"]
diff --git a/conf/logback.xml b/conf/logback.xml
index 970fc68..b7c6b18 100644
--- a/conf/logback.xml
+++ b/conf/logback.xml
@@ -2,10 +2,18 @@
+
- logs/application.log
+
+
+ ${LOG_FILE}.%d{yyyy-MM-dd}.gz
+
+
+ 30
+ 3GB
+
- %date [%level] from %logger in %thread - %message%n%xException
+ %-4relative [%thread] %-5level %logger{35} - %msg%n
diff --git a/conf/routes b/conf/routes
index f0442d1..b8c5df2 100644
--- a/conf/routes
+++ b/conf/routes
@@ -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)