forked from noxious/server
GM event fixes
This commit is contained in:
parent
0a629bf80f
commit
6b2433f814
@ -1,6 +1,5 @@
|
|||||||
import { Server } from 'socket.io'
|
import { Server } from 'socket.io'
|
||||||
import { TSocket } from '../utilities/types'
|
import { TSocket } from '../utilities/types'
|
||||||
import ZoneManager from '../managers/zoneManager'
|
|
||||||
import CharacterManager from '../managers/characterManager'
|
import CharacterManager from '../managers/characterManager'
|
||||||
|
|
||||||
export default function (socket: TSocket, io: Server) {
|
export default function (socket: TSocket, io: Server) {
|
||||||
|
@ -3,6 +3,7 @@ import { TSocket } from '../../../../utilities/types'
|
|||||||
import { Object } from '@prisma/client'
|
import { Object } from '@prisma/client'
|
||||||
import ObjectRepository from '../../../../repositories/objectRepository'
|
import ObjectRepository from '../../../../repositories/objectRepository'
|
||||||
import CharacterManager from '../../../../managers/characterManager'
|
import CharacterManager from '../../../../managers/characterManager'
|
||||||
|
import characterRepository from '../../../../repositories/characterRepository'
|
||||||
|
|
||||||
interface IPayload {}
|
interface IPayload {}
|
||||||
|
|
||||||
@ -13,10 +14,11 @@ interface IPayload {}
|
|||||||
*/
|
*/
|
||||||
export default function (socket: TSocket, io: Server) {
|
export default function (socket: TSocket, io: Server) {
|
||||||
socket.on('gm:object:list', async (data: any, callback: (response: Object[]) => void) => {
|
socket.on('gm:object:list', async (data: any, callback: (response: Object[]) => void) => {
|
||||||
const character = CharacterManager.getCharacterFromSocket(socket);
|
const character = await characterRepository.getById(socket.characterId as number);
|
||||||
if (character?.role !== 'gm') {
|
if (!character) return callback([])
|
||||||
console.log(`---Character #${character?.id} is not a game master.`)
|
|
||||||
return
|
if (character.role !== 'gm') {
|
||||||
|
return callback([])
|
||||||
}
|
}
|
||||||
|
|
||||||
// get all objects
|
// get all objects
|
||||||
|
@ -4,6 +4,7 @@ import path from 'path'
|
|||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import prisma from '../../../../utilities/prisma'
|
import prisma from '../../../../utilities/prisma'
|
||||||
import CharacterManager from '../../../../managers/characterManager'
|
import CharacterManager from '../../../../managers/characterManager'
|
||||||
|
import characterRepository from '../../../../repositories/characterRepository'
|
||||||
|
|
||||||
interface IPayload {
|
interface IPayload {
|
||||||
object: string
|
object: string
|
||||||
@ -16,9 +17,11 @@ interface IPayload {
|
|||||||
*/
|
*/
|
||||||
export default function (socket: TSocket, io: Server) {
|
export default function (socket: TSocket, io: Server) {
|
||||||
socket.on('gm:object:remove', async (data: IPayload, callback: (response: boolean) => void) => {
|
socket.on('gm:object:remove', async (data: IPayload, callback: (response: boolean) => void) => {
|
||||||
const character = CharacterManager.getCharacterFromSocket(socket);
|
const character = await characterRepository.getById(socket.characterId as number);
|
||||||
if (character?.role !== 'gm') {
|
if (!character) return callback(false)
|
||||||
return
|
|
||||||
|
if (character.role !== 'gm') {
|
||||||
|
return callback(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -2,6 +2,7 @@ import { Server } from 'socket.io'
|
|||||||
import { TSocket } from '../../../../utilities/types'
|
import { TSocket } from '../../../../utilities/types'
|
||||||
import prisma from '../../../../utilities/prisma'
|
import prisma from '../../../../utilities/prisma'
|
||||||
import CharacterManager from '../../../../managers/characterManager'
|
import CharacterManager from '../../../../managers/characterManager'
|
||||||
|
import characterRepository from '../../../../repositories/characterRepository'
|
||||||
|
|
||||||
type Payload = {
|
type Payload = {
|
||||||
id: string
|
id: string
|
||||||
@ -22,9 +23,11 @@ type Payload = {
|
|||||||
*/
|
*/
|
||||||
export default function (socket: TSocket, io: Server) {
|
export default function (socket: TSocket, io: Server) {
|
||||||
socket.on('gm:object:update', async (data: Payload, callback: (success: boolean) => void) => {
|
socket.on('gm:object:update', async (data: Payload, callback: (success: boolean) => void) => {
|
||||||
const character = CharacterManager.getCharacterFromSocket(socket);
|
const character = await characterRepository.getById(socket.characterId as number);
|
||||||
if (character?.role !== 'gm') {
|
if (!character) return callback(false)
|
||||||
return
|
|
||||||
|
if (character.role !== 'gm') {
|
||||||
|
return callback(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -7,6 +7,7 @@ import prisma from '../../../../utilities/prisma'
|
|||||||
import sharp from 'sharp'
|
import sharp from 'sharp'
|
||||||
import logger from '../../../../utilities/logger'
|
import logger from '../../../../utilities/logger'
|
||||||
import CharacterManager from '../../../../managers/characterManager'
|
import CharacterManager from '../../../../managers/characterManager'
|
||||||
|
import characterRepository from '../../../../repositories/characterRepository'
|
||||||
|
|
||||||
interface IObjectData {
|
interface IObjectData {
|
||||||
[key: string]: Buffer
|
[key: string]: Buffer
|
||||||
@ -24,12 +25,12 @@ export default class ObjectUploadEvent {
|
|||||||
|
|
||||||
private async handleObjectUpload(data: IObjectData, callback: (response: boolean) => void): Promise<void> {
|
private async handleObjectUpload(data: IObjectData, callback: (response: boolean) => void): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const character = CharacterManager.getCharacterFromSocket(this.socket);
|
const character = await characterRepository.getById(this.socket.characterId as number);
|
||||||
if (character?.role !== 'gm') {
|
if (!character) return callback(false)
|
||||||
callback(false)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (character.role !== 'gm') {
|
||||||
|
return callback(false)
|
||||||
|
}
|
||||||
const public_folder = path.join(process.cwd(), 'public', 'objects')
|
const public_folder = path.join(process.cwd(), 'public', 'objects')
|
||||||
|
|
||||||
// Ensure the folder exists
|
// Ensure the folder exists
|
||||||
|
@ -4,6 +4,7 @@ import path from 'path'
|
|||||||
import fs from 'fs/promises'
|
import fs from 'fs/promises'
|
||||||
import prisma from '../../../../utilities/prisma'
|
import prisma from '../../../../utilities/prisma'
|
||||||
import CharacterManager from '../../../../managers/characterManager'
|
import CharacterManager from '../../../../managers/characterManager'
|
||||||
|
import characterRepository from '../../../../repositories/characterRepository'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle game master new sprite event
|
* Handle game master new sprite event
|
||||||
@ -13,13 +14,11 @@ import CharacterManager from '../../../../managers/characterManager'
|
|||||||
export default function (socket: TSocket, io: Server) {
|
export default function (socket: TSocket, io: Server) {
|
||||||
socket.on('gm:sprite:create', async (data: undefined, callback: (response: boolean) => void) => {
|
socket.on('gm:sprite:create', async (data: undefined, callback: (response: boolean) => void) => {
|
||||||
try {
|
try {
|
||||||
if (!socket.characterId) return
|
const character = await characterRepository.getById(socket.characterId as number);
|
||||||
const character = CharacterManager.getCharacterFromSocket(socket);
|
if (!character) return callback(false)
|
||||||
if(!character) return
|
|
||||||
|
|
||||||
if (character.role !== 'gm') {
|
if (character.role !== 'gm') {
|
||||||
callback(false)
|
return callback(false)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const public_folder = path.join(process.cwd(), 'public', 'sprites')
|
const public_folder = path.join(process.cwd(), 'public', 'sprites')
|
||||||
|
@ -27,8 +27,7 @@ export default class GMSpriteDeleteEvent {
|
|||||||
private async handleSpriteDelete(data: Payload, callback: (response: boolean) => void): Promise<void> {
|
private async handleSpriteDelete(data: Payload, callback: (response: boolean) => void): Promise<void> {
|
||||||
const character = CharacterManager.getCharacterFromSocket(this.socket);
|
const character = CharacterManager.getCharacterFromSocket(this.socket);
|
||||||
if (character?.role !== 'gm') {
|
if (character?.role !== 'gm') {
|
||||||
callback(false)
|
return callback(false)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -3,6 +3,7 @@ import { TSocket } from '../../../../utilities/types'
|
|||||||
import { Sprite } from '@prisma/client'
|
import { Sprite } from '@prisma/client'
|
||||||
import SpriteRepository from '../../../../repositories/spriteRepository'
|
import SpriteRepository from '../../../../repositories/spriteRepository'
|
||||||
import CharacterManager from '../../../../managers/characterManager'
|
import CharacterManager from '../../../../managers/characterManager'
|
||||||
|
import characterRepository from '../../../../repositories/characterRepository'
|
||||||
|
|
||||||
interface IPayload {}
|
interface IPayload {}
|
||||||
|
|
||||||
@ -13,10 +14,11 @@ interface IPayload {}
|
|||||||
*/
|
*/
|
||||||
export default function (socket: TSocket, io: Server) {
|
export default function (socket: TSocket, io: Server) {
|
||||||
socket.on('gm:sprite:list', async (data: any, callback: (response: Sprite[]) => void) => {
|
socket.on('gm:sprite:list', async (data: any, callback: (response: Sprite[]) => void) => {
|
||||||
const character = CharacterManager.getCharacterFromSocket(socket);
|
const character = await characterRepository.getById(socket.characterId as number);
|
||||||
if (character?.role !== 'gm') {
|
if (!character) return callback([])
|
||||||
console.log(`---Character #${character?.id} is not a game master.`)
|
|
||||||
return
|
if (character.role !== 'gm') {
|
||||||
|
return callback([])
|
||||||
}
|
}
|
||||||
|
|
||||||
// get all sprites
|
// get all sprites
|
||||||
|
@ -31,8 +31,7 @@ export default function (socket: TSocket, io: Server) {
|
|||||||
socket.on('gm:sprite:update', async (data: Payload, callback: (success: boolean) => void) => {
|
socket.on('gm:sprite:update', async (data: Payload, callback: (success: boolean) => void) => {
|
||||||
const character = CharacterManager.getCharacterFromSocket(socket);
|
const character = CharacterManager.getCharacterFromSocket(socket);
|
||||||
if (character?.role !== 'gm') {
|
if (character?.role !== 'gm') {
|
||||||
callback(false)
|
return callback(false)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -5,6 +5,7 @@ import { TSocket } from '../../../../utilities/types'
|
|||||||
import prisma from '../../../../utilities/prisma'
|
import prisma from '../../../../utilities/prisma'
|
||||||
import logger from '../../../../utilities/logger'
|
import logger from '../../../../utilities/logger'
|
||||||
import CharacterManager from '../../../../managers/characterManager'
|
import CharacterManager from '../../../../managers/characterManager'
|
||||||
|
import characterRepository from '../../../../repositories/characterRepository'
|
||||||
|
|
||||||
type Payload = {
|
type Payload = {
|
||||||
id: string
|
id: string
|
||||||
@ -25,9 +26,10 @@ export default class GMTileDeleteEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async handleTileDelete(data: Payload, callback: (response: boolean) => void): Promise<void> {
|
private async handleTileDelete(data: Payload, callback: (response: boolean) => void): Promise<void> {
|
||||||
const character = CharacterManager.getCharacterFromSocket(this.socket);
|
const character = await characterRepository.getById(this.socket.characterId as number);
|
||||||
if (character?.role !== 'gm') {
|
if (!character) return callback(false)
|
||||||
callback(false)
|
|
||||||
|
if (character.role !== 'gm') {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ import { TSocket } from '../../../../utilities/types'
|
|||||||
import { Tile } from '@prisma/client'
|
import { Tile } from '@prisma/client'
|
||||||
import TileRepository from '../../../../repositories/tileRepository'
|
import TileRepository from '../../../../repositories/tileRepository'
|
||||||
import CharacterManager from '../../../../managers/characterManager'
|
import CharacterManager from '../../../../managers/characterManager'
|
||||||
|
import characterRepository from '../../../../repositories/characterRepository'
|
||||||
|
|
||||||
interface IPayload {}
|
interface IPayload {}
|
||||||
|
|
||||||
@ -13,9 +14,10 @@ interface IPayload {}
|
|||||||
*/
|
*/
|
||||||
export default function (socket: TSocket, io: Server) {
|
export default function (socket: TSocket, io: Server) {
|
||||||
socket.on('gm:tile:list', async (data: any, callback: (response: Tile[]) => void) => {
|
socket.on('gm:tile:list', async (data: any, callback: (response: Tile[]) => void) => {
|
||||||
const character = CharacterManager.getCharacterFromSocket(socket);
|
const character = await characterRepository.getById(socket.characterId as number);
|
||||||
if (character?.role !== 'gm') {
|
if (!character) return
|
||||||
console.log(`---Character #${character?.id} is not a game master.`)
|
|
||||||
|
if (character.role !== 'gm') {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ import { Server } from 'socket.io'
|
|||||||
import { TSocket } from '../../../../utilities/types'
|
import { TSocket } from '../../../../utilities/types'
|
||||||
import prisma from '../../../../utilities/prisma'
|
import prisma from '../../../../utilities/prisma'
|
||||||
import CharacterManager from '../../../../managers/characterManager'
|
import CharacterManager from '../../../../managers/characterManager'
|
||||||
|
import characterRepository from '../../../../repositories/characterRepository'
|
||||||
|
|
||||||
type Payload = {
|
type Payload = {
|
||||||
id: string
|
id: string
|
||||||
@ -16,8 +17,10 @@ type Payload = {
|
|||||||
*/
|
*/
|
||||||
export default function (socket: TSocket, io: Server) {
|
export default function (socket: TSocket, io: Server) {
|
||||||
socket.on('gm:tile:update', async (data: Payload, callback: (success: boolean) => void) => {
|
socket.on('gm:tile:update', async (data: Payload, callback: (success: boolean) => void) => {
|
||||||
const character = CharacterManager.getCharacterFromSocket(socket);
|
const character = await characterRepository.getById(socket.characterId as number);
|
||||||
if (character?.role !== 'gm') {
|
if (!character) return callback(false)
|
||||||
|
|
||||||
|
if (character.role !== 'gm') {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,8 @@ import path from 'path'
|
|||||||
import fs from 'fs/promises'
|
import fs from 'fs/promises'
|
||||||
import prisma from '../../../../utilities/prisma'
|
import prisma from '../../../../utilities/prisma'
|
||||||
import CharacterManager from '../../../../managers/characterManager'
|
import CharacterManager from '../../../../managers/characterManager'
|
||||||
|
import characterRepository from '../../../../repositories/characterRepository'
|
||||||
|
import logger from '../../../../utilities/logger'
|
||||||
|
|
||||||
interface ITileData {
|
interface ITileData {
|
||||||
[key: string]: Buffer
|
[key: string]: Buffer
|
||||||
@ -18,9 +20,10 @@ interface ITileData {
|
|||||||
export default function (socket: TSocket, io: Server) {
|
export default function (socket: TSocket, io: Server) {
|
||||||
socket.on('gm:tile:upload', async (data: ITileData, callback: (response: boolean) => void) => {
|
socket.on('gm:tile:upload', async (data: ITileData, callback: (response: boolean) => void) => {
|
||||||
try {
|
try {
|
||||||
const character = CharacterManager.getCharacterFromSocket(socket);
|
const character = await characterRepository.getById(socket.characterId as number);
|
||||||
if (character?.role !== 'gm') {
|
if (!character) return callback(false)
|
||||||
callback(false)
|
|
||||||
|
if (character.role !== 'gm') {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,8 @@ import ZoneRepository from '../../../repositories/zoneRepository'
|
|||||||
import { Zone } from '@prisma/client'
|
import { Zone } from '@prisma/client'
|
||||||
import prisma from '../../../utilities/prisma'
|
import prisma from '../../../utilities/prisma'
|
||||||
import CharacterManager from '../../../managers/characterManager'
|
import CharacterManager from '../../../managers/characterManager'
|
||||||
|
import characterRepository from '../../../repositories/characterRepository'
|
||||||
|
import logger from '../../../utilities/logger'
|
||||||
|
|
||||||
type Payload = {
|
type Payload = {
|
||||||
name: string
|
name: string
|
||||||
@ -18,13 +20,16 @@ type Payload = {
|
|||||||
*/
|
*/
|
||||||
export default function (socket: TSocket, io: Server) {
|
export default function (socket: TSocket, io: Server) {
|
||||||
socket.on('gm:zone_editor:zone:create', async (data: Payload, callback: (response: Zone[]) => void) => {
|
socket.on('gm:zone_editor:zone:create', async (data: Payload, callback: (response: Zone[]) => void) => {
|
||||||
const character = CharacterManager.getCharacterFromSocket(socket);
|
const character = await characterRepository.getById(socket.characterId as number);
|
||||||
if (character?.role !== 'gm') {
|
if (!character) return
|
||||||
console.log(`---Character #${character?.id} is not a game master.`)
|
|
||||||
|
if (character.role !== 'gm') {
|
||||||
|
logger.info(`User ${character.id} tried to create zone but is not a game master.`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`---GM ${character?.id} has created a new zone via zone editor.`)
|
logger.info(`User ${character.id} has created a new zone via zone editor.`)
|
||||||
|
|
||||||
let zoneList: Zone[] = []
|
let zoneList: Zone[] = []
|
||||||
try {
|
try {
|
||||||
const zone = await prisma.zone.create({
|
const zone = await prisma.zone.create({
|
||||||
|
@ -3,6 +3,8 @@ import { TSocket } from '../../../utilities/types'
|
|||||||
import ZoneRepository from '../../../repositories/zoneRepository'
|
import ZoneRepository from '../../../repositories/zoneRepository'
|
||||||
import prisma from '../../../utilities/prisma'
|
import prisma from '../../../utilities/prisma'
|
||||||
import CharacterManager from '../../../managers/characterManager'
|
import CharacterManager from '../../../managers/characterManager'
|
||||||
|
import characterRepository from '../../../repositories/characterRepository'
|
||||||
|
import logger from '../../../utilities/logger'
|
||||||
|
|
||||||
type Payload = {
|
type Payload = {
|
||||||
zoneId: number
|
zoneId: number
|
||||||
@ -15,14 +17,15 @@ type Payload = {
|
|||||||
*/
|
*/
|
||||||
export default function (socket: TSocket, io: Server) {
|
export default function (socket: TSocket, io: Server) {
|
||||||
socket.on('gm:zone_editor:zone:delete', async (data: Payload, callback: (response: boolean) => void) => {
|
socket.on('gm:zone_editor:zone:delete', async (data: Payload, callback: (response: boolean) => void) => {
|
||||||
const character = CharacterManager.getCharacterFromSocket(socket);
|
const character = await characterRepository.getById(socket.characterId as number);
|
||||||
|
if (!character) return
|
||||||
if (character?.role !== 'gm') {
|
|
||||||
console.log(`---Character #${character?.id} is not a game master.`)
|
if (character.role !== 'gm') {
|
||||||
|
logger.info(`User ${character.id} tried to delete zone but is not a game master.`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`---GM ${character?.id} has deleted a zone via zone editor.`)
|
logger.info(`User ${character.id} has deleted a zone via zone editor.`)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const zone = await ZoneRepository.getById(data.zoneId)
|
const zone = await ZoneRepository.getById(data.zoneId)
|
||||||
|
@ -3,6 +3,8 @@ import { TSocket } from '../../../utilities/types'
|
|||||||
import { Zone } from '@prisma/client'
|
import { Zone } from '@prisma/client'
|
||||||
import ZoneRepository from '../../../repositories/zoneRepository'
|
import ZoneRepository from '../../../repositories/zoneRepository'
|
||||||
import CharacterManager from '../../../managers/characterManager'
|
import CharacterManager from '../../../managers/characterManager'
|
||||||
|
import characterRepository from '../../../repositories/characterRepository'
|
||||||
|
import logger from '../../../utilities/logger'
|
||||||
|
|
||||||
interface IPayload {}
|
interface IPayload {}
|
||||||
|
|
||||||
@ -13,13 +15,15 @@ interface IPayload {}
|
|||||||
*/
|
*/
|
||||||
export default function (socket: TSocket, io: Server) {
|
export default function (socket: TSocket, io: Server) {
|
||||||
socket.on('gm:zone_editor:zone:list', async (data: IPayload, callback: (response: Zone[]) => void) => {
|
socket.on('gm:zone_editor:zone:list', async (data: IPayload, callback: (response: Zone[]) => void) => {
|
||||||
const character = CharacterManager.getCharacterFromSocket(socket);
|
const character = await characterRepository.getById(socket.characterId as number);
|
||||||
if (character?.role !== 'gm') {
|
if (!character) return
|
||||||
console.log(`---Character #${character?.id} is not a game master.`)
|
|
||||||
|
if (character.role !== 'gm') {
|
||||||
|
logger.info(`User ${character.id} tried to list zones but is not a game master.`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`---GM ${character?.id} has requested zone list via zone editor.`)
|
logger.info(`User ${character.id} has requested zone list via zone editor.`)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const zones = await ZoneRepository.getAll()
|
const zones = await ZoneRepository.getAll()
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
import { Server } from 'socket.io'
|
import { Server } from 'socket.io'
|
||||||
import { TSocket } from '../../../utilities/types'
|
import { TSocket } from '../../../utilities/types'
|
||||||
import ZoneRepository from '../../../repositories/zoneRepository'
|
import ZoneRepository from '../../../repositories/zoneRepository'
|
||||||
import { Zone } from '@prisma/client'
|
import { Character, Zone } from '@prisma/client'
|
||||||
import CharacterManager from '../../../managers/characterManager'
|
import CharacterManager from '../../../managers/characterManager'
|
||||||
|
import characterRepository from '../../../repositories/characterRepository'
|
||||||
|
import logger from '../../../utilities/logger'
|
||||||
|
|
||||||
interface IPayload {
|
interface IPayload {
|
||||||
zoneId: number
|
zoneId: number
|
||||||
@ -15,15 +17,18 @@ interface IPayload {
|
|||||||
*/
|
*/
|
||||||
export default function (socket: TSocket, io: Server) {
|
export default function (socket: TSocket, io: Server) {
|
||||||
socket.on('gm:zone_editor:zone:request', async (data: IPayload, callback: (response: Zone) => void) => {
|
socket.on('gm:zone_editor:zone:request', async (data: IPayload, callback: (response: Zone) => void) => {
|
||||||
const character = CharacterManager.getCharacterFromSocket(socket);
|
const character = await characterRepository.getById(socket.characterId as number);
|
||||||
if (character?.role !== 'gm') {
|
if (!character) return
|
||||||
|
|
||||||
|
if (character.role !== 'gm') {
|
||||||
|
logger.info(`User ${character!.id} tried to request zone but is not a game master.`)
|
||||||
return
|
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) {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,7 +36,7 @@ export default function (socket: TSocket, io: Server) {
|
|||||||
const zone = await ZoneRepository.getById(data.zoneId)
|
const zone = await ZoneRepository.getById(data.zoneId)
|
||||||
|
|
||||||
if (!zone) {
|
if (!zone) {
|
||||||
console.log(`---Zone not found.`)
|
logger.info(`User ${character.id} tried to request zone ${data.zoneId} but it does not exist.`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import prisma from '../../../utilities/prisma'
|
|||||||
import zoneManager from '../../../managers/zoneManager'
|
import zoneManager from '../../../managers/zoneManager'
|
||||||
import logger from '../../../utilities/logger'
|
import logger from '../../../utilities/logger'
|
||||||
import CharacterManager from '../../../managers/characterManager'
|
import CharacterManager from '../../../managers/characterManager'
|
||||||
|
import characterRepository from '../../../repositories/characterRepository'
|
||||||
|
|
||||||
interface IPayload {
|
interface IPayload {
|
||||||
zoneId: number
|
zoneId: number
|
||||||
@ -34,16 +35,18 @@ interface IPayload {
|
|||||||
*/
|
*/
|
||||||
export default function (socket: TSocket, io: Server) {
|
export default function (socket: TSocket, io: Server) {
|
||||||
socket.on('gm:zone_editor:zone:update', async (data: IPayload, callback: (response: Zone) => void) => {
|
socket.on('gm:zone_editor:zone:update', async (data: IPayload, callback: (response: Zone) => void) => {
|
||||||
const character = CharacterManager.getCharacterFromSocket(socket);
|
const character = await characterRepository.getById(socket.characterId as number);
|
||||||
if (character?.role !== 'gm') {
|
if (!character) return
|
||||||
logger.info(`User ${character?.id} tried to update zone but is not a game master.`)
|
|
||||||
|
if (character.role !== 'gm') {
|
||||||
|
logger.info(`User ${character.id} tried to update zone but is not a game master.`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info(`User ${character?.id} has updated zone via zone editor.`)
|
logger.info(`User ${character.id} has updated zone via zone editor.`)
|
||||||
|
|
||||||
if (!data.zoneId) {
|
if (!data.zoneId) {
|
||||||
logger.info(`User ${character?.id} tried to update zone but did not provide a zone id.`)
|
logger.info(`User ${character.id} tried to update zone but did not provide a zone id.`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +54,7 @@ export default function (socket: TSocket, io: Server) {
|
|||||||
let zone = await ZoneRepository.getById(data.zoneId)
|
let zone = await ZoneRepository.getById(data.zoneId)
|
||||||
|
|
||||||
if (!zone) {
|
if (!zone) {
|
||||||
logger.info(`User ${character?.id} tried to update zone ${data.zoneId} but it does not exist.`)
|
logger.info(`User ${character.id} tried to update zone ${data.zoneId} but it does not exist.`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +108,7 @@ export default function (socket: TSocket, io: Server) {
|
|||||||
zone = await ZoneRepository.getById(data.zoneId)
|
zone = await ZoneRepository.getById(data.zoneId)
|
||||||
|
|
||||||
if (!zone) {
|
if (!zone) {
|
||||||
logger.info(`User ${character?.id} tried to update zone ${data.zoneId} but it does not exist.`)
|
logger.info(`User ${character.id} tried to update zone ${data.zoneId} but it does not exist.`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import { TSocket } from '../utilities/types'
|
|||||||
|
|
||||||
export default function (socket: TSocket, io: Server) {
|
export default function (socket: TSocket, io: Server) {
|
||||||
socket.on('login', () => {
|
socket.on('login', () => {
|
||||||
// return user data
|
if (!socket.user) return
|
||||||
socket.emit('logged_in', { user: socket.user })
|
socket.emit('logged_in', { user: socket.user })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ class CharacterManager {
|
|||||||
this.characters = []
|
this.characters = []
|
||||||
}
|
}
|
||||||
|
|
||||||
public initCharacter(character: ExtendedCharacter) {
|
public initCharacter(character: ExtendedCharacter) {
|
||||||
this.characters = [...this.characters, character]
|
this.characters = [...this.characters, character]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,10 +26,6 @@ class CharacterManager {
|
|||||||
this.characters = this.characters.filter((x) => x.id !== character.id)
|
this.characters = this.characters.filter((x) => x.id !== character.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
public getCharacter(characterId: number) {
|
|
||||||
return this.characters.find((x) => x.id === characterId)
|
|
||||||
}
|
|
||||||
|
|
||||||
public getCharacterFromSocket(socket: TSocket) {
|
public getCharacterFromSocket(socket: TSocket) {
|
||||||
return this.characters.find((x) => x.id === socket?.characterId)
|
return this.characters.find((x) => x.id === socket?.characterId)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user