Fix crashing issue
This commit is contained in:
parent
b330432541
commit
60f76a1594
|
@ -14,7 +14,6 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@prisma/client": "5.7.0",
|
"@prisma/client": "5.7.0",
|
||||||
"@t3-oss/env-core": "^0.6.1",
|
"@t3-oss/env-core": "^0.6.1",
|
||||||
"bun": "^1.0.0",
|
|
||||||
"bun-types": "^1.0.1",
|
"bun-types": "^1.0.1",
|
||||||
"commander": "^11.1.0",
|
"commander": "^11.1.0",
|
||||||
"date-holidays": "^3.21.5",
|
"date-holidays": "^3.21.5",
|
||||||
|
|
|
@ -11,7 +11,7 @@ import {
|
||||||
} from "../util/types";
|
} from "../util/types";
|
||||||
import { Socket } from "../ws/Socket";
|
import { Socket } from "../ws/Socket";
|
||||||
import { validateChannelSettings } from "./settings";
|
import { validateChannelSettings } from "./settings";
|
||||||
import { findSocketByPartID, socketsBySocketID } from "../ws/server";
|
import { findSocketByPartID, socketsBySocketID } from "../ws/Socket";
|
||||||
import Crown from "./Crown";
|
import Crown from "./Crown";
|
||||||
|
|
||||||
interface ChannelConfig {
|
interface ChannelConfig {
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
import dotenv from "dotenv";
|
|
||||||
import { createEnv } from "@t3-oss/env-core";
|
import { createEnv } from "@t3-oss/env-core";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
dotenv.config({
|
|
||||||
path: "./.env"
|
|
||||||
});
|
|
||||||
|
|
||||||
export const env = createEnv({
|
export const env = createEnv({
|
||||||
server: {
|
server: {
|
||||||
PORT: z.coerce.number(),
|
PORT: z.coerce.number(),
|
||||||
|
@ -14,8 +9,6 @@ export const env = createEnv({
|
||||||
ADMIN_PASS: z.string()
|
ADMIN_PASS: z.string()
|
||||||
},
|
},
|
||||||
isServer: true,
|
isServer: true,
|
||||||
clientPrefix: "",
|
|
||||||
client: {},
|
|
||||||
runtimeEnv: process.env
|
runtimeEnv: process.env
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@ import { eventGroups } from "./events";
|
||||||
import { Gateway } from "./Gateway";
|
import { Gateway } from "./Gateway";
|
||||||
import { channelList, Channel } from "../channel/Channel";
|
import { channelList, Channel } from "../channel/Channel";
|
||||||
import { ServerWebSocket } from "bun";
|
import { ServerWebSocket } from "bun";
|
||||||
import { socketsBySocketID } from "./server";
|
|
||||||
import { Logger } from "../util/Logger";
|
import { Logger } from "../util/Logger";
|
||||||
import { RateLimitConstructorList, RateLimitList } from "./ratelimit/config";
|
import { RateLimitConstructorList, RateLimitList } from "./ratelimit/config";
|
||||||
import { adminLimits } from "./ratelimit/limits/admin";
|
import { adminLimits } from "./ratelimit/limits/admin";
|
||||||
|
@ -372,3 +371,26 @@ export class Socket extends EventEmitter {
|
||||||
ch.playNotes(msg, this);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -4,35 +4,12 @@ import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { handleMessage } from "./message";
|
import { handleMessage } from "./message";
|
||||||
import { decoder } from "../util/helpers";
|
import { decoder } from "../util/helpers";
|
||||||
import { Socket } from "./Socket";
|
import { Socket, socketsBySocketID } from "./Socket";
|
||||||
import { serve, file } from "bun";
|
import { serve, file } from "bun";
|
||||||
import env from "../util/env";
|
import env from "../util/env";
|
||||||
|
|
||||||
const logger = new Logger("WebSocket Server");
|
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({
|
export const app = Bun.serve({
|
||||||
port: env.PORT,
|
port: env.PORT,
|
||||||
hostname: "0.0.0.0",
|
hostname: "0.0.0.0",
|
||||||
|
|
Loading…
Reference in New Issue