Commit 4c6f0a0a authored by nanahira's avatar nanahira

fix

parent fa91a3d9
...@@ -120,7 +120,7 @@ class YGOProMessagesHelper { ...@@ -120,7 +120,7 @@ class YGOProMessagesHelper {
//console.log(proto, this.proto_structs[direction][proto]); //console.log(proto, this.proto_structs[direction][proto]);
//const directionProtoList = this.constants[direction]; //const directionProtoList = this.constants[direction];
if (typeof info === 'undefined') { if (typeof info === 'undefined') {
buffer = ""; buffer = null;
} }
else if (Buffer.isBuffer(info)) { else if (Buffer.isBuffer(info)) {
buffer = info; buffer = info;
...@@ -132,13 +132,13 @@ class YGOProMessagesHelper { ...@@ -132,13 +132,13 @@ class YGOProMessagesHelper {
buffer = struct.buffer(); buffer = struct.buffer();
} }
const translatedProto = this.translateProto(proto, direction); const translatedProto = this.translateProto(proto, direction);
let header = Buffer.allocUnsafe(3); let sendBuffer = Buffer.allocUnsafe(3 + (buffer ? buffer.length : 0));
header.writeUInt16LE(buffer.length + 1, 0); sendBuffer.writeUInt16LE(buffer.length + 1, 0);
header.writeUInt8(translatedProto, 2); sendBuffer.writeUInt8(translatedProto, 2);
socket.write(header); if (buffer) {
if (buffer.length) { buffer.copy(sendBuffer, 3);
socket.write(buffer);
} }
socket.write(sendBuffer);
} }
addHandler(protostr, handler, synchronous, priority) { addHandler(protostr, handler, synchronous, priority) {
if (priority < 0 || priority > 4) { if (priority < 0 || priority > 4) {
......
...@@ -146,14 +146,14 @@ export class YGOProMessagesHelper { ...@@ -146,14 +146,14 @@ export class YGOProMessagesHelper {
direction, direction,
proto proto
} = this.getDirectionAndProto(protostr); } = this.getDirectionAndProto(protostr);
let buffer: string | Buffer; let buffer: Buffer;
if (!socket.remoteAddress) { if (!socket.remoteAddress) {
return; return;
} }
//console.log(proto, this.proto_structs[direction][proto]); //console.log(proto, this.proto_structs[direction][proto]);
//const directionProtoList = this.constants[direction]; //const directionProtoList = this.constants[direction];
if (typeof info === 'undefined') { if (typeof info === 'undefined') {
buffer = ""; buffer = null;
} else if (Buffer.isBuffer(info)) { } else if (Buffer.isBuffer(info)) {
buffer = info; buffer = info;
} else { } else {
...@@ -163,13 +163,13 @@ export class YGOProMessagesHelper { ...@@ -163,13 +163,13 @@ export class YGOProMessagesHelper {
buffer = struct.buffer(); buffer = struct.buffer();
} }
const translatedProto = this.translateProto(proto, direction); const translatedProto = this.translateProto(proto, direction);
let header = Buffer.allocUnsafe(3); let sendBuffer = Buffer.allocUnsafe(3 + (buffer ? buffer.length : 0));
header.writeUInt16LE(buffer.length + 1, 0); sendBuffer.writeUInt16LE(buffer.length + 1, 0);
header.writeUInt8(translatedProto, 2); sendBuffer.writeUInt8(translatedProto, 2);
socket.write(header); if (buffer) {
if (buffer.length) { buffer.copy(sendBuffer, 3)
socket.write(buffer);
} }
socket.write(sendBuffer);
} }
addHandler(protostr: string, handler: (buffer: Buffer, info: any, datas: Buffer[], params: any) => Promise<boolean>, synchronous: boolean, priority: number) { 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