forked from noxious/server
#184: Added commands to toggle rain / fog, command bug fix, minor improvements
This commit is contained in:
@ -24,16 +24,24 @@ export default class AlertCommandEvent {
|
||||
return
|
||||
}
|
||||
|
||||
const args = getArgs('alert', data.message)
|
||||
|
||||
if (!args) {
|
||||
// Check if character exists
|
||||
const character = await CharacterRepository.getByUserAndId(this.socket.user?.id as number, this.socket.characterId as number)
|
||||
if (!character) {
|
||||
gameLogger.error('chat:alert_command error', 'Character not found')
|
||||
callback(false)
|
||||
return
|
||||
}
|
||||
|
||||
const character = await CharacterRepository.getByUserAndId(this.socket.user?.id as number, this.socket.characterId as number)
|
||||
if (!character) {
|
||||
gameLogger.error('chat:alert_command error', 'Character not found')
|
||||
// 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
|
||||
}
|
||||
|
||||
const args = getArgs('alert', data.message)
|
||||
|
||||
if (!args) {
|
||||
callback(false)
|
||||
return
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
import { Server } from 'socket.io'
|
||||
import { TSocket } from '../../../utilities/types'
|
||||
import { ExtendedCharacter, TSocket } from '../../../utilities/types'
|
||||
import { getArgs, isCommand } from '../../../utilities/chat'
|
||||
import ZoneRepository from '../../../repositories/zoneRepository'
|
||||
import CharacterManager from '../../../managers/characterManager'
|
||||
import { gameMasterLogger } from '../../../utilities/logger'
|
||||
import { gameLogger, gameMasterLogger } from '../../../utilities/logger'
|
||||
import CharacterRepository from '../../../repositories/characterRepository'
|
||||
|
||||
type TypePayload = {
|
||||
message: string
|
||||
@ -21,9 +22,18 @@ export default class TeleportCommandEvent {
|
||||
|
||||
private async handleTeleportCommand(data: TypePayload, callback: (response: boolean) => void): Promise<void> {
|
||||
try {
|
||||
const character = CharacterManager.getCharacterFromSocket(this.socket)
|
||||
// Check if character exists
|
||||
const character = await CharacterRepository.getByUserAndId(this.socket.user?.id as number, this.socket.characterId as number) as ExtendedCharacter
|
||||
if (!character) {
|
||||
this.socket.emit('notification', { title: 'Server message', message: 'Character not found' })
|
||||
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
|
||||
}
|
||||
|
||||
|
51
src/socketEvents/chat/gameMaster/toggleFogCommand.ts
Normal file
51
src/socketEvents/chat/gameMaster/toggleFogCommand.ts
Normal file
@ -0,0 +1,51 @@
|
||||
import { Server } from 'socket.io'
|
||||
import { TSocket } from '../../../utilities/types'
|
||||
import { isCommand } from '../../../utilities/chat'
|
||||
import CharacterRepository from '../../../repositories/characterRepository'
|
||||
import { gameLogger } from '../../../utilities/logger'
|
||||
import WeatherManager from '../../../managers/weatherManager'
|
||||
|
||||
type TypePayload = {
|
||||
message: string
|
||||
}
|
||||
|
||||
export default class ToggleFogCommand {
|
||||
constructor(
|
||||
private readonly io: Server,
|
||||
private readonly socket: TSocket
|
||||
) {}
|
||||
|
||||
public listen(): void {
|
||||
this.socket.on('chat:send_message', this.handleAlertCommand.bind(this))
|
||||
}
|
||||
|
||||
private async handleAlertCommand(data: TypePayload, callback: (response: boolean) => void): Promise<void> {
|
||||
try {
|
||||
if (!isCommand(data.message, 'fog')) {
|
||||
return
|
||||
}
|
||||
|
||||
// Check if character exists
|
||||
const character = await CharacterRepository.getByUserAndId(this.socket.user?.id as number, this.socket.characterId as number)
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
51
src/socketEvents/chat/gameMaster/toggleRainCommand.ts
Normal file
51
src/socketEvents/chat/gameMaster/toggleRainCommand.ts
Normal file
@ -0,0 +1,51 @@
|
||||
import { Server } from 'socket.io'
|
||||
import { TSocket } from '../../../utilities/types'
|
||||
import { isCommand } from '../../../utilities/chat'
|
||||
import CharacterRepository from '../../../repositories/characterRepository'
|
||||
import { gameLogger } from '../../../utilities/logger'
|
||||
import WeatherManager from '../../../managers/weatherManager'
|
||||
|
||||
type TypePayload = {
|
||||
message: string
|
||||
}
|
||||
|
||||
export default class ToggleRainCommand {
|
||||
constructor(
|
||||
private readonly io: Server,
|
||||
private readonly socket: TSocket
|
||||
) {}
|
||||
|
||||
public listen(): void {
|
||||
this.socket.on('chat:send_message', this.handleAlertCommand.bind(this))
|
||||
}
|
||||
|
||||
private async handleAlertCommand(data: TypePayload, callback: (response: boolean) => void): Promise<void> {
|
||||
try {
|
||||
if (!isCommand(data.message, 'rain')) {
|
||||
return
|
||||
}
|
||||
|
||||
// Check if character exists
|
||||
const character = await CharacterRepository.getByUserAndId(this.socket.user?.id as number, this.socket.characterId as number)
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user