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