forked from noxious/server
42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import { Server } from "socket.io";
|
|
import {TSocket} from "../../../utilities/Types";
|
|
import {writeFile} from "node:fs";
|
|
import {randomUUID} from "node:crypto";
|
|
import path from "path";
|
|
import fs from "fs";
|
|
import ObjectRepository from '../../../repositories/ObjectRepository'
|
|
|
|
interface IPayload {
|
|
object: string;
|
|
}
|
|
|
|
/**
|
|
* Handle game master remove object event
|
|
* @param socket
|
|
* @param io
|
|
*/
|
|
export default function (socket: TSocket, io: Server) {
|
|
socket.on('gm:object:remove', async (data: IPayload, callback: (response: boolean) => void) => {
|
|
|
|
if (socket.character?.role !== 'gm') {
|
|
return;
|
|
}
|
|
|
|
await ObjectRepository.delete(data.object);
|
|
|
|
// get root path
|
|
const public_folder = path.join(process.cwd(), 'public', 'objects');
|
|
|
|
// remove the tile from the disk
|
|
const finalFilePath = path.join(public_folder, data.object);
|
|
fs.unlink(finalFilePath, (err) => {
|
|
if (err) {
|
|
console.log(err);
|
|
callback(false);
|
|
return;
|
|
}
|
|
|
|
callback(true);
|
|
});
|
|
});
|
|
} |