42 lines
945 B
TypeScript
42 lines
945 B
TypeScript
import { Server } from 'socket.io'
|
|
import { TSocket } from '../../../utilities/types'
|
|
import ZoneRepository from '../../../repositories/zoneRepository'
|
|
import { Zone } from '@prisma/client'
|
|
|
|
interface IPayload {
|
|
zoneId: number
|
|
}
|
|
|
|
/**
|
|
* Handle game master zone request event
|
|
* @param socket
|
|
* @param io
|
|
*/
|
|
export default function (socket: TSocket, io: Server) {
|
|
socket.on('gm:zone_editor:zone:request', async (data: IPayload, callback: (response: Zone) => void) => {
|
|
if (socket.character?.role !== 'gm') {
|
|
return
|
|
}
|
|
|
|
console.log(`---GM ${socket.character?.id} has requested zone via zone editor.`)
|
|
|
|
if (!data.zoneId) {
|
|
console.log(`---Zone id not provided.`)
|
|
return
|
|
}
|
|
|
|
try {
|
|
const zone = await ZoneRepository.getById(data.zoneId)
|
|
|
|
if (!zone) {
|
|
console.log(`---Zone not found.`)
|
|
return
|
|
}
|
|
|
|
callback(zone)
|
|
} catch (e) {
|
|
console.error(e)
|
|
}
|
|
})
|
|
}
|