This commit is contained in:
2014-07-06 20:33:21 +04:00
parent 6623a031d0
commit c7ac39a3bd
7 changed files with 41 additions and 16 deletions

View File

@@ -1,5 +1,6 @@
-main ru.m.armageddon.server.Server -main ru.m.armageddon.server.Server
-lib protohx -lib protohx
-lib haxework
-cp src/common/haxe -cp src/common/haxe
-cp src/server/haxe -cp src/server/haxe
-cp src-gen/haxe -cp src-gen/haxe

View File

@@ -1,5 +1,6 @@
package ru.m.armageddon.client.frames; package ru.m.armageddon.client.frames;
import flash.net.SharedObject;
import ru.m.armageddon.proto.ErrorResponse; import ru.m.armageddon.proto.ErrorResponse;
import protohx.Message; import protohx.Message;
import haxework.frame.IFrameSwitcher; import haxework.frame.IFrameSwitcher;
@@ -18,13 +19,25 @@ class AuthFrame extends VGroupView implements IPacketHandler {
public static inline var ID = "auth"; public static inline var ID = "auth";
private var so:SharedObject;
private var loginInput:InputView;
private var passwordInput:InputView;
public function new() { public function new() {
super(); super();
so = SharedObject.getLocal("auth", "/");
} }
public function init():Void { public function init():Void {
findViewById("auth", ButtonView).onPress = this; 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 { public function onShow():Void {
@@ -32,8 +45,8 @@ class AuthFrame extends VGroupView implements IPacketHandler {
} }
public function onPress(view:ButtonView):Void { public function onPress(view:ButtonView):Void {
var login:String = findViewById("login:input", InputView).text; var login:String = loginInput.text;
var password:String = Md5.encode(findViewById("password:input", InputView).text); var password:String = Md5.encode(passwordInput.text);
var connection:IConnection = Provider.get(IConnection); var connection:IConnection = Provider.get(IConnection);
connection.connect() connection.connect()
.success(function(_) { .success(function(_) {
@@ -46,6 +59,9 @@ class AuthFrame extends VGroupView implements IPacketHandler {
} }
public function onLoginResponse(packet:LoginResponse):Void { public function onLoginResponse(packet:LoginResponse):Void {
so.setProperty("login", loginInput.text);
so.setProperty("password", passwordInput.text);
so.flush();
Provider.get(IFrameSwitcher).change("person"); Provider.get(IFrameSwitcher).change("person");
} }

View File

@@ -1,6 +1,5 @@
package ru.m.armageddon.core.connect; package ru.m.armageddon.core.connect;
import flash.errors.Error;
import haxework.net.callback.ICallback; import haxework.net.callback.ICallback;
import haxe.io.Bytes; import haxe.io.Bytes;
import protohx.Message; import protohx.Message;
@@ -13,20 +12,24 @@ class BaseConnection implements IConnection {
private var builder:IPacketBuilder; private var builder:IPacketBuilder;
public function new(?handler:IConnectionHandler = null) { public function new(?handler:IConnectionHandler = null, ?packetHandler:IPacketHandler) {
this.builder = new PacketBuilder(); this.builder = new PacketBuilder();
this.packetHandler = packetHandler;
this.handler = handler; this.handler = handler;
} }
public function connect():ICallback<Dynamic> { public function connect():ICallback<Dynamic> {
throw new Error("Not implemented"); throw "Not implemented";
} }
public function pushData(bytes:Bytes):Void {} 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 { private function receive(packet:Message):Void {
L.d("Receive", Type.getClassName(Type.getClass(packet)).split(".").pop());
if (packetHandler == null) return; if (packetHandler == null) return;
var name = "on" + Type.getClassName(Type.getClass(packet)).split(".").pop(); var name = "on" + Type.getClassName(Type.getClass(packet)).split(".").pop();
var method = Reflect.field(packetHandler, name); var method = Reflect.field(packetHandler, name);

View File

@@ -82,6 +82,7 @@ class FlashConnection extends BaseConnection {
} }
override public function send(packet:Message):Void { override public function send(packet:Message):Void {
super.send(packet);
var meta = builder.packetMeta(packet); var meta = builder.packetMeta(packet);
socket.writeByte(meta.family); socket.writeByte(meta.family);
socket.writeByte(meta.id); socket.writeByte(meta.id);

View File

@@ -4,7 +4,7 @@ import haxe.io.BytesOutput;
import protohx.Message; import protohx.Message;
import haxe.io.Bytes; import haxe.io.Bytes;
import sys.net.Socket; import sys.net.Socket;
import ru.m.armageddon.core.connect.IConnection.IConnectionHandler; import ru.m.armageddon.core.connect.IConnection;
class NekoConnection extends BaseConnection { class NekoConnection extends BaseConnection {
@@ -12,8 +12,8 @@ class NekoConnection extends BaseConnection {
private var socket:Socket; private var socket:Socket;
public function new(socket:Socket, handler:IConnectionHandler) { public function new(socket:Socket, ?handler:IConnectionHandler = null, ?packetHandler:IPacketHandler = null) {
super(handler); super(handler, packetHandler);
this.socket = socket; this.socket = socket;
socket.setFastSend(true); socket.setFastSend(true);
socket.output.bigEndian = false; socket.output.bigEndian = false;
@@ -35,6 +35,7 @@ class NekoConnection extends BaseConnection {
} }
override public function send(packet:Message):Void { override public function send(packet:Message):Void {
super.send(packet);
try { try {
var meta = builder.packetMeta(packet); var meta = builder.packetMeta(packet);
var b = new BytesOutput(); var b = new BytesOutput();

View File

@@ -1,25 +1,27 @@
package ru.m.armageddon.server; package ru.m.armageddon.server;
import haxework.log.TraceLogger;
import ru.m.armageddon.server.session.Session; import ru.m.armageddon.server.session.Session;
import neko.Lib;
import haxe.io.Bytes; import haxe.io.Bytes;
import sys.net.Socket; import sys.net.Socket;
import neko.net.ThreadServer; import neko.net.ThreadServer;
class Server extends ThreadServer<Session, Bytes> { class Server extends ThreadServer<Session, Bytes> {
private static inline var TAG = "Server";
public function new() { public function new() {
super(); super();
} }
override function clientConnected(s:Socket):Session { override function clientConnected(s:Socket):Session {
var session = new Session(s); var session = new Session(s);
Lib.println("client: " + s.peer()); L.d(TAG, "Client connected");
return session; return session;
} }
override function clientDisconnected(session: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) { override function readClientMessage(session:Session, buf:Bytes, pos:Int, len:Int) {
@@ -31,7 +33,8 @@ class Server extends ThreadServer<Session, Bytes> {
} }
public static function main() { public static function main() {
Lib.println("Running"); L.push(new TraceLogger());
L.d(TAG, "Running");
var server = new Server(); var server = new Server();
server.run("localhost", 5000); server.run("localhost", 5000);
} }

View File

@@ -10,13 +10,13 @@ import protohx.Message;
import ru.m.armageddon.core.connect.IConnection; import ru.m.armageddon.core.connect.IConnection;
import sys.net.Socket; import sys.net.Socket;
class Session implements IConnectionHandler { class Session implements IConnectionHandler implements IPacketHandler {
public var account(default, null):Account; public var account(default, null):Account;
public var connection(default, null):IConnection; public var connection(default, null):IConnection;
public function new(socket:Socket) { public function new(socket:Socket) {
connection = new NekoConnection(socket, this); connection = new NekoConnection(socket, this, this);
} }
public function onConnected():Void { public function onConnected():Void {