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,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);

View File

@@ -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);

View File

@@ -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();