Renamed zone > map
This commit is contained in:
39
src/events/gameMaster/mapEditor/request.ts
Normal file
39
src/events/gameMaster/mapEditor/request.ts
Normal file
@ -0,0 +1,39 @@
|
||||
import { BaseEvent } from '#application/base/baseEvent'
|
||||
import { UUID } from '#application/types'
|
||||
import { Map } from '#entities/map'
|
||||
import MapRepository from '#repositories/mapRepository'
|
||||
|
||||
interface IPayload {
|
||||
mapId: UUID
|
||||
}
|
||||
|
||||
export default class MapRequestEvent extends BaseEvent {
|
||||
public listen(): void {
|
||||
this.socket.on('gm:map_editor:map:request', this.handleEvent.bind(this))
|
||||
}
|
||||
|
||||
private async handleEvent(data: IPayload, callback: (response: Map | null) => void): Promise<void> {
|
||||
try {
|
||||
if (!(await this.isCharacterGM())) return
|
||||
|
||||
this.logger.info(`User ${(await this.getCharacter())!.getId()} has requested map via map editor.`)
|
||||
|
||||
if (!data.mapId) {
|
||||
this.logger.info(`User ${(await this.getCharacter())!.getId()} tried to request map but did not provide a map id.`)
|
||||
return callback(null)
|
||||
}
|
||||
|
||||
const map = await MapRepository.getById(data.mapId)
|
||||
|
||||
if (!map) {
|
||||
this.logger.info(`User ${(await this.getCharacter())!.getId()} tried to request map ${data.mapId} but it does not exist.`)
|
||||
return callback(null)
|
||||
}
|
||||
|
||||
return callback(map)
|
||||
} catch (error: any) {
|
||||
this.logger.error('gm:map_editor:map:request error', error.message)
|
||||
return callback(null)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user