forked from noxious/server
WIP event delays
This commit is contained in:
@@ -8,12 +8,26 @@ import CharacterRepository from '#repositories/characterRepository'
|
||||
|
||||
export abstract class BaseEvent {
|
||||
protected readonly logger = Logger.type(LoggerType.GAME)
|
||||
private lastActionTimes: Map<string, number> = new Map()
|
||||
|
||||
constructor(
|
||||
readonly io: Server,
|
||||
readonly socket: TSocket
|
||||
) {}
|
||||
|
||||
protected isThrottled(actionId: string, throttleTime: number): boolean {
|
||||
const now = Date.now()
|
||||
const lastActionTime = this.lastActionTimes.get(actionId) || 0
|
||||
|
||||
if (now - lastActionTime < throttleTime) {
|
||||
return true
|
||||
}
|
||||
|
||||
this.lastActionTimes.set(actionId, now)
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
protected async getCharacter(): Promise<Character | null> {
|
||||
const characterRepository = new CharacterRepository()
|
||||
return characterRepository.getById(this.socket.characterId!)
|
||||
|
Reference in New Issue
Block a user