feat: remove iprooms, add rooms.txt

This commit is contained in:
2026-03-07 17:01:38 +01:00
parent c506108ca8
commit 952373bbee
4 changed files with 46 additions and 69 deletions

View File

@@ -1,16 +1,8 @@
import type { ServerWebSocket } from "bun";
import { callTicket, completeTicket, getCurrentTicket, getDisplayTickets, getLogEntries, getTicket, noShowTicket } from "./redis";
let IP_TO_ROOMS: Record<string, string> = {};
const iprooms = await Bun.file("./iprooms.csv").text();
const lines = iprooms.split("\n");
for (const line of lines.slice(1)) {
const [ip, room] = line.split(",");
if (ip && room) {
IP_TO_ROOMS[ip.trim()] = room.trim();
}
}
const roomstxt = await Bun.file("./rooms.txt").text();
const ROOMS = roomstxt.split("\n");
const MOTD = process.env.MOTD || "50;";
@@ -36,22 +28,7 @@ Bun.serve({
async message(ws, message) {
console.log("Received message:", message);
const data = JSON.parse(message.toString());
if (data.type === "hello") {}
else if (data.type === "my-room") {
console.log("Client requested room for IP:", ws.remoteAddress);
const room = IP_TO_ROOMS[ws.remoteAddress];
if (!room) {
return void ws.send(JSON.stringify({ type: "error", code: -1, message: "No room" }));
}
ws.send(JSON.stringify({ type: "my-room", room }) );
// } else if (data.type === "create-ticket") {
// const ticket = await getTicket(data.ticket);
// if(!ticket || ticket.status == "completed" || ticket.status == "no-show") {
// await createTicket(data.ticket);
// ws.send(JSON.stringify({ type: "create-ticket", status: "created", ticket, num: data.ticket }) );
// return;
// }
// ws.send(JSON.stringify({ type: "error", code: -2, message: "Ticket already exists and is not completed or no-show", ticket, num: data.ticket }));
if (data.type === "hello") {
} else if (data.type === "call-ticket") {
// const ticket = await getTicket(data.ticket);
// if(!ticket || ticket.status == "completed" || ticket.status == "no-show") {
@@ -115,6 +92,8 @@ Bun.serve({
console.log("Added display socket. Total:", displaySockets.length);
ws.send(JSON.stringify({ type: "display", tickets: await getDisplayTickets(), motd: MOTD }));
}
} else if (data.type == "rooms") {
ws.send(JSON.stringify({ type: "rooms", rooms: ROOMS }));
}
}, // a message is received
open(ws) {