Commit 7dcde5ac authored by nanahira's avatar nanahira

update config things & ocgcore wasm path

parent 2d537ea0
...@@ -19,6 +19,7 @@ DECK_EXTRA_MAX: "15" ...@@ -19,6 +19,7 @@ DECK_EXTRA_MAX: "15"
DECK_SIDE_MAX: "15" DECK_SIDE_MAX: "15"
DECK_MAX_COPIES: "3" DECK_MAX_COPIES: "3"
OCGCORE_DEBUG_LOG: "" OCGCORE_DEBUG_LOG: ""
OCGCORE_WASM_PATH: ""
WELCOME: "" WELCOME: ""
ENABLE_RECONNECT: "1" ENABLE_RECONNECT: "1"
RECONNECT_TIMEOUT: "180000" RECONNECT_TIMEOUT: "180000"
......
...@@ -174,7 +174,7 @@ export class IpResolver { ...@@ -174,7 +174,7 @@ export class IpResolver {
*/ */
clearConnectionCounts(): void { clearConnectionCounts(): void {
this.connectedIpCount.clear(); this.connectedIpCount.clear();
this.logger.info('Connection counts cleared'); this.logger.debug('Connection counts cleared');
} }
/** /**
...@@ -182,6 +182,6 @@ export class IpResolver { ...@@ -182,6 +182,6 @@ export class IpResolver {
*/ */
clearBadIpCounts(): void { clearBadIpCounts(): void {
this.badIpCount.clear(); this.badIpCount.clear();
this.logger.info('Bad IP counts cleared'); this.logger.debug('Bad IP counts cleared');
} }
} }
...@@ -53,6 +53,8 @@ export const defaultConfig = { ...@@ -53,6 +53,8 @@ export const defaultConfig = {
// Enable ocgcore debug logs. // Enable ocgcore debug logs.
// Boolean parse rule (default false): ''/'0'/'false'/'null' => false, otherwise true. // Boolean parse rule (default false): ''/'0'/'false'/'null' => false, otherwise true.
OCGCORE_DEBUG_LOG: '', OCGCORE_DEBUG_LOG: '',
// OCGCore wasm file path. Format: filesystem path string. Empty means use default wasm loading.
OCGCORE_WASM_PATH: '',
// Welcome message sent when players join. Format: plain string. // Welcome message sent when players join. Format: plain string.
WELCOME: '', WELCOME: '',
// Enable reconnect feature. // Enable reconnect feature.
......
...@@ -5,6 +5,7 @@ import { TransportType } from 'yuzuthread'; ...@@ -5,6 +5,7 @@ import { TransportType } from 'yuzuthread';
export class OcgcoreWorkerOptions { export class OcgcoreWorkerOptions {
ygoproPaths: string[]; ygoproPaths: string[];
extraScriptPaths: string[]; extraScriptPaths: string[];
ocgcoreWasmPath?: string;
seed: number[]; seed: number[];
hostinfo: HostInfo; hostinfo: HostInfo;
@TransportType(() => [YGOProDeck]) @TransportType(() => [YGOProDeck])
......
...@@ -37,6 +37,7 @@ import { ...@@ -37,6 +37,7 @@ import {
YGOProMsgResponseBase, YGOProMsgResponseBase,
YGOProMsgRetry, YGOProMsgRetry,
} from 'ygopro-msg-encode'; } from 'ygopro-msg-encode';
import * as fs from 'node:fs';
const { OcgcoreScriptConstants } = _OcgcoreConstants; const { OcgcoreScriptConstants } = _OcgcoreConstants;
...@@ -90,8 +91,15 @@ export class OcgcoreWorker { ...@@ -90,8 +91,15 @@ export class OcgcoreWorker {
@WorkerInit() @WorkerInit()
async init() { async init() {
let wasmBinary: Uint8Array | undefined;
if (this.options.ocgcoreWasmPath) {
wasmBinary = await fs.promises.readFile(this.options.ocgcoreWasmPath);
}
// Create ocgcore wrapper // Create ocgcore wrapper
this.ocgcore = await createOcgcoreWrapper(); this.ocgcore = await createOcgcoreWrapper(
wasmBinary ? { wasmBinary } : undefined,
);
this.ocgcore.setMessageHandler((_, message, type) => this.ocgcore.setMessageHandler((_, message, type) =>
this.handleMessage(message, type), this.handleMessage(message, type),
); );
......
...@@ -27,6 +27,8 @@ export class RoomManager { ...@@ -27,6 +27,8 @@ export class RoomManager {
private roomCreateLock = new BetterLock(); private roomCreateLock = new BetterLock();
private logger = this.ctx.createLogger('RoomManager');
async findOrCreateByName(name: string) { async findOrCreateByName(name: string) {
const existing = this.findByName(name); const existing = this.findByName(name);
if (existing) return existing; if (existing) return existing;
...@@ -37,12 +39,20 @@ export class RoomManager { ...@@ -37,12 +39,20 @@ export class RoomManager {
const room = new Room(this.ctx, name).addFinalizor((r) => { const room = new Room(this.ctx, name).addFinalizor((r) => {
this.rooms.delete(r.name); this.rooms.delete(r.name);
this.logger.debug(
{ room: r.name, roomCount: this.rooms.size },
'Room finalized and removed',
);
}); });
for (const finalizor of this.finalizors) { for (const finalizor of this.finalizors) {
room.addFinalizor(finalizor); room.addFinalizor(finalizor);
} }
await room.init(); await room.init();
this.rooms.set(name, room); this.rooms.set(name, room);
this.logger.debug(
{ room: name, roomCount: this.rooms.size },
'Room created',
);
return room; return room;
}); });
} }
......
...@@ -92,6 +92,7 @@ import { canIncreaseTime } from '../utility/can-increase-time'; ...@@ -92,6 +92,7 @@ import { canIncreaseTime } from '../utility/can-increase-time';
import { parseConfigBoolean } from '../utility/parse-config-boolean'; import { parseConfigBoolean } from '../utility/parse-config-boolean';
import { TimerState } from './timer-state'; import { TimerState } from './timer-state';
import { makeArray } from 'aragami/dist/src/utility/utility'; import { makeArray } from 'aragami/dist/src/utility/utility';
import path from 'path';
const { OcgcoreScriptConstants } = _OcgcoreConstants; const { OcgcoreScriptConstants } = _OcgcoreConstants;
...@@ -204,6 +205,13 @@ export class Room { ...@@ -204,6 +205,13 @@ export class Room {
} }
this.finalizing = true; this.finalizing = true;
this.resetResponseState(); this.resetResponseState();
this.logger.debug(
{
playerCount: this.playingPlayers.length,
watcherCount: this.watchers.size,
},
'Finalizing room',
);
await this.cleanPlayers(sendReplays); await this.cleanPlayers(sendReplays);
while (this.finalizors.length) { while (this.finalizors.length) {
const finalizor = this.finalizors.pop()!; const finalizor = this.finalizors.pop()!;
...@@ -1202,11 +1210,18 @@ export class Room { ...@@ -1202,11 +1210,18 @@ export class Room {
{ seed: duelRecord.seed, registry, hostinfo: this.hostinfo }, { seed: duelRecord.seed, registry, hostinfo: this.hostinfo },
'Initializing OCGCoreWorker', 'Initializing OCGCoreWorker',
); );
const ocgcoreWasmPathConfig = this.ctx.getConfig('OCGCORE_WASM_PATH', '');
const ocgcoreWasmPath = ocgcoreWasmPathConfig
? path.resolve(process.cwd(), ocgcoreWasmPathConfig)
: undefined;
this.ocgcore = await initWorker(OcgcoreWorker, { this.ocgcore = await initWorker(OcgcoreWorker, {
seed: duelRecord.seed, seed: duelRecord.seed,
hostinfo: this.hostinfo, hostinfo: this.hostinfo,
ygoproPaths: this.resourceLoader.ygoproPaths, ygoproPaths: this.resourceLoader.ygoproPaths,
extraScriptPaths, extraScriptPaths,
ocgcoreWasmPath,
registry, registry,
decks: duelRecord.players.map((p) => p.deck), decks: duelRecord.players.map((p) => p.deck),
isTag: this.isTag, isTag: this.isTag,
......
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