2024-06-15 02:52:45 +02:00
import fs from "fs" ;
2025-04-01 15:49:08 -07:00
import path from "path" ;
2025-08-25 13:37:14 -07:00
import { repoDir } from "../helpers/pathHelper.ts" ;
import { args } from "../helpers/commandLineArguments.ts" ;
import { Inbox } from "../models/inboxModel.ts" ;
2025-09-01 20:30:03 -07:00
import type { Request } from "express" ;
2024-05-15 21:55:59 +02:00
2025-08-30 19:34:55 -07:00
export interface IConfig {
2024-05-15 21:55:59 +02:00
mongodbUrl : string ;
2025-04-05 06:50:57 -07:00
logger : {
files : boolean ;
level : string ; // "fatal" | "error" | "warn" | "info" | "http" | "debug" | "trace";
} ;
2024-05-15 21:55:59 +02:00
myAddress : string ;
2025-09-09 23:54:33 -07:00
bindAddress? : string ;
2024-05-22 23:32:11 +02:00
httpPort? : number ;
httpsPort? : number ;
2025-09-03 22:45:22 -07:00
ircAddress? : string ;
hubAddress? : string ;
nrsAddress? : string ;
2025-03-23 09:06:08 -07:00
administratorNames? : string [ ] ;
2024-05-15 21:55:59 +02:00
autoCreateAccount? : boolean ;
skipTutorial? : boolean ;
2024-05-29 22:08:41 +02:00
unlockAllSkins? : boolean ;
2025-06-22 06:55:44 -07:00
fullyStockedVendors? : boolean ;
2025-08-24 15:36:59 -07:00
skipClanKeyCrafting? : boolean ;
2024-05-28 13:28:35 +02:00
spoofMasteryRank? : number ;
2025-07-01 07:44:13 -07:00
relicRewardItemCountMultiplier? : number ;
2025-06-14 12:58:26 -07:00
nightwaveStandingMultiplier? : number ;
2025-06-23 21:51:48 -07:00
unfaithfulBugFixes ? : {
ignore1999LastRegionPlayed? : boolean ;
fixXtraCheeseTimer? : boolean ;
2025-08-17 13:11:55 -07:00
useAnniversaryTagForOldGoals? : boolean ;
2025-06-23 21:51:48 -07:00
} ;
2025-03-29 15:42:42 -07:00
worldState ? : {
2025-03-15 03:21:54 -07:00
creditBoost? : boolean ;
affinityBoost? : boolean ;
resourceBoost? : boolean ;
2025-07-30 01:50:43 -07:00
tennoLiveRelay? : boolean ;
2025-07-31 02:27:38 -07:00
baroTennoConRelay? : boolean ;
2025-08-27 01:29:38 -07:00
baroAlwaysAvailable? : boolean ;
baroFullyStocked? : boolean ;
varziaFullyStocked? : boolean ;
2025-08-13 07:13:05 -07:00
wolfHunt? : boolean ;
2025-08-16 09:52:58 -07:00
orphixVenom? : boolean ;
2025-08-13 07:13:05 -07:00
longShadow? : boolean ;
hallowedFlame? : boolean ;
2025-08-17 13:11:55 -07:00
anniversary? : number ;
2025-08-13 07:13:05 -07:00
hallowedNightmares? : boolean ;
hallowedNightmaresRewardsOverride? : number ;
2025-09-29 23:59:17 -07:00
naberusNightsOverride? : boolean ;
2025-08-13 07:13:05 -07:00
proxyRebellion? : boolean ;
proxyRebellionRewardsOverride? : number ;
2025-10-09 00:28:34 -07:00
voidCorruption2025Week1? : boolean ;
voidCorruption2025Week2? : boolean ;
voidCorruption2025Week3? : boolean ;
voidCorruption2025Week4? : boolean ;
2025-10-09 23:01:36 -07:00
qtccAlerts? : boolean ;
2025-06-25 08:04:03 -07:00
galleonOfGhouls? : number ;
2025-08-11 08:08:40 -07:00
ghoulEmergenceOverride? : boolean ;
plagueStarOverride? : boolean ;
2025-07-30 05:44:42 -07:00
starDaysOverride? : boolean ;
2025-08-13 07:13:05 -07:00
dogDaysOverride? : boolean ;
dogDaysRewardsOverride? : number ;
2025-08-15 08:14:36 -07:00
bellyOfTheBeast? : boolean ;
bellyOfTheBeastProgressOverride? : number ;
eightClaw? : boolean ;
eightClawProgressOverride? : number ;
2025-08-21 11:07:31 -07:00
thermiaFracturesOverride? : boolean ;
thermiaFracturesProgressOverride? : number ;
2025-06-09 06:54:58 -07:00
eidolonOverride? : string ;
vallisOverride? : string ;
2025-06-19 16:18:17 -07:00
duviriOverride? : string ;
2025-06-07 02:16:19 -07:00
nightwaveOverride? : string ;
2025-06-26 14:32:26 -07:00
allTheFissures? : string ;
2025-08-27 01:29:38 -07:00
varziaOverride? : string ;
2025-06-18 05:51:56 -07:00
circuitGameModes? : string [ ] ;
2025-06-28 09:39:41 -07:00
darvoStockMultiplier? : number ;
2025-03-08 04:28:05 -08:00
} ;
2025-06-14 12:58:26 -07:00
dev ? : {
keepVendorsExpired? : boolean ;
} ;
2024-05-15 21:55:59 +02:00
}
2025-08-24 15:30:31 -07:00
export const configRemovedOptionsKeys = [
2025-08-31 18:49:48 -07:00
"NRS" ,
2025-09-03 22:45:22 -07:00
"myIrcAddresses" ,
2025-08-28 05:50:21 -07:00
"skipAllDialogue" ,
2025-08-24 15:30:31 -07:00
"infiniteCredits" ,
"infinitePlatinum" ,
"infiniteEndo" ,
"infiniteRegalAya" ,
"infiniteHelminthMaterials" ,
"claimingBlueprintRefundsIngredients" ,
"dontSubtractPurchaseCreditCost" ,
"dontSubtractPurchasePlatinumCost" ,
"dontSubtractPurchaseItemCost" ,
"dontSubtractPurchaseStandingCost" ,
"dontSubtractVoidTraces" ,
"dontSubtractConsumables" ,
"universalPolarityEverywhere" ,
"unlockDoubleCapacityPotatoesEverywhere" ,
"unlockExilusEverywhere" ,
"unlockArcanesEverywhere" ,
2025-08-29 17:36:31 -07:00
"unlockAllProfitTakerStages" ,
2025-08-30 19:34:55 -07:00
"unlockAllSimarisResearchEntries" ,
2025-09-02 20:22:47 -07:00
"unlockAllScans" ,
"unlockAllShipFeatures" ,
"unlockAllCapturaScenes" ,
2025-08-24 15:30:31 -07:00
"noDailyStandingLimits" ,
"noDailyFocusLimit" ,
"noArgonCrystalDecay" ,
"noMasteryRankUpCooldown" ,
"noVendorPurchaseLimits" ,
2025-08-31 18:50:08 -07:00
"noDecoBuildStage" ,
2025-08-24 15:30:31 -07:00
"noDeathMarks" ,
"noKimCooldowns" ,
"syndicateMissionsRepeatable" ,
"instantFinishRivenChallenge" ,
"instantResourceExtractorDrones" ,
2025-08-27 01:29:38 -07:00
"noResourceExtractorDronesDamage" ,
"baroAlwaysAvailable" ,
2025-08-28 05:50:21 -07:00
"baroFullyStocked" ,
"missionsCanGiveAllRelics" ,
"exceptionalRelicsAlwaysGiveBronzeReward" ,
"flawlessRelicsAlwaysGiveSilverReward" ,
"radiantRelicsAlwaysGiveGoldReward" ,
2025-09-09 23:55:10 -07:00
"disableDailyTribute" ,
"noDojoRoomBuildStage" ,
"noDojoDecoBuildStage" ,
"fastDojoRoomDestruction" ,
"noDojoResearchCosts" ,
"noDojoResearchTime" ,
"fastClanAscension" ,
2025-09-15 10:40:21 -07:00
"unlockAllFlavourItems" ,
"unlockAllShipDecorations" ,
"unlockAllDecoRecipes"
2025-08-30 19:34:55 -07:00
] ;
2025-08-24 15:30:31 -07:00
2025-06-20 18:30:52 -07:00
export const configPath = path . join ( repoDir , args . configPath ? ? "config.json" ) ;
2024-05-15 21:55:59 +02:00
2025-04-05 06:50:57 -07:00
export const config : IConfig = {
mongodbUrl : "mongodb://127.0.0.1:27017/openWF" ,
logger : {
files : true ,
level : "trace"
} ,
myAddress : "localhost"
2024-06-15 02:52:45 +02:00
} ;
2024-12-29 23:34:26 +01:00
2025-04-05 06:50:57 -07:00
export const loadConfig = ( ) : void = > {
2025-06-29 11:54:20 -07:00
const newConfig = JSON . parse ( fs . readFileSync ( configPath , "utf-8" ) ) as IConfig ;
2025-04-05 06:50:57 -07:00
// 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 ) ) {
2025-07-23 07:51:51 -07:00
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
2025-04-05 06:50:57 -07:00
( config as any ) [ key ] = undefined ;
2024-12-29 23:34:26 +01:00
}
2025-04-05 06:50:57 -07:00
2025-06-29 11:54:20 -07:00
Object . assign ( config , newConfig ) ;
2024-12-29 23:34:26 +01:00
} ;
2025-07-17 05:04:30 -07:00
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 ( ( ) = > { } ) ;
}
} ;
2025-09-01 20:30:03 -07:00
export const getReflexiveAddress = ( request : Request ) : { myAddress : string ; myUrlBase : string } = > {
let myAddress : string ;
let myUrlBase : string = request . protocol + "://" ;
if ( request . host . indexOf ( "warframe.com" ) == - 1 ) {
// Client request was redirected cleanly, so we know it can reach us how it's reaching us now.
myAddress = request . hostname ;
myUrlBase += request . host ;
} else {
// Don't know how the client reached us, hoping the config does.
myAddress = config . myAddress ;
myUrlBase += myAddress ;
const port : number = request . protocol == "http" ? config . httpPort || 80 : config.httpsPort || 443 ;
if ( port != ( request . protocol == "http" ? 80 : 443 ) ) {
myUrlBase += ":" + port ;
}
}
return { myAddress , myUrlBase } ;
} ;
2025-09-09 23:54:33 -07:00
export interface IBindings {
address : string ;
httpPort : number ;
httpsPort : number ;
}
export const configGetWebBindings = ( ) : IBindings = > {
return {
address : config.bindAddress || "0.0.0.0" ,
httpPort : config.httpPort || 80 ,
httpsPort : config.httpsPort || 443
} ;
} ;