Added logic that allows socket events to exist in sub directories, moved said events for better DX, added logics for tile management (upload & read), started working on (zone) object logics too
This commit is contained in:
@ -12,6 +12,7 @@ import ZoneManager from "./app/ZoneManager";
|
||||
import UserManager from "./app/UserManager";
|
||||
import {Authentication} from "./app/middleware/Authentication";
|
||||
import CommandManager from "./app/CommandManager";
|
||||
import {Dirent} from "node:fs";
|
||||
|
||||
export class Server
|
||||
{
|
||||
@ -76,15 +77,26 @@ export class Server
|
||||
private async handleConnection(socket: TSocket) {
|
||||
const eventsPath = path.join(__dirname, 'app', 'events');
|
||||
try {
|
||||
const files: string[] = await fs.promises.readdir(eventsPath);
|
||||
for (const file of files) {
|
||||
const module = await import(path.join(eventsPath, file));
|
||||
module.default(socket, this.io);
|
||||
}
|
||||
await this.loadEventHandlers(eventsPath, socket);
|
||||
} catch (error: any) {
|
||||
throw new Error('[❌] Failed to load event handlers: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
private async loadEventHandlers(dir: string, socket: TSocket) {
|
||||
const files: Dirent[] = await fs.promises.readdir(dir, { withFileTypes: true });
|
||||
|
||||
for (const file of files) {
|
||||
const fullPath = path.join(dir, file.name);
|
||||
|
||||
if (file.isDirectory()) {
|
||||
await this.loadEventHandlers(fullPath, socket);
|
||||
} else if (file.isFile()) {
|
||||
const module = await import(fullPath);
|
||||
module.default(socket, this.io);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Start the server
|
||||
|
Reference in New Issue
Block a user