Fix crashing issue

This commit is contained in:
Hri7566 2024-01-22 03:16:47 -05:00
parent b330432541
commit 60f76a1594
6 changed files with 25 additions and 34 deletions

BIN
bun.lockb

Binary file not shown.

View File

@ -14,7 +14,6 @@
"dependencies": {
"@prisma/client": "5.7.0",
"@t3-oss/env-core": "^0.6.1",
"bun": "^1.0.0",
"bun-types": "^1.0.1",
"commander": "^11.1.0",
"date-holidays": "^3.21.5",

View File

@ -11,7 +11,7 @@ import {
} from "../util/types";
import { Socket } from "../ws/Socket";
import { validateChannelSettings } from "./settings";
import { findSocketByPartID, socketsBySocketID } from "../ws/server";
import { findSocketByPartID, socketsBySocketID } from "../ws/Socket";
import Crown from "./Crown";
interface ChannelConfig {

View File

@ -1,11 +1,6 @@
import dotenv from "dotenv";
import { createEnv } from "@t3-oss/env-core";
import { z } from "zod";
dotenv.config({
path: "./.env"
});
export const env = createEnv({
server: {
PORT: z.coerce.number(),
@ -14,8 +9,6 @@ export const env = createEnv({
ADMIN_PASS: z.string()
},
isServer: true,
clientPrefix: "",
client: {},
runtimeEnv: process.env
});

View File

@ -21,7 +21,6 @@ import { eventGroups } from "./events";
import { Gateway } from "./Gateway";
import { channelList, Channel } from "../channel/Channel";
import { ServerWebSocket } from "bun";
import { socketsBySocketID } from "./server";
import { Logger } from "../util/Logger";
import { RateLimitConstructorList, RateLimitList } from "./ratelimit/config";
import { adminLimits } from "./ratelimit/limits/admin";
@ -372,3 +371,26 @@ export class Socket extends EventEmitter {
ch.playNotes(msg, this);
}
}
export const socketsBySocketID = new Map<string, Socket>();
export function findSocketByPartID(id: string) {
for (const socket of socketsBySocketID.values()) {
if (socket.getParticipantID() == id) return socket;
}
}
export function findSocketByUserID(_id: string) {
for (const socket of socketsBySocketID.values()) {
// logger.debug("User ID:", socket.getUserID());
if (socket.getUserID() == _id) return socket;
}
}
export function findSocketByIP(ip: string) {
for (const socket of socketsBySocketID.values()) {
if (socket.getIP() == ip) {
return socket;
}
}
}

View File

@ -4,35 +4,12 @@ import fs from "fs";
import path from "path";
import { handleMessage } from "./message";
import { decoder } from "../util/helpers";
import { Socket } from "./Socket";
import { Socket, socketsBySocketID } from "./Socket";
import { serve, file } from "bun";
import env from "../util/env";
const logger = new Logger("WebSocket Server");
export const socketsBySocketID = new Map<string, Socket>();
export function findSocketByPartID(id: string) {
for (const socket of socketsBySocketID.values()) {
if (socket.getParticipantID() == id) return socket;
}
}
export function findSocketByUserID(_id: string) {
for (const socket of socketsBySocketID.values()) {
// logger.debug("User ID:", socket.getUserID());
if (socket.getUserID() == _id) return socket;
}
}
export function findSocketByIP(ip: string) {
for (const socket of socketsBySocketID.values()) {
if (socket.getIP() == ip) {
return socket;
}
}
}
export const app = Bun.serve({
port: env.PORT,
hostname: "0.0.0.0",