diff --git a/client/Terminal-00-Multiuser.user.js b/client/Terminal-00-Multiuser.user.js index 6cee498..403f3c1 100644 --- a/client/Terminal-00-Multiuser.user.js +++ b/client/Terminal-00-Multiuser.user.js @@ -35,7 +35,9 @@ if (!window.TE_ACTIVE) { (function() { 'use strict'; - const USERSCRIPT_VERSION = "20240426.1"; + // Make sure to change the userscript version too!!!!!!!!!! + const USERSCRIPT_VERSION_RAW = "20240425.1"; + const USERSCRIPT_VERSION = parseInt(USERSCRIPT_VERSION_RAW.replace(".", "")); if (!continueRunningScript) { return; @@ -256,14 +258,16 @@ kbd { } }, 1000); - /*fetch(`https://git.eusv.net/tgpholly/t00-multiuser/raw/branch/master/client/Terminal-00-Multiuser.user.js?${Date.now()}`).then(res => { - res.text(text => { - if (text.includes("@version")) { - const version = file.split("@version")[1].split("\n")[0].trim().split(".").join(""); - if () + fetch(`http://localhost:39194/api/version`, { method: "post" }).then(response => { + console.log("hi"); + response.text().then(versionNumberRaw => { + const versionNumber = parseInt(versionNumberRaw); + if (versionNumber > USERSCRIPT_VERSION) { + // We're out of date >:( + createUpdateDialog(`${versionNumberRaw.slice(0, versionNumberRaw.length - 1)}.${versionNumberRaw.slice(-1)}`); } }); - });*/ + }); const keepAlivePacket = createWriter(Endian.LE, 1).writeByte(MessageType.KeepAlive).toBuffer(); @@ -602,6 +606,37 @@ kbd { document.body.appendChild(bg); } + function createUpdateDialog(versionNumber) { + const bg = document.createElement("div"); + windowContainer = bg; + bg.style = "z-index:1000000000;position:fixed;top:0px;left:0px;width:100%;height:100%;background-color:rgba(0,0,0,0.5)"; + const dialog = document.createElement("div"); + dialog.style = "position:absolute;top:50%;left:50%;min-width:15rem;background-color:#343434;padding:1rem;transform:translate(-50%,-50%);text-align:center;color:white"; + bg.appendChild(dialog); + const title = document.createElement("h4"); + title.innerText = "An update is available!"; + title.style.marginBottom = "0px"; + dialog.appendChild(title); + + const updateText = document.createElement("p"); + updateText.innerHTML = `Please click here to update to the latest version.
This takes less than a few seconds to do and ensures you can continue to use MultiProbe.

Current Version: ${USERSCRIPT_VERSION_RAW}
New Version: ${versionNumber}`; + dialog.appendChild(updateText); + + const buttons = document.createElement("div"); + buttons.style.marginTop = "1rem"; + + const gotIt = document.createElement("button"); + gotIt.onclick = () => { + bg.remove(); + } + gotIt.innerText = "Later"; + buttons.appendChild(gotIt); + + dialog.appendChild(buttons); + + document.body.appendChild(bg); + } + function createFirstTimeDialog() { if (localStorage["mpshowfirsttime"] && localStorage["mpshowfirsttime"] === "false") { return; diff --git a/server/config.example.json b/server/config.example.json index 51124d0..76642c6 100644 --- a/server/config.example.json +++ b/server/config.example.json @@ -8,6 +8,7 @@ "length": 64, "secret": "changeme" }, + "githost": "localhost:3000", "database": { "address": "localhost", "port": 3306, diff --git a/server/index.ts b/server/index.ts index a31117b..721aaaa 100644 --- a/server/index.ts +++ b/server/index.ts @@ -274,6 +274,8 @@ fastify.post("/party/join", async (req, res) => { // API fastify.post("/api/login", async (req, res) => { + res.header("access-control-allow-origin", "*"); + const data = req.body as UsernameData; if (typeof(data.username) !== "string" || typeof(data.password) !== "string" || data.username.length > 32 || data.password.length < 8) { return res.status(401).send("Username or Password incorrect"); @@ -291,6 +293,30 @@ fastify.post("/api/login", async (req, res) => { return res.status(401).send("Username or Password incorrect"); }); +let cachedVersion = ""; +let cacheExpiry = 0; +fastify.post("/api/version", async (req, res) => { + res.header("access-control-allow-origin", "*"); + + if (Date.now() < cacheExpiry) { + res.send(cachedVersion); + } else { + const response = await fetch(`http://${Config.githost}/tgpholly/t00-multiuser/raw/branch/master/client/Terminal-00-Multiuser.user.js?${Date.now()}`); + if (response.status === 200) { + const content = await response.text(); + if (content.includes("@version")) { + cachedVersion = content.split("@version")[1].split("\n")[0].trim().split(".").join(""); + cacheExpiry = Date.now() + 30000; + return res.send(cachedVersion); + } else { + return res.send("0"); + } + } else { + return res.send("0"); + } + } +}); + // Websocket stuff const websocketServer = new WebSocketServer({ @@ -446,9 +472,9 @@ websocketServer.on("connection", (socket) => { return; } - if ((performance.now() - user.lastPingReset) >= 1000) { + if ((Date.now() - user.lastPingReset) >= 1000) { user.allowedPings = 10; - user.lastPingReset = performance.now(); + user.lastPingReset = Date.now(); } if (user.allowedPings > 0) { diff --git a/server/objects/Config.ts b/server/objects/Config.ts index ebd5820..24d115f 100644 --- a/server/objects/Config.ts +++ b/server/objects/Config.ts @@ -7,6 +7,7 @@ export default class Config { public static ports:ConfigPorts = config.ports; public static session:ConfigSession = config.session; + public static githost:string = config.githost; public static database:ConfigDatabase = config.database; }