GM event fixes
This commit is contained in:
@ -1,8 +1,10 @@
|
||||
import { Server } from 'socket.io'
|
||||
import { TSocket } from '../../../utilities/types'
|
||||
import ZoneRepository from '../../../repositories/zoneRepository'
|
||||
import { Zone } from '@prisma/client'
|
||||
import { Character, Zone } from '@prisma/client'
|
||||
import CharacterManager from '../../../managers/characterManager'
|
||||
import characterRepository from '../../../repositories/characterRepository'
|
||||
import logger from '../../../utilities/logger'
|
||||
|
||||
interface IPayload {
|
||||
zoneId: number
|
||||
@ -15,15 +17,18 @@ interface IPayload {
|
||||
*/
|
||||
export default function (socket: TSocket, io: Server) {
|
||||
socket.on('gm:zone_editor:zone:request', async (data: IPayload, callback: (response: Zone) => void) => {
|
||||
const character = CharacterManager.getCharacterFromSocket(socket);
|
||||
if (character?.role !== 'gm') {
|
||||
const character = await characterRepository.getById(socket.characterId as number);
|
||||
if (!character) return
|
||||
|
||||
if (character.role !== 'gm') {
|
||||
logger.info(`User ${character!.id} tried to request zone but is not a game master.`)
|
||||
return
|
||||
}
|
||||
|
||||
console.log(`---GM ${character?.id} has requested zone via zone editor.`)
|
||||
logger.info(`User ${character.id} has requested zone via zone editor.`)
|
||||
|
||||
if (!data.zoneId) {
|
||||
console.log(`---Zone id not provided.`)
|
||||
logger.info(`User ${character.id} tried to request zone but did not provide a zone id.`)
|
||||
return
|
||||
}
|
||||
|
||||
@ -31,7 +36,7 @@ export default function (socket: TSocket, io: Server) {
|
||||
const zone = await ZoneRepository.getById(data.zoneId)
|
||||
|
||||
if (!zone) {
|
||||
console.log(`---Zone not found.`)
|
||||
logger.info(`User ${character.id} tried to request zone ${data.zoneId} but it does not exist.`)
|
||||
return
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user