it is done.

This commit is contained in:
Holly Stubbs 2024-04-26 10:21:27 +01:00
parent f85bd3fcb8
commit cc20ddfd2a
Signed by: tgpholly
GPG key ID: B8583C4B7D18119E
4 changed files with 72 additions and 9 deletions

View file

@ -35,7 +35,9 @@ if (!window.TE_ACTIVE) {
(function() { (function() {
'use strict'; '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) { if (!continueRunningScript) {
return; return;
@ -256,14 +258,16 @@ kbd {
} }
}, 1000); }, 1000);
/*fetch(`https://git.eusv.net/tgpholly/t00-multiuser/raw/branch/master/client/Terminal-00-Multiuser.user.js?${Date.now()}`).then(res => { fetch(`http://localhost:39194/api/version`, { method: "post" }).then(response => {
res.text(text => { console.log("hi");
if (text.includes("@version")) { response.text().then(versionNumberRaw => {
const version = file.split("@version")[1].split("\n")[0].trim().split(".").join(""); const versionNumber = parseInt(versionNumberRaw);
if () 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(); const keepAlivePacket = createWriter(Endian.LE, 1).writeByte(MessageType.KeepAlive).toBuffer();
@ -602,6 +606,37 @@ kbd {
document.body.appendChild(bg); 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 = `<a class="mplink" href="https://git.eusv.net/tgpholly/t00-multiuser/raw/branch/master/client/Terminal-00-Multiuser.user.js?${Date.now()}">Please click here to update to the latest version.</a><br>This takes less than a few seconds to do and ensures you can continue to use MultiProbe.<br><br>Current Version: ${USERSCRIPT_VERSION_RAW}<br>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() { function createFirstTimeDialog() {
if (localStorage["mpshowfirsttime"] && localStorage["mpshowfirsttime"] === "false") { if (localStorage["mpshowfirsttime"] && localStorage["mpshowfirsttime"] === "false") {
return; return;

View file

@ -8,6 +8,7 @@
"length": 64, "length": 64,
"secret": "changeme" "secret": "changeme"
}, },
"githost": "localhost:3000",
"database": { "database": {
"address": "localhost", "address": "localhost",
"port": 3306, "port": 3306,

View file

@ -274,6 +274,8 @@ fastify.post("/party/join", async (req, res) => {
// API // API
fastify.post("/api/login", async (req, res) => { fastify.post("/api/login", async (req, res) => {
res.header("access-control-allow-origin", "*");
const data = req.body as UsernameData; const data = req.body as UsernameData;
if (typeof(data.username) !== "string" || typeof(data.password) !== "string" || data.username.length > 32 || data.password.length < 8) { 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"); 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"); 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 // Websocket stuff
const websocketServer = new WebSocketServer({ const websocketServer = new WebSocketServer({
@ -446,9 +472,9 @@ websocketServer.on("connection", (socket) => {
return; return;
} }
if ((performance.now() - user.lastPingReset) >= 1000) { if ((Date.now() - user.lastPingReset) >= 1000) {
user.allowedPings = 10; user.allowedPings = 10;
user.lastPingReset = performance.now(); user.lastPingReset = Date.now();
} }
if (user.allowedPings > 0) { if (user.allowedPings > 0) {

View file

@ -7,6 +7,7 @@ export default class Config {
public static ports:ConfigPorts = config.ports; public static ports:ConfigPorts = config.ports;
public static session:ConfigSession = config.session; public static session:ConfigSession = config.session;
public static githost:string = config.githost;
public static database:ConfigDatabase = config.database; public static database:ConfigDatabase = config.database;
} }