diff --git a/bun.lockb b/bun.lockb index 12f607a..dce4de8 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 55bf8e0..f1b5ee0 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/channel/Channel.ts b/src/channel/Channel.ts index 930da6f..fbd9c3f 100644 --- a/src/channel/Channel.ts +++ b/src/channel/Channel.ts @@ -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 { diff --git a/src/util/env.ts b/src/util/env.ts index ff2b12e..183d1aa 100644 --- a/src/util/env.ts +++ b/src/util/env.ts @@ -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 }); diff --git a/src/ws/Socket.ts b/src/ws/Socket.ts index 09e17b8..0cf57a5 100644 --- a/src/ws/Socket.ts +++ b/src/ws/Socket.ts @@ -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(); + +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; + } + } +} diff --git a/src/ws/server.ts b/src/ws/server.ts index f12d3c4..1fe877d 100644 --- a/src/ws/server.ts +++ b/src/ws/server.ts @@ -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(); - -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",