Commit 13923e5e authored by Sophia's avatar Sophia

add winner information

parent 6e05bb51
...@@ -20,7 +20,8 @@ function compressData(jsonData, replays) { ...@@ -20,7 +20,8 @@ function compressData(jsonData, replays) {
const headerContentBuffer = Buffer.from(jsonData, "utf8"); const headerContentBuffer = Buffer.from(jsonData, "utf8");
headerLengthBuffer.writeUInt32BE(headerContentBuffer.length); headerLengthBuffer.writeUInt32BE(headerContentBuffer.length);
let replayBuffer = null; let replayBuffer = null;
replays.forEach(replayData => { for (let i = 0; i < replays.length; i++) {
const replayData = replays[i];
const replayDataLengthBuffer = Buffer.alloc(4); const replayDataLengthBuffer = Buffer.alloc(4);
replayDataLengthBuffer.writeUInt32BE(replayData.length, 0); replayDataLengthBuffer.writeUInt32BE(replayData.length, 0);
if (!replayBuffer) { if (!replayBuffer) {
...@@ -29,7 +30,10 @@ function compressData(jsonData, replays) { ...@@ -29,7 +30,10 @@ function compressData(jsonData, replays) {
else { else {
replayBuffer = Buffer.concat([replayBuffer, replayDataLengthBuffer, replayData]); replayBuffer = Buffer.concat([replayBuffer, replayDataLengthBuffer, replayData]);
} }
}); }
if (!replayBuffer) {
return null;
}
return Buffer.concat([headerLengthBuffer, headerContentBuffer, replayBuffer]); return Buffer.concat([headerLengthBuffer, headerContentBuffer, replayBuffer]);
} }
function uploadResult(room) { function uploadResult(room) {
...@@ -40,14 +44,19 @@ function uploadResult(room) { ...@@ -40,14 +44,19 @@ function uploadResult(room) {
room.finishedAt.push(moment()); room.finishedAt.push(moment());
const data = { const data = {
roomSettings: Object.assign(Object.assign({}, room.hostinfo), { lflist: Object.assign(Object.assign({}, lflists[room.hostinfo.lflist]), { date: lflists[room.hostinfo.lflist].date.add(1, "day").format("YYYY.MM") }) }), roomSettings: Object.assign(Object.assign({}, room.hostinfo), { lflist: Object.assign(Object.assign({}, lflists[room.hostinfo.lflist]), { date: lflists[room.hostinfo.lflist].date.add(1, "day").format("YYYY.MM") }) }),
players: room.customPlayerInformation, players: room.customPlayerInformation || [],
startedAt: room.startedAt.map(formatTime), startedAt: room.startedAt ? room.startedAt.map(formatTime) : [],
finishedAt: room.finishedAt.map(formatTime), finishedAt: room.finishedAt ? room.finishedAt.map(formatTime) : [],
type: room.arena || "normal", type: room.arena || "normal",
isRandomMatch: Boolean(room.random_type), isRandomMatch: Boolean(room.random_type),
winnerNames: room.winnerNames || [],
scores: room.scores,
}; };
room.replaySaved = true; room.replaySaved = true;
const compressedData = compressData(JSON.stringify(data), room.replays); const compressedData = compressData(JSON.stringify(data), room.replays);
if (!compressedData) {
return;
}
const formData = new FormData(); const formData = new FormData();
formData.append("data", compressedData, { formData.append("data", compressedData, {
filename: "data.bin", filename: "data.bin",
...@@ -70,7 +79,8 @@ function uploadResult(room) { ...@@ -70,7 +79,8 @@ function uploadResult(room) {
}); });
} }
catch (e) { catch (e) {
log.warn(`YGOReplay: an error occurred during uploading match result: ${e.message}`); const err = e;
log.warn(`YGOReplay: an error occurred during uploading match result: ${err.message}`);
} }
} }
ygopro.stoc_follow("DUEL_START", false, (buffer, info, client) => __awaiter(void 0, void 0, void 0, function* () { ygopro.stoc_follow("DUEL_START", false, (buffer, info, client) => __awaiter(void 0, void 0, void 0, function* () {
...@@ -110,6 +120,22 @@ ygopro.stoc_follow("DUEL_START", false, (buffer, info, client) => __awaiter(void ...@@ -110,6 +120,22 @@ ygopro.stoc_follow("DUEL_START", false, (buffer, info, client) => __awaiter(void
} }
return true; return true;
})); }));
ygopro.stoc_follow_after("GAME_MSG", false, (buffer, info, client) => __awaiter(void 0, void 0, void 0, function* () {
if (buffer.readUInt8(0) === 5 && client.pos === 0) {
const room = ROOM_all[client.rid];
const player = room.dueling_players.find(p => p.name === room.winner_name);
if (!player) {
return false;
}
if (!room.winnerNames) {
room.winnerNames = [];
}
if (room.winner_name) {
room.winnerNames.push(room.winner_name);
}
}
return false;
}));
ygopro.stoc_follow_after("CHANGE_SIDE", false, (buffer, info, client) => __awaiter(void 0, void 0, void 0, function* () { ygopro.stoc_follow_after("CHANGE_SIDE", false, (buffer, info, client) => __awaiter(void 0, void 0, void 0, function* () {
try { try {
client.needToChangeSide = true; client.needToChangeSide = true;
......
...@@ -11,7 +11,9 @@ ...@@ -11,7 +11,9 @@
"build": "tsc" "build": "tsc"
}, },
"devDependencies": { "devDependencies": {
"@types/lodash": "^4.14.175",
"@types/node": "^16.10.3", "@types/node": "^16.10.3",
"@types/node-fetch": "^2.5.12",
"@typescript-eslint/eslint-plugin": "^4.33.0", "@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0", "@typescript-eslint/parser": "^4.33.0",
"eslint": "^7.32.0", "eslint": "^7.32.0",
...@@ -21,6 +23,7 @@ ...@@ -21,6 +23,7 @@
}, },
"dependencies": { "dependencies": {
"form-data": "^4.0.0", "form-data": "^4.0.0",
"lodash": "^4.17.21",
"moment": "^2.29.1", "moment": "^2.29.1",
"node-fetch": "^2.6.5" "node-fetch": "^2.6.5"
} }
......
...@@ -34,11 +34,14 @@ interface ExportData { ...@@ -34,11 +34,14 @@ interface ExportData {
finishedAt: number[]; finishedAt: number[];
type: "athletic" | "entertain" | "normal"; type: "athletic" | "entertain" | "normal";
isRandomMatch: boolean; isRandomMatch: boolean;
winnerNames: string[];
scores: { [playerName: string]: number };
} }
declare const lflists: Array<{ date: moment.Moment; tcg: boolean }>; declare const lflists: Array<{ date: moment.Moment; tcg: boolean }>;
declare const ygopro: YGOPro; declare const ygopro: YGOPro;
declare const ROOM_all: Array<{ declare const ROOM_all: Array<{
duel_stage: number;
name: string; // 방 제목 name: string; // 방 제목
// 방 설정 // 방 설정
hostinfo: { hostinfo: {
...@@ -53,6 +56,9 @@ declare const ROOM_all: Array<{ ...@@ -53,6 +56,9 @@ declare const ROOM_all: Array<{
lflist: number; // 금제 index lflist: number; // 금제 index
time_limit: number; // 턴당 시간 time_limit: number; // 턴당 시간
}; };
winner_name: string;
scores: { [userName: string]: number };
winnerNames?: string[];
dueling_players: Array<{ dueling_players: Array<{
ip: string; // IP 주소 ip: string; // IP 주소
name: string; // 플레이어 이름 name: string; // 플레이어 이름
...@@ -88,7 +94,8 @@ function compressData(jsonData: string, replays: Array<Buffer>) { ...@@ -88,7 +94,8 @@ function compressData(jsonData: string, replays: Array<Buffer>) {
headerLengthBuffer.writeUInt32BE(headerContentBuffer.length); headerLengthBuffer.writeUInt32BE(headerContentBuffer.length);
let replayBuffer: Buffer | null = null; let replayBuffer: Buffer | null = null;
replays.forEach(replayData => { for (let i = 0; i < replays.length; i++) {
const replayData = replays[i];
const replayDataLengthBuffer = Buffer.alloc(4); const replayDataLengthBuffer = Buffer.alloc(4);
replayDataLengthBuffer.writeUInt32BE(replayData.length, 0); replayDataLengthBuffer.writeUInt32BE(replayData.length, 0);
...@@ -97,7 +104,11 @@ function compressData(jsonData: string, replays: Array<Buffer>) { ...@@ -97,7 +104,11 @@ function compressData(jsonData: string, replays: Array<Buffer>) {
} else { } else {
replayBuffer = Buffer.concat([replayBuffer, replayDataLengthBuffer, replayData]); replayBuffer = Buffer.concat([replayBuffer, replayDataLengthBuffer, replayData]);
} }
}); }
if (!replayBuffer) {
return null;
}
return Buffer.concat([headerLengthBuffer, headerContentBuffer, replayBuffer]); return Buffer.concat([headerLengthBuffer, headerContentBuffer, replayBuffer]);
} }
...@@ -118,16 +129,21 @@ function uploadResult(room: typeof ROOM_all[0]) { ...@@ -118,16 +129,21 @@ function uploadResult(room: typeof ROOM_all[0]) {
date: lflists[room.hostinfo.lflist].date.add(1, "day").format("YYYY.MM"), date: lflists[room.hostinfo.lflist].date.add(1, "day").format("YYYY.MM"),
}, },
}, },
players: room.customPlayerInformation, players: room.customPlayerInformation || [],
startedAt: room.startedAt.map(formatTime), startedAt: room.startedAt ? room.startedAt.map(formatTime) : [],
finishedAt: room.finishedAt.map(formatTime), finishedAt: room.finishedAt ? room.finishedAt.map(formatTime) : [],
type: room.arena || "normal", type: room.arena || "normal",
isRandomMatch: Boolean(room.random_type), isRandomMatch: Boolean(room.random_type),
winnerNames: room.winnerNames || [],
scores: room.scores,
}; };
room.replaySaved = true; room.replaySaved = true;
const compressedData = compressData(JSON.stringify(data), room.replays); const compressedData = compressData(JSON.stringify(data), room.replays);
if (!compressedData) {
return;
}
const formData = new FormData(); const formData = new FormData();
formData.append("data", compressedData, { formData.append("data", compressedData, {
...@@ -153,7 +169,8 @@ function uploadResult(room: typeof ROOM_all[0]) { ...@@ -153,7 +169,8 @@ function uploadResult(room: typeof ROOM_all[0]) {
log.warn(`YGOReplay data collecting plugin error: ${e.message}`); log.warn(`YGOReplay data collecting plugin error: ${e.message}`);
}); });
} catch (e) { } catch (e) {
log.warn(`YGOReplay: an error occurred during uploading match result: ${e.message}`); const err = e as Error;
log.warn(`YGOReplay: an error occurred during uploading match result: ${err.message}`);
} }
} }
...@@ -193,12 +210,32 @@ ygopro.stoc_follow("DUEL_START", false, async (buffer, info, client) => { ...@@ -193,12 +210,32 @@ ygopro.stoc_follow("DUEL_START", false, async (buffer, info, client) => {
}); });
} }
} catch (e) { } catch (e) {
log.warn(`YGOReplay: an error occurred during processing DUEL_START message: ${e.message}`); log.warn(`YGOReplay: an error occurred during processing DUEL_START message: ${(e as Error).message}`);
} }
return true; return true;
}); });
ygopro.stoc_follow_after("GAME_MSG", false, async (buffer, info, client) => {
if (buffer.readUInt8(0) === 5 && client.pos === 0) {
const room = ROOM_all[client.rid];
const player = room.dueling_players.find(p => p.name === room.winner_name);
if (!player) {
return false;
}
if (!room.winnerNames) {
room.winnerNames = [];
}
if (room.winner_name) {
room.winnerNames.push(room.winner_name);
}
}
return false;
});
ygopro.stoc_follow_after("CHANGE_SIDE", false, async (buffer, info, client) => { ygopro.stoc_follow_after("CHANGE_SIDE", false, async (buffer, info, client) => {
try { try {
client.needToChangeSide = true; client.needToChangeSide = true;
...@@ -218,7 +255,7 @@ ygopro.stoc_follow_after("CHANGE_SIDE", false, async (buffer, info, client) => { ...@@ -218,7 +255,7 @@ ygopro.stoc_follow_after("CHANGE_SIDE", false, async (buffer, info, client) => {
room.finishedAt.push(moment()); room.finishedAt.push(moment());
} catch (e) { } catch (e) {
log.warn(`YGOReplay: an error occurred during processing CHANGE_SIDE message: ${e.message}`); log.warn(`YGOReplay: an error occurred during processing CHANGE_SIDE message: ${(e as Error).message}`);
} }
return false; return false;
...@@ -235,7 +272,7 @@ ygopro.stoc_follow_after("REPLAY", false, async (buffer, info, client) => { ...@@ -235,7 +272,7 @@ ygopro.stoc_follow_after("REPLAY", false, async (buffer, info, client) => {
uploadResult(room); uploadResult(room);
} }
} catch (e) { } catch (e) {
log.warn(`YGOReplay: an error occurred during processing REPLAY message: ${e.message}`); log.warn(`YGOReplay: an error occurred during processing REPLAY message: ${(e as Error).message}`);
} }
return false; return false;
...@@ -271,7 +308,7 @@ ygopro.ctos_follow_after("UPDATE_DECK", false, async (buffer, info, client) => { ...@@ -271,7 +308,7 @@ ygopro.ctos_follow_after("UPDATE_DECK", false, async (buffer, info, client) => {
client.needToChangeSide = false; client.needToChangeSide = false;
} }
} catch (e) { } catch (e) {
log.warn(`YGOReplay: an error occurred during processing UPDATE_DECK message: ${e.message}`); log.warn(`YGOReplay: an error occurred during processing UPDATE_DECK message: ${(e as Error).message}`);
} }
return false; return false;
...@@ -290,7 +327,7 @@ ygopro.ctos_follow_after("UPDATE_DECK", false, async (buffer, info, client) => { ...@@ -290,7 +327,7 @@ ygopro.ctos_follow_after("UPDATE_DECK", false, async (buffer, info, client) => {
uploadResult(room); uploadResult(room);
} }
} catch (e) { } catch (e) {
log.warn(`YGOReplay: an error occurred during processing UPDATE_DECK message: ${e.message}`); log.warn(`YGOReplay: an error occurred during processing UPDATE_DECK message: ${(e as Error).message}`);
} }
return oldSTOCSend(client, message, buffer); return oldSTOCSend(client, message, buffer);
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
"experimentalDecorators": true, "experimentalDecorators": true,
"allowSyntheticDefaultImports": true, "allowSyntheticDefaultImports": true,
"target": "ES2015", "target": "ES2015",
"strict": true,
"lib": ["ES2015", "ES2015.Promise"], "lib": ["ES2015", "ES2015.Promise"],
"sourceMap": false, "sourceMap": false,
"outDir": "./dist", "outDir": "./dist",
......
...@@ -78,7 +78,20 @@ ...@@ -78,7 +78,20 @@
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.9.tgz#97edc9037ea0c38585320b28964dde3b39e4660d" resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.9.tgz#97edc9037ea0c38585320b28964dde3b39e4660d"
integrity sha512-qcUXuemtEu+E5wZSJHNxUXeCZhAfXKQ41D+duX+VYPde7xyEVZci+/oXKJL13tnRs9lR2pr4fod59GT6/X1/yQ== integrity sha512-qcUXuemtEu+E5wZSJHNxUXeCZhAfXKQ41D+duX+VYPde7xyEVZci+/oXKJL13tnRs9lR2pr4fod59GT6/X1/yQ==
"@types/node@^16.10.3": "@types/lodash@^4.14.175":
version "4.14.175"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.175.tgz#b78dfa959192b01fae0ad90e166478769b215f45"
integrity sha512-XmdEOrKQ8a1Y/yxQFOMbC47G/V2VDO1GvMRnl4O75M4GW/abC5tnfzadQYkqEveqRM1dEJGFFegfPNA2vvx2iw==
"@types/node-fetch@^2.5.12":
version "2.5.12"
resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.5.12.tgz#8a6f779b1d4e60b7a57fb6fd48d84fb545b9cc66"
integrity sha512-MKgC4dlq4kKNa/mYrwpKfzQMB5X3ee5U6fSprkKpToBqBmX4nFZL9cW5jl6sWn+xpRJ7ypWh2yyqqr8UUCstSw==
dependencies:
"@types/node" "*"
form-data "^3.0.0"
"@types/node@*", "@types/node@^16.10.3":
version "16.10.3" version "16.10.3"
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.10.3.tgz#7a8f2838603ea314d1d22bb3171d899e15c57bd5" resolved "https://registry.yarnpkg.com/@types/node/-/node-16.10.3.tgz#7a8f2838603ea314d1d22bb3171d899e15c57bd5"
integrity sha512-ho3Ruq+fFnBrZhUYI46n/bV2GjwzSkwuT4dTf0GkuNFmnb8nq4ny2z9JEVemFi6bdEJanHLlYfy9c6FN9B9McQ== integrity sha512-ho3Ruq+fFnBrZhUYI46n/bV2GjwzSkwuT4dTf0GkuNFmnb8nq4ny2z9JEVemFi6bdEJanHLlYfy9c6FN9B9McQ==
...@@ -562,6 +575,15 @@ flatted@^3.1.0: ...@@ -562,6 +575,15 @@ flatted@^3.1.0:
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.2.tgz#64bfed5cb68fe3ca78b3eb214ad97b63bedce561" resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.2.tgz#64bfed5cb68fe3ca78b3eb214ad97b63bedce561"
integrity sha512-JaTY/wtrcSyvXJl4IMFHPKyFur1sE9AUqc0QnhOaJ0CxHtAoIV8pYDzeEfAaNEtGkOfq4gr3LBFmdXW5mOQFnA== integrity sha512-JaTY/wtrcSyvXJl4IMFHPKyFur1sE9AUqc0QnhOaJ0CxHtAoIV8pYDzeEfAaNEtGkOfq4gr3LBFmdXW5mOQFnA==
form-data@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-3.0.1.tgz#ebd53791b78356a99af9a300d4282c4d5eb9755f"
integrity sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==
dependencies:
asynckit "^0.4.0"
combined-stream "^1.0.8"
mime-types "^2.1.12"
form-data@^4.0.0: form-data@^4.0.0:
version "4.0.0" version "4.0.0"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452" resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452"
...@@ -743,6 +765,11 @@ lodash.truncate@^4.4.2: ...@@ -743,6 +765,11 @@ lodash.truncate@^4.4.2:
resolved "https://registry.yarnpkg.com/lodash.truncate/-/lodash.truncate-4.4.2.tgz#5a350da0b1113b837ecfffd5812cbe58d6eae193" resolved "https://registry.yarnpkg.com/lodash.truncate/-/lodash.truncate-4.4.2.tgz#5a350da0b1113b837ecfffd5812cbe58d6eae193"
integrity sha1-WjUNoLERO4N+z//VgSy+WNbq4ZM= integrity sha1-WjUNoLERO4N+z//VgSy+WNbq4ZM=
lodash@^4.17.21:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
lru-cache@^6.0.0: lru-cache@^6.0.0:
version "6.0.0" version "6.0.0"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-6.0.0.tgz#6d6fe6570ebd96aaf90fcad1dafa3b2566db3a94" resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-6.0.0.tgz#6d6fe6570ebd96aaf90fcad1dafa3b2566db3a94"
......
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