Refactor 4 with bugfixes

This commit is contained in:
2026-03-04 03:56:23 +01:00
parent be91b6dfe8
commit 0ed9ca93d3
51 changed files with 1552 additions and 996 deletions

View File

@@ -0,0 +1,37 @@
import { connectedUsers } from './state';
interface WsMessage {
[key: string]: unknown;
type: string;
}
export function broadcastToServer(serverId: string, message: WsMessage, excludeOderId?: string): void {
console.log(`Broadcasting to server ${serverId}, excluding ${excludeOderId}:`, message.type);
connectedUsers.forEach((user) => {
if (user.serverIds.has(serverId) && user.oderId !== excludeOderId) {
console.log(` -> Sending to ${user.displayName} (${user.oderId})`);
user.ws.send(JSON.stringify(message));
}
});
}
export function notifyServerOwner(ownerId: string, message: WsMessage): void {
const owner = findUserByOderId(ownerId);
if (owner) {
owner.ws.send(JSON.stringify(message));
}
}
export function notifyUser(oderId: string, message: WsMessage): void {
const user = findUserByOderId(oderId);
if (user) {
user.ws.send(JSON.stringify(message));
}
}
export function findUserByOderId(oderId: string) {
return Array.from(connectedUsers.values()).find(user => user.oderId === oderId);
}