small clean
This commit is contained in:
parent
14b6443cef
commit
552d9bb4db
@ -27,16 +27,15 @@ export default function characterZoneLoad(socket: Socket, io: Server) {
|
||||
|
||||
socket.join(zone.name);
|
||||
|
||||
const characters = await io.in(zone.name).fetchSockets();
|
||||
const socketConnectionsInRoom = await io.in(zone.name).fetchSockets();
|
||||
const characters = socketConnectionsInRoom.filter(socket => socket.id !== socket.id);
|
||||
|
||||
// update to match with model Character
|
||||
|
||||
// send over zone and characters
|
||||
io.in(zone.name).to(socket.id).emit('character:zone:load', {
|
||||
zone: zone,
|
||||
characters: characters.map(socket => ({
|
||||
id: socket.id
|
||||
})),
|
||||
characters: characters,
|
||||
});
|
||||
});
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
import { Socket } from 'socket.io';
|
||||
import {Character, User} from "@prisma/client";
|
||||
|
||||
interface NQSocket extends Socket
|
||||
{
|
||||
user?: User,
|
||||
character?: Character
|
||||
}
|
6
src/app/interfaces/zoneCharacters.ts
Normal file
6
src/app/interfaces/zoneCharacters.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import {Character} from "@prisma/client";
|
||||
|
||||
interface zoneCharacters extends Character
|
||||
{
|
||||
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import express from 'express';
|
||||
import express, {Application} from 'express';
|
||||
import http from 'http';
|
||||
import cors from 'cors';
|
||||
import {Server as HttpServer, Socket} from 'socket.io';
|
||||
import {Server as SocketServer, Socket} from 'socket.io';
|
||||
import config from './app/utilities/config';
|
||||
import prisma from './app/utilities/prisma';
|
||||
import api from "./app/utilities/api";
|
||||
@ -11,9 +11,9 @@ import ZoneManager from "./app/ZoneManager";
|
||||
|
||||
export class Server
|
||||
{
|
||||
private readonly app: express.Application;
|
||||
private readonly app: Application;
|
||||
private readonly server: any;
|
||||
private readonly io: HttpServer;
|
||||
private readonly io: SocketServer;
|
||||
|
||||
/**
|
||||
* Creates an instance of GameServer.
|
||||
@ -24,7 +24,7 @@ export class Server
|
||||
this.app.use(express.json());
|
||||
this.app.use(express.urlencoded({ extended: true }));
|
||||
this.server = http.createServer(this.app)
|
||||
this.io = new HttpServer(this.server);
|
||||
this.io = new SocketServer(this.server);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,12 +70,16 @@ export class Server
|
||||
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 Promise.all(files.map(async (file) => {
|
||||
try {
|
||||
const module = await import(path.join(eventsPath, file));
|
||||
module.default(socket, this.io);
|
||||
} catch (error: any) {
|
||||
console.error(`[❌] Failed to load event handler ${file}: ${error.message}`);
|
||||
}
|
||||
}));
|
||||
} catch (error: any) {
|
||||
throw new Error('[❌] Failed to load event handlers: ' + error.message);
|
||||
throw new Error('[❌] Failed to read event handlers directory: ' + error.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user