-
This commit is contained in:
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Dynamic> {
|
||||
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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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<Session, Bytes> {
|
||||
|
||||
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<Session, Bytes> {
|
||||
}
|
||||
|
||||
public static function main() {
|
||||
Lib.println("Running");
|
||||
L.push(new TraceLogger());
|
||||
L.d(TAG, "Running");
|
||||
var server = new Server();
|
||||
server.run("localhost", 5000);
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user