mirror of
https://github.com/MercuryWorkshop/adrift.git
synced 2025-05-12 13:50:01 -04:00
allow tracker to reject outdated servers
This commit is contained in:
parent
55dece7bc3
commit
c6f06d9724
5 changed files with 19 additions and 9 deletions
3
pnpm-lock.yaml
generated
3
pnpm-lock.yaml
generated
|
@ -480,6 +480,9 @@ importers:
|
|||
firebase-admin:
|
||||
specifier: ^11.10.1
|
||||
version: 11.10.1
|
||||
protocol:
|
||||
specifier: workspace:*
|
||||
version: link:../protocol
|
||||
tracker-list:
|
||||
specifier: workspace:*
|
||||
version: link:../tracker-list
|
||||
|
|
|
@ -17,10 +17,8 @@ https.get(
|
|||
|
||||
file.on("finish", () => {
|
||||
fs.chmodSync(`${dir}/${appname}`, "755");
|
||||
setTimeout(() => {
|
||||
// this timeout shouldn't be needed, but it is
|
||||
start();
|
||||
}, 2000);
|
||||
setTimeout(start, 2000);
|
||||
});
|
||||
})
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import { AdriftServer, connectTracker } from "./server";
|
|||
|
||||
import WebSocket from "isomorphic-ws";
|
||||
import { answerRtc, bufferToArrayBuffer } from "./rtc";
|
||||
import { PROTOCOL_VERSION } from "protocol";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
|
@ -50,9 +51,9 @@ app.ws("/dev-ws", (ws, _req) => {
|
|||
});
|
||||
|
||||
try {
|
||||
let tracker = new WebSocket("ws://localhost:17776/join");
|
||||
let tracker = new WebSocket(`ws://localhost:17776/join?protocol=${PROTOCOL_VERSION}`);
|
||||
tracker.onerror = console.error;
|
||||
connectTracker(tracker);
|
||||
} catch (_) {}
|
||||
} catch (_) { }
|
||||
|
||||
app.listen(3000, () => console.log("listening"));
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
"firebase": "^10.1.0",
|
||||
"firebase-admin": "^11.10.1",
|
||||
"tracker-list": "workspace:*",
|
||||
"protocol": "workspace:*",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^5.1.6",
|
||||
"uuid": "^9.0.0"
|
||||
|
|
|
@ -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(() => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue