Add server status check

This commit is contained in:
olcxja 2026-04-30 21:05:30 +02:00
commit e908702025
3 changed files with 105 additions and 21 deletions

26
main.js
View file

@ -26,7 +26,7 @@ async function getNonce(username, key) {
let nonce;
let fetchRes = await (await fetch(`${url}/nextnonce?u=${username}`)).text();
console.log(key, fetchRes);
try {
nonce = await decryptString(fetchRes, key);
}
@ -229,20 +229,34 @@ async function fetchPostEnc(url, value) {
async function fetchAsync(url) {
let response = await fetch(url, {
method: "GET",
credentials: "omit",
headers: {
"secret": await encryptWithNonce(passwordHash, passwordHash, await getNonce(username, passwordHash))
}
credentials: "omit"
});
let data = await response.text();
return data;
}
async function fetchAsyncWAuth(url) {
let response = await fetch(url, {
method: "GET",
credentials: "omit",
headers: {
"secret": await encryptWithNonce(passwordHash, passwordHash, await getNonce(username, passwordHash))
}
});
let data = await response.text();
return data;
}
async function getServerInfo(host){
console.log(`${window.location.protocol}//${host}/_larpix/serverinfo`)
return JSON.parse(await fetchAsync(`${window.location.protocol}//${host}/_larpix/serverinfo`));
}
async function Auth(username, password) {
let passwordHash = await hashSHA3_512(password);
console.log(username, password, passwordHash);
let response = await fetch(`${url}/auth?u=${username}`, {
method: "GET",
credentials: "omit",