diff --git a/project.xml b/project.xml
index 63a896c..13e48ff 100755
--- a/project.xml
+++ b/project.xml
@@ -9,13 +9,13 @@
-
-
-
+
-
+
+
+
\ No newline at end of file
diff --git a/server.hxml b/server.hxml
index e2720f0..5b5c8d2 100755
--- a/server.hxml
+++ b/server.hxml
@@ -6,4 +6,4 @@
-cp src/server/haxe
-cp src-gen/haxe
-neko target/server.n
--D proto_debug
\ No newline at end of file
+# -D proto_debug
\ No newline at end of file
diff --git a/src/client/haxe/ru/m/tankz/view/frames/GameListFrame.hx b/src/client/haxe/ru/m/tankz/view/frames/GameListFrame.hx
index d57bb33..ca877c8 100755
--- a/src/client/haxe/ru/m/tankz/view/frames/GameListFrame.hx
+++ b/src/client/haxe/ru/m/tankz/view/frames/GameListFrame.hx
@@ -1,5 +1,7 @@
package ru.m.tankz.view.frames;
+import ru.m.tankz.proto.GamesUnSubscribeRequest;
+import ru.m.tankz.proto.GamesSubscribeRequest;
import haxework.gui.ViewBuilder;
import ru.m.tankz.proto.JoinGameResponse;
import ru.m.tankz.proto.JoinGameRequest;
@@ -9,14 +11,12 @@ import haxework.gui.frame.IFrameSwitcher;
import haxework.gui.ButtonView;
import haxework.gui.LabelView;
import ru.m.tankz.proto.GamesResponse;
-import ru.m.tankz.proto.GamesRequest;
import ru.m.tankz.proto.Game;
import haxework.gui.list.ListView;
import protohx.Message;
import ru.m.core.connect.IConnection;
import ru.m.tankz.data.GameData;
import haxework.provider.Provider;
-import haxework.gui.list.VListView;
import haxework.gui.VGroupView;
@:template("layout/frames/game_list.json", "layout/styles.json")
@@ -35,10 +35,11 @@ class GameListFrame extends VGroupView implements ViewBuilder implements IPacket
public function onShow() {
findViewById("name", LabelView).text = Provider.get(GameData).person.name;
Provider.get(IConnection).packetHandler.addListener(this);
- Provider.get(IConnection).send(new GamesRequest());
+ Provider.get(IConnection).send(new GamesSubscribeRequest());
}
public function onHide() {
+ Provider.get(IConnection).send(new GamesUnSubscribeRequest());
Provider.get(IConnection).packetHandler.removeListener(this);
}
diff --git a/src/client/haxe/ru/m/tankz/view/frames/GameReadyFrame.hx b/src/client/haxe/ru/m/tankz/view/frames/GameReadyFrame.hx
index 6c46db4..e722ac3 100755
--- a/src/client/haxe/ru/m/tankz/view/frames/GameReadyFrame.hx
+++ b/src/client/haxe/ru/m/tankz/view/frames/GameReadyFrame.hx
@@ -1,19 +1,15 @@
package ru.m.tankz.view.frames;
+import ru.m.tankz.proto.LeaveGameRequest;
import ru.m.tankz.proto.LeaveGameResponse;
import ru.m.tankz.proto.JoinGameResponse;
import haxework.gui.ViewBuilder;
-import ru.m.tankz.proto.ExitGameResponse;
import haxework.gui.frame.IFrameSwitcher;
-import ru.m.tankz.proto.GamesResponse;
-import ru.m.tankz.proto.ExitGameRequest;
import ru.m.tankz.proto.StartGameResponse;
import ru.m.tankz.proto.StartGameRequest;
import ru.m.tankz.data.GameData;
import protohx.Message;
import haxework.gui.ButtonView;
-import haxework.gui.list.VListView;
-import ru.m.tankz.proto.Person;
import haxework.provider.Provider;
import haxework.gui.VGroupView;
import ru.m.core.connect.IConnection;
@@ -53,11 +49,11 @@ class GameReadyFrame extends VGroupView implements ViewBuilder implements IPacke
public function onLeaveGameResponse(packet:LeaveGameResponse):Void {
Provider.get(GameData).game = packet.game;
list.data = Provider.get(GameData).game.persons;
- }
-
- public function onExitGameResponse(packet:ExitGameResponse):Void {
- Provider.get(GameData).game = null;
- Provider.get(IFrameSwitcher).change(GameListFrame.ID);
+ var person = Provider.get(GameData).person;
+ if (!Lambda.exists(packet.game.persons, function(person) return person.id == person.id)) {
+ Provider.get(GameData).game = null;
+ Provider.get(IFrameSwitcher).change(GameListFrame.ID);
+ }
}
public function onPacket(packet:Message):Void {}
@@ -67,7 +63,7 @@ class GameReadyFrame extends VGroupView implements ViewBuilder implements IPacke
case "start":
Provider.get(IConnection).send(new StartGameRequest());
case "exit":
- Provider.get(IConnection).send(new ExitGameRequest());
+ Provider.get(IConnection).send(new LeaveGameRequest());
}
}
}
diff --git a/src/client/webapp/index_template.html b/src/client/webapp/index_template.html
new file mode 100644
index 0000000..4be61ac
--- /dev/null
+++ b/src/client/webapp/index_template.html
@@ -0,0 +1,51 @@
+
+
+
+
+
+
+
+ ::APP_TITLE::
+
+
+
+
+ ::if linkedLibraries::::foreach (linkedLibraries)::
+ ::end::::end::
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/common/haxe/ru/m/tankz/PacketBuilder.hx b/src/common/haxe/ru/m/tankz/PacketBuilder.hx
index 9ef9791..b344478 100755
--- a/src/common/haxe/ru/m/tankz/PacketBuilder.hx
+++ b/src/common/haxe/ru/m/tankz/PacketBuilder.hx
@@ -1,5 +1,7 @@
package ru.m.tankz;
+import ru.m.tankz.proto.LeaveGameRequest;
+import ru.m.tankz.proto.LeaveGameResponse;
import ru.m.tankz.proto.GameUpdateResponse;
import ru.m.tankz.proto.GameActionRequest;
import ru.m.core.connect.IConnection;
@@ -9,7 +11,8 @@ import ru.m.tankz.proto.LoginResponse;
import ru.m.tankz.proto.PersonSelectRequest;
import ru.m.tankz.proto.PersonSelectResponse;
import ru.m.tankz.proto.ErrorResponse;
-import ru.m.tankz.proto.GamesRequest;
+import ru.m.tankz.proto.GamesSubscribeRequest;
+import ru.m.tankz.proto.GamesUnSubscribeRequest;
import ru.m.tankz.proto.GamesResponse;
import ru.m.tankz.proto.CreateGameRequest;
import ru.m.tankz.proto.CreateGameResponse;
@@ -17,8 +20,6 @@ import ru.m.tankz.proto.JoinGameRequest;
import ru.m.tankz.proto.JoinGameResponse;
import ru.m.tankz.proto.StartGameRequest;
import ru.m.tankz.proto.StartGameResponse;
-import ru.m.tankz.proto.ExitGameRequest;
-import ru.m.tankz.proto.ExitGameResponse;
class PacketBuilder implements IPacketBuilder {
@@ -33,7 +34,7 @@ class PacketBuilder implements IPacketBuilder {
0x0004 => PersonSelectResponse
],
0x02 => [
- 0x0001 => GamesRequest,
+ 0x0001 => GamesSubscribeRequest,
0x0002 => GamesResponse,
0x0003 => CreateGameRequest,
0x0004 => CreateGameResponse,
@@ -41,8 +42,9 @@ class PacketBuilder implements IPacketBuilder {
0x0006 => JoinGameResponse,
0x0007 => StartGameRequest,
0x0008 => StartGameResponse,
- 0x0009 => ExitGameRequest,
- 0x000a => ExitGameResponse
+ 0x0009 => LeaveGameRequest,
+ 0x000a => LeaveGameResponse,
+ 0x000b => GamesUnSubscribeRequest
],
0x03 => [
0x0001 => GameActionRequest,
diff --git a/src/common/haxe/ru/m/tankz/core/Tank.hx b/src/common/haxe/ru/m/tankz/core/Tank.hx
index 93ca9a2..f000253 100755
--- a/src/common/haxe/ru/m/tankz/core/Tank.hx
+++ b/src/common/haxe/ru/m/tankz/core/Tank.hx
@@ -11,7 +11,7 @@ class Tank extends MobileEntity {
public var bulletsCount:Int = 0;
- public function new(personId:Int, id:Int, x:Float, y:Float, direction:Directiondo apt-g) {
+ public function new(personId:Int, id:Int, x:Float, y:Float, direction:Direction) {
super(id, x, y, 4, direction);
this.personId = personId;
width = 34;
diff --git a/src/common/proto/base.proto b/src/common/proto/base.proto
index 93a46ca..97e19e2 100755
--- a/src/common/proto/base.proto
+++ b/src/common/proto/base.proto
@@ -47,7 +47,11 @@ message Game {
required GameState state = 4;
}
-message GamesRequest {
+message GamesSubscribeRequest {
+
+}
+
+message GamesUnSubscribeRequest {
}
@@ -72,7 +76,7 @@ message JoinGameResponse {
}
message LeaveGameRequest {
- required int32 game_id = 1;
+
}
message LeaveGameResponse {
@@ -87,14 +91,6 @@ message StartGameResponse {
required Game game = 1;
}
-message ExitGameRequest {
-
-}
-
-message ExitGameResponse {
-
-}
-
/**
Game
*/
diff --git a/src/server/haxe/ru/m/tankz/server/game/GameManager.hx b/src/server/haxe/ru/m/tankz/server/game/GameManager.hx
index 627c5af..36b21a8 100644
--- a/src/server/haxe/ru/m/tankz/server/game/GameManager.hx
+++ b/src/server/haxe/ru/m/tankz/server/game/GameManager.hx
@@ -1,8 +1,8 @@
package ru.m.tankz.server.game;
+import ru.m.tankz.proto.GamesResponse;
import ru.m.tankz.proto.GameActionType;
import ru.m.tankz.proto.GameActionRequest;
-import ru.m.tankz.proto.ExitGameResponse;
import ru.m.tankz.proto.GameObjectType;
import ru.m.tankz.proto.GameChangeType;
import ru.m.tankz.proto.GameUpdateResponse;
@@ -59,6 +59,7 @@ class GameManager {
public static var byGameId:Map = new Map();
public static var byPersonId:Map = new Map();
+ public static var subscribers:Map = new Map();
private static var idCounter:Int = 0;
@@ -79,6 +80,19 @@ class GameManager {
byGameId.set(game.id, this);
byPersonId.set(person.id, this);
broadcast(new CreateGameResponse().setGame(game));
+ broadcastGames();
+ }
+
+ public static function getReadyGames():Array {
+ return Lambda.array(Lambda.filter(Lambda.map(GameManager.byGameId, function(gm) return gm.game), function(game) return game.state == GameState.READY));
+ }
+
+ public function broadcastGames() {
+ var packet = new GamesResponse().setGames(getReadyGames());
+ for (personId in subscribers.keys()) {
+ var session = Session.sessions.get(personId);
+ session.send(packet);
+ }
}
public function broadcast(packet:Message) {
@@ -97,10 +111,12 @@ class GameManager {
public function leave(person:Person) {
game.setPersons(game.persons.filter(function(p) return p.id != person.id));
byPersonId.remove(person.id);
+ var packet = new LeaveGameResponse().setGame(game);
+ Session.sessions.get(person.id).send(packet);
if (game.persons.length == 0/* || person.id == game.creator.id*/) {
stop();
} else {
- broadcast(new LeaveGameResponse().setGame(game));
+ broadcast(packet);
}
}
@@ -117,13 +133,15 @@ class GameManager {
public function stop() {
game.setState(GameState.ENDED);
+ game.setPersons([]);
byGameId.remove(game.id);
for (p in game.persons) byPersonId.remove(p.id);
if (timer != null) {
timer.stop();
timer = null;
}
- broadcast(new ExitGameResponse());
+ broadcast(new LeaveGameResponse().setGame(game));
+ broadcastGames();
}
public function action(person:Person, action:GameActionRequest) {
diff --git a/src/server/haxe/ru/m/tankz/server/session/Session.hx b/src/server/haxe/ru/m/tankz/server/session/Session.hx
index 5d14e07..ea15c10 100755
--- a/src/server/haxe/ru/m/tankz/server/session/Session.hx
+++ b/src/server/haxe/ru/m/tankz/server/session/Session.hx
@@ -1,27 +1,13 @@
package ru.m.tankz.server.session;
+import ru.m.tankz.proto.GamesUnSubscribeRequest;
+import ru.m.tankz.proto.GamesSubscribeRequest;
+import ru.m.tankz.proto.LeaveGameRequest;
import ru.m.tankz.server.game.GameManager;
-import ru.m.tankz.proto.GameObjectType;
-import ru.m.tankz.proto.GameChangeType;
-import ru.m.tankz.proto.GameChange;
-import ru.m.tankz.config.TankzConfig.DEFAULT;
-import ru.m.tankz.proto.GameUpdateResponse;
-import haxe.Timer;
-import ru.m.tankz.core.Direction;
-import ru.m.tankz.engine.Engine;
-import ru.m.tankz.engine.IEngine;
-import ru.m.tankz.proto.GameActionType;
import ru.m.tankz.proto.GameActionRequest;
-import ru.m.tankz.proto.ExitGameResponse;
-import ru.m.tankz.proto.ExitGameRequest;
import ru.m.tankz.proto.StartGameRequest;
-import ru.m.tankz.proto.StartGameResponse;
-import ru.m.tankz.proto.GameState;
import ru.m.tankz.proto.Person;
-import ru.m.tankz.proto.JoinGameResponse;
import ru.m.tankz.proto.JoinGameRequest;
-import ru.m.tankz.proto.Game;
-import ru.m.tankz.proto.CreateGameResponse;
import ru.m.tankz.proto.CreateGameRequest;
import ru.m.core.connect.neko.NekoWebConnection;
import haxe.io.Bytes;
@@ -33,7 +19,6 @@ import ru.m.tankz.proto.ErrorResponse;
import ru.m.tankz.server.db.DbProvider;
import ru.m.tankz.proto.LoginResponse;
import ru.m.tankz.proto.LoginRequest;
-import ru.m.tankz.proto.GamesRequest;
import ru.m.tankz.proto.GamesResponse;
import protohx.Message;
import ru.m.core.connect.IConnection;
@@ -122,9 +107,13 @@ class Session implements IConnectionHandler implements IPacketHandler {
}
}
- public function onGamesRequest(packet:GamesRequest):Void {
- var games = Lambda.array(Lambda.map(GameManager.byGameId, function(gm) return gm.game));
- connection.send(new GamesResponse().setGames(games));
+ public function onGamesSubscribeRequest(packet:GamesSubscribeRequest):Void {
+ GameManager.subscribers.set(person.id, true);
+ connection.send(new GamesResponse().setGames(GameManager.getReadyGames()));
+ }
+
+ public function onGamesUnSubscribeRequest(packet:GamesUnSubscribeRequest):Void {
+ GameManager.subscribers.remove(person.id);
}
public function onCreateGameRequest(packet:CreateGameRequest):Void {
@@ -135,12 +124,12 @@ class Session implements IConnectionHandler implements IPacketHandler {
GameManager.byGameId.get(packet.gameId).join(person);
}
- public function onStartGameRequest(packet:StartGameRequest):Void {
- GameManager.byPersonId.get(person.id).start();
+ public function onLeaveGameRequest(packet:LeaveGameRequest):Void {
+ GameManager.byPersonId.get(person.id).leave(person);
}
- public function onExitGameRequest(packet:ExitGameRequest):Void {
- GameManager.byPersonId.get(person.id).leave(person);
+ public function onStartGameRequest(packet:StartGameRequest):Void {
+ GameManager.byPersonId.get(person.id).start();
}
public function onGameActionRequest(packet:GameActionRequest):Void {