Commit ffe6f9a1 authored by nanahira's avatar nanahira

Merge branch 'msg-encode' of ../srvpro into develop

parents 8c03717a ab9e3c3d
Pipeline #42908 passed with stages
in 7 minutes and 46 seconds
...@@ -9,6 +9,7 @@ const load_constants_1 = __importDefault(require("./load-constants")); ...@@ -9,6 +9,7 @@ const load_constants_1 = __importDefault(require("./load-constants"));
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");
class Handler { class Handler {
constructor(handler, synchronous) { constructor(handler, synchronous) {
this.handler = handler; this.handler = handler;
...@@ -38,15 +39,7 @@ class LegacyStructInst { ...@@ -38,15 +39,7 @@ class LegacyStructInst {
return; return;
const inst = (0, ygopro_msg_struct_compat_1.applyYGOProMsgStructCompat)(new this.cls().fromPayload(this.buffer)); const inst = (0, ygopro_msg_struct_compat_1.applyYGOProMsgStructCompat)(new this.cls().fromPayload(this.buffer));
inst[field] = value; inst[field] = value;
const parsed = Buffer.from(inst.toPayload()); (0, utility_1.overwriteBuffer)(this.buffer, inst.toPayload());
if (parsed.length >= this.buffer.length) {
// slice it down
parsed.copy(this.buffer, 0, 0, this.buffer.length);
}
else {
// copy a small part only
parsed.copy(this.buffer, 0, 0, parsed.length);
}
} }
} }
exports.LegacyStructInst = LegacyStructInst; exports.LegacyStructInst = LegacyStructInst;
......
...@@ -4,6 +4,7 @@ import net from "net"; ...@@ -4,6 +4,7 @@ import net from "net";
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";
class Handler { class Handler {
...@@ -82,14 +83,7 @@ export class LegacyStructInst { ...@@ -82,14 +83,7 @@ export class LegacyStructInst {
if (!this.buffer || !this.cls) return; if (!this.buffer || !this.cls) return;
const inst = applyYGOProMsgStructCompat(new this.cls().fromPayload(this.buffer)); const inst = applyYGOProMsgStructCompat(new this.cls().fromPayload(this.buffer));
inst[field] = value; inst[field] = value;
const parsed = Buffer.from(inst.toPayload()); overwriteBuffer(this.buffer, inst.toPayload());
if (parsed.length >= this.buffer.length) {
// slice it down
parsed.copy(this.buffer, 0, 0, this.buffer.length);
} else {
// copy a small part only
parsed.copy(this.buffer, 0, 0, parsed.length);
}
} }
} }
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
"license": "AGPL-3.0", "license": "AGPL-3.0",
"dependencies": { "dependencies": {
"aragami": "^1.2.5", "aragami": "^1.2.5",
"async": "^3.2.0",
"axios": "^0.19.2", "axios": "^0.19.2",
"bunyan": "^1.8.14", "bunyan": "^1.8.14",
"deepmerge": "^4.2.2", "deepmerge": "^4.2.2",
...@@ -25,8 +24,6 @@ ...@@ -25,8 +24,6 @@
"mysql": "^2.18.1", "mysql": "^2.18.1",
"node-os-utils": "^1.3.2", "node-os-utils": "^1.3.2",
"p-queue": "^6.6.2", "p-queue": "^6.6.2",
"pg": "^6.4.2",
"q": "^1.5.1",
"querystring": "^0.2.0", "querystring": "^0.2.0",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"request": "^2.88.2", "request": "^2.88.2",
...@@ -36,11 +33,10 @@ ...@@ -36,11 +33,10 @@
"underscore.string": "^3.3.6", "underscore.string": "^3.3.6",
"ws": "^8.9.0", "ws": "^8.9.0",
"ygopro-deck-encode": "^1.0.15", "ygopro-deck-encode": "^1.0.15",
"ygopro-msg-encode": "^1.1.5", "ygopro-msg-encode": "^1.1.6",
"ygopro-yrp-encode": "^1.0.1" "ygopro-yrp-encode": "^1.0.1"
}, },
"devDependencies": { "devDependencies": {
"@types/async": "^3.2.25",
"@types/bunyan": "^1.8.8", "@types/bunyan": "^1.8.8",
"@types/formidable": "^3.4.6", "@types/formidable": "^3.4.6",
"@types/ip6addr": "^0.2.3", "@types/ip6addr": "^0.2.3",
...@@ -107,13 +103,6 @@ ...@@ -107,13 +103,6 @@
"resolved": "https://registry.npmjs.org/@sqltools/formatter/-/formatter-1.2.2.tgz", "resolved": "https://registry.npmjs.org/@sqltools/formatter/-/formatter-1.2.2.tgz",
"integrity": "sha512-/5O7Fq6Vnv8L6ucmPjaWbVG1XkP4FO+w5glqfkIsq3Xw4oyNAdJddbnYodNDAfjVUvo/rrSCTom4kAND7T1o5Q==" "integrity": "sha512-/5O7Fq6Vnv8L6ucmPjaWbVG1XkP4FO+w5glqfkIsq3Xw4oyNAdJddbnYodNDAfjVUvo/rrSCTom4kAND7T1o5Q=="
}, },
"node_modules/@types/async": {
"version": "3.2.25",
"resolved": "https://registry.npmjs.org/@types/async/-/async-3.2.25.tgz",
"integrity": "sha512-O6Th/DI18XjrL9TX8LO9F/g26qAz5vynmQqlXt/qLGrskvzCKXKc5/tATz3G2N6lM8eOf3M8/StB14FncAmocg==",
"dev": true,
"license": "MIT"
},
"node_modules/@types/bunyan": { "node_modules/@types/bunyan": {
"version": "1.8.8", "version": "1.8.8",
"resolved": "https://registry.npmjs.org/@types/bunyan/-/bunyan-1.8.8.tgz", "resolved": "https://registry.npmjs.org/@types/bunyan/-/bunyan-1.8.8.tgz",
...@@ -291,11 +280,6 @@ ...@@ -291,11 +280,6 @@
"node": ">=0.8" "node": ">=0.8"
} }
}, },
"node_modules/async": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/async/-/async-3.2.0.tgz",
"integrity": "sha512-TR2mEZFVOj2pLStYxLht7TyfuRzaydfpxr3k9RpHIzMgw7A64dzsdqCxH1WJyQdoe8T10nDXd9wnEigmiuHIZw=="
},
"node_modules/asynckit": { "node_modules/asynckit": {
"version": "0.4.0", "version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
...@@ -428,11 +412,6 @@ ...@@ -428,11 +412,6 @@
"ieee754": "^1.1.13" "ieee754": "^1.1.13"
} }
}, },
"node_modules/buffer-writer": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/buffer-writer/-/buffer-writer-1.0.1.tgz",
"integrity": "sha1-Iqk2kB4wKa/NdUfrRIfOtpejvwg="
},
"node_modules/buffers": { "node_modules/buffers": {
"version": "0.1.1", "version": "0.1.1",
"resolved": "https://registry.npmjs.org/buffers/-/buffers-0.1.1.tgz", "resolved": "https://registry.npmjs.org/buffers/-/buffers-0.1.1.tgz",
...@@ -1149,14 +1128,6 @@ ...@@ -1149,14 +1128,6 @@
"url": "https://github.com/sponsors/ljharb" "url": "https://github.com/sponsors/ljharb"
} }
}, },
"node_modules/generic-pool": {
"version": "2.4.3",
"resolved": "https://registry.npmjs.org/generic-pool/-/generic-pool-2.4.3.tgz",
"integrity": "sha1-eAw29p360FpaBF3Te+etyhGk9v8=",
"engines": {
"node": ">= 0.2.0"
}
},
"node_modules/geoip-country-lite": { "node_modules/geoip-country-lite": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/geoip-country-lite/-/geoip-country-lite-1.0.0.tgz", "resolved": "https://registry.npmjs.org/geoip-country-lite/-/geoip-country-lite-1.0.0.tgz",
...@@ -1593,14 +1564,6 @@ ...@@ -1593,14 +1564,6 @@
"resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz",
"integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=" "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo="
}, },
"node_modules/js-string-escape": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/js-string-escape/-/js-string-escape-1.0.1.tgz",
"integrity": "sha1-4mJbrbwNZ8dTPp7cEGjFh65BN+8=",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/js-tokens": { "node_modules/js-tokens": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
...@@ -1988,11 +1951,6 @@ ...@@ -1988,11 +1951,6 @@
"node": ">=6" "node": ">=6"
} }
}, },
"node_modules/packet-reader": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/packet-reader/-/packet-reader-0.3.1.tgz",
"integrity": "sha1-zWLmCvjX/qinBexP+ZCHHEaHHyc="
},
"node_modules/pako": { "node_modules/pako": {
"version": "1.0.11", "version": "1.0.11",
"resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz", "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz",
...@@ -2057,82 +2015,6 @@ ...@@ -2057,82 +2015,6 @@
"resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz",
"integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=" "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns="
}, },
"node_modules/pg": {
"version": "6.4.2",
"resolved": "https://registry.npmjs.org/pg/-/pg-6.4.2.tgz",
"integrity": "sha1-w2QBEGDqx6UHoq4GPrhX7OkQ4n8=",
"dependencies": {
"buffer-writer": "1.0.1",
"js-string-escape": "1.0.1",
"packet-reader": "0.3.1",
"pg-connection-string": "0.1.3",
"pg-pool": "1.*",
"pg-types": "1.*",
"pgpass": "1.*",
"semver": "4.3.2"
},
"engines": {
"node": ">= 0.8.0"
}
},
"node_modules/pg-connection-string": {
"version": "0.1.3",
"resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-0.1.3.tgz",
"integrity": "sha1-2hhHsglA5C7hSSvq9l1J2RskXfc="
},
"node_modules/pg-int8": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz",
"integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==",
"engines": {
"node": ">=4.0.0"
}
},
"node_modules/pg-pool": {
"version": "1.8.0",
"resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-1.8.0.tgz",
"integrity": "sha1-9+xzgkw3oD8Hb1G/33DjQBR8Tzc=",
"dependencies": {
"generic-pool": "2.4.3",
"object-assign": "4.1.0"
}
},
"node_modules/pg-pool/node_modules/object-assign": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.0.tgz",
"integrity": "sha1-ejs9DpgGPUP0wD8uiubNUahog6A=",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/pg-types": {
"version": "1.13.0",
"resolved": "https://registry.npmjs.org/pg-types/-/pg-types-1.13.0.tgz",
"integrity": "sha512-lfKli0Gkl/+za/+b6lzENajczwZHc7D5kiUCZfgm914jipD2kIOIvEkAhZ8GrW3/TUoP9w8FHjwpPObBye5KQQ==",
"dependencies": {
"pg-int8": "1.0.1",
"postgres-array": "~1.0.0",
"postgres-bytea": "~1.0.0",
"postgres-date": "~1.0.0",
"postgres-interval": "^1.1.0"
}
},
"node_modules/pg/node_modules/semver": {
"version": "4.3.2",
"resolved": "https://registry.npmjs.org/semver/-/semver-4.3.2.tgz",
"integrity": "sha1-x6BxWKgL7dBSNVt3DYLWZA+AO+c=",
"bin": {
"semver": "bin/semver"
}
},
"node_modules/pgpass": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.2.tgz",
"integrity": "sha1-Knu0G2BltnkH6R2hsHwYR8h3swY=",
"dependencies": {
"split": "^1.0.0"
}
},
"node_modules/possible-typed-array-names": { "node_modules/possible-typed-array-names": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/possible-typed-array-names/-/possible-typed-array-names-1.1.0.tgz", "resolved": "https://registry.npmjs.org/possible-typed-array-names/-/possible-typed-array-names-1.1.0.tgz",
...@@ -2142,41 +2024,6 @@ ...@@ -2142,41 +2024,6 @@
"node": ">= 0.4" "node": ">= 0.4"
} }
}, },
"node_modules/postgres-array": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-1.0.2.tgz",
"integrity": "sha1-jgsy6wO/d6XAp4UeBEHBaaJWojg=",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/postgres-bytea": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.0.tgz",
"integrity": "sha1-AntTPAqokOJtFy1Hz5zOzFIazTU=",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/postgres-date": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.3.tgz",
"integrity": "sha1-4tiXAu/bJY/52c7g/pG9BpdSV6g=",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/postgres-interval": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.1.2.tgz",
"integrity": "sha512-fC3xNHeTskCxL1dC8KOtxXt7YeFmlbTYtn7ul8MkVERuTmf7pI4DrkAxcw3kh1fQ9uz4wQmd03a1mRiXUZChfQ==",
"dependencies": {
"xtend": "^4.0.0"
},
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/process-nextick-args": { "node_modules/process-nextick-args": {
"version": "2.0.1", "version": "2.0.1",
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
...@@ -2204,15 +2051,6 @@ ...@@ -2204,15 +2051,6 @@
"node": ">=6" "node": ">=6"
} }
}, },
"node_modules/q": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/q/-/q-1.5.1.tgz",
"integrity": "sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc=",
"engines": {
"node": ">=0.6.0",
"teleport": ">=0.2.0"
}
},
"node_modules/qs": { "node_modules/qs": {
"version": "6.5.2", "version": "6.5.2",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz", "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz",
...@@ -2412,17 +2250,6 @@ ...@@ -2412,17 +2250,6 @@
"resolved": "https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz", "resolved": "https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz",
"integrity": "sha1-P/IfGYytIXX587eBhT/ZTQ0ZtZA=" "integrity": "sha1-P/IfGYytIXX587eBhT/ZTQ0ZtZA="
}, },
"node_modules/split": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/split/-/split-1.0.1.tgz",
"integrity": "sha512-mTyOoPbrivtXnwnIxZRFYRrPNtEFKlpB2fvjSnCQUiAA6qAZzqwna5envK4uk6OIeP17CsdF3rSBGYVBsU0Tkg==",
"dependencies": {
"through": "2"
},
"engines": {
"node": "*"
}
},
"node_modules/sprintf-js": { "node_modules/sprintf-js": {
"version": "1.1.2", "version": "1.1.2",
"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.2.tgz", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.2.tgz",
...@@ -2542,11 +2369,6 @@ ...@@ -2542,11 +2369,6 @@
"node": ">=0.8" "node": ">=0.8"
} }
}, },
"node_modules/through": {
"version": "2.3.8",
"resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz",
"integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU="
},
"node_modules/to-buffer": { "node_modules/to-buffer": {
"version": "1.2.1", "version": "1.2.1",
"resolved": "https://registry.npmjs.org/to-buffer/-/to-buffer-1.2.1.tgz", "resolved": "https://registry.npmjs.org/to-buffer/-/to-buffer-1.2.1.tgz",
...@@ -3009,14 +2831,6 @@ ...@@ -3009,14 +2831,6 @@
"node": ">=4.0" "node": ">=4.0"
} }
}, },
"node_modules/xtend": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz",
"integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68=",
"engines": {
"node": ">=0.4"
}
},
"node_modules/y18n": { "node_modules/y18n": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz",
...@@ -3211,9 +3025,9 @@ ...@@ -3211,9 +3025,9 @@
"license": "MIT" "license": "MIT"
}, },
"node_modules/ygopro-msg-encode": { "node_modules/ygopro-msg-encode": {
"version": "1.1.5", "version": "1.1.6",
"resolved": "https://registry.npmjs.org/ygopro-msg-encode/-/ygopro-msg-encode-1.1.5.tgz", "resolved": "https://registry.npmjs.org/ygopro-msg-encode/-/ygopro-msg-encode-1.1.6.tgz",
"integrity": "sha512-scsIDy7aBksNXCDiIEij23JIpVF1bosGvUJ2OGtfbcmuMEMbrUlX6JQp179AL86sjTkQg8DJ8cYj4UzEYMrrtQ==", "integrity": "sha512-ViNMcSM5o32zW0GhaPgXCQSz8hJJ/4Nd5HPQVRA6o9qqZ+2+0tjLZX8vviMA48iFmsA03ABTx6Y5iT8h1e11jQ==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"typed-reflector": "^1.0.14", "typed-reflector": "^1.0.14",
...@@ -3277,12 +3091,6 @@ ...@@ -3277,12 +3091,6 @@
"resolved": "https://registry.npmjs.org/@sqltools/formatter/-/formatter-1.2.2.tgz", "resolved": "https://registry.npmjs.org/@sqltools/formatter/-/formatter-1.2.2.tgz",
"integrity": "sha512-/5O7Fq6Vnv8L6ucmPjaWbVG1XkP4FO+w5glqfkIsq3Xw4oyNAdJddbnYodNDAfjVUvo/rrSCTom4kAND7T1o5Q==" "integrity": "sha512-/5O7Fq6Vnv8L6ucmPjaWbVG1XkP4FO+w5glqfkIsq3Xw4oyNAdJddbnYodNDAfjVUvo/rrSCTom4kAND7T1o5Q=="
}, },
"@types/async": {
"version": "3.2.25",
"resolved": "https://registry.npmjs.org/@types/async/-/async-3.2.25.tgz",
"integrity": "sha512-O6Th/DI18XjrL9TX8LO9F/g26qAz5vynmQqlXt/qLGrskvzCKXKc5/tATz3G2N6lM8eOf3M8/StB14FncAmocg==",
"dev": true
},
"@types/bunyan": { "@types/bunyan": {
"version": "1.8.8", "version": "1.8.8",
"resolved": "https://registry.npmjs.org/@types/bunyan/-/bunyan-1.8.8.tgz", "resolved": "https://registry.npmjs.org/@types/bunyan/-/bunyan-1.8.8.tgz",
...@@ -3434,11 +3242,6 @@ ...@@ -3434,11 +3242,6 @@
"resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz",
"integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU="
}, },
"async": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/async/-/async-3.2.0.tgz",
"integrity": "sha512-TR2mEZFVOj2pLStYxLht7TyfuRzaydfpxr3k9RpHIzMgw7A64dzsdqCxH1WJyQdoe8T10nDXd9wnEigmiuHIZw=="
},
"asynckit": { "asynckit": {
"version": "0.4.0", "version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
...@@ -3525,11 +3328,6 @@ ...@@ -3525,11 +3328,6 @@
"ieee754": "^1.1.13" "ieee754": "^1.1.13"
} }
}, },
"buffer-writer": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/buffer-writer/-/buffer-writer-1.0.1.tgz",
"integrity": "sha1-Iqk2kB4wKa/NdUfrRIfOtpejvwg="
},
"buffers": { "buffers": {
"version": "0.1.1", "version": "0.1.1",
"resolved": "https://registry.npmjs.org/buffers/-/buffers-0.1.1.tgz", "resolved": "https://registry.npmjs.org/buffers/-/buffers-0.1.1.tgz",
...@@ -4047,11 +3845,6 @@ ...@@ -4047,11 +3845,6 @@
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==" "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA=="
}, },
"generic-pool": {
"version": "2.4.3",
"resolved": "https://registry.npmjs.org/generic-pool/-/generic-pool-2.4.3.tgz",
"integrity": "sha1-eAw29p360FpaBF3Te+etyhGk9v8="
},
"geoip-country-lite": { "geoip-country-lite": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/geoip-country-lite/-/geoip-country-lite-1.0.0.tgz", "resolved": "https://registry.npmjs.org/geoip-country-lite/-/geoip-country-lite-1.0.0.tgz",
...@@ -4360,11 +4153,6 @@ ...@@ -4360,11 +4153,6 @@
"resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz",
"integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=" "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo="
}, },
"js-string-escape": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/js-string-escape/-/js-string-escape-1.0.1.tgz",
"integrity": "sha1-4mJbrbwNZ8dTPp7cEGjFh65BN+8="
},
"js-tokens": { "js-tokens": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
...@@ -4671,11 +4459,6 @@ ...@@ -4671,11 +4459,6 @@
"resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz",
"integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==" "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ=="
}, },
"packet-reader": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/packet-reader/-/packet-reader-0.3.1.tgz",
"integrity": "sha1-zWLmCvjX/qinBexP+ZCHHEaHHyc="
},
"pako": { "pako": {
"version": "1.0.11", "version": "1.0.11",
"resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz", "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz",
...@@ -4725,102 +4508,11 @@ ...@@ -4725,102 +4508,11 @@
"resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz",
"integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=" "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns="
}, },
"pg": {
"version": "6.4.2",
"resolved": "https://registry.npmjs.org/pg/-/pg-6.4.2.tgz",
"integrity": "sha1-w2QBEGDqx6UHoq4GPrhX7OkQ4n8=",
"requires": {
"buffer-writer": "1.0.1",
"js-string-escape": "1.0.1",
"packet-reader": "0.3.1",
"pg-connection-string": "0.1.3",
"pg-pool": "1.*",
"pg-types": "1.*",
"pgpass": "1.*",
"semver": "4.3.2"
},
"dependencies": {
"semver": {
"version": "4.3.2",
"resolved": "https://registry.npmjs.org/semver/-/semver-4.3.2.tgz",
"integrity": "sha1-x6BxWKgL7dBSNVt3DYLWZA+AO+c="
}
}
},
"pg-connection-string": {
"version": "0.1.3",
"resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-0.1.3.tgz",
"integrity": "sha1-2hhHsglA5C7hSSvq9l1J2RskXfc="
},
"pg-int8": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz",
"integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw=="
},
"pg-pool": {
"version": "1.8.0",
"resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-1.8.0.tgz",
"integrity": "sha1-9+xzgkw3oD8Hb1G/33DjQBR8Tzc=",
"requires": {
"generic-pool": "2.4.3",
"object-assign": "4.1.0"
},
"dependencies": {
"object-assign": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.0.tgz",
"integrity": "sha1-ejs9DpgGPUP0wD8uiubNUahog6A="
}
}
},
"pg-types": {
"version": "1.13.0",
"resolved": "https://registry.npmjs.org/pg-types/-/pg-types-1.13.0.tgz",
"integrity": "sha512-lfKli0Gkl/+za/+b6lzENajczwZHc7D5kiUCZfgm914jipD2kIOIvEkAhZ8GrW3/TUoP9w8FHjwpPObBye5KQQ==",
"requires": {
"pg-int8": "1.0.1",
"postgres-array": "~1.0.0",
"postgres-bytea": "~1.0.0",
"postgres-date": "~1.0.0",
"postgres-interval": "^1.1.0"
}
},
"pgpass": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.2.tgz",
"integrity": "sha1-Knu0G2BltnkH6R2hsHwYR8h3swY=",
"requires": {
"split": "^1.0.0"
}
},
"possible-typed-array-names": { "possible-typed-array-names": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/possible-typed-array-names/-/possible-typed-array-names-1.1.0.tgz", "resolved": "https://registry.npmjs.org/possible-typed-array-names/-/possible-typed-array-names-1.1.0.tgz",
"integrity": "sha512-/+5VFTchJDoVj3bhoqi6UeymcD00DAwb1nJwamzPvHEszJ4FpF6SNNbUbOS8yI56qHzdV8eK0qEfOSiodkTdxg==" "integrity": "sha512-/+5VFTchJDoVj3bhoqi6UeymcD00DAwb1nJwamzPvHEszJ4FpF6SNNbUbOS8yI56qHzdV8eK0qEfOSiodkTdxg=="
}, },
"postgres-array": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-1.0.2.tgz",
"integrity": "sha1-jgsy6wO/d6XAp4UeBEHBaaJWojg="
},
"postgres-bytea": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.0.tgz",
"integrity": "sha1-AntTPAqokOJtFy1Hz5zOzFIazTU="
},
"postgres-date": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.3.tgz",
"integrity": "sha1-4tiXAu/bJY/52c7g/pG9BpdSV6g="
},
"postgres-interval": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.1.2.tgz",
"integrity": "sha512-fC3xNHeTskCxL1dC8KOtxXt7YeFmlbTYtn7ul8MkVERuTmf7pI4DrkAxcw3kh1fQ9uz4wQmd03a1mRiXUZChfQ==",
"requires": {
"xtend": "^4.0.0"
}
},
"process-nextick-args": { "process-nextick-args": {
"version": "2.0.1", "version": "2.0.1",
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
...@@ -4845,11 +4537,6 @@ ...@@ -4845,11 +4537,6 @@
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz",
"integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==" "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A=="
}, },
"q": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/q/-/q-1.5.1.tgz",
"integrity": "sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc="
},
"qs": { "qs": {
"version": "6.5.2", "version": "6.5.2",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz", "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz",
...@@ -5002,14 +4689,6 @@ ...@@ -5002,14 +4689,6 @@
"resolved": "https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz", "resolved": "https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz",
"integrity": "sha1-P/IfGYytIXX587eBhT/ZTQ0ZtZA=" "integrity": "sha1-P/IfGYytIXX587eBhT/ZTQ0ZtZA="
}, },
"split": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/split/-/split-1.0.1.tgz",
"integrity": "sha512-mTyOoPbrivtXnwnIxZRFYRrPNtEFKlpB2fvjSnCQUiAA6qAZzqwna5envK4uk6OIeP17CsdF3rSBGYVBsU0Tkg==",
"requires": {
"through": "2"
}
},
"sprintf-js": { "sprintf-js": {
"version": "1.1.2", "version": "1.1.2",
"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.2.tgz", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.2.tgz",
...@@ -5103,11 +4782,6 @@ ...@@ -5103,11 +4782,6 @@
"thenify": ">= 3.1.0 < 4" "thenify": ">= 3.1.0 < 4"
} }
}, },
"through": {
"version": "2.3.8",
"resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz",
"integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU="
},
"to-buffer": { "to-buffer": {
"version": "1.2.1", "version": "1.2.1",
"resolved": "https://registry.npmjs.org/to-buffer/-/to-buffer-1.2.1.tgz", "resolved": "https://registry.npmjs.org/to-buffer/-/to-buffer-1.2.1.tgz",
...@@ -5437,11 +5111,6 @@ ...@@ -5437,11 +5111,6 @@
"resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz", "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz",
"integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==" "integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA=="
}, },
"xtend": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz",
"integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68="
},
"y18n": { "y18n": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz",
...@@ -5591,9 +5260,9 @@ ...@@ -5591,9 +5260,9 @@
"integrity": "sha512-NMvgWuC3SKant50RDu0bHa3QIRlwBhdTR3bNDrMpNthTTQmCCq8i2HZaWFiCmYIBi9fR3W9CkFIgK6hI4d+PzQ==" "integrity": "sha512-NMvgWuC3SKant50RDu0bHa3QIRlwBhdTR3bNDrMpNthTTQmCCq8i2HZaWFiCmYIBi9fR3W9CkFIgK6hI4d+PzQ=="
}, },
"ygopro-msg-encode": { "ygopro-msg-encode": {
"version": "1.1.5", "version": "1.1.6",
"resolved": "https://registry.npmjs.org/ygopro-msg-encode/-/ygopro-msg-encode-1.1.5.tgz", "resolved": "https://registry.npmjs.org/ygopro-msg-encode/-/ygopro-msg-encode-1.1.6.tgz",
"integrity": "sha512-scsIDy7aBksNXCDiIEij23JIpVF1bosGvUJ2OGtfbcmuMEMbrUlX6JQp179AL86sjTkQg8DJ8cYj4UzEYMrrtQ==", "integrity": "sha512-ViNMcSM5o32zW0GhaPgXCQSz8hJJ/4Nd5HPQVRA6o9qqZ+2+0tjLZX8vviMA48iFmsA03ABTx6Y5iT8h1e11jQ==",
"requires": { "requires": {
"typed-reflector": "^1.0.14", "typed-reflector": "^1.0.14",
"ygopro-deck-encode": "^1.0.15", "ygopro-deck-encode": "^1.0.15",
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
"author": "zh99998 <zh99998@gmail.com>, mercury233 <me@mercury233.me>, Nanahira <78877@qq.com>", "author": "zh99998 <zh99998@gmail.com>, mercury233 <me@mercury233.me>, Nanahira <78877@qq.com>",
"dependencies": { "dependencies": {
"aragami": "^1.2.5", "aragami": "^1.2.5",
"async": "^3.2.0",
"axios": "^0.19.2", "axios": "^0.19.2",
"bunyan": "^1.8.14", "bunyan": "^1.8.14",
"deepmerge": "^4.2.2", "deepmerge": "^4.2.2",
...@@ -27,8 +26,6 @@ ...@@ -27,8 +26,6 @@
"mysql": "^2.18.1", "mysql": "^2.18.1",
"node-os-utils": "^1.3.2", "node-os-utils": "^1.3.2",
"p-queue": "^6.6.2", "p-queue": "^6.6.2",
"pg": "^6.4.2",
"q": "^1.5.1",
"querystring": "^0.2.0", "querystring": "^0.2.0",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"request": "^2.88.2", "request": "^2.88.2",
...@@ -38,7 +35,7 @@ ...@@ -38,7 +35,7 @@
"underscore.string": "^3.3.6", "underscore.string": "^3.3.6",
"ws": "^8.9.0", "ws": "^8.9.0",
"ygopro-deck-encode": "^1.0.15", "ygopro-deck-encode": "^1.0.15",
"ygopro-msg-encode": "^1.1.5", "ygopro-msg-encode": "^1.1.6",
"ygopro-yrp-encode": "^1.0.1" "ygopro-yrp-encode": "^1.0.1"
}, },
"license": "AGPL-3.0", "license": "AGPL-3.0",
...@@ -51,7 +48,6 @@ ...@@ -51,7 +48,6 @@
"webhook": "node ygopro-webhook.js" "webhook": "node ygopro-webhook.js"
}, },
"devDependencies": { "devDependencies": {
"@types/async": "^3.2.25",
"@types/bunyan": "^1.8.8", "@types/bunyan": "^1.8.8",
"@types/formidable": "^3.4.6", "@types/formidable": "^3.4.6",
"@types/ip6addr": "^0.2.3", "@types/ip6addr": "^0.2.3",
......
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.overwriteBuffer = void 0;
exports.retry = retry; exports.retry = retry;
async function retry(fn, count, delayFn = (attempt) => Math.pow(2, attempt) * 100) { async function retry(fn, count, delayFn = (attempt) => Math.pow(2, attempt) * 100) {
let lastError; let lastError;
...@@ -18,3 +19,13 @@ async function retry(fn, count, delayFn = (attempt) => Math.pow(2, attempt) * 10 ...@@ -18,3 +19,13 @@ async function retry(fn, count, delayFn = (attempt) => Math.pow(2, attempt) * 10
// 如果全部尝试失败,抛出最后一个错误 // 如果全部尝试失败,抛出最后一个错误
throw lastError; throw lastError;
} }
const overwriteBuffer = (buf, _input) => {
const input = Buffer.isBuffer(_input) ? _input : Buffer.from(_input);
if (input.length >= buf.length) {
input.copy(buf, 0, 0, buf.length);
}
else {
input.copy(buf, 0, 0, input.length);
}
};
exports.overwriteBuffer = overwriteBuffer;
...@@ -20,3 +20,13 @@ export async function retry<T>( ...@@ -20,3 +20,13 @@ export async function retry<T>(
// 如果全部尝试失败,抛出最后一个错误 // 如果全部尝试失败,抛出最后一个错误
throw lastError; throw lastError;
} }
export const overwriteBuffer = (buf: Buffer, _input: Buffer | Uint8Array) => {
const input = Buffer.isBuffer(_input) ? _input : Buffer.from(_input);
if (input.length >= buf.length) {
input.copy(buf, 0, 0, buf.length);
} else {
input.copy(buf, 0, 0, input.length);
}
}
...@@ -34,7 +34,6 @@ var cardHTMLs=[]; ...@@ -34,7 +34,6 @@ var cardHTMLs=[];
var responder; var responder;
//URL里的更新时间戳 //URL里的更新时间戳
var dataver = moment().format("YYYYMMDDHHmmss"); var dataver = moment().format("YYYYMMDDHHmmss");
const _async = require("async");
var sqlJsPromise; var sqlJsPromise;
var SQL = null; var SQL = null;
...@@ -53,6 +52,8 @@ function ensureSqlJs() { ...@@ -53,6 +52,8 @@ function ensureSqlJs() {
return sqlJsPromise; return sqlJsPromise;
} }
var execAsync = util.promisify(exec);
//输出反馈信息,如有http长连接则输出到http,否则输出到控制台 //输出反馈信息,如有http长连接则输出到http,否则输出到控制台
var sendResponse = function(text) { var sendResponse = function(text) {
text=""+text; text=""+text;
...@@ -221,57 +222,55 @@ var loadDb = function(db_file, callback) { ...@@ -221,57 +222,55 @@ var loadDb = function(db_file, callback) {
} }
//将cardHTMLs中内容更新到指定列表页,同步 //将cardHTMLs中内容更新到指定列表页,同步
var writeToFile = function(message, callback) { var writeToFile = async function(message, callback) {
var fileContent=fs.readFileSync(config.html_path+config.html_filename, {"encoding":"utf-8"}); try {
var newContent=cardHTMLs.join("\n"); var fileContent=fs.readFileSync(config.html_path+config.html_filename, {"encoding":"utf-8"});
fileContent=fileContent.replace(/<tbody class="auto-generated">[\w\W]*<\/tbody>/,'<tbody class="auto-generated">\n'+newContent+'\n</tbody>'); var newContent=cardHTMLs.join("\n");
fileContent = fileContent.replace(/data-ygosrv233-download="(http.+)" href="http.+"/g, 'data-ygosrv233-download="$1" href="$1"'); fileContent=fileContent.replace(/<tbody class="auto-generated">[\w\W]*<\/tbody>/,'<tbody class="auto-generated">\n'+newContent+'\n</tbody>');
fileContent = fileContent.replace(/href="(http.+)dataver/g, 'href="$1' + dataver); fileContent = fileContent.replace(/data-ygosrv233-download="(http.+)" href="http.+"/g, 'data-ygosrv233-download="$1" href="$1"');
if (message) { fileContent = fileContent.replace(/href="(http.+)dataver/g, 'href="$1' + dataver);
message="<li>"+moment().format('L HH:mm')+"<ul><li>"+message.split("!换行符!").join("</li><li>")+"</li></ul></li>"; if (message) {
fileContent=fileContent.replace(/<ul class="auto-generated">/,'<ul class="auto-generated">\n'+message); message="<li>"+moment().format('L HH:mm')+"<ul><li>"+message.split("!换行符!").join("</li><li>")+"</li></ul></li>";
} fileContent=fileContent.replace(/<ul class="auto-generated">/,'<ul class="auto-generated">\n'+message);
_async.auto({
write: (done) => {
fs.writeFile(config.html_path + config.html_filename, fileContent, done)
}/*,
copy: ["write", (results, done) => {
if (!config.cdn.enabled) {
copyImages(done);
} else {
done();
}
}]*/
}, (err) => {
if (!err) {
sendResponse("列表更新完成。");
} }
callback(err); await fs.promises.writeFile(config.html_path + config.html_filename, fileContent);
}) // if (!config.cdn.enabled) {
// await util.promisify(copyImages)();
// }
sendResponse("列表更新完成。");
callback(null);
} catch (err) {
callback(err);
}
} }
//读取指定文件夹里所有数据库,异步 //读取指定文件夹里所有数据库,异步
var loadAllDbs = function(callback) { var loadAllDbs = async function(callback) {
cardHTMLs=[]; try {
_async.auto({ cardHTMLs=[];
files: (done) => { var files = await fs.promises.readdir(config.db_path + "expansions/");
fs.readdir(config.db_path + "expansions/", done); var list = files.filter((filename) => {
}, return filename.slice(-4) === ".cdb" && (!config.only_show_dbs || config.only_show_dbs.length == 0 || config.only_show_dbs[filename]);
loadDbs: ["files", (results, done) => { }).map(filename => config.db_path + "expansions/" + filename);
_async.each(results.files.filter((filename) => { for (var i = 0; i < list.length; i++) {
return filename.slice(-4) === ".cdb" && (!config.only_show_dbs || config.only_show_dbs.length == 0 || config.only_show_dbs[filename]) await util.promisify(loadDb)(list[i]);
} ).map(filename => config.db_path + "expansions/" + filename), loadDb, done); }
}] callback(null);
}, callback); } catch (err) {
callback(err);
}
} }
function execCommands(commands, callback) { async function execCommands(commands, callback) {
_async.eachSeries(commands, (command, done) => { try {
exec(command, (err) => { for (var i = 0; i < commands.length; i++) {
done(err); await execAsync(commands[i]);
}); }
}, callback); callback(null);
} catch (err) {
callback(err);
}
} }
//从远程更新数据库,异步 //从远程更新数据库,异步
...@@ -303,22 +302,17 @@ var fetchDatas = function() { ...@@ -303,22 +302,17 @@ var fetchDatas = function() {
} }
//更新本地网页到服务器,异步 //更新本地网页到服务器,异步
var pushDatas = function(callback) { var pushDatas = async function(callback) {
if (config.cdn.enabled) { try {
_async.auto({ if (config.cdn.enabled) {
local: (done) => { await util.promisify(uploadCDN)(config.cdn.local, config.cdn.remote + "/" + dataver);
uploadCDN(config.cdn.local, config.cdn.remote + "/" + dataver, done); await util.promisify(uploadCDN)(config.db_path + "pics", config.cdn.pics_remote + "pics");
}, sendResponse("CDN上传全部完成。");
pics: ["local", (results, done) => { }
uploadCDN(config.db_path + "pics", config.cdn.pics_remote + "pics", done); await util.promisify(pushHTMLs)();
}], callback(null);
push: ["local", "pics", (results, done) => { } catch (err) {
sendResponse("CDN上传全部完成。"); callback(err);
pushHTMLs(done);
}]
}, callback);
} else {
pushHTMLs(callback);
} }
} }
...@@ -432,85 +426,59 @@ function run7z(params, cwd, callback) { ...@@ -432,85 +426,59 @@ function run7z(params, cwd, callback) {
} }
//生成更新包,异步 //生成更新包,异步
var packDatas = function (callback) { var packDatas = async function (callback) {
file_path = config.html_path; file_path = config.html_path;
if (config.cdn.enabled) { if (config.cdn.enabled) {
file_path = config.cdn.local; file_path = config.cdn.local;
} }
try {
_async.auto({ await util.promisify(execCommands)([
preCommands: (done) => { 'rm -rf "' + config.db_path +'expansions/' + config.ypk_name + '"',
execCommands([ 'rm -rf "' + config.db_path +'expansions/script"',
'rm -rf "' + config.db_path +'expansions/' + config.ypk_name + '"', 'rm -rf "' + config.db_path +'expansions/pics"',
'rm -rf "' + config.db_path +'expansions/script"', 'rm -rf "' + config.db_path +'cdb"',
'rm -rf "' + config.db_path +'expansions/pics"', 'rm -rf "' + config.db_path +'picture"',
'rm -rf "' + config.db_path +'cdb"', 'mkdir "' + config.db_path +'picture"',
'rm -rf "' + config.db_path +'picture"', 'cp -r "' + config.db_path + 'expansions" "' + config.db_path + 'cdb"',
'mkdir "' + config.db_path +'picture"', 'cp -r "' + config.db_path + 'pics" "' + config.db_path + 'expansions/pics"',
'cp -r "' + config.db_path + 'expansions" "' + config.db_path + 'cdb"', 'cp -r "' + config.db_path + 'field" "' + config.db_path + 'expansions/pics/field"',
'cp -r "' + config.db_path + 'pics" "' + config.db_path + 'expansions/pics"', 'cp -r "' + config.db_path + 'script" "' + config.db_path + 'expansions/script"',
'cp -r "' + config.db_path + 'field" "' + config.db_path + 'expansions/pics/field"', 'cp -r "' + config.db_path + 'pics" "' + config.db_path + 'picture/card"',
'cp -r "' + config.db_path + 'script" "' + config.db_path + 'expansions/script"', 'cp -r "' + config.db_path + 'field" "' + config.db_path + 'picture/field"'
'cp -r "' + config.db_path + 'pics" "' + config.db_path + 'picture/card"', ]);
'cp -r "' + config.db_path + 'field" "' + config.db_path + 'picture/field"' await util.promisify(run7z)(["a", "-tzip", "-x!*.ypk", config.ypk_name, "*"], config.db_path + "expansions/");
], done); await util.promisify(run7z)(["a", "-x!*.zip", "-x!.git", "-x!LICENSE", "-x!README.md",
}, "-x!cdb", "-x!picture", "-x!field", "-x!script", "-x!pics",
run7zYPK: ["preCommands", (results, done) => { "-x!expansions/pics", "-x!expansions/script", "-x!expansions/*.cdb", "-x!expansions/*.conf",
run7z(["a", "-tzip", "-x!*.ypk", config.ypk_name, "*"], config.db_path + "expansions/", done); "ygosrv233-pre.zip", "*"], config.db_path);
}], await util.promisify(execCommands)([
run7zPC: ["run7zYPK", (results, done) => { 'mv -f "' + config.db_path + 'ygosrv233-pre.zip" "' + file_path + '"'
run7z(["a", "-x!*.zip", "-x!.git", "-x!LICENSE", "-x!README.md", ]);
"-x!cdb", "-x!picture", "-x!field", "-x!script", "-x!pics", sendResponse("电脑更新包打包完成。");
"-x!expansions/pics", "-x!expansions/script", "-x!expansions/*.cdb", "-x!expansions/*.conf", await util.promisify(run7z)(["a", "-x!*.zip", "-x!.git", "-x!LICENSE", "-x!README.md",
"ygosrv233-pre.zip", "*"], config.db_path, done); "-x!cdb", "-x!picture", "-x!field", "-x!script", "-x!pics",
}], "-x!expansions/pics", "-x!expansions/script", "-x!expansions/*.cdb", "-x!expansions/*.conf",
run7zMobile: ["run7zYPK", (results, done) => { "ygosrv233-pre-mobile.zip", "*"], config.db_path);
run7z(["a", "-x!*.zip", "-x!.git", "-x!LICENSE", "-x!README.md", await util.promisify(execCommands)([
"-x!cdb", "-x!picture", "-x!field", "-x!script", "-x!pics", 'mv -f "' + config.db_path +'ygosrv233-pre-mobile.zip" "'+ file_path +'"',
"-x!expansions/pics", "-x!expansions/script", "-x!expansions/*.cdb", "-x!expansions/*.conf", 'rm -rf "' + config.db_path +'expansions/' + config.ypk_name + '"',
"ygosrv233-pre-mobile.zip", "*"], config.db_path, done); 'rm -rf "' + config.db_path +'expansions/script"',
}], 'rm -rf "' + config.db_path +'expansions/pics"'
run7zPro2: ["preCommands", (results, done) => { ]);
run7z(["a", "-x!*.zip", "-x!.git", "-x!LICENSE", "-x!README.md", sendResponse("手机更新包打包完成。");
"-x!expansions", "-x!pics", "-x!field", await util.promisify(run7z)(["a", "-x!*.zip", "-x!.git", "-x!LICENSE", "-x!README.md",
"ygosrv233-pre-2.zip", "*"], config.db_path, done); "-x!expansions", "-x!pics", "-x!field",
}], "ygosrv233-pre-2.zip", "*"], config.db_path);
commandsAfterPC: ["run7zPC", (results, done) => { await util.promisify(execCommands)([
execCommands([ 'mv -f "' + config.db_path + 'ygosrv233-pre-2.zip" "' + file_path + '"',
'mv -f "' + config.db_path + 'ygosrv233-pre.zip" "' + file_path + '"' 'rm -rf "' + config.db_path +'cdb"',
], (err) => { 'rm -rf "' + config.db_path +'picture"'
if (!err) { ]);
sendResponse("电脑更新包打包完成。"); sendResponse("Pro2更新包打包完成。");
} callback(null);
done(err); } catch (err) {
}); callback(err);
}], }
commandsAfterMobile: ["run7zPC", "run7zMobile", (results, done) => {
execCommands([
'mv -f "' + config.db_path +'ygosrv233-pre-mobile.zip" "'+ file_path +'"',
'rm -rf "' + config.db_path +'expansions/' + config.ypk_name + '"',
'rm -rf "' + config.db_path +'expansions/script"',
'rm -rf "' + config.db_path +'expansions/pics"'
], (err) => {
if (!err) {
sendResponse("手机更新包打包完成。");
}
done(err);
});
}],
commandsAfterPro2: ["run7zPro2", (results, done) => {
execCommands([
'mv -f "' + config.db_path + 'ygosrv233-pre-2.zip" "' + file_path + '"',
'rm -rf "' + config.db_path +'cdb"',
'rm -rf "' + config.db_path +'picture"'
], (err) => {
if (!err) {
sendResponse("Pro2更新包打包完成。");
}
done(err);
});
}]
}, callback);
} }
//建立一个http服务器,接收API操作 //建立一个http服务器,接收API操作
......
...@@ -9,7 +9,6 @@ exec = require('child_process').exec ...@@ -9,7 +9,6 @@ exec = require('child_process').exec
execFile = require('child_process').execFile execFile = require('child_process').execFile
spawn = require('child_process').spawn spawn = require('child_process').spawn
spawnSync = require('child_process').spawnSync spawnSync = require('child_process').spawnSync
_async = require('async')
# ts utility # ts utility
utility = require './utility.js' utility = require './utility.js'
...@@ -95,10 +94,9 @@ loadJSONAsync = require('load-json-file') ...@@ -95,10 +94,9 @@ loadJSONAsync = require('load-json-file')
util = require("util") util = require("util")
Q = require("q")
YGOProDeck = require('ygopro-deck-encode').default YGOProDeck = require('ygopro-deck-encode').default
YGOProYrp = require('ygopro-yrp-encode').YGOProYrp YGOProYrp = require('ygopro-yrp-encode').YGOProYrp
YGOProMsg = require 'ygopro-msg-encode'
Aragami = require('aragami').Aragami Aragami = require('aragami').Aragami
...@@ -838,17 +836,12 @@ ROOM_ban_player = global.ROOM_ban_player = (name, ip, reason, countadd = 1)-> ...@@ -838,17 +836,12 @@ ROOM_ban_player = global.ROOM_ban_player = (name, ip, reason, countadd = 1)->
ROOM_kick = (name, callback)-> ROOM_kick = (name, callback)->
found = false found = false
_async.each(ROOM_all, (room, done)-> for room in ROOM_all when room and room.established
if !(room and room.established and (name == "all" or name == room.process_pid.toString() or name == room.name)) continue unless name == "all" or name == room.process_pid.toString() or name == room.name
done()
return
found = true found = true
room.terminate() room.terminate()
done() callback(null, found)
, (err)-> return
callback(null, found)
return
)
ROOM_player_win = global.ROOM_player_win = (name)-> ROOM_player_win = global.ROOM_player_win = (name)->
...@@ -2918,24 +2911,25 @@ load_words = global.load_words = () -> ...@@ -2918,24 +2911,25 @@ load_words = global.load_words = () ->
ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)-> ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
room=ROOM_all[client.rid] room=ROOM_all[client.rid]
return unless room and !client.reconnecting return unless room and !client.reconnecting
msg = buffer.readInt8(0) msg_inst = info.msg
msg_name = ygopro.constants.MSG[msg] msg_name = if msg_inst then ygopro.constants.MSG[msg_inst.identifier] else null
new_buf = await msg_polyfill.polyfillGameMsg(client.actual_version, msg_name, buffer) new_buf = if msg_name then await msg_polyfill.polyfillGameMsg(client.actual_version, msg_name, buffer) else undefined
if new_buf if new_buf
buffer = new_buf buffer = new_buf
return new_buf unless msg_inst
record_last_game_msg = () -> record_last_game_msg = () ->
client.last_game_msg = buffer client.last_game_msg = buffer
client.last_game_msg_title = msg_name 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_inst instanceof YGOProMsg.YGOProMsgRetry and room.recovering
room.finish_recover(true) room.finish_recover(true)
return true return true
if settings.modules.retry_handle.enabled if settings.modules.retry_handle.enabled
if msg_name == 'RETRY' if msg_inst instanceof YGOProMsg.YGOProMsgRetry
if !client.retry_count? if !client.retry_count?
client.retry_count = 0 client.retry_count = 0
client.retry_count++ client.retry_count++
log.warn "MSG_RETRY detected", client.name, client.ip, msg, client.retry_count log.warn "MSG_RETRY detected", client.name, client.ip, msg_inst.identifier, client.retry_count
if settings.modules.retry_handle.max_retry_count and client.retry_count >= settings.modules.retry_handle.max_retry_count if settings.modules.retry_handle.max_retry_count and client.retry_count >= settings.modules.retry_handle.max_retry_count
ygopro.stoc_send_chat_to_room(room, client.name + "${retry_too_much_room_part1}" + settings.modules.retry_handle.max_retry_count + "${retry_too_much_room_part2}", ygopro.constants.COLORS.BABYBLUE) ygopro.stoc_send_chat_to_room(room, client.name + "${retry_too_much_room_part1}" + settings.modules.retry_handle.max_retry_count + "${retry_too_much_room_part2}", ygopro.constants.COLORS.BABYBLUE)
ygopro.stoc_send_chat(client, "${retry_too_much_part1}" + settings.modules.retry_handle.max_retry_count + "${retry_too_much_part2}", ygopro.constants.COLORS.RED) ygopro.stoc_send_chat(client, "${retry_too_much_part1}" + settings.modules.retry_handle.max_retry_count + "${retry_too_much_part2}", ygopro.constants.COLORS.RED)
...@@ -2953,11 +2947,11 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)-> ...@@ -2953,11 +2947,11 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
else else
record_last_game_msg() record_last_game_msg()
# 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_inst instanceof YGOProMsg.YGOProMsgRetry)
record_last_game_msg() record_last_game_msg()
# 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_inst instanceof YGOProMsg.YGOProMsgResponseBase #SELECT和ANNOUNCE开头的消息
if room.recovering if room.recovering
response = room.recover_replay.responses.splice(0, 1)[0] response = room.recover_replay.responses.splice(0, 1)[0]
ygopro.ctos_send(server, 'RESPONSE', Buffer.from(response)) ygopro.ctos_send(server, 'RESPONSE', Buffer.from(response))
...@@ -2970,8 +2964,8 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)-> ...@@ -2970,8 +2964,8 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
#log.info("#{msg_name}等待#{room.waiting_for_player.name}") #log.info("#{msg_name}等待#{room.waiting_for_player.name}")
#log.info 'MSG', msg_name #log.info 'MSG', msg_name
if msg_name == 'START' if msg_inst instanceof YGOProMsg.YGOProMsgStart
playertype = buffer.readUInt8(1) playertype = msg_inst.playerType
client.is_first = !(playertype & 0xf) client.is_first = !(playertype & 0xf)
client.lp = room.hostinfo.start_lp client.lp = room.hostinfo.start_lp
client.card_count = 0 if room.hostinfo.mode != 2 client.card_count = 0 if room.hostinfo.mode != 2
...@@ -2996,12 +2990,12 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)-> ...@@ -2996,12 +2990,12 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
#ygopro.stoc_send_chat_to_room(room, "LP跟踪调试信息: #{client.name} 初始LP #{client.lp}") #ygopro.stoc_send_chat_to_room(room, "LP跟踪调试信息: #{client.name} 初始LP #{client.lp}")
if msg_name == 'HINT' if msg_inst instanceof YGOProMsg.YGOProMsgHint
hint_type = buffer.readUInt8(1) hint_type = msg_inst.type
if hint_type == 3 if hint_type == 3
client.last_hint_msg = buffer client.last_hint_msg = buffer
if msg_name == 'NEW_TURN' if msg_inst instanceof YGOProMsg.YGOProMsgNewTurn
r_player = buffer.readUInt8(1) r_player = buffer.readUInt8(1)
if client.pos == 0 and (r_player & 0x2) == 0 if client.pos == 0 and (r_player & 0x2) == 0
room.turn++ room.turn++
...@@ -3023,8 +3017,8 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)-> ...@@ -3023,8 +3017,8 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
client.surrend_confirm = false client.surrend_confirm = false
ygopro.stoc_send_chat(client, "${surrender_canceled}", ygopro.constants.COLORS.BABYBLUE) ygopro.stoc_send_chat(client, "${surrender_canceled}", ygopro.constants.COLORS.BABYBLUE)
if msg_name == 'NEW_PHASE' if msg_inst instanceof YGOProMsg.YGOProMsgNewPhase
phase = buffer.readInt16LE(1) phase = msg_inst.phase
oppo_pos = if room.hostinfo.mode == 2 then 2 else 1 oppo_pos = if room.hostinfo.mode == 2 then 2 else 1
if client.pos == 0 and room.death == -2 and not (phase == 0x1 and room.turn < 2) if client.pos == 0 and room.death == -2 and not (phase == 0x1 and room.turn < 2)
if room.dueling_players[0].lp != room.dueling_players[oppo_pos].lp if room.dueling_players[0].lp != room.dueling_players[oppo_pos].lp
...@@ -3035,14 +3029,14 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)-> ...@@ -3035,14 +3029,14 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
room.death = -1 room.death = -1
ygopro.stoc_send_chat_to_room(room, "${death_remain_final}", ygopro.constants.COLORS.BABYBLUE) ygopro.stoc_send_chat_to_room(room, "${death_remain_final}", ygopro.constants.COLORS.BABYBLUE)
if msg_name == 'WIN' and client.pos == 0 if msg_inst instanceof YGOProMsg.YGOProMsgWin and client.pos == 0
if room.recovering if room.recovering
room.finish_recover(true) room.finish_recover(true)
return true return true
pos = buffer.readUInt8(1) pos = msg_inst.player
pos = 1 - pos unless client.is_first or pos == 2 or room.duel_stage != ygopro.constants.DUEL_STAGE.DUELING pos = 1 - pos unless client.is_first or pos == 2 or room.duel_stage != ygopro.constants.DUEL_STAGE.DUELING
pos = pos * 2 if pos >= 0 and room.hostinfo.mode == 2 pos = pos * 2 if pos >= 0 and room.hostinfo.mode == 2
reason = buffer.readUInt8(2) reason = msg_inst.type
#log.info {winner: pos, reason: reason} #log.info {winner: pos, reason: reason}
#room.duels.push {winner: pos, reason: reason} #room.duels.push {winner: pos, reason: reason}
room.winner = pos room.winner = pos
...@@ -3073,42 +3067,42 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)-> ...@@ -3073,42 +3067,42 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
else else
room.death = 5 room.death = 5
if msg_name == 'MATCH_KILL' and client.pos == 0 if msg_inst instanceof YGOProMsg.YGOProMsgMatchKill and client.pos == 0
room.match_kill = true room.match_kill = true
#lp跟踪 #lp跟踪
if msg_name == 'DAMAGE' and client.pos == 0 if msg_inst instanceof YGOProMsg.YGOProMsgDamage and client.pos == 0
pos = buffer.readUInt8(1) pos = msg_inst.player
pos = 1 - pos unless client.is_first pos = 1 - pos unless client.is_first
pos = pos * 2 if pos >= 0 and room.hostinfo.mode == 2 pos = pos * 2 if pos >= 0 and room.hostinfo.mode == 2
val = buffer.readInt32LE(2) val = msg_inst.value
if room.dueling_players[pos] if room.dueling_players[pos]
room.dueling_players[pos].lp -= val room.dueling_players[pos].lp -= val
room.dueling_players[pos].lp = 0 if room.dueling_players[pos].lp < 0 room.dueling_players[pos].lp = 0 if room.dueling_players[pos].lp < 0
if 0 < room.dueling_players[pos].lp <= 100 if 0 < room.dueling_players[pos].lp <= 100
ygopro.stoc_send_chat_to_room(room, "${lp_low_opponent}", ygopro.constants.COLORS.PINK) ygopro.stoc_send_chat_to_room(room, "${lp_low_opponent}", ygopro.constants.COLORS.PINK)
if msg_name == 'RECOVER' and client.pos == 0 if msg_inst instanceof YGOProMsg.YGOProMsgRecover and client.pos == 0
pos = buffer.readUInt8(1) pos = msg_inst.player
pos = 1 - pos unless client.is_first pos = 1 - pos unless client.is_first
pos = pos * 2 if pos >= 0 and room.hostinfo.mode == 2 pos = pos * 2 if pos >= 0 and room.hostinfo.mode == 2
val = buffer.readInt32LE(2) val = msg_inst.value
if room.dueling_players[pos] if room.dueling_players[pos]
room.dueling_players[pos].lp += val room.dueling_players[pos].lp += val
if msg_name == 'LPUPDATE' and client.pos == 0 if msg_inst instanceof YGOProMsg.YGOProMsgLpUpdate and client.pos == 0
pos = buffer.readUInt8(1) pos = msg_inst.player
pos = 1 - pos unless client.is_first pos = 1 - pos unless client.is_first
pos = pos * 2 if pos >= 0 and room.hostinfo.mode == 2 pos = pos * 2 if pos >= 0 and room.hostinfo.mode == 2
val = buffer.readInt32LE(2) val = msg_inst.lp
if room.dueling_players[pos] if room.dueling_players[pos]
room.dueling_players[pos].lp = val room.dueling_players[pos].lp = val
if msg_name == 'PAY_LPCOST' and client.pos == 0 if msg_inst instanceof YGOProMsg.YGOProMsgPayLpCost and client.pos == 0
pos = buffer.readUInt8(1) pos = msg_inst.player
pos = 1 - pos unless client.is_first pos = 1 - pos unless client.is_first
pos = pos * 2 if pos >= 0 and room.hostinfo.mode == 2 pos = pos * 2 if pos >= 0 and room.hostinfo.mode == 2
val = buffer.readInt32LE(2) val = msg_inst.cost
if room.dueling_players[pos] if room.dueling_players[pos]
room.dueling_players[pos].lp -= val room.dueling_players[pos].lp -= val
room.dueling_players[pos].lp = 0 if room.dueling_players[pos].lp < 0 room.dueling_players[pos].lp = 0 if room.dueling_players[pos].lp < 0
...@@ -3117,32 +3111,30 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)-> ...@@ -3117,32 +3111,30 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
#track card count #track card count
#todo: track card count in tag mode #todo: track card count in tag mode
if msg_name == 'MOVE' and room.hostinfo.mode != 2 if msg_inst instanceof YGOProMsg.YGOProMsgMove and room.hostinfo.mode != 2
pos = buffer.readUInt8(5) pos = msg_inst.previous.controller
pos = 1 - pos unless client.is_first pos = 1 - pos unless client.is_first
loc = buffer.readUInt8(6) loc = msg_inst.previous.location
client.card_count-- if (loc & 0xe) and pos == 0 client.card_count-- if (loc & 0xe) and pos == 0
pos = buffer.readUInt8(9) pos = msg_inst.current.controller
pos = 1 - pos unless client.is_first pos = 1 - pos unless client.is_first
loc = buffer.readUInt8(10) loc = msg_inst.current.location
client.card_count++ if (loc & 0xe) and pos == 0 client.card_count++ if (loc & 0xe) and pos == 0
if msg_name == 'DRAW' and room.hostinfo.mode != 2 if msg_inst instanceof YGOProMsg.YGOProMsgDraw and room.hostinfo.mode != 2
pos = buffer.readUInt8(1) pos = msg_inst.player
pos = 1 - pos unless client.is_first pos = 1 - pos unless client.is_first
if pos == 0 if pos == 0
count = buffer.readInt8(2) count = msg_inst.count
client.card_count += count client.card_count += count
# check panel confirming cards in heartbeat # check panel confirming cards in heartbeat
if settings.modules.heartbeat_detection.enabled and msg_name == 'CONFIRM_CARDS' if settings.modules.heartbeat_detection.enabled and msg_inst instanceof YGOProMsg.YGOProMsgConfirmCards
check = false check = false
count = buffer.readInt8(2)
max_loop = 3 + (count - 1) * 7
deck_found = 0 deck_found = 0
limbo_found = 0 # support custom cards which may be in location 0 in KoishiPro or EdoPro limbo_found = 0 # support custom cards which may be in location 0 in KoishiPro or EdoPro
for i in [3..max_loop] by 7 for card in msg_inst.cards
loc = buffer.readInt8(i + 5) loc = card.location
if (loc & 0x41) > 0 if (loc & 0x41) > 0
deck_found++ deck_found++
else if loc == 0 else if loc == 0
...@@ -3156,8 +3148,8 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)-> ...@@ -3156,8 +3148,8 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
# chain detection # chain detection
if settings.modules.heartbeat_detection.enabled and client.pos == 0 if settings.modules.heartbeat_detection.enabled and client.pos == 0
if msg_name == 'CHAINING' if msg_inst instanceof YGOProMsg.YGOProMsgChaining
card = buffer.readUInt32LE(1) card = msg_inst.code
found = false found = false
for id in long_resolve_cards when id == card for id in long_resolve_cards when id == card
found = true found = true
...@@ -3167,33 +3159,33 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)-> ...@@ -3167,33 +3159,33 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
# console.log(0,card) # console.log(0,card)
else else
delete room.long_resolve_card delete room.long_resolve_card
else if msg_name == 'CHAINED' and room.long_resolve_card else if msg_inst instanceof YGOProMsg.YGOProMsgChained and room.long_resolve_card
chain = buffer.readInt8(1) chain = msg_inst.chainCount
if !room.long_resolve_chain if !room.long_resolve_chain
room.long_resolve_chain = [] room.long_resolve_chain = []
room.long_resolve_chain[chain] = true room.long_resolve_chain[chain] = true
# console.log(1,chain) # console.log(1,chain)
delete room.long_resolve_card delete room.long_resolve_card
else if msg_name == 'CHAIN_SOLVING' and room.long_resolve_chain else if msg_inst instanceof YGOProMsg.YGOProMsgChainSolving and room.long_resolve_chain
chain = buffer.readInt8(1) chain = msg_inst.chainCount
# console.log(2,chain) # console.log(2,chain)
if room.long_resolve_chain[chain] if room.long_resolve_chain[chain]
for player in room.get_playing_player() for player in room.get_playing_player()
player.heartbeat_protected = true player.heartbeat_protected = true
else if (msg_name == 'CHAIN_NEGATED' or msg_name == 'CHAIN_DISABLED') and room.long_resolve_chain else if (msg_inst instanceof YGOProMsg.YGOProMsgChainNegated or msg_inst instanceof YGOProMsg.YGOProMsgChainDisabled) and room.long_resolve_chain
chain = buffer.readInt8(1) chain = msg_inst.chainCount
# console.log(3,chain) # console.log(3,chain)
delete room.long_resolve_chain[chain] delete room.long_resolve_chain[chain]
else if msg_name == 'CHAIN_END' else if msg_inst instanceof YGOProMsg.YGOProMsgChainEnd
# console.log(4,chain) # console.log(4,chain)
delete room.long_resolve_card delete room.long_resolve_card
delete room.long_resolve_chain delete room.long_resolve_chain
#登场台词 #登场台词
if (settings.modules.dialogues.enabled or settings.modules.vip.enabled) and !room.recovering if (settings.modules.dialogues.enabled or settings.modules.vip.enabled) and !room.recovering
if msg_name == 'SUMMONING' or msg_name == 'SPSUMMONING' or msg_name == 'CHAINING' if msg_inst instanceof YGOProMsg.YGOProMsgSummoning or msg_inst instanceof YGOProMsg.YGOProMsgSpSummoning or msg_inst instanceof YGOProMsg.YGOProMsgChaining
card = buffer.readUInt32LE(1) card = msg_inst.code
trigger_location = buffer.readUInt8(6) trigger_location = msg_inst.location
act_pos = buffer.readUInt8(if msg_name == 'CHAINING' then 9 else 5) act_pos = buffer.readUInt8(if msg_name == 'CHAINING' then 9 else 5)
if !room.dueling_players[0].is_first if !room.dueling_players[0].is_first
act_pos = 1 - act_pos act_pos = 1 - act_pos
...@@ -3208,16 +3200,16 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)-> ...@@ -3208,16 +3200,16 @@ ygopro.stoc_follow 'GAME_MSG', true, (buffer, info, client, server, datas)->
client.playLines dialogues.dialogues[card][Math.floor(Math.random() * dialogues.dialogues[card].length)] client.playLines dialogues.dialogues[card][Math.floor(Math.random() * dialogues.dialogues[card].length)]
else if settings.modules.dialogues.enabled and dialogues.dialogues_custom[card] else if settings.modules.dialogues.enabled and dialogues.dialogues_custom[card]
client.playLines dialogues.dialogues_custom[card][Math.floor(Math.random() * dialogues.dialogues_custom[card].length)] client.playLines dialogues.dialogues_custom[card][Math.floor(Math.random() * dialogues.dialogues_custom[card].length)]
if msg_name == 'POS_CHANGE' if msg_inst instanceof YGOProMsg.YGOProMsgPosChange
loc = buffer.readUInt8(6) loc = msg_inst.card.location
ppos = buffer.readUInt8(8) ppos = msg_inst.previousPosition
cpos = buffer.readUInt8(9) cpos = msg_inst.currentPosition
client.ready_trap = !!(loc & 0x8) and !!(ppos & 0xa) and !!(cpos & 0x5) client.ready_trap = !!(loc & 0x8) and !!(ppos & 0xa) and !!(cpos & 0x5)
else if msg_name != 'UPDATE_CARD' and msg_name != 'WAITING' else if !(msg_inst instanceof YGOProMsg.YGOProMsgUpdateCard) and !(msg_inst instanceof YGOProMsg.YGOProMsgWaiting)
client.ready_trap = false client.ready_trap = false
if room.recovering and client.pos < 4 if room.recovering and client.pos < 4
if msg_name != 'WAITING' if !(msg_inst instanceof YGOProMsg.YGOProMsgWaiting)
room.recover_buffers[client.pos].push(buffer) room.recover_buffers[client.pos].push(buffer)
return true return true
...@@ -4303,10 +4295,7 @@ if true ...@@ -4303,10 +4295,7 @@ if true
response.end(addCallback(u.query.callback, '{"rooms":[{"roomid":"0","roomname":"密码错误","needpass":"true"}]}')) response.end(addCallback(u.query.callback, '{"rooms":[{"roomid":"0","roomname":"密码错误","needpass":"true"}]}'))
else else
roomsjson = []; roomsjson = [];
_async.each(ROOM_all, (room, done)-> for room in ROOM_all when room and room.established
if !(room and room.established)
done()
return
roomsjson.push({ roomsjson.push({
roomid: room.process_pid.toString(), roomid: room.process_pid.toString(),
roomname: if pass_validated then room.name else room.name.split('$', 2)[0], roomname: if pass_validated then room.name else room.name.split('$', 2)[0],
...@@ -4325,11 +4314,8 @@ if true ...@@ -4325,11 +4314,8 @@ if true
), "pos"), ), "pos"),
istart: if room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN then (if settings.modules.http.show_info then ("Duel:" + room.duel_count + " " + (if room.duel_stage == ygopro.constants.DUEL_STAGE.SIDING then "Siding" else "Turn:" + (if room.turn? then room.turn else 0) + (if room.death then "/" + (if room.death > 0 then room.death - 1 else "Death") else ""))) else 'start') else 'wait' istart: if room.duel_stage != ygopro.constants.DUEL_STAGE.BEGIN then (if settings.modules.http.show_info then ("Duel:" + room.duel_count + " " + (if room.duel_stage == ygopro.constants.DUEL_STAGE.SIDING then "Siding" else "Turn:" + (if room.turn? then room.turn else 0) + (if room.death then "/" + (if room.death > 0 then room.death - 1 else "Death") else ""))) else 'start') else 'wait'
}) })
done() response.writeHead(200)
, ()-> response.end(addCallback(u.query.callback, JSON.stringify({rooms: roomsjson})))
response.writeHead(200)
response.end(addCallback(u.query.callback, JSON.stringify({rooms: roomsjson})))
)
else if u.pathname == '/api/duellog' and settings.modules.mysql.enabled else if u.pathname == '/api/duellog' and settings.modules.mysql.enabled
...@@ -4426,9 +4412,8 @@ if true ...@@ -4426,9 +4412,8 @@ if true
response.writeHead(200) response.writeHead(200)
response.end(addCallback(u.query.callback, "['密码错误', 0]")) response.end(addCallback(u.query.callback, "['密码错误', 0]"))
return return
_async.each ROOM_all, (room)-> for room in ROOM_all when room and room.established
if room and room.established ygopro.stoc_send_chat_to_room(room, u.query.shout, ygopro.constants.COLORS.YELLOW)
ygopro.stoc_send_chat_to_room(room, u.query.shout, ygopro.constants.COLORS.YELLOW)
response.writeHead(200) response.writeHead(200)
response.end(addCallback(u.query.callback, "['shout ok', '" + u.query.shout + "']")) response.end(addCallback(u.query.callback, "['shout ok', '" + u.query.shout + "']"))
...@@ -4528,21 +4513,15 @@ if true ...@@ -4528,21 +4513,15 @@ if true
response.end(addCallback(u.query.callback, "['密码错误', 0]")) response.end(addCallback(u.query.callback, "['密码错误', 0]"))
return return
death_room_found = false death_room_found = false
_async.each(ROOM_all, (room, done)-> for room in ROOM_all when room
if !(room and (u.query.death == "all" or u.query.death == room.process_pid.toString() or u.query.death == room.name)) continue unless u.query.death == "all" or u.query.death == room.process_pid.toString() or u.query.death == room.name
done()
return
if room.start_death() if room.start_death()
death_room_found = true death_room_found = true
done() response.writeHead(200)
return if death_room_found
, () -> response.end(addCallback(u.query.callback, "['death ok', '" + u.query.death + "']"))
response.writeHead(200) else
if death_room_found response.end(addCallback(u.query.callback, "['room not found', '" + u.query.death + "']"))
response.end(addCallback(u.query.callback, "['death ok', '" + u.query.death + "']"))
else
response.end(addCallback(u.query.callback, "['room not found', '" + u.query.death + "']"))
)
else if u.query.deathcancel else if u.query.deathcancel
if !await auth.auth(u.query.username, u.query.pass, "start_death", "cancel_death") if !await auth.auth(u.query.username, u.query.pass, "start_death", "cancel_death")
...@@ -4550,20 +4529,15 @@ if true ...@@ -4550,20 +4529,15 @@ if true
response.end(addCallback(u.query.callback, "['密码错误', 0]")) response.end(addCallback(u.query.callback, "['密码错误', 0]"))
return return
death_room_found = false death_room_found = false
_async.each(ROOM_all, (room, done)-> for room in ROOM_all when room
if !(room and (u.query.deathcancel == "all" or u.query.deathcancel == room.process_pid.toString() or u.query.deathcancel == room.name)) continue unless u.query.deathcancel == "all" or u.query.deathcancel == room.process_pid.toString() or u.query.deathcancel == room.name
done()
return
if room.cancel_death() if room.cancel_death()
death_room_found = true death_room_found = true
done() response.writeHead(200)
, () -> if death_room_found
response.writeHead(200) response.end(addCallback(u.query.callback, "['death cancel ok', '" + u.query.deathcancel + "']"))
if death_room_found else
response.end(addCallback(u.query.callback, "['death cancel ok', '" + u.query.deathcancel + "']")) response.end(addCallback(u.query.callback, "['room not found', '" + u.query.deathcancel + "']"))
else
response.end(addCallback(u.query.callback, "['room not found', '" + u.query.deathcancel + "']"))
)
else if u.query.reboot else if u.query.reboot
if !await auth.auth(u.query.username, u.query.pass, "stop", "reboot") if !await auth.auth(u.query.username, u.query.pass, "stop", "reboot")
......
// Generated by CoffeeScript 2.7.0 // Generated by CoffeeScript 2.7.0
(function() { (function() {
// 标准库 // 标准库
var Aragami, CLIENT_check_vip, CLIENT_get_absolute_pos, CLIENT_get_authorize_key, CLIENT_get_kick_reconnect_target, CLIENT_get_partner, CLIENT_get_save_data, CLIENT_heartbeat_register, CLIENT_heartbeat_unregister, CLIENT_import_data, CLIENT_is_able_to_kick_reconnect, CLIENT_is_able_to_reconnect, CLIENT_is_banned_by_mc, CLIENT_is_player, CLIENT_kick, CLIENT_kick_reconnect, CLIENT_pre_reconnect, CLIENT_reconnect, CLIENT_reconnect_register, CLIENT_reconnect_unregister, CLIENT_send_pre_reconnect_info, CLIENT_send_reconnect_info, CLIENT_send_replays, CLIENT_send_replays_and_kick, CLIENT_send_vip_status, CLIENT_set_ip, CLIENT_use_cdkey, PQueue, Q, ROOM_all, ROOM_bad_ip, ROOM_ban_player, ROOM_clear_disconnect, ROOM_connected_ip, ROOM_find_by_name, ROOM_find_by_pid, ROOM_find_by_port, ROOM_find_by_title, ROOM_find_or_create_ai, ROOM_find_or_create_by_name, ROOM_find_or_create_random, ROOM_kick, ROOM_player_flee, ROOM_player_get_score, ROOM_player_lose, ROOM_player_win, ROOM_players_oppentlist, ROOM_unwelcome, ROOM_validate, ReplayParser, ResolveData, Room, SERVER_clear_disconnect, SERVER_kick, SOCKET_flush_data, VIP_generate_cdkeys, YGOProDeck, YGOProYrp, _, _async, addCallback, aragami, aragami_classes, athleticChecker, auth, axios, badwordR, badwords, ban_user, bunyan, call_match_api, challonge, checkFileExists, concat_name, createDirectoryIfNotExists, crypto, dataManager, deck_name_match, dialogues, disconnect_list, exec, execFile, extra_mode_list, fs, geoip, getDuelLogQueryFromQs, getRealIp, get_memory_usage, gpt_tokenizer, http, httpRequestListener, importOldConfig, import_datas, init, ip6addr, isTrustedProxy, lflists, loadJSON, loadJSONAsync, loadLFList, loadRemoteData, load_dialogues, load_dialogues_custom, load_tips, load_tips_zh, load_words, log, long_resolve_cards, memory_usage, merge, moment, moment_long_ago_string, moment_now, moment_now_string, msg_polyfill, mustache, neosRequestListener, net, netRequestHandler, os, osu, path, qs, real_windbot_server_ip, release_disconnect, report_to_big_brother, request, roomlist, rooms_count, setting_change, setting_get, setting_save, settings, spawn, spawnSync, spawn_windbot, tips, toIpv4, toIpv6, util, utility, wait_room_start, wait_room_start_arena, windbot_looplimit, windbot_process, windbots, words, ygopro, zlib; var Aragami, CLIENT_check_vip, CLIENT_get_absolute_pos, CLIENT_get_authorize_key, CLIENT_get_kick_reconnect_target, CLIENT_get_partner, CLIENT_get_save_data, CLIENT_heartbeat_register, CLIENT_heartbeat_unregister, CLIENT_import_data, CLIENT_is_able_to_kick_reconnect, CLIENT_is_able_to_reconnect, CLIENT_is_banned_by_mc, CLIENT_is_player, CLIENT_kick, CLIENT_kick_reconnect, CLIENT_pre_reconnect, CLIENT_reconnect, CLIENT_reconnect_register, CLIENT_reconnect_unregister, CLIENT_send_pre_reconnect_info, CLIENT_send_reconnect_info, CLIENT_send_replays, CLIENT_send_replays_and_kick, CLIENT_send_vip_status, CLIENT_set_ip, CLIENT_use_cdkey, PQueue, ROOM_all, ROOM_bad_ip, ROOM_ban_player, ROOM_clear_disconnect, ROOM_connected_ip, ROOM_find_by_name, ROOM_find_by_pid, ROOM_find_by_port, ROOM_find_by_title, ROOM_find_or_create_ai, ROOM_find_or_create_by_name, ROOM_find_or_create_random, ROOM_kick, ROOM_player_flee, ROOM_player_get_score, ROOM_player_lose, ROOM_player_win, ROOM_players_oppentlist, ROOM_unwelcome, ROOM_validate, ReplayParser, ResolveData, Room, SERVER_clear_disconnect, SERVER_kick, SOCKET_flush_data, VIP_generate_cdkeys, YGOProDeck, YGOProMsg, YGOProYrp, _, addCallback, aragami, aragami_classes, athleticChecker, auth, axios, badwordR, badwords, ban_user, bunyan, call_match_api, challonge, checkFileExists, concat_name, createDirectoryIfNotExists, crypto, dataManager, deck_name_match, dialogues, disconnect_list, exec, execFile, extra_mode_list, fs, geoip, getDuelLogQueryFromQs, getRealIp, get_memory_usage, gpt_tokenizer, http, httpRequestListener, importOldConfig, import_datas, init, ip6addr, isTrustedProxy, lflists, loadJSON, loadJSONAsync, loadLFList, loadRemoteData, load_dialogues, load_dialogues_custom, load_tips, load_tips_zh, load_words, log, long_resolve_cards, memory_usage, merge, moment, moment_long_ago_string, moment_now, moment_now_string, msg_polyfill, mustache, neosRequestListener, net, netRequestHandler, os, osu, path, qs, real_windbot_server_ip, release_disconnect, report_to_big_brother, request, roomlist, rooms_count, setting_change, setting_get, setting_save, settings, spawn, spawnSync, spawn_windbot, tips, toIpv4, toIpv6, util, utility, wait_room_start, wait_room_start_arena, windbot_looplimit, windbot_process, windbots, words, ygopro, zlib;
net = require('net'); net = require('net');
...@@ -23,8 +23,6 @@ ...@@ -23,8 +23,6 @@
spawnSync = require('child_process').spawnSync; spawnSync = require('child_process').spawnSync;
_async = require('async');
// ts utility // ts utility
utility = require('./utility.js'); utility = require('./utility.js');
...@@ -85,12 +83,12 @@ ...@@ -85,12 +83,12 @@
util = require("util"); util = require("util");
Q = require("q");
YGOProDeck = require('ygopro-deck-encode').default; YGOProDeck = require('ygopro-deck-encode').default;
YGOProYrp = require('ygopro-yrp-encode').YGOProYrp; YGOProYrp = require('ygopro-yrp-encode').YGOProYrp;
YGOProMsg = require('ygopro-msg-encode');
Aragami = require('aragami').Aragami; Aragami = require('aragami').Aragami;
aragami = global.aragami = new Aragami(); // we use memory mode only aragami = global.aragami = new Aragami(); // we use memory mode only
...@@ -1085,19 +1083,20 @@ ...@@ -1085,19 +1083,20 @@
}; };
ROOM_kick = function(name, callback) { ROOM_kick = function(name, callback) {
var found; var found, j, len, room;
found = false; found = false;
return _async.each(ROOM_all, function(room, done) { for (j = 0, len = ROOM_all.length; j < len; j++) {
if (!(room && room.established && (name === "all" || name === room.process_pid.toString() || name === room.name))) { room = ROOM_all[j];
done(); if (!(room && room.established)) {
return; continue;
}
if (!(name === "all" || name === room.process_pid.toString() || name === room.name)) {
continue;
} }
found = true; found = true;
room.terminate(); room.terminate();
return done(); }
}, function(err) { callback(null, found);
callback(null, found);
});
}; };
ROOM_player_win = global.ROOM_player_win = async function(name) { ROOM_player_win = global.ROOM_player_win = async function(name) {
...@@ -3806,33 +3805,36 @@ ...@@ -3806,33 +3805,36 @@
}; };
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 act_pos, card, chain, check, count, cpos, deck_found, dialogText, found, hint_type, i, id, j, l, len, len1, len2, len3, limbo_found, loc, m, max_loop, msg, msg_name, n, new_buf, o, oppo_pos, phase, player, playertype, pos, ppos, r_player, reason, record_last_game_msg, ref, ref1, ref2, ref3, ref4, response, room, trigger_location, val, victoryWordPlayerList, win_pos; var act_pos, card, chain, check, count, cpos, deck_found, dialogText, found, hint_type, id, j, l, len, len1, len2, len3, len4, limbo_found, loc, m, msg_inst, msg_name, n, new_buf, o, oppo_pos, phase, player, playertype, pos, ppos, r_player, reason, record_last_game_msg, ref, ref1, ref2, ref3, ref4, response, room, trigger_location, val, victoryWordPlayerList, 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_inst = info.msg;
msg_name = ygopro.constants.MSG[msg]; msg_name = msg_inst ? ygopro.constants.MSG[msg_inst.identifier] : null;
new_buf = (await msg_polyfill.polyfillGameMsg(client.actual_version, msg_name, buffer)); new_buf = msg_name ? (await msg_polyfill.polyfillGameMsg(client.actual_version, msg_name, buffer)) : void 0;
if (new_buf) { if (new_buf) {
buffer = new_buf; buffer = new_buf;
} }
if (!msg_inst) {
return new_buf;
}
record_last_game_msg = function() { record_last_game_msg = function() {
client.last_game_msg = buffer; client.last_game_msg = buffer;
return client.last_game_msg_title = msg_name; 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_inst instanceof YGOProMsg.YGOProMsgRetry && room.recovering) {
room.finish_recover(true); room.finish_recover(true);
return true; return true;
} }
if (settings.modules.retry_handle.enabled) { if (settings.modules.retry_handle.enabled) {
if (msg_name === 'RETRY') { if (msg_inst instanceof YGOProMsg.YGOProMsgRetry) {
if (client.retry_count == null) { if (client.retry_count == null) {
client.retry_count = 0; client.retry_count = 0;
} }
client.retry_count++; client.retry_count++;
log.warn("MSG_RETRY detected", client.name, client.ip, msg, client.retry_count); log.warn("MSG_RETRY detected", client.name, client.ip, msg_inst.identifier, client.retry_count);
if (settings.modules.retry_handle.max_retry_count && client.retry_count >= settings.modules.retry_handle.max_retry_count) { if (settings.modules.retry_handle.max_retry_count && client.retry_count >= settings.modules.retry_handle.max_retry_count) {
ygopro.stoc_send_chat_to_room(room, client.name + "${retry_too_much_room_part1}" + settings.modules.retry_handle.max_retry_count + "${retry_too_much_room_part2}", ygopro.constants.COLORS.BABYBLUE); ygopro.stoc_send_chat_to_room(room, client.name + "${retry_too_much_room_part1}" + settings.modules.retry_handle.max_retry_count + "${retry_too_much_room_part2}", ygopro.constants.COLORS.BABYBLUE);
ygopro.stoc_send_chat(client, "${retry_too_much_part1}" + settings.modules.retry_handle.max_retry_count + "${retry_too_much_part2}", ygopro.constants.COLORS.RED); ygopro.stoc_send_chat(client, "${retry_too_much_part1}" + settings.modules.retry_handle.max_retry_count + "${retry_too_much_part2}", ygopro.constants.COLORS.RED);
...@@ -3854,12 +3856,11 @@ ...@@ -3854,12 +3856,11 @@
} else { } else {
record_last_game_msg(); record_last_game_msg();
} }
// log.info(client.name, client.last_game_msg_title) } else if (!(msg_inst instanceof YGOProMsg.YGOProMsgRetry)) {
} else if (msg_name !== 'RETRY') {
record_last_game_msg(); record_last_game_msg();
} }
// 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_inst instanceof YGOProMsg.YGOProMsgResponseBase) { //SELECT和ANNOUNCE开头的消息
if (room.recovering) { if (room.recovering) {
response = room.recover_replay.responses.splice(0, 1)[0]; response = room.recover_replay.responses.splice(0, 1)[0];
ygopro.ctos_send(server, 'RESPONSE', Buffer.from(response)); ygopro.ctos_send(server, 'RESPONSE', Buffer.from(response));
...@@ -3875,8 +3876,8 @@ ...@@ -3875,8 +3876,8 @@
//log.info("#{msg_name}等待#{room.waiting_for_player.name}") //log.info("#{msg_name}等待#{room.waiting_for_player.name}")
//log.info 'MSG', msg_name //log.info 'MSG', msg_name
if (msg_name === 'START') { if (msg_inst instanceof YGOProMsg.YGOProMsgStart) {
playertype = buffer.readUInt8(1); playertype = msg_inst.playerType;
client.is_first = !(playertype & 0xf); client.is_first = !(playertype & 0xf);
client.lp = room.hostinfo.start_lp; client.lp = room.hostinfo.start_lp;
if (room.hostinfo.mode !== 2) { if (room.hostinfo.mode !== 2) {
...@@ -3909,13 +3910,13 @@ ...@@ -3909,13 +3910,13 @@
} }
} }
//ygopro.stoc_send_chat_to_room(room, "LP跟踪调试信息: #{client.name} 初始LP #{client.lp}") //ygopro.stoc_send_chat_to_room(room, "LP跟踪调试信息: #{client.name} 初始LP #{client.lp}")
if (msg_name === 'HINT') { if (msg_inst instanceof YGOProMsg.YGOProMsgHint) {
hint_type = buffer.readUInt8(1); hint_type = msg_inst.type;
if (hint_type === 3) { if (hint_type === 3) {
client.last_hint_msg = buffer; client.last_hint_msg = buffer;
} }
} }
if (msg_name === 'NEW_TURN') { if (msg_inst instanceof YGOProMsg.YGOProMsgNewTurn) {
r_player = buffer.readUInt8(1); r_player = buffer.readUInt8(1);
if (client.pos === 0 && (r_player & 0x2) === 0) { if (client.pos === 0 && (r_player & 0x2) === 0) {
room.turn++; room.turn++;
...@@ -3943,8 +3944,8 @@ ...@@ -3943,8 +3944,8 @@
ygopro.stoc_send_chat(client, "${surrender_canceled}", ygopro.constants.COLORS.BABYBLUE); ygopro.stoc_send_chat(client, "${surrender_canceled}", ygopro.constants.COLORS.BABYBLUE);
} }
} }
if (msg_name === 'NEW_PHASE') { if (msg_inst instanceof YGOProMsg.YGOProMsgNewPhase) {
phase = buffer.readInt16LE(1); phase = msg_inst.phase;
oppo_pos = room.hostinfo.mode === 2 ? 2 : 1; oppo_pos = room.hostinfo.mode === 2 ? 2 : 1;
if (client.pos === 0 && room.death === -2 && !(phase === 0x1 && room.turn < 2)) { if (client.pos === 0 && room.death === -2 && !(phase === 0x1 && room.turn < 2)) {
if (room.dueling_players[0].lp !== room.dueling_players[oppo_pos].lp) { if (room.dueling_players[0].lp !== room.dueling_players[oppo_pos].lp) {
...@@ -3957,19 +3958,19 @@ ...@@ -3957,19 +3958,19 @@
} }
} }
} }
if (msg_name === 'WIN' && client.pos === 0) { if (msg_inst instanceof YGOProMsg.YGOProMsgWin && client.pos === 0) {
if (room.recovering) { if (room.recovering) {
room.finish_recover(true); room.finish_recover(true);
return true; return true;
} }
pos = buffer.readUInt8(1); pos = msg_inst.player;
if (!(client.is_first || pos === 2 || room.duel_stage !== ygopro.constants.DUEL_STAGE.DUELING)) { if (!(client.is_first || pos === 2 || room.duel_stage !== ygopro.constants.DUEL_STAGE.DUELING)) {
pos = 1 - pos; pos = 1 - pos;
} }
if (pos >= 0 && room.hostinfo.mode === 2) { if (pos >= 0 && room.hostinfo.mode === 2) {
pos = pos * 2; pos = pos * 2;
} }
reason = buffer.readUInt8(2); reason = msg_inst.type;
//log.info {winner: pos, reason: reason} //log.info {winner: pos, reason: reason}
//room.duels.push {winner: pos, reason: reason} //room.duels.push {winner: pos, reason: reason}
room.winner = pos; room.winner = pos;
...@@ -4015,19 +4016,19 @@ ...@@ -4015,19 +4016,19 @@
} }
} }
} }
if (msg_name === 'MATCH_KILL' && client.pos === 0) { if (msg_inst instanceof YGOProMsg.YGOProMsgMatchKill && client.pos === 0) {
room.match_kill = true; room.match_kill = true;
} }
//lp跟踪 //lp跟踪
if (msg_name === 'DAMAGE' && client.pos === 0) { if (msg_inst instanceof YGOProMsg.YGOProMsgDamage && client.pos === 0) {
pos = buffer.readUInt8(1); pos = msg_inst.player;
if (!client.is_first) { if (!client.is_first) {
pos = 1 - pos; pos = 1 - pos;
} }
if (pos >= 0 && room.hostinfo.mode === 2) { if (pos >= 0 && room.hostinfo.mode === 2) {
pos = pos * 2; pos = pos * 2;
} }
val = buffer.readInt32LE(2); val = msg_inst.value;
if (room.dueling_players[pos]) { if (room.dueling_players[pos]) {
room.dueling_players[pos].lp -= val; room.dueling_players[pos].lp -= val;
if (room.dueling_players[pos].lp < 0) { if (room.dueling_players[pos].lp < 0) {
...@@ -4038,41 +4039,41 @@ ...@@ -4038,41 +4039,41 @@
} }
} }
} }
if (msg_name === 'RECOVER' && client.pos === 0) { if (msg_inst instanceof YGOProMsg.YGOProMsgRecover && client.pos === 0) {
pos = buffer.readUInt8(1); pos = msg_inst.player;
if (!client.is_first) { if (!client.is_first) {
pos = 1 - pos; pos = 1 - pos;
} }
if (pos >= 0 && room.hostinfo.mode === 2) { if (pos >= 0 && room.hostinfo.mode === 2) {
pos = pos * 2; pos = pos * 2;
} }
val = buffer.readInt32LE(2); val = msg_inst.value;
if (room.dueling_players[pos]) { if (room.dueling_players[pos]) {
room.dueling_players[pos].lp += val; room.dueling_players[pos].lp += val;
} }
} }
if (msg_name === 'LPUPDATE' && client.pos === 0) { if (msg_inst instanceof YGOProMsg.YGOProMsgLpUpdate && client.pos === 0) {
pos = buffer.readUInt8(1); pos = msg_inst.player;
if (!client.is_first) { if (!client.is_first) {
pos = 1 - pos; pos = 1 - pos;
} }
if (pos >= 0 && room.hostinfo.mode === 2) { if (pos >= 0 && room.hostinfo.mode === 2) {
pos = pos * 2; pos = pos * 2;
} }
val = buffer.readInt32LE(2); val = msg_inst.lp;
if (room.dueling_players[pos]) { if (room.dueling_players[pos]) {
room.dueling_players[pos].lp = val; room.dueling_players[pos].lp = val;
} }
} }
if (msg_name === 'PAY_LPCOST' && client.pos === 0) { if (msg_inst instanceof YGOProMsg.YGOProMsgPayLpCost && client.pos === 0) {
pos = buffer.readUInt8(1); pos = msg_inst.player;
if (!client.is_first) { if (!client.is_first) {
pos = 1 - pos; pos = 1 - pos;
} }
if (pos >= 0 && room.hostinfo.mode === 2) { if (pos >= 0 && room.hostinfo.mode === 2) {
pos = pos * 2; pos = pos * 2;
} }
val = buffer.readInt32LE(2); val = msg_inst.cost;
if (room.dueling_players[pos]) { if (room.dueling_players[pos]) {
room.dueling_players[pos].lp -= val; room.dueling_players[pos].lp -= val;
if (room.dueling_players[pos].lp < 0) { if (room.dueling_players[pos].lp < 0) {
...@@ -4085,43 +4086,43 @@ ...@@ -4085,43 +4086,43 @@
} }
//track card count //track card count
//todo: track card count in tag mode //todo: track card count in tag mode
if (msg_name === 'MOVE' && room.hostinfo.mode !== 2) { if (msg_inst instanceof YGOProMsg.YGOProMsgMove && room.hostinfo.mode !== 2) {
pos = buffer.readUInt8(5); pos = msg_inst.previous.controller;
if (!client.is_first) { if (!client.is_first) {
pos = 1 - pos; pos = 1 - pos;
} }
loc = buffer.readUInt8(6); loc = msg_inst.previous.location;
if ((loc & 0xe) && pos === 0) { if ((loc & 0xe) && pos === 0) {
client.card_count--; client.card_count--;
} }
pos = buffer.readUInt8(9); pos = msg_inst.current.controller;
if (!client.is_first) { if (!client.is_first) {
pos = 1 - pos; pos = 1 - pos;
} }
loc = buffer.readUInt8(10); loc = msg_inst.current.location;
if ((loc & 0xe) && pos === 0) { if ((loc & 0xe) && pos === 0) {
client.card_count++; client.card_count++;
} }
} }
if (msg_name === 'DRAW' && room.hostinfo.mode !== 2) { if (msg_inst instanceof YGOProMsg.YGOProMsgDraw && room.hostinfo.mode !== 2) {
pos = buffer.readUInt8(1); pos = msg_inst.player;
if (!client.is_first) { if (!client.is_first) {
pos = 1 - pos; pos = 1 - pos;
} }
if (pos === 0) { if (pos === 0) {
count = buffer.readInt8(2); count = msg_inst.count;
client.card_count += count; client.card_count += count;
} }
} }
// check panel confirming cards in heartbeat // check panel confirming cards in heartbeat
if (settings.modules.heartbeat_detection.enabled && msg_name === 'CONFIRM_CARDS') { if (settings.modules.heartbeat_detection.enabled && msg_inst instanceof YGOProMsg.YGOProMsgConfirmCards) {
check = false; check = false;
count = buffer.readInt8(2);
max_loop = 3 + (count - 1) * 7;
deck_found = 0; deck_found = 0;
limbo_found = 0; // support custom cards which may be in location 0 in KoishiPro or EdoPro limbo_found = 0; // support custom cards which may be in location 0 in KoishiPro or EdoPro
for (i = m = 3, ref3 = max_loop; m <= ref3; i = m += 7) { ref3 = msg_inst.cards;
loc = buffer.readInt8(i + 5); for (m = 0, len2 = ref3.length; m < len2; m++) {
card = ref3[m];
loc = card.location;
if ((loc & 0x41) > 0) { if ((loc & 0x41) > 0) {
deck_found++; deck_found++;
} else if (loc === 0) { } else if (loc === 0) {
...@@ -4139,10 +4140,10 @@ ...@@ -4139,10 +4140,10 @@
} }
// chain detection // chain detection
if (settings.modules.heartbeat_detection.enabled && client.pos === 0) { if (settings.modules.heartbeat_detection.enabled && client.pos === 0) {
if (msg_name === 'CHAINING') { if (msg_inst instanceof YGOProMsg.YGOProMsgChaining) {
card = buffer.readUInt32LE(1); card = msg_inst.code;
found = false; found = false;
for (n = 0, len2 = long_resolve_cards.length; n < len2; n++) { for (n = 0, len3 = long_resolve_cards.length; n < len3; n++) {
id = long_resolve_cards[n]; id = long_resolve_cards[n];
if (!(id === card)) { if (!(id === card)) {
continue; continue;
...@@ -4156,29 +4157,29 @@ ...@@ -4156,29 +4157,29 @@
// console.log(0,card) // console.log(0,card)
delete room.long_resolve_card; delete room.long_resolve_card;
} }
} else if (msg_name === 'CHAINED' && room.long_resolve_card) { } else if (msg_inst instanceof YGOProMsg.YGOProMsgChained && room.long_resolve_card) {
chain = buffer.readInt8(1); chain = msg_inst.chainCount;
if (!room.long_resolve_chain) { if (!room.long_resolve_chain) {
room.long_resolve_chain = []; room.long_resolve_chain = [];
} }
room.long_resolve_chain[chain] = true; room.long_resolve_chain[chain] = true;
// console.log(1,chain) // console.log(1,chain)
delete room.long_resolve_card; delete room.long_resolve_card;
} else if (msg_name === 'CHAIN_SOLVING' && room.long_resolve_chain) { } else if (msg_inst instanceof YGOProMsg.YGOProMsgChainSolving && room.long_resolve_chain) {
chain = buffer.readInt8(1); chain = msg_inst.chainCount;
// console.log(2,chain) // console.log(2,chain)
if (room.long_resolve_chain[chain]) { if (room.long_resolve_chain[chain]) {
ref4 = room.get_playing_player(); ref4 = room.get_playing_player();
for (o = 0, len3 = ref4.length; o < len3; o++) { for (o = 0, len4 = ref4.length; o < len4; o++) {
player = ref4[o]; player = ref4[o];
player.heartbeat_protected = true; player.heartbeat_protected = true;
} }
} }
} else if ((msg_name === 'CHAIN_NEGATED' || msg_name === 'CHAIN_DISABLED') && room.long_resolve_chain) { } else if ((msg_inst instanceof YGOProMsg.YGOProMsgChainNegated || msg_inst instanceof YGOProMsg.YGOProMsgChainDisabled) && room.long_resolve_chain) {
chain = buffer.readInt8(1); chain = msg_inst.chainCount;
// console.log(3,chain) // console.log(3,chain)
delete room.long_resolve_chain[chain]; delete room.long_resolve_chain[chain];
} else if (msg_name === 'CHAIN_END') { } else if (msg_inst instanceof YGOProMsg.YGOProMsgChainEnd) {
// console.log(4,chain) // console.log(4,chain)
delete room.long_resolve_card; delete room.long_resolve_card;
delete room.long_resolve_chain; delete room.long_resolve_chain;
...@@ -4186,9 +4187,9 @@ ...@@ -4186,9 +4187,9 @@
} }
//登场台词 //登场台词
if ((settings.modules.dialogues.enabled || settings.modules.vip.enabled) && !room.recovering) { if ((settings.modules.dialogues.enabled || settings.modules.vip.enabled) && !room.recovering) {
if (msg_name === 'SUMMONING' || msg_name === 'SPSUMMONING' || msg_name === 'CHAINING') { if (msg_inst instanceof YGOProMsg.YGOProMsgSummoning || msg_inst instanceof YGOProMsg.YGOProMsgSpSummoning || msg_inst instanceof YGOProMsg.YGOProMsgChaining) {
card = buffer.readUInt32LE(1); card = msg_inst.code;
trigger_location = buffer.readUInt8(6); trigger_location = msg_inst.location;
act_pos = buffer.readUInt8(msg_name === 'CHAINING' ? 9 : 5); act_pos = buffer.readUInt8(msg_name === 'CHAINING' ? 9 : 5);
if (!room.dueling_players[0].is_first) { if (!room.dueling_players[0].is_first) {
act_pos = 1 - act_pos; act_pos = 1 - act_pos;
...@@ -4208,17 +4209,17 @@ ...@@ -4208,17 +4209,17 @@
} }
} }
} }
if (msg_name === 'POS_CHANGE') { if (msg_inst instanceof YGOProMsg.YGOProMsgPosChange) {
loc = buffer.readUInt8(6); loc = msg_inst.card.location;
ppos = buffer.readUInt8(8); ppos = msg_inst.previousPosition;
cpos = buffer.readUInt8(9); cpos = msg_inst.currentPosition;
client.ready_trap = !!(loc & 0x8) && !!(ppos & 0xa) && !!(cpos & 0x5); client.ready_trap = !!(loc & 0x8) && !!(ppos & 0xa) && !!(cpos & 0x5);
} else if (msg_name !== 'UPDATE_CARD' && msg_name !== 'WAITING') { } else if (!(msg_inst instanceof YGOProMsg.YGOProMsgUpdateCard) && !(msg_inst instanceof YGOProMsg.YGOProMsgWaiting)) {
client.ready_trap = false; client.ready_trap = false;
} }
} }
if (room.recovering && client.pos < 4) { if (room.recovering && client.pos < 4) {
if (msg_name !== 'WAITING') { if (!(msg_inst instanceof YGOProMsg.YGOProMsgWaiting)) {
room.recover_buffers[client.pos].push(buffer); room.recover_buffers[client.pos].push(buffer);
} }
return true; return true;
...@@ -5730,7 +5731,7 @@ ...@@ -5730,7 +5731,7 @@
return callback + "( " + text + " );"; return callback + "( " + text + " );";
}; };
httpRequestListener = async function(request, response) { httpRequestListener = async function(request, response) {
var allowHeaders, archiveStream, base, buffer, death_room_found, duellog, e, err, error, filename, getpath, parseQueryString, pass_validated, requestHeaders, ret_keys, roomsjson, success, u, urlObj; var allowHeaders, archiveStream, base, buffer, death_room_found, duellog, e, err, error, filename, getpath, j, l, len, len1, len2, len3, m, n, parseQueryString, pass_validated, player, requestHeaders, ret_keys, room, roomsjson, success, u, urlObj;
parseQueryString = true; parseQueryString = true;
base = `http://${request.headers.host || 'localhost'}`; base = `http://${request.headers.host || 'localhost'}`;
urlObj = new URL(request.url, base); urlObj = new URL(request.url, base);
...@@ -5765,48 +5766,44 @@ ...@@ -5765,48 +5766,44 @@
response.end(addCallback(u.query.callback, '{"rooms":[{"roomid":"0","roomname":"密码错误","needpass":"true"}]}')); response.end(addCallback(u.query.callback, '{"rooms":[{"roomid":"0","roomname":"密码错误","needpass":"true"}]}'));
} else { } else {
roomsjson = []; roomsjson = [];
_async.each(ROOM_all, function(room, done) { for (j = 0, len = ROOM_all.length; j < len; j++) {
var player; room = ROOM_all[j];
if (!(room && room.established)) { if (room && room.established) {
done(); roomsjson.push({
return; roomid: room.process_pid.toString(),
} roomname: pass_validated ? room.name : room.name.split('$', 2)[0],
roomsjson.push({ roommode: room.hostinfo.mode,
roomid: room.process_pid.toString(), needpass: (room.name.indexOf('$') !== -1).toString(),
roomname: pass_validated ? room.name : room.name.split('$', 2)[0], users: _.sortBy((function() {
roommode: room.hostinfo.mode, var l, len1, ref, results;
needpass: (room.name.indexOf('$') !== -1).toString(), ref = room.players;
users: _.sortBy((function() { results = [];
var j, len, ref, results; for (l = 0, len1 = ref.length; l < len1; l++) {
ref = room.players; player = ref[l];
results = []; if (player.pos != null) {
for (j = 0, len = ref.length; j < len; j++) { results.push({
player = ref[j]; id: (-1).toString(),
if (player.pos != null) { name: player.name,
results.push({ ip: settings.modules.http.show_ip && pass_validated && !player.is_local ? toIpv4(player.ip) : null,
id: (-1).toString(), status: settings.modules.http.show_info && room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN && player.pos !== 7 ? {
name: player.name, score: room.scores[player.name_vpass],
ip: settings.modules.http.show_ip && pass_validated && !player.is_local ? toIpv4(player.ip) : null, lp: player.lp != null ? player.lp : room.hostinfo.start_lp,
status: settings.modules.http.show_info && room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN && player.pos !== 7 ? { cards: room.hostinfo.mode !== 2 ? (player.card_count != null ? player.card_count : room.hostinfo.start_hand) : null
score: room.scores[player.name_vpass], } : null,
lp: player.lp != null ? player.lp : room.hostinfo.start_lp, pos: player.pos
cards: room.hostinfo.mode !== 2 ? (player.card_count != null ? player.card_count : room.hostinfo.start_hand) : null });
} : null, }
pos: player.pos
});
} }
} return results;
return results; })(), "pos"),
})(), "pos"), istart: room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN ? (settings.modules.http.show_info ? "Duel:" + room.duel_count + " " + (room.duel_stage === ygopro.constants.DUEL_STAGE.SIDING ? "Siding" : "Turn:" + (room.turn != null ? room.turn : 0) + (room.death ? "/" + (room.death > 0 ? room.death - 1 : "Death") : "")) : 'start') : 'wait'
istart: room.duel_stage !== ygopro.constants.DUEL_STAGE.BEGIN ? (settings.modules.http.show_info ? "Duel:" + room.duel_count + " " + (room.duel_stage === ygopro.constants.DUEL_STAGE.SIDING ? "Siding" : "Turn:" + (room.turn != null ? room.turn : 0) + (room.death ? "/" + (room.death > 0 ? room.death - 1 : "Death") : "")) : 'start') : 'wait' });
}); }
return done(); }
}, function() { response.writeHead(200);
response.writeHead(200); response.end(addCallback(u.query.callback, JSON.stringify({
return response.end(addCallback(u.query.callback, JSON.stringify({ rooms: roomsjson
rooms: roomsjson })));
})));
});
} }
} else if (u.pathname === '/api/duellog' && settings.modules.mysql.enabled) { } else if (u.pathname === '/api/duellog' && settings.modules.mysql.enabled) {
if (!(await auth.auth(u.query.username, u.query.pass, "duel_log", "duel_log"))) { if (!(await auth.auth(u.query.username, u.query.pass, "duel_log", "duel_log"))) {
...@@ -5920,11 +5917,12 @@ ...@@ -5920,11 +5917,12 @@
response.end(addCallback(u.query.callback, "['密码错误', 0]")); response.end(addCallback(u.query.callback, "['密码错误', 0]"));
return; return;
} }
_async.each(ROOM_all, function(room) { for (l = 0, len1 = ROOM_all.length; l < len1; l++) {
room = ROOM_all[l];
if (room && room.established) { if (room && room.established) {
return ygopro.stoc_send_chat_to_room(room, u.query.shout, ygopro.constants.COLORS.YELLOW); ygopro.stoc_send_chat_to_room(room, u.query.shout, ygopro.constants.COLORS.YELLOW);
} }
}); }
response.writeHead(200); response.writeHead(200);
response.end(addCallback(u.query.callback, "['shout ok', '" + u.query.shout + "']")); response.end(addCallback(u.query.callback, "['shout ok', '" + u.query.shout + "']"));
} else if (u.query.stop) { } else if (u.query.stop) {
...@@ -6034,23 +6032,24 @@ ...@@ -6034,23 +6032,24 @@
return; return;
} }
death_room_found = false; death_room_found = false;
_async.each(ROOM_all, function(room, done) { for (m = 0, len2 = ROOM_all.length; m < len2; m++) {
if (!(room && (u.query.death === "all" || u.query.death === room.process_pid.toString() || u.query.death === room.name))) { room = ROOM_all[m];
done(); if (!(room)) {
return; continue;
}
if (!(u.query.death === "all" || u.query.death === room.process_pid.toString() || u.query.death === room.name)) {
continue;
} }
if (room.start_death()) { if (room.start_death()) {
death_room_found = true; death_room_found = true;
} }
done(); }
}, function() { response.writeHead(200);
response.writeHead(200); if (death_room_found) {
if (death_room_found) { response.end(addCallback(u.query.callback, "['death ok', '" + u.query.death + "']"));
return response.end(addCallback(u.query.callback, "['death ok', '" + u.query.death + "']")); } else {
} else { response.end(addCallback(u.query.callback, "['room not found', '" + u.query.death + "']"));
return response.end(addCallback(u.query.callback, "['room not found', '" + u.query.death + "']")); }
}
});
} else if (u.query.deathcancel) { } else if (u.query.deathcancel) {
if (!(await auth.auth(u.query.username, u.query.pass, "start_death", "cancel_death"))) { if (!(await auth.auth(u.query.username, u.query.pass, "start_death", "cancel_death"))) {
response.writeHead(200); response.writeHead(200);
...@@ -6058,23 +6057,24 @@ ...@@ -6058,23 +6057,24 @@
return; return;
} }
death_room_found = false; death_room_found = false;
_async.each(ROOM_all, function(room, done) { for (n = 0, len3 = ROOM_all.length; n < len3; n++) {
if (!(room && (u.query.deathcancel === "all" || u.query.deathcancel === room.process_pid.toString() || u.query.deathcancel === room.name))) { room = ROOM_all[n];
done(); if (!(room)) {
return; continue;
}
if (!(u.query.deathcancel === "all" || u.query.deathcancel === room.process_pid.toString() || u.query.deathcancel === room.name)) {
continue;
} }
if (room.cancel_death()) { if (room.cancel_death()) {
death_room_found = true; death_room_found = true;
} }
return done(); }
}, function() { response.writeHead(200);
response.writeHead(200); if (death_room_found) {
if (death_room_found) { response.end(addCallback(u.query.callback, "['death cancel ok', '" + u.query.deathcancel + "']"));
return response.end(addCallback(u.query.callback, "['death cancel ok', '" + u.query.deathcancel + "']")); } else {
} else { response.end(addCallback(u.query.callback, "['room not found', '" + u.query.deathcancel + "']"));
return response.end(addCallback(u.query.callback, "['room not found', '" + u.query.deathcancel + "']")); }
}
});
} else if (u.query.reboot) { } else if (u.query.reboot) {
if (!(await auth.auth(u.query.username, u.query.pass, "stop", "reboot"))) { if (!(await auth.auth(u.query.username, u.query.pass, "stop", "reboot"))) {
response.writeHead(200); response.writeHead(200);
......
...@@ -51,7 +51,6 @@ const axios_1 = __importDefault(require("axios")); ...@@ -51,7 +51,6 @@ const axios_1 = __importDefault(require("axios"));
const formidable = __importStar(require("formidable")); const formidable = __importStar(require("formidable"));
const load_json_file_1 = require("load-json-file"); const load_json_file_1 = require("load-json-file");
const challonge_1 = require("./challonge"); const challonge_1 = require("./challonge");
const asyncLib = __importStar(require("async"));
const ygopro_deck_encode_1 = __importDefault(require("ygopro-deck-encode")); const ygopro_deck_encode_1 = __importDefault(require("ygopro-deck-encode"));
const auth = __importStar(require("./ygopro-auth")); const auth = __importStar(require("./ygopro-auth"));
const underscore_1 = __importDefault(require("underscore")); const underscore_1 = __importDefault(require("underscore"));
...@@ -114,27 +113,21 @@ const readDeck = async function (deck_name, deck_full_path) { ...@@ -114,27 +113,21 @@ const readDeck = async function (deck_name, deck_full_path) {
return deck; return deck;
}; };
//读取指定文件夹中所有卡组 //读取指定文件夹中所有卡组
const getDecks = function (callback) { const getDecks = async function (callback) {
const decks = []; try {
asyncLib.auto({ const decks = [];
readDir: (done) => { const decks_list = await fs.promises.readdir(config.deck_path);
fs.readdir(config.deck_path, done); for (const deck_name of decks_list) {
}, if (deck_name.endsWith(".ydk")) {
handleDecks: [ const deck = await readDeck(deck_name, config.deck_path + deck_name);
"readDir", decks.push(deck);
(results, done) => { }
const decks_list = results.readDir; }
asyncLib.each(decks_list, async (deck_name) => { callback(null, decks);
if (deck_name.endsWith(".ydk")) { }
const deck = await readDeck(deck_name, config.deck_path + deck_name); catch (err) {
decks.push(deck); callback(err, []);
} }
}, done);
},
],
}, (err) => {
callback(err, decks);
});
}; };
const delDeck = function (deck_name, callback) { const delDeck = function (deck_name, callback) {
if (deck_name.startsWith("../") || deck_name.match(/\/\.\.\//)) { if (deck_name.startsWith("../") || deck_name.match(/\/\.\.\//)) {
...@@ -143,19 +136,19 @@ const delDeck = function (deck_name, callback) { ...@@ -143,19 +136,19 @@ const delDeck = function (deck_name, callback) {
} }
fs.unlink(config.deck_path + deck_name, callback); fs.unlink(config.deck_path + deck_name, callback);
}; };
const clearDecks = function (callback) { const clearDecks = async function (callback) {
asyncLib.auto({ try {
deckList: (done) => { const decks_list = await fs.promises.readdir(config.deck_path);
fs.readdir(config.deck_path, done); for (const deck_name of decks_list) {
}, await new Promise((resolve, reject) => {
removeAll: [ delDeck(deck_name, (err) => (err ? reject(err) : resolve()));
"deckList", });
(results, done) => { }
const decks_list = results.deckList; callback(null);
asyncLib.each(decks_list, delDeck, done); }
}, catch (err) {
], callback(err);
}, callback); }
}; };
const UploadToChallonge = async function () { const UploadToChallonge = async function () {
if (!challonge_config.enabled) { if (!challonge_config.enabled) {
...@@ -194,34 +187,38 @@ const UploadToChallonge = async function () { ...@@ -194,34 +187,38 @@ const UploadToChallonge = async function () {
} }
return true; return true;
}; };
const receiveDecks = function (files, callback) { const receiveDecks = async function (files, callback) {
const result = []; try {
asyncLib.eachSeries(files, async (file) => { const result = [];
if (file.name.endsWith(".ydk")) { for (const file of files) {
const deck = await readDeck(file.name, file.path); if (file.name.endsWith(".ydk")) {
if (deck.main.length >= 40) { const deck = await readDeck(file.name, file.path);
fs.createReadStream(file.path).pipe(fs.createWriteStream(config.deck_path + file.name)); if (deck.main.length >= 40) {
result.push({ fs.createReadStream(file.path).pipe(fs.createWriteStream(config.deck_path + file.name));
file: file.name, result.push({
status: "OK", file: file.name,
}); status: "OK",
});
}
else {
result.push({
file: file.name,
status: "卡组不合格",
});
}
} }
else { else {
result.push({ result.push({
file: file.name, file: file.name,
status: "卡组不合格", status: "不是卡组文件",
}); });
} }
} }
else { callback(null, result);
result.push({ }
file: file.name, catch (err) {
status: "不是卡组文件", callback(err, []);
}); }
}
}, (err) => {
callback(err, result);
});
}; };
//建立一个http服务器,接收API操作 //建立一个http服务器,接收API操作
async function requestListener(req, res) { async function requestListener(req, res) {
......
...@@ -15,7 +15,6 @@ import * as formidable from "formidable"; ...@@ -15,7 +15,6 @@ import * as formidable from "formidable";
import { sync as loadJSON } from "load-json-file"; import { sync as loadJSON } from "load-json-file";
import defaultConfig from "./data/default_config.json"; import defaultConfig from "./data/default_config.json";
import { Challonge } from "./challonge"; import { Challonge } from "./challonge";
import * as asyncLib from "async";
import YGOProDeckEncode from "ygopro-deck-encode"; import YGOProDeckEncode from "ygopro-deck-encode";
import * as auth from "./ygopro-auth"; import * as auth from "./ygopro-auth";
import _ from "underscore"; import _ from "underscore";
...@@ -82,34 +81,20 @@ const readDeck = async function (deck_name: string, deck_full_path: string) { ...@@ -82,34 +81,20 @@ const readDeck = async function (deck_name: string, deck_full_path: string) {
}; };
//读取指定文件夹中所有卡组 //读取指定文件夹中所有卡组
const getDecks = function (callback: (err: Error | null, decks: any[]) => void) { const getDecks = async function (callback: (err: Error | null, decks: any[]) => void) {
const decks: any[] = []; try {
asyncLib.auto( const decks: any[] = [];
{ const decks_list = await fs.promises.readdir(config.deck_path);
readDir: (done: (err: NodeJS.ErrnoException | null, files?: string[]) => void) => { for (const deck_name of decks_list) {
fs.readdir(config.deck_path, done); if (deck_name.endsWith(".ydk")) {
}, const deck = await readDeck(deck_name, config.deck_path + deck_name);
handleDecks: [ decks.push(deck);
"readDir", }
(results: any, done: (err?: Error | null) => void) => {
const decks_list = results.readDir as string[];
asyncLib.each(
decks_list,
async (deck_name: string) => {
if (deck_name.endsWith(".ydk")) {
const deck = await readDeck(deck_name, config.deck_path + deck_name);
decks.push(deck);
}
},
done
);
},
],
},
(err: Error | null) => {
callback(err, decks);
} }
); callback(null, decks);
} catch (err) {
callback(err as Error, []);
}
}; };
const delDeck = function (deck_name: string, callback: (err?: NodeJS.ErrnoException | null) => void) { const delDeck = function (deck_name: string, callback: (err?: NodeJS.ErrnoException | null) => void) {
...@@ -120,22 +105,18 @@ const delDeck = function (deck_name: string, callback: (err?: NodeJS.ErrnoExcept ...@@ -120,22 +105,18 @@ const delDeck = function (deck_name: string, callback: (err?: NodeJS.ErrnoExcept
fs.unlink(config.deck_path + deck_name, callback); fs.unlink(config.deck_path + deck_name, callback);
}; };
const clearDecks = function (callback: (err?: Error | null) => void) { const clearDecks = async function (callback: (err?: Error | null) => void) {
asyncLib.auto( try {
{ const decks_list = await fs.promises.readdir(config.deck_path);
deckList: (done: (err: NodeJS.ErrnoException | null, files?: string[]) => void) => { for (const deck_name of decks_list) {
fs.readdir(config.deck_path, done); await new Promise<void>((resolve, reject) => {
}, delDeck(deck_name, (err) => (err ? reject(err) : resolve()));
removeAll: [ });
"deckList", }
(results: any, done: (err?: Error | null) => void) => { callback(null);
const decks_list = results.deckList as string[]; } catch (err) {
asyncLib.each(decks_list, delDeck as any, done); callback(err as Error);
}, }
],
},
callback
);
}; };
const UploadToChallonge = async function () { const UploadToChallonge = async function () {
...@@ -179,14 +160,13 @@ const UploadToChallonge = async function () { ...@@ -179,14 +160,13 @@ const UploadToChallonge = async function () {
return true; return true;
}; };
const receiveDecks = function ( const receiveDecks = async function (
files: any, files: any,
callback: (err: Error | null, result: Array<{ file: string; status: string }>) => void callback: (err: Error | null, result: Array<{ file: string; status: string }>) => void
) { ) {
const result: Array<{ file: string; status: string }> = []; try {
asyncLib.eachSeries( const result: Array<{ file: string; status: string }> = [];
files, for (const file of files) {
async (file: any) => {
if (file.name.endsWith(".ydk")) { if (file.name.endsWith(".ydk")) {
const deck = await readDeck(file.name, file.path); const deck = await readDeck(file.name, file.path);
if (deck.main.length >= 40) { if (deck.main.length >= 40) {
...@@ -207,11 +187,11 @@ const receiveDecks = function ( ...@@ -207,11 +187,11 @@ const receiveDecks = function (
status: "不是卡组文件", status: "不是卡组文件",
}); });
} }
},
(err: Error | null) => {
callback(err, result);
} }
); callback(null, result);
} catch (err) {
callback(err as Error, []);
}
}; };
//建立一个http服务器,接收API操作 //建立一个http服务器,接收API操作
......
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