1
0
forked from noxious/server
Files
noxious_server/src/app/events/gm/GmTileList.ts
2024-06-29 22:39:14 +02:00

42 lines
1.0 KiB
TypeScript

import { Server } from "socket.io";
import {TSocket} from "../../utilities/Types";
import fs from 'fs';
import path from "path";
interface IPayload {
}
/**
* Handle game master list tiles event
* @param socket
* @param io
*/
export default function (socket: TSocket, io: Server) {
socket.on('gm:tile:list', async (data: any, callback: (response: string[]) => void) => {
if (socket.character?.role !== 'gm') {
console.log(`---Character #${socket.character?.id} is not a game master.`);
return;
}
// get root path
const folder = path.join(process.cwd(), 'public', 'tiles');
// list the files in the folder
let tiles: string[] = [];
fs.readdir(folder, (err, files) => {
if (err) {
console.log(err);
return;
}
files.forEach(file => {
tiles.push(file);
});
// send over the list of tiles to the socket
callback(tiles);
});
});
}