More event progress
This commit is contained in:
@ -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}`)
|
||||
|
Reference in New Issue
Block a user