// Metro module 11574 (f11575). import LocaleStore from "../../user_settings/LocaleStore"; import UserStore from "../../../stores/UserStore"; import OwnedGameServersStore from "./OwnedGameServersStore"; import { GAME_SERVER_COLLECTION_ID } from "./GameServerConstants"; import { AnalyticEvents, Endpoints } from "../../../Constants"; import Dispatcher from "../../../Dispatcher"; import { GAME_SERVER_GAME_MOCKS, GAME_SERVER_INSTANCE_MOCKS } from "./mocks/GameServerMocks"; import { httpGetWithCountryCodeQuery } from "../../../utils/StoreUtils"; import { rejectWithMigratedError, HTTP } from "../../../_bundle/sendRequest"; import { productToGameServerGame } from "./utils/productToGameServerGame"; import gameServerResponseToInstance from "./utils/gameServerResponseToInstance"; import AnalyticsUtils from "../../../utils/AnalyticsUtils"; import regionResponseToRegion from "./utils/regionResponseToRegion"; import { GameServerStatus } from "../../../_bundle/Module11577"; let $mk87645 = function() { return (a0) => { let game_servers = a0.body.game_servers; if (game_servers == null) { game_servers = []; } Dispatcher.dispatch({ type: "GAME_SERVER_FETCH_MY_SERVERS_SUCCESS", gameServers: game_servers }); }; }; export function fetchGameServerCatalog(a0) { const guildId = a0; let r5 = arguments[1]; if (r5 === void 0) { r5 = false; } if (r5) { setTimeout(() => { Dispatcher.dispatch({ type: "GAME_SERVER_FETCH_CATALOG_SUCCESS", guildId, catalog: GAME_SERVER_GAME_MOCKS.reduce((acc, item) => { acc[item.id] = item; return acc; }, {}) }); }, 5000); return void 0; } const currentUser = UserStore.getCurrentUser(); let include_unpublished_products = currentUser == null ? void 0 : currentUser.isStaff(); if (include_unpublished_products == null) { include_unpublished_products = false; } return httpGetWithCountryCodeQuery({ url: Endpoints.STOREFRONT_COLLECTION_WITH_PRODUCTS(GAME_SERVER_COLLECTION_ID), query: { locale: LocaleStore.locale, guild_id: a0, include_unpublished_products, include_unpublished_collection: include_unpublished_products }, oldFormErrors: true, rejectWithError: rejectWithMigratedError(), retries: 2 }).then((result) => { Dispatcher.dispatch({ type: "GAME_SERVER_FETCH_CATALOG_SUCCESS", guildId, catalog: result.body.products.reduce((acc, product) => { const r9 = productToGameServerGame(product); acc[r9.id] = r9; return acc; }, {}) }); }); } export function fetchGameServerGlobalCatalog() { const currentUser = UserStore.getCurrentUser(); let include_unpublished_products = currentUser == null ? void 0 : currentUser.isStaff(); if (include_unpublished_products == null) { include_unpublished_products = false; } return httpGetWithCountryCodeQuery({ url: Endpoints.STOREFRONT_COLLECTION_WITH_PRODUCTS(GAME_SERVER_COLLECTION_ID), query: { locale: LocaleStore.locale, include_unpublished_products, include_unpublished_collection: include_unpublished_products }, oldFormErrors: true, rejectWithError: rejectWithMigratedError(), retries: 2 }).then((result) => { Dispatcher.dispatch({ type: "GAME_SERVER_FETCH_GLOBAL_CATALOG_SUCCESS", catalog: result.body.products.reduce((acc, product) => { const r9 = productToGameServerGame(product); acc[r9.id] = r9; return acc; }, {}) }); }); } export function fetchGameServerInstances(a0) { let r21; const guildId2 = a0; let r3 = arguments[1]; if (r3 === void 0) { r3 = false; } if (r3) { setTimeout(() => { Dispatcher.dispatch({ type: "GAME_SERVER_FETCH_INSTANCES_SUCCESS", guildId: guildId2, instances: GAME_SERVER_INSTANCE_MOCKS.reduce((acc, item) => { acc[item.id] = item; return acc; }, {}) }); }, 5000); r21 = Promise.resolve(); } else { const signal = arguments[2]; r21 = HTTP.get({ url: Endpoints.GAME_SERVERS(a0), rejectWithError: true, retries: 2, signal }).then((result) => { if (result.body != null) { Dispatcher.dispatch({ type: "GAME_SERVER_FETCH_INSTANCES_SUCCESS", guildId: guildId2, instances: result.body.reduce((acc, item) => { acc[item.id] = gameServerResponseToInstance(item); return acc; }, {}) }); } }); } return r21; } export function fetchGameServerInstructions(guildId3, a1) { const skuId = a1; return httpGetWithCountryCodeQuery({ url: Endpoints.STOREFRONT_PRODUCT_BY_SKU_ID(a1), query: { locale: LocaleStore.locale }, rejectWithError: true, retries: 3 }).then((result) => { if (result.body != null) { const tenant_metadata = result.body.tenant_metadata; const r2 = tenant_metadata == null; let instructions = void 0; if (!r2) { const guild_monetization = tenant_metadata.guild_monetization; const r12 = guild_monetization == null; instructions = void 0; if (!r12) { const game_server = guild_monetization.game_server; instructions = game_server == null ? void 0 : game_server.instructions.pc; } } if (instructions == null) { instructions = []; } Dispatcher.dispatch({ type: "GAME_SERVER_FETCH_GAME_INSTRUCTIONS_SUCCESS", guildId: guildId3, skuId, instructions }); } }); } export function acceptGameServerToS(a0, a1) { if (a0) { AnalyticsUtils.track(AnalyticEvents.GAME_SERVER_HOSTING_THIRD_PARTY_CONSENT_ACCEPTED, { user_id: UserStore.getCurrentUser()?.id, provider: a1 }); } } export function resetGameServerRegionState() { Dispatcher.dispatch({ type: "GAME_SERVER_REGION_PING_STATE_RESET" }); } export function updateGameServerRegionPingState(a0, a1) { Dispatcher.dispatch({ type: "GAME_SERVER_REGION_PING_STATE_UPDATE", pingUrl: a0, state: a1 }); } export function enableGameServerForGuild(a0, a1, a2, a3) { return HTTP.post({ url: Endpoints.GUILD_POWERUP_TOGGLE(a0, a1), body: { game_server_name: a2, game_server_region: a3 }, rejectWithError: true, oldFormErrors: true }); } export function updateGameServerForGuild(a0, a1, a2, a3) { return HTTP.patch({ url: Endpoints.GUILD_POWERUP_UPDATE(a0, a1), body: { game_server_name: a3, sku_id: a2 }, rejectWithError: true, oldFormErrors: true }); } export function disableGameServerForGuild(a0, a1, a2) { return HTTP.del({ url: Endpoints.GUILD_POWERUP_TOGGLE(a0, a1), query: { entitlement_id: a2 }, rejectWithError: true, oldFormErrors: true }); } export function fetchGameServerRegions(a0) { return HTTP.get({ url: Endpoints.GAME_SERVER_REGIONS(a0), rejectWithError: true, oldFormErrors: true, retries: 3 }).then((result) => { Dispatcher.dispatch({ type: "GAME_SERVER_FETCH_REGIONS_SUCCESS", regions: result.body.map(regionResponseToRegion).sort((a, b) => a.name.localeCompare(b.name)) }); }); } export function fetchMyGameServerRegions() { return HTTP.get({ url: Endpoints.GAME_SERVER_MY_REGIONS, rejectWithError: true, oldFormErrors: true, retries: 3 }).then((result) => { Dispatcher.dispatch({ type: "GAME_SERVER_FETCH_REGIONS_SUCCESS", regions: result.body.regions.map(regionResponseToRegion).sort((a, b) => a.name.localeCompare(b.name)), creationDisabled: result.body.creation_disabled === true }); }); } export function fetchMyGameServers() { return HTTP.get({ url: Endpoints.GAME_SERVERS_ME, rejectWithError: true, oldFormErrors: true, retries: 3 }).then($mk87645()); } export function optimisticallyMarkGameServerResizing(c18995_0) { const r7 = OwnedGameServersStore.getGameServers().find((item) => item.subscription_id === c18995_0); if (r7 != null) { Dispatcher.dispatch({ type: "GAME_SERVER_UPDATE", guildId: void 0, gameServer: { ...r7, status: GameServerStatus.STARTING } }); } } export function updateMyGameServerName(c18996_0, a1) { let r40; const r5 = OwnedGameServersStore.getGameServers().find((item) => item.subscription_id === c18996_0); if (r5 == null) { r40 = Promise.resolve(); } else { Dispatcher.dispatch({ type: "GAME_SERVER_UPDATE", guildId: void 0, gameServer: { ...r5, name: a1 } }); r40 = HTTP.patch({ url: Endpoints.GAME_SERVER_ME(r5.id), body: { name: a1 }, rejectWithError: true }).then(() => { HTTP.get({ url: Endpoints.GAME_SERVERS_ME, rejectWithError: true, oldFormErrors: true, retries: 3 }).then($mk87645()).catch(() => {}); }).catch((error) => { HTTP.get({ url: Endpoints.GAME_SERVERS_ME, rejectWithError: true, oldFormErrors: true, retries: 3 }).then($mk87645()).catch(() => {}); throw error; }); } return r40; } export function wakeGameServer(a0, a1) { const guildId4 = a0; return HTTP.post({ url: Endpoints.GAME_SERVER_WAKE(a0, a1), rejectWithError: true }).then((result) => { Dispatcher.dispatch({ type: "GAME_SERVER_UPDATE_INSTANCE_SUCCESS", guildId: guildId4, instance: gameServerResponseToInstance(result.body) }); }); }