import { BaseEvent } from '#application/base/baseEvent' import { UUID } from '#application/types' import { Zone } from '#entities/zone' import ZoneRepository from '#repositories/zoneRepository' interface IPayload { zoneId: UUID } export default class ZoneRequestEvent extends BaseEvent { public listen(): void { this.socket.on('gm:zone_editor:zone:request', this.handleEvent.bind(this)) } private async handleEvent(data: IPayload, callback: (response: Zone | null) => void): Promise { try { if (!(await this.isCharacterGM())) return this.logger.info(`User ${(await this.getCharacter())!.getId()} has requested zone via zone editor.`) if (!data.zoneId) { this.logger.info(`User ${(await this.getCharacter())!.getId()} tried to request zone but did not provide a zone id.`) return callback(null) } const zone = await ZoneRepository.getById(data.zoneId) if (!zone) { this.logger.info(`User ${(await this.getCharacter())!.getId()} tried to request zone ${data.zoneId} but it does not exist.`) return callback(null) } return callback(zone) } catch (error: any) { this.logger.error('gm:zone_editor:zone:request error', error.message) return callback(null) } } }