[server] update
This commit is contained in:
@@ -79,6 +79,9 @@ const app = new Project(
|
|||||||
width: 1280,
|
width: 1280,
|
||||||
height: 768,
|
height: 768,
|
||||||
},
|
},
|
||||||
|
flags: [
|
||||||
|
'app',
|
||||||
|
]
|
||||||
}),
|
}),
|
||||||
).bind(module, gulp);
|
).bind(module, gulp);
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package ru.m.puzzlez.wrap;
|
package ru.m.puzzlez.wrap;
|
||||||
|
|
||||||
import ru.m.puzzlez.proto.core.Point;
|
import ru.m.puzzlez.proto.core.Point;
|
||||||
#if openfl
|
#if app
|
||||||
import flash.geom.Point as FlashPoint;
|
import flash.geom.Point as FlashPoint;
|
||||||
#end
|
#end
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ abstract PointExt(Point) from Point to Point {
|
|||||||
.setY(this.y - point.y);
|
.setY(this.y - point.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if openfl
|
#if app
|
||||||
@:from public static function fromFlashPoint(point:FlashPoint):PointExt {
|
@:from public static function fromFlashPoint(point:FlashPoint):PointExt {
|
||||||
return new Point()
|
return new Point()
|
||||||
.setX(point.x)
|
.setX(point.x)
|
||||||
|
|||||||
@@ -1,16 +1,11 @@
|
|||||||
package ru.m.puzzlez;
|
package ru.m.puzzlez;
|
||||||
|
|
||||||
import com.hurlant.crypto.extra.UUID;
|
|
||||||
import com.hurlant.crypto.prng.Random;
|
|
||||||
import haxe.Serializer;
|
|
||||||
import haxe.Unserializer;
|
|
||||||
import hw.connect.session.ProtoSession;
|
import hw.connect.session.ProtoSession;
|
||||||
import hw.log.BaseLogger.LoggerUtil;
|
import hw.log.BaseLogger.LoggerUtil;
|
||||||
import ru.m.puzzlez.core.GameEvent;
|
|
||||||
import ru.m.puzzlez.game.IGameManager;
|
import ru.m.puzzlez.game.IGameManager;
|
||||||
import ru.m.puzzlez.game.ServerGame;
|
import ru.m.puzzlez.game.ServerGame;
|
||||||
import ru.m.puzzlez.proto.core.GameEventProto;
|
import ru.m.puzzlez.proto.core.User;
|
||||||
import ru.m.puzzlez.proto.core.UserProto;
|
import ru.m.puzzlez.proto.event.GameEvent;
|
||||||
import ru.m.puzzlez.proto.pack.ErrorResponse;
|
import ru.m.puzzlez.proto.pack.ErrorResponse;
|
||||||
import ru.m.puzzlez.proto.pack.GameEventResponse;
|
import ru.m.puzzlez.proto.pack.GameEventResponse;
|
||||||
import ru.m.puzzlez.proto.pack.GameListResponse;
|
import ru.m.puzzlez.proto.pack.GameListResponse;
|
||||||
@@ -26,7 +21,7 @@ class GameSession extends ProtoSession<Response, Request> implements GameManager
|
|||||||
|
|
||||||
@:provide static var gameManager:IGameManager;
|
@:provide static var gameManager:IGameManager;
|
||||||
|
|
||||||
public var user(default, null):UserProto;
|
public var user(default, null):User;
|
||||||
public var gameId(default, null):String;
|
public var gameId(default, null):String;
|
||||||
|
|
||||||
private var subscribed:Bool;
|
private var subscribed:Bool;
|
||||||
@@ -81,8 +76,8 @@ class GameSession extends ProtoSession<Response, Request> implements GameManager
|
|||||||
}
|
}
|
||||||
// login
|
// login
|
||||||
if (request.hasLogin()) {
|
if (request.hasLogin()) {
|
||||||
user = new UserProto()
|
user = new User()
|
||||||
.setUuid(request.login.user.uuid != null ? request.login.user.uuid : UUID.generateRandom(new Random()).toString())
|
.setUuid(request.login.user.uuid != null ? request.login.user.uuid : IdUtil.generate())
|
||||||
.setName(request.login.user.name);
|
.setName(request.login.user.name);
|
||||||
gameManager.connect(this);
|
gameManager.connect(this);
|
||||||
send(new Response().setLogin(new LoginResponse().setUser(user)));
|
send(new Response().setLogin(new LoginResponse().setUser(user)));
|
||||||
@@ -108,11 +103,11 @@ class GameSession extends ProtoSession<Response, Request> implements GameManager
|
|||||||
if (subscribed) {
|
if (subscribed) {
|
||||||
send(new Response().setGameList(listGame()));
|
send(new Response().setGameList(listGame()));
|
||||||
}
|
}
|
||||||
} else if (request.hasGameEvent()) {
|
} else if (request.hasGameAction()) {
|
||||||
if (gameManager.gamesById.exists(gameId)) {
|
if (gameManager.gamesById.exists(gameId)) {
|
||||||
var events:Array<GameEvent> = cast request.gameEvent.events.map(item -> Unserializer.run(item.event));
|
for (action in request.gameAction.actions) {
|
||||||
// ToDo: emit event
|
gameManager.gamesById[gameId].events.emit(new GameEvent().setAction(action));
|
||||||
///gameManager.gamesById[gameId].gameEventSignal.emit(event);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error:Dynamic) {
|
} catch (error:Dynamic) {
|
||||||
@@ -163,9 +158,7 @@ class GameSession extends ProtoSession<Response, Request> implements GameManager
|
|||||||
|
|
||||||
public function onEvent(game:ServerGame, event:GameEvent):Void {
|
public function onEvent(game:ServerGame, event:GameEvent):Void {
|
||||||
if (gameId == game.id) {
|
if (gameId == game.id) {
|
||||||
send(new Response().setGameEvent(new GameEventResponse().setEvents([
|
send(new Response().setGameEvent(new GameEventResponse().setEvents([event])));
|
||||||
new GameEventProto().setTime(0).setEvent(Serializer.run(event))
|
|
||||||
])));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
package ru.m.puzzlez.game;
|
package ru.m.puzzlez.game;
|
||||||
|
|
||||||
import ru.m.puzzlez.proto.core.GamePresetProto;
|
|
||||||
import ru.m.puzzlez.proto.core.GameStateProto;
|
|
||||||
import ru.m.puzzlez.core.GameState;
|
|
||||||
import ru.m.puzzlez.core.Id;
|
import ru.m.puzzlez.core.Id;
|
||||||
import ru.m.puzzlez.core.GameEvent;
|
|
||||||
import ru.m.puzzlez.game.IGameManager;
|
import ru.m.puzzlez.game.IGameManager;
|
||||||
import ru.m.puzzlez.proto.core.GameProto;
|
import ru.m.puzzlez.proto.core.User;
|
||||||
import ru.m.puzzlez.proto.core.UserProto;
|
import ru.m.puzzlez.proto.event.GameEvent;
|
||||||
|
import ru.m.puzzlez.proto.game.GameItem;
|
||||||
|
import ru.m.puzzlez.proto.game.GamePreset;
|
||||||
|
import ru.m.puzzlez.proto.game.GameState;
|
||||||
|
|
||||||
class _GameListener implements GameListener {
|
class _GameListener implements GameListener {
|
||||||
private var game:ServerGame;
|
private var game:ServerGame;
|
||||||
@@ -20,11 +19,9 @@ class _GameListener implements GameListener {
|
|||||||
|
|
||||||
public function onGameEvent(event:GameEvent):Void {
|
public function onGameEvent(event:GameEvent):Void {
|
||||||
dispatcher.dispatchEvent(game, event);
|
dispatcher.dispatchEvent(game, event);
|
||||||
switch event {
|
if (event.hasComplete()) {
|
||||||
case COMPLETE:
|
dispatcher.delete(game.id);
|
||||||
dispatcher.delete(game.id);
|
dispose();
|
||||||
dispose();
|
|
||||||
case _:
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,11 +43,11 @@ class _GameListener implements GameListener {
|
|||||||
gamesByUser = new Map();
|
gamesByUser = new Map();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create(user:UserProto, imageId:ImageId):ServerGame {
|
public function create(user:User, imageId:ImageId):ServerGame {
|
||||||
var gameProto = new GameProto().setState(
|
var gameProto = new GameItem().setState(
|
||||||
new GameStateProto()
|
new GameState()
|
||||||
.setId(IdUtil.generate())
|
.setId(IdUtil.generate())
|
||||||
.setPreset(new GamePresetProto().setImageId(imageId))
|
.setPreset(new GamePreset().setImageId(imageId))
|
||||||
);
|
);
|
||||||
var game = new ServerGame(gameProto);
|
var game = new ServerGame(gameProto);
|
||||||
games.push(game);
|
games.push(game);
|
||||||
@@ -60,7 +57,7 @@ class _GameListener implements GameListener {
|
|||||||
return game;
|
return game;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function join(gameId:String, user:UserProto):Void {
|
public function join(gameId:String, user:User):Void {
|
||||||
if (gamesById.exists(gameId)) {
|
if (gamesById.exists(gameId)) {
|
||||||
var game = gamesById[gameId];
|
var game = gamesById[gameId];
|
||||||
game.join(user);
|
game.join(user);
|
||||||
@@ -78,7 +75,7 @@ class _GameListener implements GameListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function leave(user:UserProto):Void {
|
public function leave(user:User):Void {
|
||||||
if (gamesByUser.exists(user.uuid)) {
|
if (gamesByUser.exists(user.uuid)) {
|
||||||
var game = gamesByUser[user.uuid];
|
var game = gamesByUser[user.uuid];
|
||||||
gamesByUser.remove(user.uuid);
|
gamesByUser.remove(user.uuid);
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package ru.m.puzzlez.game;
|
package ru.m.puzzlez.game;
|
||||||
|
|
||||||
import ru.m.puzzlez.core.Id;
|
|
||||||
import hw.signal.Signal;
|
import hw.signal.Signal;
|
||||||
import ru.m.puzzlez.core.GameEvent;
|
import ru.m.puzzlez.core.Id;
|
||||||
import ru.m.puzzlez.proto.core.UserProto;
|
import ru.m.puzzlez.proto.core.User;
|
||||||
|
import ru.m.puzzlez.proto.event.GameEvent;
|
||||||
|
|
||||||
enum GameChange {
|
enum GameChange {
|
||||||
JOIN(user:UserProto);
|
JOIN(user:User);
|
||||||
LEAVE(user:UserProto);
|
LEAVE(user:User);
|
||||||
START();
|
START();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,9 +33,9 @@ interface GameManagerListener {
|
|||||||
public function connect(listener:GameManagerListener):Void;
|
public function connect(listener:GameManagerListener):Void;
|
||||||
public function disconnect(listener:GameManagerListener):Void;
|
public function disconnect(listener:GameManagerListener):Void;
|
||||||
|
|
||||||
public function create(user:UserProto, imageId:ImageId):ServerGame;
|
public function create(user:User, imageId:ImageId):ServerGame;
|
||||||
public function delete(gameId:String):Void;
|
public function delete(gameId:String):Void;
|
||||||
public function join(gameId:String, user:UserProto):Void;
|
public function join(gameId:String, user:User):Void;
|
||||||
public function leave(user:UserProto):Void;
|
public function leave(user:User):Void;
|
||||||
public function start(gameId:String):Void;
|
public function start(gameId:String):Void;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
package ru.m.puzzlez.game;
|
package ru.m.puzzlez.game;
|
||||||
|
|
||||||
import ru.m.puzzlez.core.GameUtil;
|
|
||||||
import haxe.Timer;
|
import haxe.Timer;
|
||||||
import ru.m.puzzlez.core.Game;
|
import ru.m.puzzlez.core.Game;
|
||||||
import ru.m.puzzlez.proto.core.GameProto;
|
import ru.m.puzzlez.core.GameUtil;
|
||||||
import ru.m.puzzlez.proto.core.UserProto;
|
import ru.m.puzzlez.proto.core.User;
|
||||||
|
import ru.m.puzzlez.proto.game.GameItem;
|
||||||
|
|
||||||
@:dispatcher(GameListener) class ServerGame extends Game {
|
@:dispatcher(GameListener) class ServerGame extends Game {
|
||||||
|
|
||||||
public var id(get, null):String;
|
public var id(get, null):String;
|
||||||
public var proto(default, default):GameProto;
|
public var proto(default, default):GameItem;
|
||||||
|
|
||||||
private var timer:Timer;
|
private var timer:Timer;
|
||||||
|
|
||||||
public function new(proto:GameProto) {
|
public function new(proto:GameItem) {
|
||||||
// ToDo:
|
// ToDo:
|
||||||
super(GameUtil.buildState(GameUtil.buildPreset(proto.state.preset.imageId)));
|
super(GameUtil.buildState(GameUtil.buildPreset(proto.state.preset.imageId)));
|
||||||
this.proto = proto;
|
this.proto = proto;
|
||||||
@@ -23,7 +23,7 @@ import ru.m.puzzlez.proto.core.UserProto;
|
|||||||
return proto.state.id;
|
return proto.state.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function contains(user:UserProto):Bool {
|
public function contains(user:User):Bool {
|
||||||
for (user in proto.users) {
|
for (user in proto.users) {
|
||||||
if (user.uuid == user.uuid) {
|
if (user.uuid == user.uuid) {
|
||||||
return true;
|
return true;
|
||||||
@@ -32,13 +32,13 @@ import ru.m.puzzlez.proto.core.UserProto;
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function join(user:UserProto):Void {
|
public function join(user:User):Void {
|
||||||
if (!contains(user)) {
|
if (!contains(user)) {
|
||||||
proto.users.push(user);
|
proto.users.push(user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function leave(user:UserProto):Void {
|
public function leave(user:User):Void {
|
||||||
proto.setUsers(proto.users.filter(function(u:UserProto) return u.uuid != user.uuid));
|
proto.setUsers(proto.users.filter(function(u:User) return u.uuid != user.uuid));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user