Add ratelimit for reset votes

This commit is contained in:
elijahr2411
2023-02-12 18:15:12 -05:00
parent 5f603a88d9
commit 7b66f7c8a3
2 changed files with 4 additions and 0 deletions

View File

@@ -21,6 +21,7 @@ export class User {
LoginRateLimit : RateLimiter; LoginRateLimit : RateLimiter;
RenameRateLimit : RateLimiter; RenameRateLimit : RateLimiter;
TurnRateLimit : RateLimiter; TurnRateLimit : RateLimiter;
VoteRateLimit : RateLimiter;
constructor(ws : WebSocket, ip : IPData, config : IConfig, username? : string, node? : string) { constructor(ws : WebSocket, ip : IPData, config : IConfig, username? : string, node? : string) {
this.IP = ip; this.IP = ip;
this.connectedToNode = false; this.connectedToNode = false;
@@ -48,6 +49,8 @@ export class User {
this.LoginRateLimit.on('limit', () => this.closeConnection()); this.LoginRateLimit.on('limit', () => this.closeConnection());
this.TurnRateLimit = new RateLimiter(5, 3); this.TurnRateLimit = new RateLimiter(5, 3);
this.TurnRateLimit.on('limit', () => this.closeConnection()); this.TurnRateLimit.on('limit', () => this.closeConnection());
this.VoteRateLimit = new RateLimiter(3, 3);
this.VoteRateLimit.on('limit', () => this.closeConnection());
} }
assignGuestName(existingUsers : string[]) : string { assignGuestName(existingUsers : string[]) : string {
var username; var username;

View File

@@ -272,6 +272,7 @@ export default class WSServer {
case "vote": case "vote":
if (!client.connectedToNode) return; if (!client.connectedToNode) return;
if (msgArr.length !== 2) return; if (msgArr.length !== 2) return;
if (!client.VoteRateLimit.request()) return;
switch (msgArr[1]) { switch (msgArr[1]) {
case "1": case "1":
if (!this.voteInProgress) { if (!this.voteInProgress) {