forked from noxious/server
34 lines
811 B
TypeScript
34 lines
811 B
TypeScript
import { Server } from "socket.io";
|
|
import {TSocket} from "../../../utilities/Types";
|
|
import ObjectRepository from '../../../repositories/ObjectRepository'
|
|
import { Object } from '@prisma/client'
|
|
|
|
interface IPayload {
|
|
id: string;
|
|
name: string;
|
|
origin_x: number;
|
|
origin_y: number;
|
|
}
|
|
|
|
/**
|
|
* Handle game master object update event
|
|
* @param socket
|
|
* @param io
|
|
*/
|
|
export default function (socket: TSocket, io: Server) {
|
|
socket.on('gm:object:update', async (data: IPayload, callback: (success: boolean) => void) => {
|
|
|
|
if (socket.character?.role !== 'gm') {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const object = await ObjectRepository.update(data.id, data.name, data.origin_x, data.origin_y);
|
|
|
|
callback(true);
|
|
} catch (error) {
|
|
console.error(error);
|
|
callback(false);
|
|
}
|
|
});
|
|
} |