Commit 7dcde5ac authored by nanahira's avatar nanahira

update config things & ocgcore wasm path

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