From 34e5ac2b9ee09d5838c3f2d3b4136e75b1c5a98f Mon Sep 17 00:00:00 2001 From: shmyga Date: Wed, 28 Feb 2018 22:06:00 +0300 Subject: [PATCH] [client] update proto --- src/client/haxe/ru/m/tankz/Client.hx | 37 ++--- src/client/haxe/ru/m/tankz/Init.hx | 7 +- src/client/haxe/ru/m/tankz/frame/GameFrame.hx | 14 +- .../haxe/ru/m/tankz/network/NetworkManager.hx | 72 +++++----- .../haxe/ru/m/connect/BaseConnection.hx | 81 +++++------ src/common/haxe/ru/m/connect/IConnection.hx | 40 ++---- src/common/haxe/ru/m/connect/PacketQueue.hx | 127 ++++++++--------- .../ru/m/connect/flash/FlashConnection.hx | 134 +++++++++--------- src/common/haxe/ru/m/tankz/PacketBuilder.hx | 63 -------- src/common/proto/pack.proto | 17 +++ 10 files changed, 249 insertions(+), 343 deletions(-) delete mode 100755 src/common/haxe/ru/m/tankz/PacketBuilder.hx diff --git a/src/client/haxe/ru/m/tankz/Client.hx b/src/client/haxe/ru/m/tankz/Client.hx index 2dfa04c..e20fcd3 100755 --- a/src/client/haxe/ru/m/tankz/Client.hx +++ b/src/client/haxe/ru/m/tankz/Client.hx @@ -1,8 +1,12 @@ package ru.m.tankz; -import flash.events.KeyboardEvent; -import flash.text.Font; +import openfl.Assets; +import ru.m.tankz.frame.StartFrame; import flash.ui.Keyboard; +import flash.events.KeyboardEvent; +import ru.m.tankz.proto.pack.Response; +import ru.m.tankz.proto.pack.Request; +import flash.text.Font; import haxework.gui.frame.IFrameSwitcher; import haxework.gui.Root; import haxework.gui.VGroupView; @@ -11,10 +15,7 @@ import haxework.log.TraceLogger; import haxework.provider.Provider; import haxework.resources.IResources; import haxework.resources.Resources; -import openfl.Assets; import ru.m.connect.IConnection; -import ru.m.tankz.frame.StartFrame; -import ru.m.tankz.PacketBuilder; #if flash import haxework.log.JSLogger; #end #if debug import haxework.log.SocketLogger; #end @@ -23,9 +24,7 @@ interface ClientLayout { var switcher(default, null):IFrameSwitcher; } -@:template('ru/m/tankz/Client.yaml', 'ru/m/tankz/Style.yaml') -class Client extends VGroupView implements ClientLayout implements ViewBuilder { - +class Client { private static inline var TAG = 'Tankz'; public static function main() { @@ -41,29 +40,35 @@ class Client extends VGroupView implements ClientLayout implements ViewBuilder { L.d(TAG, 'Debug: ${Const.DEBUG}'); L.i(TAG, 'Version: ${Const.VERSION}'); L.i(TAG, 'Build: ${Const.BUILD}'); - var client:Client = new Client(); - Root.bind(client); + var view:ClientView = new ClientView(); + Root.bind(view); + view.launch(); } - public function init() { - Provider.setFactory(IResources, Resources); +} +@:template('ru/m/tankz/Client.yaml', 'ru/m/tankz/Style.yaml') +class ClientView extends VGroupView implements ClientLayout implements ViewBuilder { + + private static inline var TAG = 'Tankz'; + + public function init():Void { var font:Font = Font.enumerateFonts()[0]; Provider.get(IResources).text.put('font', 'Bookman Old Style'); Provider.get(IResources).text.put('version', 'v${Const.VERSION} b${Const.BUILD}'); - Provider.set(IPacketBuilder, new PacketBuilder()); #if flash - Provider.set(IConnection, new ru.m.connect.flash.FlashConnection('localhost', 5001)); + Provider.set(IConnection, new ru.m.connect.flash.FlashConnection('localhost', 5001, Response)); #elseif html5 Provider.set(IConnection, new ru.m.connect.js.JsConnection('localhost', 5001)); #else Provider.set(IConnection, new ru.m.connect.fake.FakeConnection()); #end - Provider.get(IConnection).handler.addListener(this); - Provider.set(IFrameSwitcher, switcher); + } + + public function launch():Void { content.stage.stageFocusRect = false; content.stage.addEventListener(KeyboardEvent.KEY_UP, function(event:KeyboardEvent):Void { diff --git a/src/client/haxe/ru/m/tankz/Init.hx b/src/client/haxe/ru/m/tankz/Init.hx index ebf8d91..830fa7a 100644 --- a/src/client/haxe/ru/m/tankz/Init.hx +++ b/src/client/haxe/ru/m/tankz/Init.hx @@ -1,8 +1,8 @@ package ru.m.tankz; import haxework.provider.Provider; -import ru.m.tankz.bundle.ConfigBundle; -import ru.m.tankz.bundle.IConfigBundle; +import haxework.resources.IResources; +import haxework.resources.Resources; import ru.m.tankz.bundle.ILevelBundle; import ru.m.tankz.bundle.LevelBundle; import ru.m.tankz.game.ClassicGame; @@ -17,7 +17,8 @@ import ru.m.tankz.storage.UserStorage; class Init { public static function init():Void { - Provider.setFactory(IConfigBundle, ConfigBundle); + Provider.setFactory(IResources, Resources); + Provider.setFactory(ILevelBundle, LevelBundle); Provider.setFactory(ILevelBundle, LevelBundle); Provider.setFactory(SaveStorage, SaveStorage); Provider.setFactory(UserStorage, UserStorage); diff --git a/src/client/haxe/ru/m/tankz/frame/GameFrame.hx b/src/client/haxe/ru/m/tankz/frame/GameFrame.hx index a6895f7..6658653 100755 --- a/src/client/haxe/ru/m/tankz/frame/GameFrame.hx +++ b/src/client/haxe/ru/m/tankz/frame/GameFrame.hx @@ -1,6 +1,5 @@ package ru.m.tankz.frame; -import ru.m.tankz.sound.SoundManager; import flash.events.Event; import haxe.ds.Option; import haxe.Timer; @@ -9,13 +8,11 @@ import haxework.gui.LabelView; import haxework.gui.VGroupView; import haxework.gui.ViewBuilder; import haxework.provider.Provider; -import protohx.Message; -import ru.m.connect.IConnection; import ru.m.tankz.game.Game; import ru.m.tankz.game.GameSave; import ru.m.tankz.game.GameState; -import ru.m.tankz.proto.pack.GameUpdateResponse; import ru.m.tankz.render.Render; +import ru.m.tankz.sound.SoundManager; import ru.m.tankz.storage.SaveStorage; @@ -25,7 +22,7 @@ interface GameFrameLayout { } @:template("ru/m/tankz/frame/GameFrame.yaml", "ru/m/tankz/Style.yaml") -class GameFrame extends VGroupView implements ViewBuilder implements IPacketHandler implements GameFrameLayout { +class GameFrame extends VGroupView implements ViewBuilder implements GameFrameLayout { private static inline var TAG = "GameFrame"; @@ -126,11 +123,4 @@ class GameFrame extends VGroupView implements ViewBuilder implements IPacketHand private function redraw(_):Void { render.draw(game.engine); } - - public function onGameUpdateResponse(packet:GameUpdateResponse):Void { - //engine.updateFromChanges(packet.changes); - render.draw(game.engine); - } - - public function onPacket(packet:Message):Void {} } diff --git a/src/client/haxe/ru/m/tankz/network/NetworkManager.hx b/src/client/haxe/ru/m/tankz/network/NetworkManager.hx index 0579ef7..5854918 100644 --- a/src/client/haxe/ru/m/tankz/network/NetworkManager.hx +++ b/src/client/haxe/ru/m/tankz/network/NetworkManager.hx @@ -2,23 +2,25 @@ package ru.m.tankz.network; import haxework.provider.Provider; import hxsignal.impl.Signal1; -import protohx.Message; import ru.m.connect.IConnection; import ru.m.tankz.proto.pack.LoginRequest; -import ru.m.tankz.proto.pack.LoginResponse; +import ru.m.tankz.proto.pack.Request; +import ru.m.tankz.proto.pack.Response; import ru.m.tankz.storage.UserStorage; -class NetworkManager implements IPacketHandler implements IConnectionHandler { +typedef ClientConnection = IConnection; + +class NetworkManager { public var state(default, null):String; public var stateSignal:Signal1; public var user(default, null):User; - private var connection(get, never):IConnection; + private var connection(get, never):ClientConnection; private var storage(get, never):UserStorage; - inline private function get_connection():IConnection { + inline private function get_connection():ClientConnection { return Provider.get(IConnection); } @@ -29,8 +31,8 @@ class NetworkManager implements IPacketHandler implements IConnectionHandler { public function new() { stateSignal = new Signal1(); updateState('offline'); - connection.handler.addListener(this); - connection.packetHandler.addListener(this); + connection.handler.connect(onConnectionEvent); + connection.packetHandler.connect(onResponse); user = storage.read(); if (user == null) { user = {name: 'User', uuid: null}; @@ -44,39 +46,29 @@ class NetworkManager implements IPacketHandler implements IConnectionHandler { public function login(name:String):Void { user.name = name; - if (!connection.connected) { - updateState('connect...'); - connection.connect(); - } else { - onConnected(); + updateState('connect...'); + connection.connect().then(function(c:ClientConnection) { + updateState('login...'); + c.send(new Request().setLogin( + new LoginRequest() + .setUuid(user.uuid) + .setName(user.name) + )); + }).catchError(function(_) {}); + } + + private function onConnectionEvent(event:ConnectionEvent):Void { + updateState(Std.string(event)); + } + + private function onResponse(packet:Response):Void { + if (packet.hasLogin()) { + user = { + uuid: packet.login.user.uuid, + name: packet.login.user.name, + }; + storage.write(user); + updateState('online'); } } - - public function onConnected():Void { - updateState('login...'); - connection.send( - new LoginRequest() - .setUuid(user.uuid) - .setName(user.name) - ); - } - - public function onDisconnected():Void { - updateState('offline'); - } - - public function onError(error:Dynamic):Void { - updateState('error'); - } - - public function onLoginResponse(packet:LoginResponse):Void { - user = { - uuid: packet.user.uuid, - name: packet.user.name, - }; - storage.write(user); - updateState('online'); - } - - public function onPacket(packet:Message):Void {} } diff --git a/src/common/haxe/ru/m/connect/BaseConnection.hx b/src/common/haxe/ru/m/connect/BaseConnection.hx index 4f0d5ed..a96e31e 100755 --- a/src/common/haxe/ru/m/connect/BaseConnection.hx +++ b/src/common/haxe/ru/m/connect/BaseConnection.hx @@ -1,60 +1,45 @@ package ru.m.connect; -import haxework.dispath.Dispatcher; -import haxework.dispath.IDispatcher; -import haxework.provider.Provider; +import promhx.Deferred; +import hxsignal.impl.Signal1; import haxe.io.Bytes; +import promhx.Promise; import protohx.Message; import ru.m.connect.IConnection; -class BaseConnection implements IConnection { - public var handler(default,default):IDispatcher; - public var packetHandler(default,default):IDispatcher; - public var connected(default, null):Bool; - public var queue(default, null):PacketQueue; - public var builder(default, null):IPacketBuilder; - public function new() { - this.builder = Provider.get(IPacketBuilder); - this.queue = new PacketQueue(builder); - this.handler = new Dispatcher(); - this.packetHandler = new Dispatcher(); - } +class BaseConnection implements IConnection { + public var handler(default, default):Signal1; + public var packetHandler(default, default):Signal1; + public var connected(default, null):Bool; + public var queue(default, null):PacketQueue; - public function connect():Void { - throw "Not implemented"; - } + private var connectDeferred:Deferred>; - public function disconnect():Void { - throw "Not implemented"; - } - - public function pushData(bytes:Bytes):Void { - queue.addBytes(bytes); - while (queue.hasMsg()) { - var packet:Message = queue.popMsg(); - try { - receive(packet); - } catch (error:Dynamic) { - trace(error); - handler.dispatch(function(h) h.onError(error)); - } + public function new(i:Class) { + queue = new PacketQueue(i); + handler = new Signal1(); + packetHandler = new Signal1(); + connectDeferred = new Deferred(); } - } - public function send(packet:Message):Void { - #if proto_debug L.d("Send", Type.getClassName(Type.getClass(packet)).split(".").pop()); #end - } - public function receive(packet:Message):Void { - #if proto_debug L.d("Receive", Type.getClassName(Type.getClass(packet)).split(".").pop()); #end - var name = "on" + Type.getClassName(Type.getClass(packet)).split(".").pop(); - packetHandler.dispatch(function(h) { - var method = Reflect.field(h, name); - if (method != null && Reflect.isFunction(method)) { - Reflect.callMethod(h, method, [packet]); - } else { - h.onPacket(packet); - } - }); - } + public function connect():Promise> { + throw "Not implemented"; + } + + public function disconnect():Void { + throw "Not implemented"; + } + + public function pushData(bytes:Bytes):Void { + queue.addBytes(bytes); + while (queue.hasMsg()) { + var packet:I = queue.popMsg(); + packetHandler.emit(packet); + } + } + + public function send(packet:O):Void { + #if proto_debug L.d("Send", Type.getClassName(Type.getClass(packet)).split(".").pop()); #end + } } \ No newline at end of file diff --git a/src/common/haxe/ru/m/connect/IConnection.hx b/src/common/haxe/ru/m/connect/IConnection.hx index c66e3ac..f4b9472 100755 --- a/src/common/haxe/ru/m/connect/IConnection.hx +++ b/src/common/haxe/ru/m/connect/IConnection.hx @@ -6,37 +6,19 @@ import promhx.Promise; import protohx.Message; -interface IConnection { +enum ConnectionEvent { + CONNECTED; + DISCONNECTED; + ERROR(error:Dynamic); +} + +interface IConnection { public var connected(default, null):Bool; - public var handler(default, default):Signal1; - public var packetHandler(default, default):Signal1; + public var handler(default, null):Signal1; + public var packetHandler(default, null):Signal1; - public var builder(default, null):IPacketBuilder; - - public function connect():Promise; + public function connect():Promise>; public function disconnect():Void; - public function send(packet:Message):Void; + public function send(packet:O):Void; public function pushData(bytes:Bytes):Void; - - public function receive(packet:Message):Void; } - -interface IConnectionHandler { - public function onConnected():Void; - public function onDisconnected():Void; - public function onError(error:Dynamic):Void; -} - -interface IPacketHandler { - public function onPacket(packet:Message):Void; -} - -typedef PacketMeta = { - var family:Int; - var id:Int; -} - -interface IPacketBuilder { - public function packetMeta(packet:Message):PacketMeta; - public function buildPacket(meta:PacketMeta):Message; -} \ No newline at end of file diff --git a/src/common/haxe/ru/m/connect/PacketQueue.hx b/src/common/haxe/ru/m/connect/PacketQueue.hx index e1c1ecf..a540aa1 100755 --- a/src/common/haxe/ru/m/connect/PacketQueue.hx +++ b/src/common/haxe/ru/m/connect/PacketQueue.hx @@ -1,80 +1,75 @@ package ru.m.connect; -import ru.m.connect.IConnection.IPacketBuilder; -import protohx.Message; -import haxe.io.BytesInput; -import haxe.io.BytesBuffer; import haxe.io.Bytes; +import haxe.io.BytesBuffer; +import haxe.io.BytesInput; +import protohx.Message; -class PacketQueue { - public static inline var HEADER_SIZE:Int = 4; +class PacketQueue { - private var builder:IPacketBuilder; - private var bytesBuff:Bytes; - private var msgs:List; + private var packetClass:Class

