Accept arguments in src/load-servers.php for path to load from

This commit is contained in:
Mia 2021-10-14 21:07:11 -05:00
parent 8a51a9fff3
commit 5dd3695003
4 changed files with 13 additions and 7 deletions

View File

@ -29,6 +29,9 @@ export function load(invalidate = false): Configuration {
if (!config.mainserver) {
config.mainserver = 'showdown';
}
if (!config.serverlist) {
config.serverlist = '/var/www/html/play.pokemonshowdown.com/config/servers.inc.php';
}
const needsSet = ['autolockip', 'sysops', 'trustedproxies', 'compromisedkeys'] as const;
for (const key of needsSet) {
if (!config[key]) config[key] = [];

View File

@ -164,7 +164,9 @@ export class Dispatcher {
}
static servers: {[k: string]: RegisteredServer} = (() => {
try {
const stdout = child.execSync(`php -f src/lib/load-servers.php`).toString();
const stdout = child.execSync(
`php -f src/lib/load-servers.php ${Config.serverlist}`
).toString();
return JSON.parse(stdout);
} catch (e: any) {
if (e.code !== 'ENOENT') throw e;

View File

@ -1,6 +1,6 @@
<?php
// needs to be changed to the absolute path of your servers.php file
include_once '/var/www/html/play.pokemonshowdown.com/config/servers.inc.php';
include_once $argv[1];
$json = json_encode($PokemonServers, JSON_FORCE_OBJECT);
if ($json === false) print("{}");

View File

@ -416,9 +416,9 @@ export class Session {
return;
}
const query = SQL`SELECT sid, timeout, \`ntbb_users\`.* `;
query.append('FROM `ntbb_sessions\`, `ntbb_users` ');
query.append('FROM `ntbb_sessions`, `ntbb_users` ');
query.append(SQL`WHERE \`session\` = ${session} `);
query.append('AND `ntbb_sessions`.`userid\` = `ntbb_users`.`userid` ');
query.append('AND `ntbb_sessions`.`userid` = `ntbb_users`.`userid` ');
query.append(' LIMIT 1');
const res = await users.database.get<{sid: string; timeout: number}>(query);
if (!res || !(await this.validateSid(sid, res.sid))) {
@ -439,10 +439,11 @@ export class Session {
this.sidhash = sid;
this.session = session;
}
async validateSid(cachedSid: string, databaseSid: string): Promise<boolean> {
validateSid(cachedSid: string, databaseSid: string): Promise<boolean> {
if (Config.validateSid) {
return Config.validateSid.call(this, cachedSid, databaseSid);
// covers async functions
return Promise.resolve(Config.validateSid.call(this, cachedSid, databaseSid));
}
return cachedSid === databaseSid;
return Promise.resolve(cachedSid === databaseSid);
}
}