Commit 4c6f0a0a authored by nanahira's avatar nanahira

fix

parent fa91a3d9
......@@ -120,7 +120,7 @@ class YGOProMessagesHelper {
//console.log(proto, this.proto_structs[direction][proto]);
//const directionProtoList = this.constants[direction];
if (typeof info === 'undefined') {
buffer = "";
buffer = null;
}
else if (Buffer.isBuffer(info)) {
buffer = info;
......@@ -132,13 +132,13 @@ class YGOProMessagesHelper {
buffer = struct.buffer();
}
const translatedProto = this.translateProto(proto, direction);
let header = Buffer.allocUnsafe(3);
header.writeUInt16LE(buffer.length + 1, 0);
header.writeUInt8(translatedProto, 2);
socket.write(header);
if (buffer.length) {
socket.write(buffer);
let sendBuffer = Buffer.allocUnsafe(3 + (buffer ? buffer.length : 0));
sendBuffer.writeUInt16LE(buffer.length + 1, 0);
sendBuffer.writeUInt8(translatedProto, 2);
if (buffer) {
buffer.copy(sendBuffer, 3);
}
socket.write(sendBuffer);
}
addHandler(protostr, handler, synchronous, priority) {
if (priority < 0 || priority > 4) {
......
......@@ -146,14 +146,14 @@ export class YGOProMessagesHelper {
direction,
proto
} = this.getDirectionAndProto(protostr);
let buffer: string | Buffer;
let buffer: Buffer;
if (!socket.remoteAddress) {
return;
}
//console.log(proto, this.proto_structs[direction][proto]);
//const directionProtoList = this.constants[direction];
if (typeof info === 'undefined') {
buffer = "";
buffer = null;
} else if (Buffer.isBuffer(info)) {
buffer = info;
} else {
......@@ -163,13 +163,13 @@ export class YGOProMessagesHelper {
buffer = struct.buffer();
}
const translatedProto = this.translateProto(proto, direction);
let header = Buffer.allocUnsafe(3);
header.writeUInt16LE(buffer.length + 1, 0);
header.writeUInt8(translatedProto, 2);
socket.write(header);
if (buffer.length) {
socket.write(buffer);
let sendBuffer = Buffer.allocUnsafe(3 + (buffer ? buffer.length : 0));
sendBuffer.writeUInt16LE(buffer.length + 1, 0);
sendBuffer.writeUInt8(translatedProto, 2);
if (buffer) {
buffer.copy(sendBuffer, 3)
}
socket.write(sendBuffer);
}
addHandler(protostr: string, handler: (buffer: Buffer, info: any, datas: Buffer[], params: any) => Promise<boolean>, synchronous: boolean, priority: number) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment