mirror of
https://github.com/smogon/pokemon-showdown.git
synced 2026-04-24 23:09:10 -05:00
TypeScript globals
A few globals: Monitor, LoginServer, etc weren't being correctly TypeScripted. This should change that.
This commit is contained in:
parent
8ad7bacb6e
commit
ffdcff3abc
|
|
@ -12,19 +12,19 @@ type NameFilter = import('./../server/chat').NameFilter
|
|||
interface AnyObject {[k: string]: any}
|
||||
type DexTable<T> = {[key: string]: T}
|
||||
|
||||
let Config = require('../config/config');
|
||||
let Config: {[k: string]: any} = require('../config/config');
|
||||
|
||||
let Monitor = require('../monitor');
|
||||
let Monitor: typeof import("../server/monitor") = require('../server/monitor');
|
||||
|
||||
let LoginServer = require('../loginserver');
|
||||
let LoginServer: typeof import('../server/loginserver') = require('../server/loginserver');
|
||||
|
||||
// type RoomBattle = AnyObject;
|
||||
|
||||
let Verifier = require('../verifier');
|
||||
let Dnsbl = require('../dnsbl');
|
||||
let Sockets = require('../sockets');
|
||||
// let TeamValidator = require('../sim/team-validator');
|
||||
let TeamValidatorAsync = require('../team-validator-async');
|
||||
let Verifier: typeof import('../server/verifier') = require('../server/verifier');
|
||||
let Dnsbl: typeof import('../server/dnsbl') = require('../server/dnsbl');
|
||||
let Sockets: typeof import('../server/sockets') = require('../server/sockets');
|
||||
// let TeamValidator: typeof import('../sim/team-validator') = require('../sim/team-validator');
|
||||
let TeamValidatorAsync: typeof import('../server/team-validator-async') = require('../server/team-validator-async');
|
||||
|
||||
type GenderName = 'M' | 'F' | 'N' | '';
|
||||
type StatName = 'hp' | 'atk' | 'def' | 'spa' | 'spd' | 'spe';
|
||||
|
|
|
|||
|
|
@ -57,8 +57,10 @@ function queryDnsblLoop(ip, callback, reversedIpDot, index) {
|
|||
* Dnsbl.query(ip, callback)
|
||||
*
|
||||
* Calls callback(blocklist), where blocklist is the blocklist domain
|
||||
* if the passed IP is in a blocklist, or boolean false if the IP is
|
||||
* not in any blocklist.
|
||||
* if the passed IP is in a blocklist, or null if the IP is not in
|
||||
* any blocklist.
|
||||
*
|
||||
* Return value matches isBlocked when treated as a boolean.
|
||||
*
|
||||
* @param {string} ip
|
||||
* @return {Promise<string?>}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ class LadderStore {
|
|||
});
|
||||
let mmr = NaN;
|
||||
if (data && !data.errorip) {
|
||||
mmr = parseInt(data);
|
||||
mmr = Number(data);
|
||||
}
|
||||
if (isNaN(mmr)) return 1000;
|
||||
|
||||
|
|
@ -95,9 +95,14 @@ class LadderStore {
|
|||
Monitor.warn(`room expired before ladder update was received`);
|
||||
return [p1score, null, null];
|
||||
}
|
||||
if (!data) {
|
||||
room.add(`|error|Unexpected response ${data} from ladder server.`);
|
||||
room.update();
|
||||
return [p1score, null, null];
|
||||
}
|
||||
if (data.errorip) {
|
||||
room.add(`||This server's request IP ${data.errorip} is not a registered server.`);
|
||||
room.add(`||You should be using ladders.js and not ladders-remote.js for ladder tracking.`);
|
||||
room.add(`|error|This server's request IP ${data.errorip} is not a registered server.`);
|
||||
room.add(`|error|You should be using ladders.js and not ladders-remote.js for ladder tracking.`);
|
||||
room.update();
|
||||
return [p1score, null, null];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ class Ladder extends LadderStore {
|
|||
if (isRated && !Ladders.disabled) {
|
||||
let userid = user.userid;
|
||||
[valResult, rating] = await Promise.all([
|
||||
TeamValidatorAsync(this.formatid).validateTeam(team, user.locked || user.namelocked),
|
||||
TeamValidatorAsync(this.formatid).validateTeam(team, !!(user.locked || user.namelocked)),
|
||||
this.getRating(userid),
|
||||
]);
|
||||
if (userid !== user.userid) {
|
||||
|
|
@ -150,7 +150,7 @@ class Ladder extends LadderStore {
|
|||
connection.popup(`The ladder is temporarily disabled due to technical difficulties - you will not receive ladder rating for this game.`);
|
||||
rating = 1;
|
||||
}
|
||||
valResult = await TeamValidatorAsync(this.formatid).validateTeam(team, user.locked || user.namelocked);
|
||||
valResult = await TeamValidatorAsync(this.formatid).validateTeam(team, !!(user.locked || user.namelocked));
|
||||
}
|
||||
|
||||
if (valResult.charAt(0) !== '1') {
|
||||
|
|
|
|||
|
|
@ -1344,14 +1344,14 @@ Punishments.checkIp = function (user, connection) {
|
|||
return null;
|
||||
}
|
||||
throw e;
|
||||
}).then((/** @type {string} */ host) => {
|
||||
}).then((/** @type {string | null} */ host) => {
|
||||
user = connection.user || user;
|
||||
if (host) user.latestHost = host;
|
||||
Chat.hostfilter(host, user, connection);
|
||||
Chat.hostfilter(host || '', user, connection);
|
||||
});
|
||||
|
||||
if (Config.dnsbl) {
|
||||
Dnsbl.query(connection.ip).then((/** @type {boolean} */ isBlocked) => {
|
||||
Dnsbl.query(connection.ip).then((/** @type {string | null} */ isBlocked) => {
|
||||
user = connection.user || user;
|
||||
if (isBlocked) {
|
||||
if (!user.locked && !user.autoconfirmed) {
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ class BattlePlayer {
|
|||
let user = Users(this.userid);
|
||||
if (user) {
|
||||
for (const connection of user.connections) {
|
||||
Sockets.subchannelMove(connection.worker, this.game.id, '0', connection.socketid);
|
||||
Sockets.subchannelMove(connection.worker, this.game.id, 0, connection.socketid);
|
||||
}
|
||||
user.games.delete(this.game.id);
|
||||
user.updateSearch();
|
||||
|
|
|
|||
|
|
@ -172,7 +172,7 @@ if (cluster.isMaster) {
|
|||
|
||||
/**
|
||||
* @param {cluster.Worker} worker
|
||||
* @param {number} socketid
|
||||
* @param {string} socketid
|
||||
* @param {string} message
|
||||
*/
|
||||
exports.socketSend = function (worker, socketid, message) {
|
||||
|
|
@ -181,7 +181,7 @@ if (cluster.isMaster) {
|
|||
|
||||
/**
|
||||
* @param {cluster.Worker} worker
|
||||
* @param {number} socketid
|
||||
* @param {string} socketid
|
||||
*/
|
||||
exports.socketDisconnect = function (worker, socketid) {
|
||||
worker.send(`!${socketid}`);
|
||||
|
|
@ -209,7 +209,7 @@ if (cluster.isMaster) {
|
|||
/**
|
||||
* @param {cluster.Worker} worker
|
||||
* @param {string} channelid
|
||||
* @param {number} socketid
|
||||
* @param {string} socketid
|
||||
*/
|
||||
exports.channelAdd = function (worker, channelid, socketid) {
|
||||
worker.send(`+${channelid}\n${socketid}`);
|
||||
|
|
@ -218,7 +218,7 @@ if (cluster.isMaster) {
|
|||
/**
|
||||
* @param {cluster.Worker} worker
|
||||
* @param {string} channelid
|
||||
* @param {number} socketid
|
||||
* @param {string} socketid
|
||||
*/
|
||||
exports.channelRemove = function (worker, channelid, socketid) {
|
||||
worker.send(`-${channelid}\n${socketid}`);
|
||||
|
|
@ -237,8 +237,8 @@ if (cluster.isMaster) {
|
|||
/**
|
||||
* @param {cluster.Worker} worker
|
||||
* @param {string} channelid
|
||||
* @param {string} subchannelid
|
||||
* @param {number} socketid
|
||||
* @param {number} subchannelid
|
||||
* @param {string} socketid
|
||||
*/
|
||||
exports.subchannelMove = function (worker, channelid, subchannelid, socketid) {
|
||||
worker.send(`.${channelid}\n${subchannelid}\n${socketid}`);
|
||||
|
|
|
|||
|
|
@ -789,17 +789,14 @@ class User {
|
|||
let tokenData = token.substr(0, tokenSemicolonPos);
|
||||
let tokenSig = token.substr(tokenSemicolonPos + 1);
|
||||
|
||||
let success = await Verifier.verify(tokenData, tokenSig);
|
||||
if (!success) {
|
||||
Monitor.warn(`verify failed: ${token}`);
|
||||
Monitor.warn(`challenge was: ${challenge}`);
|
||||
this.send(`|nametaken|${name}|Your verification signature was invalid.`);
|
||||
let tokenDataSplit = tokenData.split(',');
|
||||
let [signedChallenge, signedUserid, userType, signedDate, signedHostname] = tokenDataSplit;
|
||||
if (signedHostname && Config.legalhosts && !Config.legalhosts.includes(signedHostname)) {
|
||||
Monitor.warn(`forged assertion: ${tokenData}`);
|
||||
this.send(`|nametaken|${name}|Your assertion is for the wrong server. This server is sim2.psim.us.`);
|
||||
return false;
|
||||
}
|
||||
|
||||
let tokenDataSplit = tokenData.split(',');
|
||||
let [signedChallenge, signedUserid, userType, signedDate] = tokenDataSplit;
|
||||
|
||||
if (tokenDataSplit.length < 5) {
|
||||
Monitor.warn(`outdated assertion format: ${tokenData}`);
|
||||
this.send(`|nametaken|${name}|Your assertion is stale. This usually means that the clock on the server computer is incorrect. If this is your server, please set the clock to the correct time.`);
|
||||
|
|
@ -809,21 +806,29 @@ class User {
|
|||
if (signedUserid !== userid) {
|
||||
// userid mismatch
|
||||
this.send(`|nametaken|${name}|Your verification signature doesn't match your new username.`);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (signedChallenge !== challenge) {
|
||||
// a user sent an invalid token
|
||||
Monitor.debug(`verify token challenge mismatch: ${signedChallenge} <=> ${challenge}`);
|
||||
this.send(`|nametaken|${name}|Your verification signature doesn't match your authentication token.`);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
let expiry = Config.tokenexpiry || 25 * 60 * 60;
|
||||
if (Math.abs(parseInt(signedDate) - Date.now() / 1000) > expiry) {
|
||||
Monitor.warn(`stale assertion: ${tokenData}`);
|
||||
this.send(`|nametaken|${name}|Your assertion is stale. This usually means that the clock on the server computer is incorrect. If this is your server, please set the clock to the correct time.`);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
let success = await Verifier.verify(tokenData, tokenSig);
|
||||
if (!success) {
|
||||
Monitor.warn(`verify failed: ${token}`);
|
||||
Monitor.warn(`challenge was: ${challenge}`);
|
||||
this.send(`|nametaken|${name}|Your verification signature was invalid.`);
|
||||
return false;
|
||||
}
|
||||
|
||||
// future-proofing
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user