{ "version": 3, "sources": ["../../server/index.ts"], "sourcesContent": ["/**\n * Main file\n * Pokemon Showdown - http://pokemonshowdown.com/\n *\n * This is the main Pokemon Showdown app, and the file that the\n * `pokemon-showdown` script runs if you start Pokemon Showdown normally.\n *\n * This file sets up our SockJS server, which handles communication\n * between users and your server, and also sets up globals. You can\n * see details in their corresponding files, but here's an overview:\n *\n * Users - from users.ts\n *\n * Most of the communication with users happens in users.ts, we just\n * forward messages between the sockets.js and users.ts.\n *\n * It exports the global tables `Users.users` and `Users.connections`.\n *\n * Rooms - from rooms.ts\n *\n * Every chat room and battle is a room, and what they do is done in\n * rooms.ts. There's also a global room which every user is in, and\n * handles miscellaneous things like welcoming the user.\n *\n * It exports the global table `Rooms.rooms`.\n *\n * Dex - from sim/dex.ts\n *\n * Handles getting data about Pokemon, items, etc.\n *\n * Ladders - from ladders.ts and ladders-remote.ts\n *\n * Handles Elo rating tracking for players.\n *\n * Chat - from chat.ts\n *\n * Handles chat and parses chat commands like /me and /ban\n *\n * Sockets - from sockets.js\n *\n * Used to abstract out network connections. sockets.js handles\n * the actual server and connection set-up.\n *\n * @license MIT\n */\nrequire('source-map-support').install();\n// NOTE: This file intentionally doesn't use too many modern JavaScript\n// features, so that it doesn't crash old versions of Node.js, so we\n// can successfully print the \"We require Node.js 18+\" message.\n\n// Check for version\nconst nodeVersion = parseInt(process.versions.node);\nif (isNaN(nodeVersion) || nodeVersion < 18) {\n\tthrow new Error(\"We require Node.js version 18 or later; you're using \" + process.version);\n}\n\nimport { FS, Repl } from '../lib';\n\n/*********************************************************\n * Set up most of our globals\n * This is in a function because swc runs `import` before any code,\n * and many of our imports require the `Config` global to be set up.\n *********************************************************/\nfunction setupGlobals() {\n\tconst ConfigLoader = require('./config-loader');\n\tglobal.Config = ConfigLoader.Config;\n\n\tconst { Monitor } = require('./monitor');\n\tglobal.Monitor = Monitor;\n\tglobal.__version = { head: '' };\n\tvoid Monitor.version().then((hash: any) => {\n\t\tglobal.__version.tree = hash;\n\t});\n\tRepl.cleanup();\n\n\tif (Config.watchconfig) {\n\t\tFS('config/config.js').onModify(() => {\n\t\t\ttry {\n\t\t\t\tglobal.Config = ConfigLoader.load(true);\n\t\t\t\t// ensure that battle prefixes configured via the chat plugin are not overwritten\n\t\t\t\t// by battle prefixes manually specified in config.js\n\t\t\t\tChat.plugins['username-prefixes']?.prefixManager.refreshConfig(true);\n\t\t\t\tMonitor.notice('Reloaded ../config/config.js');\n\t\t\t} catch (e: any) {\n\t\t\t\tMonitor.adminlog(\"Error reloading ../config/config.js: \" + e.stack);\n\t\t\t}\n\t\t});\n\t}\n\n\tconst { Dex } = require('../sim/dex');\n\tglobal.Dex = Dex;\n\tglobal.toID = Dex.toID;\n\n\tconst { Teams } = require('../sim/teams');\n\tglobal.Teams = Teams;\n\n\tconst { LoginServer } = require('./loginserver');\n\tglobal.LoginServer = LoginServer;\n\n\tconst { Ladders } = require('./ladders');\n\tglobal.Ladders = Ladders;\n\n\tconst { Chat } = require('./chat');\n\tglobal.Chat = Chat;\n\n\tconst { Users } = require('./users');\n\tglobal.Users = Users;\n\n\tconst { Punishments } = require('./punishments');\n\tglobal.Punishments = Punishments;\n\n\tconst { Rooms } = require('./rooms');\n\tglobal.Rooms = Rooms;\n\t// We initialize the global room here because roomlogs.ts needs the Rooms global\n\tRooms.global = new Rooms.GlobalRoomState();\n\n\tconst Verifier = require('./verifier');\n\tglobal.Verifier = Verifier;\n\tVerifier.PM.spawn();\n\n\tconst { Tournaments } = require('./tournaments');\n\tglobal.Tournaments = Tournaments;\n\n\tconst { IPTools } = require('./ip-tools');\n\tglobal.IPTools = IPTools;\n\tvoid IPTools.loadHostsAndRanges();\n}\nsetupGlobals();\n\nif (Config.crashguard) {\n\t// graceful crash - allow current battles to finish before restarting\n\tprocess.on('uncaughtException', (err: Error) => {\n\t\tMonitor.crashlog(err, 'The main process');\n\t});\n\n\tprocess.on('unhandledRejection', err => {\n\t\tMonitor.crashlog(err as any, 'A main process Promise');\n\t});\n}\n\n/*********************************************************\n * Start networking processes to be connected to\n *********************************************************/\n\nimport { Sockets } from './sockets';\nglobal.Sockets = Sockets;\n\nexport function listen(port: number, bindAddress: string, workerCount: number) {\n\tSockets.listen(port, bindAddress, workerCount);\n}\n\nif (require.main === module) {\n\t// Launch the server directly when app.js is the main module. Otherwise,\n\t// in the case of app.js being imported as a module (e.g. unit tests),\n\t// postpone launching until app.listen() is called.\n\tlet port;\n\tfor (const arg of process.argv) {\n\t\tif (/^[0-9]+$/.test(arg)) {\n\t\t\tport = parseInt(arg);\n\t\t\tbreak;\n\t\t}\n\t}\n\tSockets.listen(port);\n}\n\n/*********************************************************\n * Set up our last global\n *********************************************************/\n\nimport * as TeamValidatorAsync from './team-validator-async';\nglobal.TeamValidatorAsync = TeamValidatorAsync;\nTeamValidatorAsync.PM.spawn();\n\n/*********************************************************\n * Start up the REPL server\n *********************************************************/\n\n// eslint-disable-next-line no-eval\nRepl.start('app', cmd => eval(cmd));\n\n/*********************************************************\n * Fully initialized, run startup hook\n *********************************************************/\n\nif (Config.startuphook) {\n\tprocess.nextTick(Config.startuphook);\n}\n\nif (Config.ofemain) {\n\ttry {\n\t\trequire.resolve('node-oom-heapdump');\n\t} catch (e: any) {\n\t\tif (e.code !== 'MODULE_NOT_FOUND') throw e; // should never happen\n\t\tthrow new Error(\n\t\t\t'node-oom-heapdump is not installed, but it is a required dependency if Config.ofe is set to true! ' +\n\t\t\t'Run npm install node-oom-heapdump and restart the server.'\n\t\t);\n\t}\n\n\t// Create a heapdump if the process runs out of memory.\n\tglobal.nodeOomHeapdump = (require as any)('node-oom-heapdump')({\n\t\taddTimestamp: true,\n\t});\n}\n"], "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAwDA,iBAAyB;AAwFzB,qBAAwB;AAyBxB,yBAAoC;AAzKpC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A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