SpaceNinjaServer/src/services/configService.ts

171 lines
5.8 KiB
TypeScript
Raw Normal View History

import fs from "fs";
import path from "path";
import { repoDir } from "../helpers/pathHelper.ts";
import { args } from "../helpers/commandLineArguments.ts";
import { Inbox } from "../models/inboxModel.ts";
2024-05-15 21:55:59 +02:00
export interface IConfig extends IConfigRemovedOptions {
2024-05-15 21:55:59 +02:00
mongodbUrl: string;
logger: {
files: boolean;
level: string; // "fatal" | "error" | "warn" | "info" | "http" | "debug" | "trace";
};
2024-05-15 21:55:59 +02:00
myAddress: string;
httpPort?: number;
httpsPort?: number;
myIrcAddresses?: string[];
2025-02-21 08:29:42 +01:00
NRS?: string[];
administratorNames?: string[];
2024-05-15 21:55:59 +02:00
autoCreateAccount?: boolean;
skipTutorial?: boolean;
skipAllDialogue?: boolean;
2024-05-15 21:55:59 +02:00
unlockAllScans?: boolean;
2024-06-11 12:56:51 +02:00
unlockAllShipFeatures?: boolean;
2024-05-15 21:55:59 +02:00
unlockAllShipDecorations?: boolean;
unlockAllFlavourItems?: boolean;
2024-05-29 22:08:41 +02:00
unlockAllSkins?: boolean;
2024-12-29 21:11:36 +01:00
unlockAllCapturaScenes?: boolean;
unlockAllDecoRecipes?: boolean;
fullyStockedVendors?: boolean;
unlockAllProfitTakerStages?: boolean;
skipClanKeyCrafting?: boolean;
noDojoRoomBuildStage?: boolean;
noDojoDecoBuildStage?: boolean;
fastDojoRoomDestruction?: boolean;
noDojoResearchCosts?: boolean;
noDojoResearchTime?: boolean;
fastClanAscension?: boolean;
missionsCanGiveAllRelics?: boolean;
exceptionalRelicsAlwaysGiveBronzeReward?: boolean;
flawlessRelicsAlwaysGiveSilverReward?: boolean;
radiantRelicsAlwaysGiveGoldReward?: boolean;
unlockAllSimarisResearchEntries?: boolean;
disableDailyTribute?: boolean;
spoofMasteryRank?: number;
relicRewardItemCountMultiplier?: number;
nightwaveStandingMultiplier?: number;
unfaithfulBugFixes?: {
ignore1999LastRegionPlayed?: boolean;
fixXtraCheeseTimer?: boolean;
useAnniversaryTagForOldGoals?: boolean;
};
worldState?: {
creditBoost?: boolean;
affinityBoost?: boolean;
resourceBoost?: boolean;
tennoLiveRelay?: boolean;
baroTennoConRelay?: boolean;
baroAlwaysAvailable?: boolean;
baroFullyStocked?: boolean;
varziaFullyStocked?: boolean;
wolfHunt?: boolean;
orphixVenom?: boolean;
longShadow?: boolean;
hallowedFlame?: boolean;
anniversary?: number;
hallowedNightmares?: boolean;
hallowedNightmaresRewardsOverride?: number;
proxyRebellion?: boolean;
proxyRebellionRewardsOverride?: number;
galleonOfGhouls?: number;
ghoulEmergenceOverride?: boolean;
plagueStarOverride?: boolean;
starDaysOverride?: boolean;
dogDaysOverride?: boolean;
dogDaysRewardsOverride?: number;
bellyOfTheBeast?: boolean;
bellyOfTheBeastProgressOverride?: number;
eightClaw?: boolean;
eightClawProgressOverride?: number;
thermiaFracturesOverride?: boolean;
thermiaFracturesProgressOverride?: number;
eidolonOverride?: string;
vallisOverride?: string;
duviriOverride?: string;
nightwaveOverride?: string;
allTheFissures?: string;
varziaOverride?: string;
circuitGameModes?: string[];
darvoStockMultiplier?: number;
};
dev?: {
keepVendorsExpired?: boolean;
};
2024-05-15 21:55:59 +02:00
}
export const configRemovedOptionsKeys = [
"infiniteCredits",
"infinitePlatinum",
"infiniteEndo",
"infiniteRegalAya",
"infiniteHelminthMaterials",
"claimingBlueprintRefundsIngredients",
"dontSubtractPurchaseCreditCost",
"dontSubtractPurchasePlatinumCost",
"dontSubtractPurchaseItemCost",
"dontSubtractPurchaseStandingCost",
"dontSubtractVoidTraces",
"dontSubtractConsumables",
"universalPolarityEverywhere",
"unlockDoubleCapacityPotatoesEverywhere",
"unlockExilusEverywhere",
"unlockArcanesEverywhere",
"noDailyStandingLimits",
"noDailyFocusLimit",
"noArgonCrystalDecay",
"noMasteryRankUpCooldown",
"noVendorPurchaseLimits",
"noDeathMarks",
"noKimCooldowns",
"syndicateMissionsRepeatable",
"instantFinishRivenChallenge",
"instantResourceExtractorDrones",
"noResourceExtractorDronesDamage",
"baroAlwaysAvailable",
"baroFullyStocked"
] as const;
type IConfigRemovedOptions = {
[K in (typeof configRemovedOptionsKeys)[number]]?: boolean;
};
export const configPath = path.join(repoDir, args.configPath ?? "config.json");
2024-05-15 21:55:59 +02:00
export const config: IConfig = {
mongodbUrl: "mongodb://127.0.0.1:27017/openWF",
logger: {
files: true,
level: "trace"
},
myAddress: "localhost"
};
export const loadConfig = (): void => {
const newConfig = JSON.parse(fs.readFileSync(configPath, "utf-8")) as IConfig;
// Set all values to undefined now so if the new config.json omits some fields that were previously present, it's correct in-memory.
for (const key of Object.keys(config)) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
(config as any)[key] = undefined;
}
Object.assign(config, newConfig);
};
export const syncConfigWithDatabase = (): void => {
// Event messages are deleted after endDate. Since we don't use beginDate/endDate and instead have config toggles, we need to delete the messages once those bools are false.
// Also, for some reason, I can't just do `Inbox.deleteMany(...)`; - it needs this whole circus.
if (!config.worldState?.creditBoost) {
void Inbox.deleteMany({ globaUpgradeId: "5b23106f283a555109666672" }).then(() => {});
}
if (!config.worldState?.affinityBoost) {
void Inbox.deleteMany({ globaUpgradeId: "5b23106f283a555109666673" }).then(() => {});
}
if (!config.worldState?.resourceBoost) {
void Inbox.deleteMany({ globaUpgradeId: "5b23106f283a555109666674" }).then(() => {});
}
if (!config.worldState?.galleonOfGhouls) {
void Inbox.deleteMany({ goalTag: "GalleonRobbery" }).then(() => {});
}
};