; + private var bytesBuff:Bytes; + private var msgs:List

; - public function new(builder:IPacketBuilder) { - this.builder = builder; - msgs = new List(); - } - - public inline function hasMsg():Bool { - return !msgs.isEmpty(); - } - - public inline function popMsg():Message { - return msgs.pop(); - } - - public inline function addMsg(msg:Message):Void { - msgs.add(msg); - } - - public function addBytes(bytes:Bytes) { - if (bytes == null) { - return; + public function new(packetClass:Class

) { + this.packetClass = packetClass; + msgs = new List

(); } - if (bytesBuff == null) { - bytesBuff = bytes; - } else { - var buffer = new BytesBuffer(); - buffer.add(bytesBuff); - buffer.add(bytes); - bytesBuff = buffer.getBytes(); + + public inline function hasMsg():Bool { + return !msgs.isEmpty(); } - if (bytesBuff == null || bytesBuff.length < HEADER_SIZE) { - return; + + public inline function popMsg():P { + return msgs.pop(); } - var available = bytesBuff.length; - var bi = new BytesInput(bytesBuff); - bi.bigEndian = false; - while (available >= HEADER_SIZE) { - var family = bi.readByte(); - var id = bi.readByte(); - var packetSize = bi.readUInt16(); - available -= HEADER_SIZE; - if (packetSize <= available) { - available -= packetSize; - var msgBytes = bi.read(packetSize); - var packet = builder.buildPacket({family:family, id:id}); - packet.mergeFrom(msgBytes); - addMsg(packet); - } else { - available += HEADER_SIZE; - break; - } + + public inline function addMsg(msg:P):Void { + msgs.add(msg); } - if (available == 0) { - bytesBuff = null; - } else if (available > 0) { - if (bytesBuff.length != available) { - var pos = bytesBuff.length - available; - bytesBuff = bytesBuff.sub(pos, available); - } - } else { - throw "Wrong available: " + available; + + public function addBytes(bytes:Bytes):Void { + if (bytes == null) { + return; + } + if (bytesBuff == null) { + bytesBuff = bytes; + } else { + var buffer = new BytesBuffer(); + buffer.add(bytesBuff); + buffer.add(bytes); + bytesBuff = buffer.getBytes(); + } + if (bytesBuff == null || bytesBuff.length < 1) { + return; + } + var available = bytesBuff.length; + var bi = new BytesInput(bytesBuff); + bi.bigEndian = false; + while (available > 0) { + var packetSize = bi.readUInt16(); + available -= 1; + if (packetSize <= available) { + var msgBytes = bi.read(packetSize); + var packet:P = Type.createInstance(packetClass, []); + packet.mergeFrom(msgBytes); + addMsg(packet); + available -= packetSize; + } else { + break; + } + } + if (available == 0) { + bytesBuff = null; + } else if (available > 0) { + if (bytesBuff.length != available) { + var pos = bytesBuff.length - available; + bytesBuff = bytesBuff.sub(pos, available); + } + } else { + throw "Wrong available: " + available; + } } - } } \ No newline at end of file diff --git a/src/common/haxe/ru/m/connect/flash/FlashConnection.hx b/src/common/haxe/ru/m/connect/flash/FlashConnection.hx index b4eb852..0590e1f 100755 --- a/src/common/haxe/ru/m/connect/flash/FlashConnection.hx +++ b/src/common/haxe/ru/m/connect/flash/FlashConnection.hx @@ -1,6 +1,7 @@ package ru.m.connect.flash; -import ru.m.connect.IConnection.IConnectionHandler; +import ru.m.connect.IConnection.ConnectionEvent; +import promhx.Promise; import flash.utils.Endian; import haxe.io.BytesOutput; import protohx.Message; @@ -12,76 +13,77 @@ import flash.events.SecurityErrorEvent; import flash.events.IOErrorEvent; import flash.net.Socket; -class FlashConnection extends BaseConnection { - private var host:String; - private var port:Int; - private var socket:Socket; +class FlashConnection extends BaseConnection { - public function new(host:String, port:Int) { - super(); - this.host = host; - this.port = port; - connected = false; - socket = new Socket(); - socket.addEventListener(IOErrorEvent.IO_ERROR, onError); - socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onError); - socket.addEventListener(Event.CLOSE, onClose); - socket.addEventListener(Event.CONNECT, onConnect); - socket.addEventListener(ProgressEvent.SOCKET_DATA, onSocketData); - socket.endian = Endian.LITTLE_ENDIAN; - } + private var host:String; + private var port:Int; + private var socket:Socket; - override public function connect():Void { - socket.connect(host, port); - } - - override public function disconnect():Void { - if (socket.connected) { - socket.close(); - connected = false; - handler.dispatch(function(h) h.onDisconnected()); + public function new(host:String, port:Int, i:Class) { + super(i); + this.host = host; + this.port = port; + connected = false; + socket = new Socket(); + socket.addEventListener(IOErrorEvent.IO_ERROR, onError); + socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onError); + socket.addEventListener(Event.CLOSE, onClose); + socket.addEventListener(Event.CONNECT, onConnect); + socket.addEventListener(ProgressEvent.SOCKET_DATA, onSocketData); + socket.endian = Endian.LITTLE_ENDIAN; } - } - private function onError(event:ErrorEvent):Void { - socket.close(); - connected = false; - handler.dispatch(function(h) h.onError(event)); - } - - private function onConnect(_):Void { - connected = true; - handler.dispatch(function(h) h.onConnected()); - } - - private function onClose(_):Void { - socket.close(); - connected = false; - handler.dispatch(function(h) h.onDisconnected()); - } - - private function onSocketData(_):Void { - try { - var b = new flash.utils.ByteArray(); - socket.readBytes(b); - var bs = Bytes.ofData(cast b); - pushData(bs); - } catch (error:Dynamic) { - handler.dispatch(function(h) h.onError(error)); + override public function connect():Promise> { + socket.connect(host, port); + return connectDeferred.promise(); } - } - override public function send(packet:Message):Void { - super.send(packet); - var meta = builder.packetMeta(packet); - socket.writeByte(meta.family); - socket.writeByte(meta.id); - var out = new BytesOutput(); - packet.writeTo(out); - var bytes = out.getBytes(); - socket.writeShort(bytes.length); - socket.writeBytes(cast bytes.getData()); - socket.flush(); - } + override public function disconnect():Void { + if (socket.connected) { + socket.close(); + //connected = false; + //handler.emit(ConnectionEvent.DISCONNECTED); + } + } + + private function onError(event:ErrorEvent):Void { + socket.close(); + connected = false; + handler.emit(ConnectionEvent.ERROR(event)); + connectDeferred.throwError(event); + } + + private function onConnect(_):Void { + connected = true; + handler.emit(ConnectionEvent.CONNECTED); + connectDeferred.resolve(this); + } + + private function onClose(_):Void { + socket.close(); + connected = false; + handler.emit(ConnectionEvent.DISCONNECTED); + } + + private function onSocketData(_):Void { + try { + var b = new flash.utils.ByteArray(); + socket.readBytes(b); + var bs = Bytes.ofData(cast b); + pushData(bs); + } catch (error:Dynamic) { + handler.emit(ConnectionEvent.ERROR(error)); + } + } + + override public function send(packet:O):Void { + super.send(packet); + var out = new BytesOutput(); + packet.writeTo(out); + var bytes = out.getBytes(); + socket.writeShort(bytes.length); + socket.writeBytes(cast bytes.getData()); + socket.flush(); + } } \ 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 deleted file mode 100755 index ac6aa7d..0000000 --- a/src/common/haxe/ru/m/tankz/PacketBuilder.hx +++ /dev/null @@ -1,63 +0,0 @@ -package ru.m.tankz; - -import protohx.Message; -import ru.m.connect.IConnection; -import ru.m.tankz.proto.pack.*; -import Type; - - -class PacketBuilder implements IPacketBuilder { - - private static var MAP:Map>> = [ - 0x00 => [ - 0x0001 => ErrorResponse - ], - 0x01 => [ - 0x0001 => LoginRequest, - 0x0002 => LoginResponse, - ], - 0x02 => [ - 0x0001 => GameListRequest, - 0x0002 => GameListResponse, - 0x0003 => CreateGameRequest, - 0x0004 => CreateGameResponse, - 0x0005 => GameListResponse, - 0x0006 => JoinGameRequest, - 0x0007 => JoinGameResponse, - 0x0008 => StartGameRequest, - 0x0009 => StartGameResponse, - 0x000a => LeaveGameRequest, - 0x000b => LeaveGameResponse - ], - 0x03 => [ - 0x0001 => GameActionRequest, - 0x0002 => GameUpdateResponse - ] - ]; - - public function new() {} - - public function packetMeta(packet:Message):PacketMeta { - for (family in MAP.keys()) { - var subMap = MAP[family]; - for (id in subMap.keys()) { - var packetClass = subMap[id]; - if (Std.is(packet, packetClass)) { - return { - family:family, - id:id - } - } - } - } - throw "Unsupported packet(" + Type.getClassName(Type.getClass(packet)).split(".").pop() + ")"; - return null; - } - - public function buildPacket(meta:PacketMeta):Message { - if (!MAP.exists(meta.family)) throw "Unsupported family(" + meta.family + ")"; - if (!MAP[meta.family].exists(meta.id)) throw "Unsupported family(" + meta.family + ") id(" + meta.id + ")"; - var packetClass = MAP[meta.family][meta.id]; - return Type.createInstance(packetClass, []); - } -} diff --git a/src/common/proto/pack.proto b/src/common/proto/pack.proto index 5aa2a69..4ca0f11 100644 --- a/src/common/proto/pack.proto +++ b/src/common/proto/pack.proto @@ -65,3 +65,20 @@ message GameActionRequest { message GameUpdateResponse { repeated ru.m.tankz.proto.game.GameChange changes = 1; } + + + + +message Request { + oneof content { + LoginRequest login = 1; + CreateGameRequest createGame = 2; + } +} + +message Response { + oneof content { + LoginResponse login = 1; + CreateGameResponse createGame = 2; + } +}