Rate limit walking
This commit is contained in:
parent
94c619192b
commit
e735522d76
@ -10,7 +10,9 @@ import TeleportService from '#services/characterTeleportService'
|
||||
export default class CharacterMove extends BaseEvent {
|
||||
private readonly characterService = CharacterService
|
||||
private readonly MOVEMENT_CANCEL_DELAY = 250
|
||||
private readonly MOVEMENT_THROTTLE = 100 // Minimum time between movement requests
|
||||
private movementTimeouts: Map<string, NodeJS.Timeout> = new Map()
|
||||
private lastMovementTime: Map<string, number> = new Map() // Track last movement time for each character
|
||||
|
||||
public listen(): void {
|
||||
this.socket.on('map:character:move', this.handleEvent.bind(this))
|
||||
@ -23,6 +25,15 @@ export default class CharacterMove extends BaseEvent {
|
||||
return
|
||||
}
|
||||
|
||||
// Implement request throttling
|
||||
const now = Date.now()
|
||||
const lastMove = this.lastMovementTime.get(this.socket.characterId!) || 0
|
||||
if (now - lastMove < this.MOVEMENT_THROTTLE) {
|
||||
this.logger.debug('Movement request throttled')
|
||||
return
|
||||
}
|
||||
this.lastMovementTime.set(this.socket.characterId!, now)
|
||||
|
||||
// Clear any existing movement timeout
|
||||
const existingTimeout = this.movementTimeouts.get(this.socket.characterId!)
|
||||
if (existingTimeout) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user