From c7ac39a3bdcb2fe3aef4e71c67b361b8529b2c0c Mon Sep 17 00:00:00 2001 From: shmyga Date: Sun, 6 Jul 2014 20:33:21 +0400 Subject: [PATCH] - --- server.hxml | 1 + .../m/armageddon/client/frames/AuthFrame.hx | 22 ++++++++++++++++--- .../armageddon/core/connect/BaseConnection.hx | 11 ++++++---- .../core/connect/flash/FlashConnection.hx | 1 + .../core/connect/neko/NekoConnection.hx | 7 +++--- .../haxe/ru/m/armageddon/server/Server.hx | 11 ++++++---- .../ru/m/armageddon/server/session/Session.hx | 4 ++-- 7 files changed, 41 insertions(+), 16 deletions(-) diff --git a/server.hxml b/server.hxml index eb76653..cb3ff7f 100755 --- a/server.hxml +++ b/server.hxml @@ -1,5 +1,6 @@ -main ru.m.armageddon.server.Server -lib protohx +-lib haxework -cp src/common/haxe -cp src/server/haxe -cp src-gen/haxe diff --git a/src/client/haxe/ru/m/armageddon/client/frames/AuthFrame.hx b/src/client/haxe/ru/m/armageddon/client/frames/AuthFrame.hx index 88db0a3..981a32a 100755 --- a/src/client/haxe/ru/m/armageddon/client/frames/AuthFrame.hx +++ b/src/client/haxe/ru/m/armageddon/client/frames/AuthFrame.hx @@ -1,5 +1,6 @@ package ru.m.armageddon.client.frames; +import flash.net.SharedObject; import ru.m.armageddon.proto.ErrorResponse; import protohx.Message; import haxework.frame.IFrameSwitcher; @@ -18,13 +19,25 @@ class AuthFrame extends VGroupView implements IPacketHandler { public static inline var ID = "auth"; + private var so:SharedObject; + + private var loginInput:InputView; + private var passwordInput:InputView; + public function new() { super(); + so = SharedObject.getLocal("auth", "/"); } public function init():Void { findViewById("auth", ButtonView).onPress = this; - findViewById("password:input", InputView).textField.displayAsPassword = true; + loginInput = findViewById("login:input"); + passwordInput = findViewById("password:input"); + passwordInput.textField.displayAsPassword = true; + if (so.data.login != null && so.data.password != null) { + loginInput.text = so.data.login; + passwordInput.text = so.data.password; + } } public function onShow():Void { @@ -32,8 +45,8 @@ class AuthFrame extends VGroupView implements IPacketHandler { } public function onPress(view:ButtonView):Void { - var login:String = findViewById("login:input", InputView).text; - var password:String = Md5.encode(findViewById("password:input", InputView).text); + var login:String = loginInput.text; + var password:String = Md5.encode(passwordInput.text); var connection:IConnection = Provider.get(IConnection); connection.connect() .success(function(_) { @@ -46,6 +59,9 @@ class AuthFrame extends VGroupView implements IPacketHandler { } public function onLoginResponse(packet:LoginResponse):Void { + so.setProperty("login", loginInput.text); + so.setProperty("password", passwordInput.text); + so.flush(); Provider.get(IFrameSwitcher).change("person"); } diff --git a/src/common/haxe/ru/m/armageddon/core/connect/BaseConnection.hx b/src/common/haxe/ru/m/armageddon/core/connect/BaseConnection.hx index 02cc22d..2edac50 100755 --- a/src/common/haxe/ru/m/armageddon/core/connect/BaseConnection.hx +++ b/src/common/haxe/ru/m/armageddon/core/connect/BaseConnection.hx @@ -1,6 +1,5 @@ package ru.m.armageddon.core.connect; -import flash.errors.Error; import haxework.net.callback.ICallback; import haxe.io.Bytes; import protohx.Message; @@ -13,20 +12,24 @@ class BaseConnection implements IConnection { private var builder:IPacketBuilder; - public function new(?handler:IConnectionHandler = null) { + public function new(?handler:IConnectionHandler = null, ?packetHandler:IPacketHandler) { this.builder = new PacketBuilder(); + this.packetHandler = packetHandler; this.handler = handler; } public function connect():ICallback { - throw new Error("Not implemented"); + throw "Not implemented"; } public function pushData(bytes:Bytes):Void {} - public function send(packet:Message):Void {} + public function send(packet:Message):Void { + L.d("Send", Type.getClassName(Type.getClass(packet)).split(".").pop()); + } private function receive(packet:Message):Void { + L.d("Receive", Type.getClassName(Type.getClass(packet)).split(".").pop()); if (packetHandler == null) return; var name = "on" + Type.getClassName(Type.getClass(packet)).split(".").pop(); var method = Reflect.field(packetHandler, name); diff --git a/src/common/haxe/ru/m/armageddon/core/connect/flash/FlashConnection.hx b/src/common/haxe/ru/m/armageddon/core/connect/flash/FlashConnection.hx index 0a9a5f8..dc68520 100755 --- a/src/common/haxe/ru/m/armageddon/core/connect/flash/FlashConnection.hx +++ b/src/common/haxe/ru/m/armageddon/core/connect/flash/FlashConnection.hx @@ -82,6 +82,7 @@ class FlashConnection extends BaseConnection { } override public function send(packet:Message):Void { + super.send(packet); var meta = builder.packetMeta(packet); socket.writeByte(meta.family); socket.writeByte(meta.id); diff --git a/src/common/haxe/ru/m/armageddon/core/connect/neko/NekoConnection.hx b/src/common/haxe/ru/m/armageddon/core/connect/neko/NekoConnection.hx index 410dd73..7ad04d7 100755 --- a/src/common/haxe/ru/m/armageddon/core/connect/neko/NekoConnection.hx +++ b/src/common/haxe/ru/m/armageddon/core/connect/neko/NekoConnection.hx @@ -4,7 +4,7 @@ import haxe.io.BytesOutput; import protohx.Message; import haxe.io.Bytes; import sys.net.Socket; -import ru.m.armageddon.core.connect.IConnection.IConnectionHandler; +import ru.m.armageddon.core.connect.IConnection; class NekoConnection extends BaseConnection { @@ -12,8 +12,8 @@ class NekoConnection extends BaseConnection { private var socket:Socket; - public function new(socket:Socket, handler:IConnectionHandler) { - super(handler); + public function new(socket:Socket, ?handler:IConnectionHandler = null, ?packetHandler:IPacketHandler = null) { + super(handler, packetHandler); this.socket = socket; socket.setFastSend(true); socket.output.bigEndian = false; @@ -35,6 +35,7 @@ class NekoConnection extends BaseConnection { } override public function send(packet:Message):Void { + super.send(packet); try { var meta = builder.packetMeta(packet); var b = new BytesOutput(); diff --git a/src/server/haxe/ru/m/armageddon/server/Server.hx b/src/server/haxe/ru/m/armageddon/server/Server.hx index 82962a9..f544974 100755 --- a/src/server/haxe/ru/m/armageddon/server/Server.hx +++ b/src/server/haxe/ru/m/armageddon/server/Server.hx @@ -1,25 +1,27 @@ package ru.m.armageddon.server; +import haxework.log.TraceLogger; import ru.m.armageddon.server.session.Session; -import neko.Lib; import haxe.io.Bytes; import sys.net.Socket; import neko.net.ThreadServer; class Server extends ThreadServer { + private static inline var TAG = "Server"; + public function new() { super(); } override function clientConnected(s:Socket):Session { var session = new Session(s); - Lib.println("client: " + s.peer()); + L.d(TAG, "Client connected"); return session; } override function clientDisconnected(session:Session) { - Lib.println("client disconnected"); + L.d(TAG, "Client disconnected"); } override function readClientMessage(session:Session, buf:Bytes, pos:Int, len:Int) { @@ -31,7 +33,8 @@ class Server extends ThreadServer { } public static function main() { - Lib.println("Running"); + L.push(new TraceLogger()); + L.d(TAG, "Running"); var server = new Server(); server.run("localhost", 5000); } diff --git a/src/server/haxe/ru/m/armageddon/server/session/Session.hx b/src/server/haxe/ru/m/armageddon/server/session/Session.hx index 44fff83..6be89b6 100755 --- a/src/server/haxe/ru/m/armageddon/server/session/Session.hx +++ b/src/server/haxe/ru/m/armageddon/server/session/Session.hx @@ -10,13 +10,13 @@ import protohx.Message; import ru.m.armageddon.core.connect.IConnection; import sys.net.Socket; -class Session implements IConnectionHandler { +class Session implements IConnectionHandler implements IPacketHandler { public var account(default, null):Account; public var connection(default, null):IConnection; public function new(socket:Socket) { - connection = new NekoConnection(socket, this); + connection = new NekoConnection(socket, this, this); } public function onConnected():Void {