Commit 06448cb3 authored by nanahira's avatar nanahira

fix

parent 25cd9a64
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
"ygopro-cdb-encode": "^1.0.2", "ygopro-cdb-encode": "^1.0.2",
"ygopro-deck-encode": "^1.0.15", "ygopro-deck-encode": "^1.0.15",
"ygopro-lflist-encode": "^1.0.3", "ygopro-lflist-encode": "^1.0.3",
"ygopro-msg-encode": "^1.1.13", "ygopro-msg-encode": "^1.1.14",
"ygopro-yrp-encode": "^1.0.1", "ygopro-yrp-encode": "^1.0.1",
"yuzuthread": "^1.0.8" "yuzuthread": "^1.0.8"
}, },
...@@ -7448,9 +7448,9 @@ ...@@ -7448,9 +7448,9 @@
} }
}, },
"node_modules/ygopro-msg-encode": { "node_modules/ygopro-msg-encode": {
"version": "1.1.13", "version": "1.1.14",
"resolved": "https://registry.npmjs.org/ygopro-msg-encode/-/ygopro-msg-encode-1.1.13.tgz", "resolved": "https://registry.npmjs.org/ygopro-msg-encode/-/ygopro-msg-encode-1.1.14.tgz",
"integrity": "sha512-wWRn6zH4kgg8vS2Z9CCzTAMwPe6WWjZLFizdtUEO6uY+uTNn+dMEIWQpQKHL4eAMXexNDZG1lVGm70eaIKeUkw==", "integrity": "sha512-IUdzJThpZhHMY4y1ob4sYvgKrlyKghblZOdYuUUeta4ujzUsKqBCIaUXu67ypH/TTH541Nu5iLaBtWZ0HfZR8Q==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"typed-reflector": "^1.0.14", "typed-reflector": "^1.0.14",
......
...@@ -87,7 +87,7 @@ export abstract class Client { ...@@ -87,7 +87,7 @@ export abstract class Client {
await this._send(Buffer.from(data.toFullPayload())); await this._send(Buffer.from(data.toFullPayload()));
} catch (e) { } catch (e) {
this.logger.warn( this.logger.warn(
{ ip: this.loggingIp(), error: (e as Error).message }, { ip: this.loggingIp(), error: (e as Error).stack },
`Failed to send message: ${(e as Error).message}`, `Failed to send message: ${(e as Error).message}`,
); );
} }
......
...@@ -48,6 +48,7 @@ import { ...@@ -48,6 +48,7 @@ import {
CardQuery, CardQuery,
YGOProCtosResponse, YGOProCtosResponse,
YGOProCtosSurrender, YGOProCtosSurrender,
YGOProMsgWaiting,
} from 'ygopro-msg-encode'; } from 'ygopro-msg-encode';
import { DefaultHostInfoProvider } from './default-hostinfo-provder'; import { DefaultHostInfoProvider } from './default-hostinfo-provder';
import { import {
...@@ -82,6 +83,7 @@ import { ...@@ -82,6 +83,7 @@ import {
getZoneQueryFlag, getZoneQueryFlag,
splitRefreshLocations, splitRefreshLocations,
} from '../utility/refresh-query'; } from '../utility/refresh-query';
import { shuffleDecksBySeed } from '../utility/shuffle-decks-by-seed';
const { OcgcoreScriptConstants } = _OcgcoreConstants; const { OcgcoreScriptConstants } = _OcgcoreConstants;
...@@ -163,6 +165,7 @@ export class Room { ...@@ -163,6 +165,7 @@ export class Room {
if (this.hostinfo.lflist >= 0) { if (this.hostinfo.lflist >= 0) {
this.lflist = (await this.findLFList()) || blankLFList; this.lflist = (await this.findLFList()) || blankLFList;
} }
this.logger.debug({ winMatchCount: this.winMatchCount }, 'Match win count');
return this; return this;
} }
...@@ -940,6 +943,16 @@ export class Room { ...@@ -940,6 +943,16 @@ export class Room {
}; };
}); });
} }
if (!this.hostinfo.no_shuffle_deck) {
const shuffledDecks = shuffleDecksBySeed(
duelRecord.players.map((p) => p.deck),
duelRecord.seed,
);
duelRecord.players = duelRecord.players.map((player, index) => ({
...player,
deck: shuffledDecks[index],
}));
}
this.duelRecords.push(duelRecord); this.duelRecords.push(duelRecord);
const extraScriptPaths = [ const extraScriptPaths = [
...@@ -968,6 +981,10 @@ export class Room { ...@@ -968,6 +981,10 @@ export class Room {
registry[`player_name_${i}`] = player.name; registry[`player_name_${i}`] = player.name;
}); });
this.logger.debug(
{ seed: duelRecord.seed, registry, hostinfo: this.hostinfo },
'Initializing OCGCoreWorker',
);
this.ocgcore = await initWorker(OcgcoreWorker, { this.ocgcore = await initWorker(OcgcoreWorker, {
seed: duelRecord.seed, seed: duelRecord.seed,
hostinfo: this.hostinfo, hostinfo: this.hostinfo,
...@@ -1150,6 +1167,9 @@ export class Room { ...@@ -1150,6 +1167,9 @@ export class Room {
} }
private async routeGameMsg(message: YGOProMsgBase) { private async routeGameMsg(message: YGOProMsgBase) {
if (!message) {
return;
}
const sendTargets = message.getSendTargets(); const sendTargets = message.getSendTargets();
const sendGameMsg = (c: Client, msg: YGOProMsgBase) => const sendGameMsg = (c: Client, msg: YGOProMsgBase) =>
c.send(new YGOProStocGameMsg().fromPartial({ msg })); c.send(new YGOProStocGameMsg().fromPartial({ msg }));
...@@ -1175,6 +1195,12 @@ export class Room { ...@@ -1175,6 +1195,12 @@ export class Room {
} }
}), }),
); );
if (
message instanceof YGOProMsgUpdateData ||
message instanceof YGOProMsgUpdateCard
) {
return;
}
await Promise.all([ await Promise.all([
...message.getRequireRefreshCards().map((loc) => this.refreshSingle(loc)), ...message.getRequireRefreshCards().map((loc) => this.refreshSingle(loc)),
...message ...message
...@@ -1184,14 +1210,20 @@ export class Room { ...@@ -1184,14 +1210,20 @@ export class Room {
} }
private async handleGameMsg(message: YGOProMsgBase, route = false) { private async handleGameMsg(message: YGOProMsgBase, route = false) {
await this.localGameMsgDispatcher.dispatch(message); const msg1 = await this.localGameMsgDispatcher.dispatch(message);
await this.ctx.dispatch(message, this.getOpreatingPlayer(this.turnPos)); const msg2 = await this.ctx.dispatch(
if (!route) { msg1,
await this.routeGameMsg(message); this.getOpreatingPlayer(this.turnPos),
);
if (route) {
await this.routeGameMsg(msg2);
} }
return msg2;
} }
localGameMsgDispatcher = new ProtoMiddlewareDispatcher() localGameMsgDispatcher = new ProtoMiddlewareDispatcher({
acceptResult: () => true,
})
.middleware(YGOProMsgBase, async (message, next) => { .middleware(YGOProMsgBase, async (message, next) => {
this.logger.debug( this.logger.debug(
{ msgName: message.constructor.name }, { msgName: message.constructor.name },
...@@ -1239,11 +1271,33 @@ export class Room { ...@@ -1239,11 +1271,33 @@ export class Room {
YGOProMsgResponseBase, YGOProMsgResponseBase,
async (message, next) => { async (message, next) => {
this.responsePos = message.responsePlayer(); this.responsePos = message.responsePlayer();
const op = this.getOpreatingPlayer(this.responsePos);
const noOps = this.playingPlayers.filter((p) => p !== op);
await Promise.all(
noOps.map((p) =>
p.send(
new YGOProStocGameMsg().fromPartial({
msg: new YGOProMsgWaiting(),
}),
),
),
);
// TODO: set timer // TODO: set timer
return next(); return next();
}, },
true, true,
)
.middleware(YGOProMsgRetry, async (message, next) => {
if (this.responsePos != null) {
const op = this.getOpreatingPlayer(this.responsePos);
await op.send(
new YGOProStocGameMsg().fromPartial({
msg: message,
}),
); );
}
return next();
});
private pendingResponse?: Buffer; private pendingResponse?: Buffer;
private responsePos?: number; private responsePos?: number;
...@@ -1265,11 +1319,11 @@ export class Room { ...@@ -1265,11 +1319,11 @@ export class Room {
} }
} }
await this.handleGameMsg(message); const handled = await this.handleGameMsg(message);
if (message instanceof YGOProMsgWin) { if (handled instanceof YGOProMsgWin) {
return this.win(message); return this.win(handled);
} }
await this.routeGameMsg(message); await this.routeGameMsg(handled);
} }
} catch (e) { } catch (e) {
this.logger.warn({ error: e }, 'Error while advancing ocgcore'); this.logger.warn({ error: e }, 'Error while advancing ocgcore');
......
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