This commit is contained in:
2014-07-05 18:16:54 +04:00
parent 6cd5eaee75
commit e207de6eb6
5 changed files with 45 additions and 46 deletions

View File

@@ -15,6 +15,16 @@ class BaseConnection implements IConnection {
}
public function pushData(bytes:Bytes):Void {}
public function send(packet:Message):Void {}
private function receive(packet:Message):Void {}
private function receive(packet:Message):Void {
var name = "on" + Type.getClassName(Type.getClass(packet)).split(".").pop();
var method = Reflect.field(handler, name);
if (method != null && Reflect.isFunction(method)) {
Reflect.callMethod(handler, method, [packet]);
} else {
handler.onPacket(packet);
}
}
}

View File

@@ -1,7 +1,6 @@
package ru.m.armageddon.core.connect.flash;
import ru.m.armageddon.core.connect.IConnection.IConnectionHandler;
import protohx.MessageUtils;
import flash.utils.Endian;
import haxe.io.BytesOutput;
import protohx.Message;
@@ -12,8 +11,6 @@ import flash.events.Event;
import flash.events.SecurityErrorEvent;
import flash.events.IOErrorEvent;
import flash.net.Socket;
import ru.m.armageddon.proto.LoginRequest;
import ru.m.armageddon.proto.LoginResponse;
class FlashConnection extends BaseConnection {
@@ -56,7 +53,6 @@ class FlashConnection extends BaseConnection {
}
override public function send(packet:Message):Void {
L.d("Send", MessageUtils.toJson(packet));
var meta = builder.packetMeta(packet);
socket.writeByte(meta.family);
socket.writeByte(meta.id);
@@ -67,11 +63,4 @@ class FlashConnection extends BaseConnection {
socket.writeBytes(cast bytes.getData());
socket.flush();
}
override private function receive(packet:Message):Void {
L.d("Receive", MessageUtils.toJson(packet));
var name = Type.getClassName(Type.getClass(packet)).split(".").pop();
L.d("xxx", name);
handler.onPacket(packet);
}
}

View File

@@ -1,7 +1,6 @@
package ru.m.armageddon.core.connect.neko;
import haxe.io.BytesOutput;
import protohx.MessageUtils;
import protohx.Message;
import haxe.io.Bytes;
import sys.net.Socket;
@@ -35,7 +34,6 @@ class NekoConnection extends BaseConnection {
}
override public function send(packet:Message):Void {
trace("Send: " + MessageUtils.toJson(packet));
try {
var meta = builder.packetMeta(packet);
var b = new BytesOutput();
@@ -50,11 +48,4 @@ class NekoConnection extends BaseConnection {
trace(e);
}
}
override private function receive(packet:Message):Void {
trace("Receive", MessageUtils.toJson(packet));
var name = Type.getClassName(Type.getClass(packet)).split(".").pop();
trace("xxx", name);
handler.onPacket(packet);
}
}