More event progress

This commit is contained in:
2025-01-02 02:24:09 +01:00
parent ab89d0cbb0
commit f7dbf09bf5
18 changed files with 194 additions and 464 deletions

View File

@ -2,6 +2,8 @@ import { Server } from 'socket.io'
import Logger, { LoggerType } from '#application/logger'
import { TSocket } from '#application/types'
import { Character } from '#entities/character'
import CharacterRepository from '#repositories/characterRepository'
export abstract class BaseEvent {
protected readonly logger = Logger.type(LoggerType.GAME)
@ -11,6 +13,15 @@ export abstract class BaseEvent {
readonly socket: TSocket
) {}
protected async getCharacter(): Promise<Character | null> {
return CharacterRepository.getById(this.socket.characterId!)
}
protected async isCharacterGM(): Promise<boolean> {
const character = await this.getCharacter()
return character?.getRole() === 'gm'
}
protected emitError(message: string): void {
this.socket.emit('notification', { title: 'Server message', message })
this.logger.error('character:connect error', `Player ${this.socket.userId}: ${message}`)