[server] update
This commit is contained in:
@@ -1,26 +1,11 @@
|
||||
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.GameObjectType;
|
||||
import ru.m.tankz.proto.GameChangeType;
|
||||
import ru.m.tankz.proto.GameUpdateResponse;
|
||||
import ru.m.tankz.proto.GameChange;
|
||||
import ru.m.tankz.proto.StartGameResponse;
|
||||
import ru.m.tankz.core.Direction;
|
||||
import ru.m.tankz.proto.core.GameState;
|
||||
import ru.m.tankz.proto.core.Game;
|
||||
import ru.m.tankz.server.session.Thread;
|
||||
import ru.m.tankz.config.TankzConfig.DEFAULT;
|
||||
import ru.m.tankz.engine.Engine;
|
||||
import ru.m.tankz.proto.CreateGameResponse;
|
||||
import ru.m.tankz.proto.LeaveGameResponse;
|
||||
import ru.m.tankz.proto.JoinGameResponse;
|
||||
import ru.m.tankz.server.session.Session;
|
||||
import protohx.Message;
|
||||
import ru.m.tankz.proto.Person;
|
||||
import ru.m.tankz.proto.GameState;
|
||||
import ru.m.tankz.proto.Game;
|
||||
import ru.m.tankz.engine.IEngine;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -58,27 +43,27 @@ class NekoTimer {
|
||||
class GameManager {
|
||||
|
||||
public static var byGameId:Map<Int, GameManager> = new Map<Int, GameManager>();
|
||||
public static var byPersonId:Map<Int, GameManager> = new Map<Int, GameManager>();
|
||||
public static var byPersonId:Map<String, GameManager> = new Map<String, GameManager>();
|
||||
public static var subscribers:Map<Int, Bool> = new Map<Int, Bool>();
|
||||
|
||||
private static var idCounter:Int = 0;
|
||||
|
||||
public var game(default, null):Game;
|
||||
|
||||
public var engine(default, null):IEngine;
|
||||
public var engine(default, null):Engine;
|
||||
|
||||
private var timer:NekoTimer;
|
||||
|
||||
private var changes:Array<GameChange> = new Array<GameChange>();
|
||||
//private var changes:Array<GameChange> = new Array<GameChange>();
|
||||
|
||||
public function new(person:Person) {
|
||||
public function new(creator:User) {
|
||||
game = new Game()
|
||||
.setId(idCounter++)
|
||||
.setState(GameState.READY)
|
||||
.setCreator(person);
|
||||
game.addPersons(person);
|
||||
.setCreator(creator);
|
||||
game.addPlayers(creator);
|
||||
byGameId.set(game.id, this);
|
||||
byPersonId.set(person.id, this);
|
||||
byPersonId.set(creator.uuid, this);
|
||||
broadcast(new CreateGameResponse().setGame(game));
|
||||
broadcastGames();
|
||||
}
|
||||
@@ -96,8 +81,8 @@ class GameManager {
|
||||
}
|
||||
|
||||
public function broadcast(packet:Message) {
|
||||
for (person in game.persons) {
|
||||
var session = Session.sessions.get(person.id);
|
||||
for (player in game.players) {
|
||||
var session = Session.sessions.get(player.uuid);
|
||||
session.send(packet);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ typedef ServerConnection = IConnection<Response, Request>;
|
||||
|
||||
class Session {
|
||||
|
||||
public static var sessions:Map<Int, Session> = new Map<Int, Session>();
|
||||
public static var sessions:Map<String, Session> = new Map<String, Session>();
|
||||
|
||||
public var user(default, null):User;
|
||||
public var gameId(default, null):Int = -1;
|
||||
@@ -84,6 +84,7 @@ class Session {
|
||||
user = new User()
|
||||
.setUuid(request.uuid != null ? request.uuid : 'xxx')
|
||||
.setName(request.name);
|
||||
sessions.set(user.uuid, this);
|
||||
return new LoginResponse().setUser(user);
|
||||
}
|
||||
|
||||
|
||||
@@ -109,5 +109,4 @@ static var thread_create = neko.Lib.load("std","thread_create",2);
|
||||
static var thread_current = neko.Lib.load("std", "thread_current", 0);
|
||||
static var thread_send = neko.Lib.load("std", "thread_send", 2);
|
||||
static var thread_read_message = neko.Lib.load("std", "thread_read_message", 1);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user