1
0
forked from noxious/server

Moved models to simplify and improve prisma schemas , added logic to update characterTypes

This commit is contained in:
2024-11-17 17:53:25 +01:00
parent 27f8bc8784
commit ec3bf0f51e
14 changed files with 80 additions and 103 deletions

View File

@ -28,26 +28,23 @@ export default class AlertCommandEvent {
const character = await CharacterRepository.getByUserAndId(this.socket.userId!, this.socket.characterId!)
if (!character) {
gameLogger.error('chat:alert_command error', 'Character not found')
callback(false)
return
return callback(false)
}
// Check if the user is the GM
if (character.role !== 'gm') {
gameLogger.info(`User ${character.id} tried to set time but is not a game master.`)
callback(false)
return
return callback(false)
}
const args = getArgs('alert', data.message)
if (!args) {
callback(false)
return
return callback(false)
}
this.io.emit('notification', { title: 'Message from GM', message: args.join(' ') })
callback(true)
return callback(true)
} catch (error: any) {
gameLogger.error('chat:alert_command error', error.message)
callback(false)

View File

@ -29,14 +29,12 @@ export default class SetTimeCommand {
const character = await CharacterRepository.getByUserAndId(this.socket.userId!, this.socket.characterId!)
if (!character) {
gameLogger.error('chat:alert_command error', 'Character not found')
callback(false)
return
}
// Check if the user is the GM
if (character.role !== 'gm') {
gameLogger.info(`User ${character.id} tried to set time but is not a game master.`)
callback(false)
return
}
@ -44,20 +42,16 @@ export default class SetTimeCommand {
const args = getArgs('time', data.message)
if (!args) {
callback(false)
return
}
const time = args[0] // 24h time, e.g. 17:34
if (!time) {
callback(false)
return
}
await DateManager.setTime(time)
callback(true)
} catch (error: any) {
gameLogger.error('command error', error.message)
callback(false)

View File

@ -26,7 +26,6 @@ export default class TeleportCommandEvent {
const zoneCharacter = ZoneManager.getCharacter(this.socket.characterId!)
if (!zoneCharacter) {
gameLogger.error('chat:message error', 'Character not found')
callback(false)
return
}
@ -35,7 +34,6 @@ export default class TeleportCommandEvent {
// Check if the user is the GM
if (character.role !== 'gm') {
gameLogger.info(`User ${character.id} tried to set time but is not a game master.`)
callback(false)
return
}
@ -86,8 +84,6 @@ export default class TeleportCommandEvent {
this.socket.emit('notification', { title: 'Server message', message: `You have been teleported to ${zone.name}` })
gameMasterLogger.info('teleport', `Character ${character.id} teleported to zone ${zone.id}`)
callback(true)
} catch (error: any) {
gameMasterLogger.error(`Error in teleport command: ${error.message}`)
this.socket.emit('notification', { title: 'Server message', message: 'An error occurred while teleporting' })

View File

@ -29,20 +29,16 @@ export default class ToggleFogCommand {
const character = await CharacterRepository.getByUserAndId(this.socket.userId!, this.socket.characterId!)
if (!character) {
gameLogger.error('chat:alert_command error', 'Character not found')
callback(false)
return
}
// Check if the user is the GM
if (character.role !== 'gm') {
gameLogger.info(`User ${character.id} tried to set time but is not a game master.`)
callback(false)
return
}
await WeatherManager.toggleFog()
callback(true)
} catch (error: any) {
gameLogger.error('command error', error.message)
callback(false)

View File

@ -29,20 +29,16 @@ export default class ToggleRainCommand {
const character = await CharacterRepository.getByUserAndId(this.socket.userId!, this.socket.characterId!)
if (!character) {
gameLogger.error('chat:alert_command error', 'Character not found')
callback(false)
return
}
// Check if the user is the GM
if (character.role !== 'gm') {
gameLogger.info(`User ${character.id} tried to set time but is not a game master.`)
callback(false)
return
}
await WeatherManager.toggleRain()
callback(true)
} catch (error: any) {
gameLogger.error('command error', error.message)
callback(false)