Commit bff2bfa0 authored by nanahira's avatar nanahira

fix polyfill shrinking

parent 829ae8e1
...@@ -17,7 +17,7 @@ class Handler { ...@@ -17,7 +17,7 @@ class Handler {
} }
async handle(buffer, info, datas, params) { async handle(buffer, info, datas, params) {
if (this.synchronous) { if (this.synchronous) {
return !!(await this.handler(buffer, info, datas, params)); return await this.handler(buffer, info, datas, params);
} }
else { else {
const newBuffer = Buffer.from(buffer); const newBuffer = Buffer.from(buffer);
...@@ -183,7 +183,7 @@ class YGOProMessagesHelper { ...@@ -183,7 +183,7 @@ class YGOProMessagesHelper {
let messageLength = 0; let messageLength = 0;
let bufferProto = 0; let bufferProto = 0;
let datas = []; let datas = [];
const limit = preconnect ? 2 : this.singleHandleLimit; const limit = preconnect ? 9 : this.singleHandleLimit;
for (let l = 0; l < limit; ++l) { for (let l = 0; l < limit; ++l) {
if (messageLength === 0) { if (messageLength === 0) {
if (messageBuffer.length >= 2) { if (messageBuffer.length >= 2) {
...@@ -224,6 +224,7 @@ class YGOProMessagesHelper { ...@@ -224,6 +224,7 @@ class YGOProMessagesHelper {
} }
let buffer = messageBuffer.slice(3, 2 + messageLength); let buffer = messageBuffer.slice(3, 2 + messageLength);
//console.log(l, direction, proto, cancel); //console.log(l, direction, proto, cancel);
let shrinkCount = 0;
for (let priority = 0; priority < 4; ++priority) { for (let priority = 0; priority < 4; ++priority) {
if (cancel) { if (cancel) {
break; break;
...@@ -239,19 +240,31 @@ class YGOProMessagesHelper { ...@@ -239,19 +240,31 @@ class YGOProMessagesHelper {
for (let handler of handlerCollection.get(bufferProto)) { for (let handler of handlerCollection.get(bufferProto)) {
cancel = await handler.handle(buffer, info, datas, params); cancel = await handler.handle(buffer, info, datas, params);
if (cancel) { if (cancel) {
if (cancel === '_cancel') { if (typeof cancel === "string") {
return { if (cancel === '_cancel') {
datas: [], return {
feedback datas: [],
}; feedback
};
}
else if (cancel.startsWith('_shrink_')) {
shrinkCount += parseInt(cancel.slice(8));
cancel = false;
}
} }
break; break;
} }
} }
} }
} }
if (!cancel) { if (!cancel && shrinkCount <= messageLength) {
datas.push(messageBuffer.slice(0, 2 + messageLength)); if (shrinkCount > 0) {
// rewrite first 2 bytes of length
const oldLength = messageBuffer.readUInt16LE(0);
const newLength = oldLength - shrinkCount;
messageBuffer.writeUInt16LE(newLength, 0);
}
datas.push(messageBuffer.slice(0, 2 + messageLength - shrinkCount));
} }
messageBuffer = messageBuffer.slice(2 + messageLength); messageBuffer = messageBuffer.slice(2 + messageLength);
messageLength = 0; messageLength = 0;
......
...@@ -16,7 +16,7 @@ class Handler { ...@@ -16,7 +16,7 @@ class Handler {
} }
async handle(buffer: Buffer, info: any, datas: Buffer[], params: any): Promise<boolean | string> { async handle(buffer: Buffer, info: any, datas: Buffer[], params: any): Promise<boolean | string> {
if (this.synchronous) { if (this.synchronous) {
return !!(await this.handler(buffer, info, datas, params)); return await this.handler(buffer, info, datas, params);
} else { } else {
const newBuffer = Buffer.from(buffer); const newBuffer = Buffer.from(buffer);
const newDatas = datas.map(b => Buffer.from(b)); const newDatas = datas.map(b => Buffer.from(b));
...@@ -237,7 +237,7 @@ export class YGOProMessagesHelper { ...@@ -237,7 +237,7 @@ export class YGOProMessagesHelper {
let messageLength = 0; let messageLength = 0;
let bufferProto = 0; let bufferProto = 0;
let datas: Buffer[] = []; let datas: Buffer[] = [];
const limit = preconnect ? 2 : this.singleHandleLimit; const limit = preconnect ? 9 : this.singleHandleLimit;
for (let l = 0; l < limit; ++l) { for (let l = 0; l < limit; ++l) {
if (messageLength === 0) { if (messageLength === 0) {
if (messageBuffer.length >= 2) { if (messageBuffer.length >= 2) {
...@@ -274,6 +274,7 @@ export class YGOProMessagesHelper { ...@@ -274,6 +274,7 @@ export class YGOProMessagesHelper {
} }
let buffer = messageBuffer.slice(3, 2 + messageLength); let buffer = messageBuffer.slice(3, 2 + messageLength);
//console.log(l, direction, proto, cancel); //console.log(l, direction, proto, cancel);
let shrinkCount = 0;
for (let priority = 0; priority < 4; ++priority) { for (let priority = 0; priority < 4; ++priority) {
if (cancel) { if (cancel) {
break; break;
...@@ -289,10 +290,15 @@ export class YGOProMessagesHelper { ...@@ -289,10 +290,15 @@ export class YGOProMessagesHelper {
for (let handler of handlerCollection.get(bufferProto)) { for (let handler of handlerCollection.get(bufferProto)) {
cancel = await handler.handle(buffer, info, datas, params); cancel = await handler.handle(buffer, info, datas, params);
if (cancel) { if (cancel) {
if (cancel === '_cancel') { if (typeof cancel === "string") {
return { if (cancel === '_cancel') {
datas: [], return {
feedback datas: [],
feedback
}
} else if (cancel.startsWith('_shrink_')) {
shrinkCount += parseInt(cancel.slice(8));
cancel = false;
} }
} }
break; break;
...@@ -300,8 +306,14 @@ export class YGOProMessagesHelper { ...@@ -300,8 +306,14 @@ export class YGOProMessagesHelper {
} }
} }
} }
if (!cancel) { if (!cancel && shrinkCount <= messageLength) {
datas.push(messageBuffer.slice(0, 2 + messageLength)); if (shrinkCount > 0) {
// rewrite first 2 bytes of length
const oldLength = messageBuffer.readUInt16LE(0);
const newLength = oldLength - shrinkCount;
messageBuffer.writeUInt16LE(newLength, 0);
}
datas.push(messageBuffer.slice(0, 2 + messageLength - shrinkCount));
} }
messageBuffer = messageBuffer.slice(2 + messageLength); messageBuffer = messageBuffer.slice(2 + messageLength);
messageLength = 0; messageLength = 0;
......
...@@ -2,12 +2,11 @@ ...@@ -2,12 +2,11 @@
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.BasePolyfiller = void 0; exports.BasePolyfiller = void 0;
class BasePolyfiller { class BasePolyfiller {
async polyfillGameMsg(msgTitle, buffer) { constructor() {
return false; this.shrinkCount = 0;
}
async polyfillResponse(msgTitle, buffer) {
return false;
} }
async polyfillGameMsg(msgTitle, buffer) { }
async polyfillResponse(msgTitle, buffer) { }
splice(buf, offset, deleteCount = 1) { splice(buf, offset, deleteCount = 1) {
if (offset < 0 || offset >= buf.length) if (offset < 0 || offset >= buf.length)
return Buffer.alloc(0); return Buffer.alloc(0);
...@@ -20,6 +19,7 @@ class BasePolyfiller { ...@@ -20,6 +19,7 @@ class BasePolyfiller {
buf.copy(buf, offset, end, buf.length); buf.copy(buf, offset, end, buf.length);
} }
buf.fill(0, buf.length - deleteCount); buf.fill(0, buf.length - deleteCount);
this.shrinkCount += deleteCount;
return deleted; return deleted;
} }
insert(buf, offset, insertBuf) { insert(buf, offset, insertBuf) {
...@@ -27,6 +27,7 @@ class BasePolyfiller { ...@@ -27,6 +27,7 @@ class BasePolyfiller {
const insertLength = Math.min(insertBuf.length, availableSpace); const insertLength = Math.min(insertBuf.length, availableSpace);
buf.copy(buf, offset + insertLength, offset, buf.length - insertLength); buf.copy(buf, offset + insertLength, offset, buf.length - insertLength);
insertBuf.copy(buf, offset, 0, insertLength); insertBuf.copy(buf, offset, 0, insertLength);
this.shrinkCount -= insertLength;
return buf; return buf;
} }
} }
......
export class BasePolyfiller { export class BasePolyfiller {
async polyfillGameMsg(msgTitle: string, buffer: Buffer) { shrinkCount = 0;
return false;
}
async polyfillResponse(msgTitle: string, buffer: Buffer) { async polyfillGameMsg(msgTitle: string, buffer: Buffer) {}
return false;
} async polyfillResponse(msgTitle: string, buffer: Buffer) {}
splice(buf: Buffer, offset: number, deleteCount = 1): Buffer { splice(buf: Buffer, offset: number, deleteCount = 1): Buffer {
if (offset < 0 || offset >= buf.length) return Buffer.alloc(0); if (offset < 0 || offset >= buf.length) return Buffer.alloc(0);
...@@ -22,6 +20,8 @@ export class BasePolyfiller { ...@@ -22,6 +20,8 @@ export class BasePolyfiller {
} }
buf.fill(0, buf.length - deleteCount); buf.fill(0, buf.length - deleteCount);
this.shrinkCount += deleteCount;
return deleted; return deleted;
} }
...@@ -33,6 +33,8 @@ export class BasePolyfiller { ...@@ -33,6 +33,8 @@ export class BasePolyfiller {
buf.copy(buf, offset + insertLength, offset, buf.length - insertLength); buf.copy(buf, offset + insertLength, offset, buf.length - insertLength);
insertBuf.copy(buf, offset, 0, insertLength); insertBuf.copy(buf, offset, 0, insertLength);
this.shrinkCount -= insertLength;
return buf; return buf;
} }
......
...@@ -5,9 +5,9 @@ exports.polyfillResponse = polyfillResponse; ...@@ -5,9 +5,9 @@ exports.polyfillResponse = polyfillResponse;
const registry_1 = require("./registry"); const registry_1 = require("./registry");
const getPolyfillers = (version) => { const getPolyfillers = (version) => {
const polyfillers = []; const polyfillers = [];
for (const [pVersion, instance] of registry_1.polyfillRegistry.entries()) { for (const [pVersion, polyfillerCls] of registry_1.polyfillRegistry.entries()) {
if (version <= pVersion) { if (version <= pVersion) {
polyfillers.push({ version: pVersion, polyfiller: instance }); polyfillers.push({ version: pVersion, polyfiller: new polyfillerCls() });
} }
} }
polyfillers.sort((a, b) => a.version - b.version); polyfillers.sort((a, b) => a.version - b.version);
...@@ -15,19 +15,21 @@ const getPolyfillers = (version) => { ...@@ -15,19 +15,21 @@ const getPolyfillers = (version) => {
}; };
async function polyfillGameMsg(version, msgTitle, buffer) { async function polyfillGameMsg(version, msgTitle, buffer) {
const polyfillers = getPolyfillers(version); const polyfillers = getPolyfillers(version);
let shrinkCount = 0;
for (const polyfiller of polyfillers) { for (const polyfiller of polyfillers) {
if (await polyfiller.polyfillGameMsg(msgTitle, buffer)) { await polyfiller.polyfillGameMsg(msgTitle, buffer);
return true; if (polyfiller.shrinkCount > 0) {
if (polyfiller.shrinkCount === 0x3f3f3f3f) {
return 0x3f3f3f3f; // special case for cancel message
}
shrinkCount += polyfiller.shrinkCount;
} }
} }
return false; return shrinkCount;
} }
async function polyfillResponse(version, msgTitle, buffer) { async function polyfillResponse(version, msgTitle, buffer) {
const polyfillers = getPolyfillers(version); const polyfillers = getPolyfillers(version);
for (const polyfiller of polyfillers) { for (const polyfiller of polyfillers) {
if (await polyfiller.polyfillResponse(msgTitle, buffer)) { await polyfiller.polyfillResponse(msgTitle, buffer);
return true;
}
} }
return false;
} }
...@@ -3,9 +3,9 @@ import { polyfillRegistry } from "./registry"; ...@@ -3,9 +3,9 @@ import { polyfillRegistry } from "./registry";
const getPolyfillers = (version: number) => { const getPolyfillers = (version: number) => {
const polyfillers: {version: number, polyfiller: BasePolyfiller}[] = []; const polyfillers: {version: number, polyfiller: BasePolyfiller}[] = [];
for (const [pVersion, instance] of polyfillRegistry.entries()) { for (const [pVersion, polyfillerCls] of polyfillRegistry.entries()) {
if (version <= pVersion) { if (version <= pVersion) {
polyfillers.push({version: pVersion, polyfiller: instance}); polyfillers.push({ version: pVersion, polyfiller: new polyfillerCls() });
} }
} }
polyfillers.sort((a, b) => a.version - b.version); polyfillers.sort((a, b) => a.version - b.version);
...@@ -15,20 +15,22 @@ const getPolyfillers = (version: number) => { ...@@ -15,20 +15,22 @@ const getPolyfillers = (version: number) => {
export async function polyfillGameMsg(version: number, msgTitle: string, buffer: Buffer) { export async function polyfillGameMsg(version: number, msgTitle: string, buffer: Buffer) {
const polyfillers = getPolyfillers(version); const polyfillers = getPolyfillers(version);
let shrinkCount = 0;
for (const polyfiller of polyfillers) { for (const polyfiller of polyfillers) {
if (await polyfiller.polyfillGameMsg(msgTitle, buffer)) { await polyfiller.polyfillGameMsg(msgTitle, buffer);
return true; if (polyfiller.shrinkCount > 0) {
if (polyfiller.shrinkCount === 0x3f3f3f3f) {
return 0x3f3f3f3f; // special case for cancel message
}
shrinkCount += polyfiller.shrinkCount;
} }
} }
return false; return shrinkCount;
} }
export async function polyfillResponse(version: number, msgTitle: string, buffer: Buffer) { export async function polyfillResponse(version: number, msgTitle: string, buffer: Buffer) {
const polyfillers = getPolyfillers(version); const polyfillers = getPolyfillers(version);
for (const polyfiller of polyfillers) { for (const polyfiller of polyfillers) {
if (await polyfiller.polyfillResponse(msgTitle, buffer)) { await polyfiller.polyfillResponse(msgTitle, buffer);
return true;
}
} }
return false;
} }
...@@ -84,7 +84,7 @@ class Polyfiller1361 extends base_polyfiller_1.BasePolyfiller { ...@@ -84,7 +84,7 @@ class Polyfiller1361 extends base_polyfiller_1.BasePolyfiller {
value: buffer.readUInt32LE(offset), value: buffer.readUInt32LE(offset),
})); }));
if (!values.some(v => v.value & 0x80000000)) { if (!values.some(v => v.value & 0x80000000)) {
return false; return;
} }
const gcds = [targetValue]; const gcds = [targetValue];
for (const { value } of values) { for (const { value } of values) {
...@@ -115,7 +115,7 @@ class Polyfiller1361 extends base_polyfiller_1.BasePolyfiller { ...@@ -115,7 +115,7 @@ class Polyfiller1361 extends base_polyfiller_1.BasePolyfiller {
buffer.writeUInt32LE(target, trans.offset); buffer.writeUInt32LE(target, trans.offset);
} }
} }
return false; return;
} }
} }
exports.Polyfiller1361 = Polyfiller1361; exports.Polyfiller1361 = Polyfiller1361;
...@@ -88,7 +88,7 @@ export class Polyfiller1361 extends BasePolyfiller { ...@@ -88,7 +88,7 @@ export class Polyfiller1361 extends BasePolyfiller {
value: buffer.readUInt32LE(offset), value: buffer.readUInt32LE(offset),
})); }));
if (!values.some(v => v.value & 0x80000000)) { if (!values.some(v => v.value & 0x80000000)) {
return false; return;
} }
const gcds = [targetValue]; const gcds = [targetValue];
for(const { value } of values) { for(const { value } of values) {
...@@ -117,6 +117,6 @@ export class Polyfiller1361 extends BasePolyfiller { ...@@ -117,6 +117,6 @@ export class Polyfiller1361 extends BasePolyfiller {
buffer.writeUInt32LE(target, trans.offset); buffer.writeUInt32LE(target, trans.offset);
} }
} }
return false; return;
} }
} }
...@@ -4,6 +4,6 @@ exports.polyfillRegistry = void 0; ...@@ -4,6 +4,6 @@ exports.polyfillRegistry = void 0;
const _0x1361_1 = require("./polyfillers/0x1361"); const _0x1361_1 = require("./polyfillers/0x1361");
exports.polyfillRegistry = new Map(); exports.polyfillRegistry = new Map();
const addPolyfiller = (version, polyfiller) => { const addPolyfiller = (version, polyfiller) => {
exports.polyfillRegistry.set(version, new polyfiller()); exports.polyfillRegistry.set(version, polyfiller);
}; };
addPolyfiller(0x1361, _0x1361_1.Polyfiller1361); addPolyfiller(0x1361, _0x1361_1.Polyfiller1361);
import { BasePolyfiller } from "./base-polyfiller"; import { BasePolyfiller } from "./base-polyfiller";
import { Polyfiller1361 } from "./polyfillers/0x1361"; import { Polyfiller1361 } from "./polyfillers/0x1361";
export const polyfillRegistry = new Map<number, BasePolyfiller>(); export const polyfillRegistry = new Map<number, typeof BasePolyfiller>();
const addPolyfiller = (version: number, polyfiller: typeof BasePolyfiller) => { const addPolyfiller = (version: number, polyfiller: typeof BasePolyfiller) => {
polyfillRegistry.set(version, new polyfiller()); polyfillRegistry.set(version, polyfiller);
} }
addPolyfiller(0x1361, Polyfiller1361); addPolyfiller(0x1361, Polyfiller1361);
...@@ -2023,8 +2023,8 @@ netRequestHandler = (client) -> ...@@ -2023,8 +2023,8 @@ netRequestHandler = (client) ->
preconnect = false preconnect = false
if settings.modules.reconnect.enabled and client.pre_reconnecting_to_room if settings.modules.reconnect.enabled and client.pre_reconnecting_to_room
ctos_filter = ["UPDATE_DECK"] ctos_filter = ["UPDATE_DECK"]
if client.name == null else if client.name == null
ctos_filter = ["JOIN_GAME", "PLAYER_INFO"] ctos_filter = ["EXTERNAL_ADDRESS", "JOIN_GAME", "PLAYER_INFO"]
preconnect = true preconnect = true
handle_data = await ygopro.helper.handleBuffer(ctos_buffer, "CTOS", ctos_filter, { handle_data = await ygopro.helper.handleBuffer(ctos_buffer, "CTOS", ctos_filter, {
client: client, client: client,
...@@ -2594,8 +2594,12 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)-> ...@@ -2594,8 +2594,12 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
return unless room and !client.reconnecting return unless room and !client.reconnecting
msg = buffer.readInt8(0) msg = buffer.readInt8(0)
msg_name = ygopro.constants.MSG[msg] msg_name = ygopro.constants.MSG[msg]
if await msg_polyfill.polyfillGameMsg(client.actual_version, msg_name, buffer) shrink_count = await msg_polyfill.polyfillGameMsg(client.actual_version, msg_name, buffer)
if shrink_count == 0x3f3f3f3f
return true return true
record_last_game_msg = () ->
client.last_game_msg = Buffer.from(buffer.slice(0, buffer.length - shrink_count))
client.last_game_msg_title = msg_name
#console.log client.pos, "MSG", msg_name #console.log client.pos, "MSG", msg_name
if msg_name == 'RETRY' and room.recovering if msg_name == 'RETRY' and room.recovering
room.finish_recover(true) room.finish_recover(true)
...@@ -2621,12 +2625,10 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)-> ...@@ -2621,12 +2625,10 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
ygopro.stoc_send(client, 'GAME_MSG', client.last_game_msg) ygopro.stoc_send(client, 'GAME_MSG', client.last_game_msg)
return true return true
else else
client.last_game_msg = buffer record_last_game_msg()
client.last_game_msg_title = msg_name
# log.info(client.name, client.last_game_msg_title) # log.info(client.name, client.last_game_msg_title)
else if msg_name != 'RETRY' else if msg_name != 'RETRY'
client.last_game_msg = buffer record_last_game_msg()
client.last_game_msg_title = msg_name
# log.info(client.name, client.last_game_msg_title) # log.info(client.name, client.last_game_msg_title)
if (msg >= 10 and msg < 30) or msg == 132 or (msg >= 140 and msg <= 144) #SELECT和ANNOUNCE开头的消息 if (msg >= 10 and msg < 30) or msg == 132 or (msg >= 140 and msg <= 144) #SELECT和ANNOUNCE开头的消息
...@@ -2871,7 +2873,10 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)-> ...@@ -2871,7 +2873,10 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
room.recover_buffers[client.pos].push(buffer) room.recover_buffers[client.pos].push(buffer)
return true return true
await return false if shrink_count > 0
return "_shrink_#{shrink_count}"
else
return false
#房间管理 #房间管理
ygopro.ctos_follow 'HS_TOOBSERVER', true, (buffer, info, client, server, datas)-> ygopro.ctos_follow 'HS_TOOBSERVER', true, (buffer, info, client, server, datas)->
...@@ -3476,8 +3481,7 @@ ygopro.ctos_follow 'RESPONSE', true, (buffer, info, client, server, datas)-> ...@@ -3476,8 +3481,7 @@ ygopro.ctos_follow 'RESPONSE', true, (buffer, info, client, server, datas)->
room=ROOM_all[client.rid] room=ROOM_all[client.rid]
if room and (room.random_type or room.arena) if room and (room.random_type or room.arena)
room.refreshLastActiveTime() room.refreshLastActiveTime()
if await msg_polyfill.polyfillResponse(client.actual_version, client.last_game_msg_title, buffer) await msg_polyfill.polyfillResponse(client.actual_version, client.last_game_msg_title, buffer)
return true
return false return false
ygopro.stoc_follow 'TIME_LIMIT', true, (buffer, info, client, server, datas)-> ygopro.stoc_follow 'TIME_LIMIT', true, (buffer, info, client, server, datas)->
......
...@@ -2708,9 +2708,8 @@ ...@@ -2708,9 +2708,8 @@
preconnect = false; preconnect = false;
if (settings.modules.reconnect.enabled && client.pre_reconnecting_to_room) { if (settings.modules.reconnect.enabled && client.pre_reconnecting_to_room) {
ctos_filter = ["UPDATE_DECK"]; ctos_filter = ["UPDATE_DECK"];
} } else if (client.name === null) {
if (client.name === null) { ctos_filter = ["EXTERNAL_ADDRESS", "JOIN_GAME", "PLAYER_INFO"];
ctos_filter = ["JOIN_GAME", "PLAYER_INFO"];
preconnect = true; preconnect = true;
} }
handle_data = (await ygopro.helper.handleBuffer(ctos_buffer, "CTOS", ctos_filter, { handle_data = (await ygopro.helper.handleBuffer(ctos_buffer, "CTOS", ctos_filter, {
...@@ -3406,16 +3405,21 @@ ...@@ -3406,16 +3405,21 @@
}; };
ygopro.stoc_follow('GAME_MSG', true, async function(buffer, info, client, server, datas) { ygopro.stoc_follow('GAME_MSG', true, async function(buffer, info, client, server, datas) {
var card, chain, check, count, cpos, deck_found, found, hint_type, i, id, j, l, len, len1, len2, len3, limbo_found, line, loc, m, max_loop, msg, msg_name, n, o, oppo_pos, phase, player, playertype, pos, ppos, reason, ref, ref1, ref2, ref3, ref4, ref5, room, trigger_location, val, win_pos; var card, chain, check, count, cpos, deck_found, found, hint_type, i, id, j, l, len, len1, len2, len3, limbo_found, line, loc, m, max_loop, msg, msg_name, n, o, oppo_pos, phase, player, playertype, pos, ppos, reason, record_last_game_msg, ref, ref1, ref2, ref3, ref4, ref5, room, shrink_count, trigger_location, val, win_pos;
room = ROOM_all[client.rid]; room = ROOM_all[client.rid];
if (!(room && !client.reconnecting)) { if (!(room && !client.reconnecting)) {
return; return;
} }
msg = buffer.readInt8(0); msg = buffer.readInt8(0);
msg_name = ygopro.constants.MSG[msg]; msg_name = ygopro.constants.MSG[msg];
if ((await msg_polyfill.polyfillGameMsg(client.actual_version, msg_name, buffer))) { shrink_count = (await msg_polyfill.polyfillGameMsg(client.actual_version, msg_name, buffer));
if (shrink_count === 0x3f3f3f3f) {
return true; return true;
} }
record_last_game_msg = function() {
client.last_game_msg = Buffer.from(buffer.slice(0, buffer.length - shrink_count));
return client.last_game_msg_title = msg_name;
};
//console.log client.pos, "MSG", msg_name //console.log client.pos, "MSG", msg_name
if (msg_name === 'RETRY' && room.recovering) { if (msg_name === 'RETRY' && room.recovering) {
room.finish_recover(true); room.finish_recover(true);
...@@ -3447,13 +3451,11 @@ ...@@ -3447,13 +3451,11 @@
return true; return true;
} }
} else { } else {
client.last_game_msg = buffer; record_last_game_msg();
client.last_game_msg_title = msg_name;
} }
// log.info(client.name, client.last_game_msg_title) // log.info(client.name, client.last_game_msg_title)
} else if (msg_name !== 'RETRY') { } else if (msg_name !== 'RETRY') {
client.last_game_msg = buffer; record_last_game_msg();
client.last_game_msg_title = msg_name;
} }
// log.info(client.name, client.last_game_msg_title) // log.info(client.name, client.last_game_msg_title)
if ((msg >= 10 && msg < 30) || msg === 132 || (msg >= 140 && msg <= 144)) { //SELECT和ANNOUNCE开头的消息 if ((msg >= 10 && msg < 30) || msg === 132 || (msg >= 140 && msg <= 144)) { //SELECT和ANNOUNCE开头的消息
...@@ -3790,7 +3792,11 @@ ...@@ -3790,7 +3792,11 @@
} }
return true; return true;
} }
return false; if (shrink_count > 0) {
return `_shrink_${shrink_count}`;
} else {
return false;
}
}); });
//房间管理 //房间管理
...@@ -4672,9 +4678,7 @@ ...@@ -4672,9 +4678,7 @@
if (room && (room.random_type || room.arena)) { if (room && (room.random_type || room.arena)) {
room.refreshLastActiveTime(); room.refreshLastActiveTime();
} }
if ((await msg_polyfill.polyfillResponse(client.version, client.last_game_msg_title, buffer))) { await msg_polyfill.polyfillResponse(client.actual_version, client.last_game_msg_title, buffer);
return true;
}
return false; return false;
}); });
......
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