Support Config.nothrottle (#7637)

This commit is contained in:
Mia 2020-11-05 06:52:04 -06:00 committed by GitHub
parent acbe53ba4a
commit 71dbb2f466
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 13 deletions

View File

@ -257,6 +257,11 @@ exports.reportbattlejoins = true;
*/
exports.monitorminpunishments = 3;
/**
* Turns off all time-based throttles - rename, challenges, laddering, etc.
*/
exports.nothrottle = false;
/**
* Removes all ip-based alt checking.
*/

View File

@ -1144,7 +1144,7 @@ export class CommandContext extends MessageContext {
const normalized = message.trim();
if (
!user.can('bypassall') && (['help', 'lobby'].includes(room.roomid)) && (normalized === user.lastMessage) &&
((Date.now() - user.lastMessageTime) < MESSAGE_COOLDOWN)
((Date.now() - user.lastMessageTime) < MESSAGE_COOLDOWN) && !Config.nothrottle
) {
throw new Chat.ErrorMessage(this.tr("You can't send the same message again so soon."));
}

View File

@ -243,7 +243,7 @@ class Ladder extends LadderStore {
Chat.maybeNotifyBlocked('challenge', targetUser, user);
return false;
}
if (Date.now() < user.lastChallenge + 10 * SECONDS) {
if (Date.now() < user.lastChallenge + 10 * SECONDS && !Config.nothrottle) {
// 10 seconds ago, probable misclick
connection.popup(`You challenged less than 10 seconds after your last challenge! It's cancelled in case it's a misclick.`);
return false;

View File

@ -152,7 +152,7 @@ export const Monitor = new class {
* Counts a connection. Returns true if the connection should be terminated for abuse.
*/
countConnection(ip: string, name = '') {
if (Config.noipchecks) return false;
if (Config.noipchecks || Config.nothrotte) return false;
const [count, duration] = this.connections.increment(ip, 30 * 60 * 1000);
if (count === 500) {
this.adminlog(`[ResourceMonitor] IP ${ip} banned for cflooding (${count} times in ${Chat.toDurationString(duration)}${name ? ': ' + name : ''})`);
@ -177,7 +177,7 @@ export const Monitor = new class {
* terminated for abuse.
*/
countBattle(ip: string, name = '') {
if (Config.noipchecks) return false;
if (Config.noipchecks || Config.nothrotte) return false;
const [count, duration] = this.battles.increment(ip, 30 * 60 * 1000);
if (duration < 5 * 60 * 1000 && count % 30 === 0) {
this.adminlog(`[ResourceMonitor] IP ${ip} has battled ${count} times in the last ${Chat.toDurationString(duration)}${name ? ': ' + name : ''})`);
@ -196,7 +196,7 @@ export const Monitor = new class {
* Counts team validations. Returns true if too many.
*/
countPrepBattle(ip: string, connection: Connection) {
if (Config.noipchecks) return false;
if (Config.noipchecks || Config.nothrotte) return false;
const count = this.battlePreps.increment(ip, 3 * 60 * 1000)[0];
if (count <= 12) return false;
if (count < 120 && Punishments.sharedIps.has(ip)) return false;
@ -208,7 +208,7 @@ export const Monitor = new class {
* Counts concurrent battles. Returns true if too many.
*/
countConcurrentBattle(count: number, connection: Connection) {
if (Config.noipchecks) return false;
if (Config.noipchecks || Config.nothrotte) return false;
if (count <= 5) return false;
connection.popup(`Due to high load, you are limited to 5 games at the same time.`);
return true;
@ -226,7 +226,7 @@ export const Monitor = new class {
* Counts commands that use HTTPs requests. Returns true if too many.
*/
countNetRequests(ip: string) {
if (Config.noipchecks) return false;
if (Config.noipchecks || Config.nothrotte) return false;
const [count] = this.netRequests.increment(ip, 1 * 60 * 1000);
if (count <= 10) return false;
if (count < 120 && Punishments.sharedIps.has(ip)) return false;
@ -237,7 +237,7 @@ export const Monitor = new class {
* Counts ticket creation. Returns true if too much.
*/
countTickets(ip: string) {
if (Config.noipchecks) return false;
if (Config.noipchecks || Config.nothrotte) return false;
const count = this.tickets.increment(ip, 60 * 60 * 1000)[0];
if (Punishments.sharedIps.has(ip)) {
return count >= 20;
@ -251,7 +251,12 @@ export const Monitor = new class {
* message, as well as the data length in the server's response.
*/
countNetworkUse(size: number) {
if (!Config.emergency || typeof this.activeIp !== 'string' || Config.noipchecks) return;
if (
!Config.emergency || typeof this.activeIp !== 'string' ||
Config.noipchecks || Config.nothrottle
) {
return;
}
if (this.activeIp in this.networkUse) {
this.networkUse[this.activeIp] += size;
this.networkCount[this.activeIp]++;

View File

@ -711,7 +711,7 @@ export class User extends Chat.MessageContext {
if (!this.trusted && userType === '1') { // userType '1' means unregistered
const elapsed = Date.now() - this.lastNewNameTime;
if (elapsed < NAMECHANGE_THROTTLE) {
if (elapsed < NAMECHANGE_THROTTLE && !Config.nothrottle) {
if (this.newNames >= NAMES_PER_THROTTLE) {
this.send(
`|nametaken|${name}|You must wait ${Chat.toDurationString(NAMECHANGE_THROTTLE - elapsed)} more
@ -1339,13 +1339,14 @@ export class User extends Chat.MessageContext {
*/
chat(message: string, room: Room | null, connection: Connection) {
const now = Date.now();
const noThrottle = this.hasSysopAccess() || Config.nothrottle;
if (message.startsWith('/cmd userdetails') || message.startsWith('>> ') || this.hasSysopAccess()) {
if (message.startsWith('/cmd userdetails') || message.startsWith('>> ') || noThrottle) {
// certain commands are exempt from the queue
Monitor.activeIp = connection.ip;
Chat.parse(message, room, this, connection);
Monitor.activeIp = null;
if (this.hasSysopAccess()) return;
if (noThrottle) return;
return false; // but end the loop here
}
@ -1622,7 +1623,7 @@ function socketReceive(worker: StreamWorker, workerid: number, socketid: string,
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
const maxLineCount = (user.isStaff || (room && room.auth.isStaff(user.id))) ?
THROTTLE_MULTILINE_WARN_STAFF : THROTTLE_MULTILINE_WARN;
if (lines.length > maxLineCount) {
if (lines.length > maxLineCount && !Config.nothrottle) {
connection.popup(`You're sending too many lines at once. Try using a paste service like [[Pastebin]].`);
return;
}