Files
discord-decomp/modules/premium/game_server/GameServerStore.tsx
T
2026-11-01 12:12:55 +02:00

315 lines
8.2 KiB
TypeScript

// Metro module 4097 (f4098).
import getPowerupEntitlementPrice from "../powerups/utils/getPowerupEntitlementPrice";
import gameServerResponseToInstance from "./utils/gameServerResponseToInstance";
import Module589 from "../../../_bundle/Module589";
import Dispatcher from "../../../Dispatcher";
let c2360_2, c2360_3, c2360_4, $mk73585 = function() {
return (a0, a1) => {
let r8 = getPowerupEntitlementPrice(a1);
if (r8 == null) {
r8 = 0;
}
return a0 + r8;
};
};
const handleGameServerInstanceCreated = function handleGameServerInstanceCreated({ guildId, gameServer }) {
if (guildId != null) {
if (c2360_3[guildId] == null) {
c2360_3[guildId] = {
catalog: {},
instances: {},
instructions: {},
entitlements: {}
};
}
const r6 = c2360_3[guildId];
const r19 = {
...c2360_3
};
const instances = {
...r6.instances
};
instances[gameServer.id] = gameServerResponseToInstance(gameServer);
r19[guildId] = {
...r6,
instances
};
c2360_3 = r19;
}
};
c2360_2 = 86400000;
c2360_3 = {};
c2360_4 = {
catalog: {},
hasFetchedCatalog: false,
catalogLastFetchedAt: void 0
};
class GameServerStore extends Module589.PersistedStore {
static displayName = "GameServerStore";
static persistKey = "GameServerStore";
initialize(a0) {
if (a0 != null) {
c2360_3 = a0;
}
}
getState() {
return c2360_3;
}
getStateForGuild(a0) {
return a0 != null ? c2360_3[a0] : void 0;
}
getGlobalCatalogState() {
return c2360_4;
}
getGlobalCatalogGame(c13847_0) {
return Object.values(c2360_4.catalog).find((item) => item.gameId === c13847_0);
}
getLowestGameCostForGuild(a0) {
if (a0 == null) {
return null;
}
const r8 = c2360_3[a0];
const r7 = Object;
let r15 = r8?.catalog;
if (r15 == null) {
r15 = {};
}
const r9 = r7.values(r15);
const length = r9.length;
let r17 = null;
if (length !== 0) {
const r18 = Math;
r17 = r18.min.apply(r18, [...r9.map((item) => item.baseCost)]);
}
return r17;
}
hasFetchedCatalog(a0) {
return a0 != null && c2360_3[a0]?.hasFetchedCatalog === true;
}
hasFetchedInstances(a0) {
return a0 != null && c2360_3[a0]?.hasFetchedInstances === true;
}
shouldFetchCatalogForGuild(a0) {
const catalogLastFetchedAt = c2360_3[a0]?.catalogLastFetchedAt;
return catalogLastFetchedAt == null || catalogLastFetchedAt + c2360_2 < Date.now();
}
shouldFetchInstancesForGuild(a0) {
const instancesLastFetchedAt = c2360_3[a0]?.instancesLastFetchedAt;
return instancesLastFetchedAt == null || instancesLastFetchedAt + 300000 < Date.now();
}
shouldFetchGlobalCatalog() {
const catalogLastFetchedAt = c2360_4.catalogLastFetchedAt;
return catalogLastFetchedAt == null || catalogLastFetchedAt + c2360_2 < Date.now();
}
}
const gameServerStore = new GameServerStore(Dispatcher, {
LOGOUT: function handleReset() {
c2360_3 = {};
c2360_4 = {
catalog: {},
hasFetchedCatalog: false,
catalogLastFetchedAt: void 0
};
},
GAME_SERVER_FETCH_CATALOG_SUCCESS: function handleFetchCatalogSuccess({ guildId, catalog }) {
const r10 = {
...c2360_3
};
if (c2360_3[guildId] == null) {
c2360_3[guildId] = {
catalog: {},
instances: {},
instructions: {},
entitlements: {}
};
}
r10[guildId] = {
...c2360_3[guildId],
catalog,
hasFetchedCatalog: true,
catalogLastFetchedAt: Date.now()
};
c2360_3 = r10;
},
GAME_SERVER_FETCH_GLOBAL_CATALOG_SUCCESS: function handleFetchGlobalCatalogSuccess(a0) {
c2360_4 = {
catalog: a0.catalog,
hasFetchedCatalog: true,
catalogLastFetchedAt: Date.now()
};
},
GAME_SERVER_FETCH_INSTANCES_SUCCESS: function handleFetchInstancesSuccess({ guildId, instances }) {
const r10 = {
...c2360_3
};
if (c2360_3[guildId] == null) {
c2360_3[guildId] = {
catalog: {},
instances: {},
instructions: {},
entitlements: {}
};
}
r10[guildId] = {
...c2360_3[guildId],
instances,
hasFetchedInstances: true,
instancesLastFetchedAt: Date.now()
};
c2360_3 = r10;
},
GAME_SERVER_FETCH_GAME_INSTRUCTIONS_SUCCESS: function handleFetchProductSuccess({ guildId, skuId, instructions }) {
const r12 = {
...c2360_3
};
if (c2360_3[guildId] == null) {
c2360_3[guildId] = {
catalog: {},
instances: {},
instructions: {},
entitlements: {}
};
}
if (c2360_3[guildId] == null) {
c2360_3[guildId] = {
catalog: {},
instances: {},
instructions: {},
entitlements: {}
};
}
const instructions2 = {
...c2360_3[guildId].instructions
};
instructions2[skuId] = instructions;
r12[guildId] = {
...c2360_3[guildId],
instructions: instructions2
};
c2360_3 = r12;
},
GAME_SERVER_UPDATE_INSTANCE_SUCCESS: function handleUpdateInstanceSuccess({ guildId, instance }) {
if (c2360_3[guildId] == null) {
c2360_3[guildId] = {
catalog: {},
instances: {},
instructions: {},
entitlements: {}
};
}
const r6 = c2360_3[guildId];
const r17 = {
...c2360_3
};
const instances = {
...r6.instances
};
instances[instance.id] = instance;
r17[guildId] = {
...r6,
instances
};
c2360_3 = r17;
},
GUILD_BOOST_ENTITLEMENTS_FETCH_SUCCESS: function handleFetchBoostEntitlementsSuccess({ guildId, unlockedGameServers }) {
const appliedBoosts = Object.values(unlockedGameServers).reduce($mk73585(), 0);
const r17 = {
...c2360_3
};
if (c2360_3[guildId] == null) {
c2360_3[guildId] = {
catalog: {},
instances: {},
instructions: {},
entitlements: {}
};
}
r17[guildId] = {
...c2360_3[guildId],
entitlements: unlockedGameServers,
appliedBoosts
};
c2360_3 = r17;
},
GAME_SERVER_CREATE: handleGameServerInstanceCreated,
GAME_SERVER_UPDATE: handleGameServerInstanceCreated,
GAME_SERVER_DELETE: function handleGameServerInstanceDeleted({ guildId, gameServerId }) {
if (guildId != null) {
if (c2360_3[guildId] == null) {
c2360_3[guildId] = {
catalog: {},
instances: {},
instructions: {},
entitlements: {}
};
}
const r16 = c2360_3[guildId];
delete r16.instances[gameServerId];
const r19 = {
...c2360_3
};
r19[guildId] = {
...r16
};
c2360_3 = r19;
}
},
GUILD_POWERUP_ENTITLEMENTS_CREATE: function handleGameServerEntitlementCreated({ guildId, entitlements }) {
if (c2360_3[guildId] == null) {
c2360_3[guildId] = {
catalog: {},
instances: {},
instructions: {},
entitlements: {}
};
}
const r19 = c2360_3[guildId];
let c13848_0 = r19;
entitlements.filter(({ sku }) => {
const r2 = sku == null;
let r5 = void 0;
if (!r2) {
const tenant_metadata = sku.tenant_metadata;
r5 = tenant_metadata == null ? void 0 : tenant_metadata.guild_monetization?.game_server;
}
return r5 != null;
}).forEach((item) => {
c13848_0.entitlements[item.id] = item;
});
const appliedBoosts = Object.values(r19.entitlements).reduce($mk73585(), 0);
const r34 = {
...c2360_3
};
r34[guildId] = {
...r19,
appliedBoosts
};
c2360_3 = r34;
},
GUILD_POWERUP_ENTITLEMENTS_DELETE: function handleGameServerEntitlementDeleted({ guildId, entitlements }) {
if (c2360_3[guildId] == null) {
c2360_3[guildId] = {
catalog: {},
instances: {},
instructions: {},
entitlements: {}
};
}
const r19 = c2360_3[guildId];
let c13849_0 = r19;
entitlements.forEach((entitlement) => {
delete c13849_0.entitlements[entitlement.id];
});
const appliedBoosts = Object.values(r19.entitlements).reduce($mk73585(), 0);
const r31 = {
...c2360_3
};
r31[guildId] = {
...r19,
appliedBoosts
};
c2360_3 = r31;
}
});
export default gameServerStore;