allow tracker to reject outdated servers

This commit is contained in:
CoolElectronics 2023-08-20 10:09:54 -04:00
parent 55dece7bc3
commit c6f06d9724
No known key found for this signature in database
GPG key ID: F63593D168636C50
5 changed files with 19 additions and 9 deletions

View file

@ -10,6 +10,8 @@ import { WebSocket } from "ws";
import { v4 as uuid } from "uuid";
import { PROTOCOL_VERSION } from "protocol";
dotenv.config();
let members: Record<string, WebSocket> = {};
@ -70,16 +72,21 @@ reff.on("value", snapshot => {
});
app.ws("/join", (ws, _req) => {
app.ws("/join", (ws, req) => {
let ver = new URL(`https://a/${req.url}`).searchParams.get("protocol");
if (ver != PROTOCOL_VERSION) {
ws.close();
}
let id = uuid();
console.log(_req.ip);
console.log(req.ip);
console.log(`ws connect of id ${id}`);
members[id] = ws;
ws.onclose = () => {
console.log(`${_req.ip} disconnected`);
console.log(`${req.ip} disconnected`);
delete members[id];
};
setInterval(() => {