{ "version": 3, "sources": ["../../../server/team-validator-async.ts"], "sourcesContent": ["/**\n * Team Validator\n * Pokemon Showdown - http://pokemonshowdown.com/\n *\n * Spawns a child process to validate teams.\n *\n * @license MIT\n */\n\nimport {TeamValidator} from '../sim/team-validator';\n\nexport class TeamValidatorAsync {\n\tformat: Format;\n\n\tconstructor(format: string) {\n\t\tthis.format = Dex.formats.get(format);\n\t}\n\n\tvalidateTeam(team: string, options?: {removeNicknames?: boolean, user?: ID}) {\n\t\tlet formatid = this.format.id;\n\t\tif (this.format.customRules) formatid += '@@@' + this.format.customRules.join(',');\n\t\tif (team.length > (25 * 1024 - 6)) { // don't even let it go to the child process\n\t\t\treturn Promise.resolve('0Your team is over 25KB. Please use a smaller team.');\n\t\t}\n\t\treturn PM.query({formatid, options, team});\n\t}\n\n\tstatic get(format: string) {\n\t\treturn new TeamValidatorAsync(format);\n\t}\n}\n\nexport const get = TeamValidatorAsync.get;\n\n/*********************************************************\n * Process manager\n *********************************************************/\n\nimport {QueryProcessManager} from '../lib/process-manager';\n\nexport const PM = new QueryProcessManager<{\n\tformatid: string, options?: {removeNicknames?: boolean}, team: string,\n}>(module, message => {\n\tconst {formatid, options, team} = message;\n\tconst parsedTeam = Teams.unpack(team);\n\n\tif (Config.debugvalidatorprocesses && process.send) {\n\t\tprocess.send('DEBUG\\n' + JSON.stringify(message));\n\t}\n\n\tlet problems;\n\ttry {\n\t\tproblems = TeamValidator.get(formatid).validateTeam(parsedTeam, options);\n\t} catch (err) {\n\t\tMonitor.crashlog(err, 'A team validation', {\n\t\t\tformatid,\n\t\t\tteam,\n\t\t});\n\t\tproblems = [\n\t\t\t`Your team crashed the validator. We'll fix this crash within a few hours (we're automatically notified),` +\n\t\t\t` but if you don't want to wait, just use a different team for now.`,\n\t\t];\n\t}\n\n\tif (problems?.length) {\n\t\treturn '0' + problems.join('\\n');\n\t}\n\tconst packedTeam = Teams.pack(parsedTeam);\n\t// console.log('FROM: ' + message.substr(pipeIndex2 + 1));\n\t// console.log('TO: ' + packedTeam);\n\treturn '1' + packedTeam;\n}, 2 * 60 * 1000);\n\nif (!PM.isParentProcess) {\n\t// This is a child process!\n\tglobal.Config = require('./config-loader').Config;\n\n\tglobal.Monitor = {\n\t\tcrashlog(error: Error, source = 'A team validator process', details: AnyObject | null = null) {\n\t\t\tconst repr = JSON.stringify([error.name, error.message, source, details]);\n\t\t\tprocess.send!(`THROW\\n@!!@${repr}\\n${error.stack}`);\n\t\t},\n\t};\n\n\tif (Config.crashguard) {\n\t\tprocess.on('uncaughtException', (err: Error) => {\n\t\t\tMonitor.crashlog(err, `A team validator process`);\n\t\t});\n\t\tprocess.on('unhandledRejection', err => {\n\t\t\tMonitor.crashlog(err as any || {}, 'A team validator process Promise');\n\t\t});\n\t}\n\n\tglobal.Dex = require('../sim/dex').Dex.includeData();\n\tglobal.Teams = require('../sim/teams').Teams;\n\n\t// eslint-disable-next-line no-eval\n\trequire('../lib/repl').Repl.start(`team-validator-${process.pid}`, (cmd: string) => eval(cmd));\n} else {\n\tPM.spawn(global.Config ? Config.validatorprocesses : 1);\n}\n"], "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,4BAA4B;AA6B5B,6BAAkC;AAtClC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWO,MAAM,mBAAmB;AAAA,EAG/B,YAAY,QAAgB;AAC3B,SAAK,SAAS,IAAI,QAAQ,IAAI,MAAM;AAAA,EACrC;AAAA,EAEA,aAAa,MAAc,SAAkD;AAC5E,QAAI,WAAW,KAAK,OAAO;AAC3B,QAAI,KAAK,OAAO;AAAa,kBAAY,QAAQ,KAAK,OAAO,YAAY,KAAK,GAAG;AACjF,QAAI,KAAK,SAAU,KAAK,OAAO,GAAI;AAClC,aAAO,QAAQ,QAAQ,qDAAqD;AAAA,IAC7E;AACA,WAAO,GAAG,MAAM,EAAC,UAAU,SAAS,KAAI,CAAC;AAAA,EAC1C;AAAA,E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