Commit 19df303c authored by 水濑真白's avatar 水濑真白

Merge remote-tracking branch 'upstream/master' into develop

parents 23c4aecd 74e0ee58
Pipeline #43230 failed with stages
in 126 minutes and 17 seconds
...@@ -6,10 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true }); ...@@ -6,10 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.YGOProMessagesHelper = exports.LegacyStruct = exports.LegacyStructInst = void 0; exports.YGOProMessagesHelper = exports.LegacyStruct = exports.LegacyStructInst = void 0;
const underscore_1 = __importDefault(require("underscore")); const underscore_1 = __importDefault(require("underscore"));
const load_constants_1 = __importDefault(require("./load-constants")); const load_constants_1 = __importDefault(require("./load-constants"));
const bunyan_1 = __importDefault(require("bunyan"));
const ygopro_msg_encode_1 = require("ygopro-msg-encode"); const ygopro_msg_encode_1 = require("ygopro-msg-encode");
const ygopro_msg_struct_compat_1 = require("./ygopro-msg-struct-compat"); const ygopro_msg_struct_compat_1 = require("./ygopro-msg-struct-compat");
const proto_structs_json_1 = __importDefault(require("./data/proto_structs.json")); const proto_structs_json_1 = __importDefault(require("./data/proto_structs.json"));
const utility_1 = require("./utility"); const utility_1 = require("./utility");
const log = global.log || bunyan_1.default.createLogger({ name: "mycard" });
class Handler { class Handler {
constructor(handler, synchronous) { constructor(handler, synchronous) {
this.handler = handler; this.handler = handler;
...@@ -236,9 +238,25 @@ class YGOProMessagesHelper { ...@@ -236,9 +238,25 @@ class YGOProMessagesHelper {
if (proto && handlerCollection.has(bufferProto)) { if (proto && handlerCollection.has(bufferProto)) {
for (const handler of handlerCollection.get(bufferProto)) { for (const handler of handlerCollection.get(bufferProto)) {
const protoCls = this.getProtoClass(bufferProto, direction); const protoCls = this.getProtoClass(bufferProto, direction);
const info = protoCls let info = null;
? (0, ygopro_msg_struct_compat_1.applyYGOProMsgStructCompat)(new protoCls().fromPayload(buffer)) if (protoCls) {
: null; try {
info = (0, ygopro_msg_struct_compat_1.applyYGOProMsgStructCompat)(new protoCls().fromPayload(buffer));
}
catch (e) {
// 解析失败不能卡死服务器:记录 warn,然后把 info 置为 {} 继续走 handler
log.warn({
err: e,
direction,
proto,
bufferProto,
messageLength,
protoCls: protoCls?.name,
bufferHex: buffer?.toString("hex")?.slice(0, 256),
}, "YGOPro message parse failed");
info = {};
}
}
cancel = await handler.handle(buffer, info, datas, params); cancel = await handler.handle(buffer, info, datas, params);
if (cancel) { if (cancel) {
if (Buffer.isBuffer(cancel)) { if (Buffer.isBuffer(cancel)) {
......
import _ from "underscore"; import _ from "underscore";
import loadConstants from "./load-constants"; import loadConstants from "./load-constants";
import net from "net"; import net from "net";
import bunyan from "bunyan";
import { YGOProCtos, YGOProCtosBase, YGOProStoc, YGOProStocBase } from "ygopro-msg-encode"; import { YGOProCtos, YGOProCtosBase, YGOProStoc, YGOProStocBase } from "ygopro-msg-encode";
import { applyYGOProMsgStructCompat, fromPartialCompat } from "./ygopro-msg-struct-compat"; import { applyYGOProMsgStructCompat, fromPartialCompat } from "./ygopro-msg-struct-compat";
import legacyProtoStructs from "./data/proto_structs.json"; import legacyProtoStructs from "./data/proto_structs.json";
import { overwriteBuffer } from "./utility"; import { overwriteBuffer } from "./utility";
const log: bunyan = ((global as any).log as bunyan) || bunyan.createLogger({ name: "mycard" });
class Handler { class Handler {
constructor( constructor(
...@@ -287,9 +290,27 @@ export class YGOProMessagesHelper { ...@@ -287,9 +290,27 @@ export class YGOProMessagesHelper {
if (proto && handlerCollection.has(bufferProto)) { if (proto && handlerCollection.has(bufferProto)) {
for (const handler of handlerCollection.get(bufferProto)) { for (const handler of handlerCollection.get(bufferProto)) {
const protoCls = this.getProtoClass(bufferProto, direction); const protoCls = this.getProtoClass(bufferProto, direction);
const info = protoCls let info: any = null;
? applyYGOProMsgStructCompat(new protoCls().fromPayload(buffer)) if (protoCls) {
: null; try {
info = applyYGOProMsgStructCompat(new protoCls().fromPayload(buffer));
} catch (e: any) {
// 解析失败不能卡死服务器:记录 warn,然后把 info 置为 {} 继续走 handler
log.warn(
{
err: e,
direction,
proto,
bufferProto,
messageLength,
protoCls: protoCls?.name,
bufferHex: buffer?.toString("hex")?.slice(0, 256),
},
"YGOPro message parse failed"
);
info = {};
}
}
cancel = await handler.handle(buffer, info, datas, params); cancel = await handler.handle(buffer, info, datas, params);
if (cancel) { if (cancel) {
if (Buffer.isBuffer(cancel)) { if (Buffer.isBuffer(cancel)) {
......
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