Skip to content

Commit bf8db3f

Browse files
author
Picoseconds
committed
feat: add CPS cap
1 parent 69df8f1 commit bf8db3f

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/moomoo/Client.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Player from "./Player";
33

44
export default class Client {
55
public tribeJoinQueue: Player[] = [];
6+
public lastAttackTime = 0;
67

78
constructor(
89
public id: string,

src/moomoo/Game.ts

+14
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ import { WeaponVariant } from './Weapons';
2222

2323
let currentGame: Game | null = null;
2424

25+
const DEFAULT_MAX_CPS = 25;
26+
27+
let MAX_CPS = (process.env.MAX_CPS && parseInt(process.env.MAX_CPS, 10)) || DEFAULT_MAX_CPS;
28+
if (isNaN(MAX_CPS)) MAX_CPS = DEFAULT_MAX_CPS;
29+
2530
interface DBSchema {
2631
bannedIPs: string[];
2732
moderatorIPs: string[];
@@ -830,10 +835,19 @@ export default class Game {
830835
case PacketType.ATTACK:
831836
if (client.player) {
832837
if (packet.data[0]) {
838+
if (Date.now() - client.lastAttackTime < 1000 / MAX_CPS) {
839+
client.lastAttackTime = Date.now();
840+
return;
841+
}
842+
843+
client.lastAttackTime = Date.now();
844+
833845
this.normalAttack(client.player);
834846
} else {
835847
client.player.isAttacking = false;
836848
}
849+
} else {
850+
this.kickClient(client, "Kicked for hacks");
837851
}
838852
break;
839853
case PacketType.PLAYER_MOVE:

0 commit comments

Comments
 (0)