Merge branch 'main' of github.com:keyzox71/knl_meowscendence

This commit is contained in:
y-syo
2025-10-24 15:46:06 +02:00
10 changed files with 28 additions and 24 deletions

View File

@ -3,9 +3,13 @@ const score_url = process.env.SCORE_URL || "http://localhost:3003";
async function fetchSave(request, reply, userId, addMatch) {
let opponentName = '';
let opponentScore = 0;
if (request.body.opponent && request.body.opponentScore) {
if (request.body.opponent) {
opponentName = request.body.opponent;
}
if (request.body.opponentScore !== undefined) {
opponentScore = request.body.opponentScore;
} else {
opponentScore = 0;
}
const res = await fetch(score_url + "/", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ p1: userId, p2: opponentName, p1Score: request.body.myScore, p2Score: opponentScore }) });
if (!res.ok) {
@ -27,7 +31,7 @@ export async function pMatchHistory(request, reply, fastify, getUserInfo, addMat
if (request.body.game !== 'pong' && request.body.game !== 'tetris') {
return reply.code(400).send({ error: "Specified game does not exist" });
}
if (request.body.game === 'pong' && (!request.body.opponent || !request.body.opponentScore)) {
if (request.body.game === 'pong' && !request.body.opponent) {
return reply.code(400).send({ error: "Game requires two players" });
}
if (!getUserInfo.get(userId)) {
@ -41,7 +45,7 @@ export async function pMatchHistory(request, reply, fastify, getUserInfo, addMat
return reply.code(400).send({ error: "Do you have dementia ? You cannot have played a match against yourself gramps" });
}
}
await fetchSave(request, reply, userId, addMatch);
fetchSave(request, reply, userId, addMatch);
if (request.body.game === 'pong') {
if (request.body.myScore > request.body.opponentScore) {
incWinsPong.run(userId);

View File

@ -170,5 +170,5 @@ async function startMenuPP() {
}
}
setInterval(startMenuPP, 3000);
setInterval(startMenuPP, 5000);
startMenuPP();

View File

@ -93,7 +93,7 @@ export default class extends Aview {
// throw new Error("invalid response");
}
} catch (error) {
console.error(error);
console.log(error);
}
}
@ -186,7 +186,7 @@ export default class extends Aview {
}
catch (error)
{
console.error(error);
console.log(error);
document.getElementById("login-error-message").innerHTML = "error: server error, try again later...";
document.getElementById("login-error-message").classList.remove("hidden");
}

View File

@ -54,7 +54,7 @@ export default class extends Aview {
credentials: "include",
});
if (userdata_req.status == 404) {
console.error("invalid user");
console.log("invalid user");
return;
}
let userdata = await userdata_req.json();
@ -74,7 +74,7 @@ export default class extends Aview {
let main = document.getElementById("profile-pong-scorelist");
if (!main)
return console.error("what");
return console.log("what");
if (matches.matchHistory) {
for (let match of matches.matchHistory) {
@ -135,7 +135,7 @@ export default class extends Aview {
main = document.getElementById("profile-tetris-scorelist");
if (!main)
return console.error("what");
return console.log("what");
// don't read this shit for you mental health
if (matches.matchHistory) {

View File

@ -54,7 +54,7 @@ export default class extends Aview {
});
if (userdata_req.status == 404)
{
console.error("invalid user");
console.log("invalid user");
return ;
}
let userdata = await userdata_req.json();
@ -69,7 +69,7 @@ export default class extends Aview {
document.getElementById("profile-items").innerHTML = await getMainHTML();
requestAnimationFrame(() => {
document.getElementById("menu-logout").addEventListener("click", async () => {
document.getElementById("menu-logout")?.addEventListener("click", async () => {
let req = fetch(`${auth_api}/logout`, {
method: "GET",
credentials: "include",
@ -79,7 +79,7 @@ export default class extends Aview {
if (res.status === 200)
this.run();
else
console.error("logout failed");
console.log("logout failed");
});
});
});

View File

@ -91,7 +91,7 @@ export default class extends Aview {
}
catch (error) {
console.error(error);
console.log(error);
if (document.getElementById("login-error-message")) {
document.getElementById("login-error-message").innerHTML = "error: server error, try again later...";
document.getElementById("login-error-message")?.classList.remove("hidden");

View File

@ -74,7 +74,7 @@ export default class extends Aview {
credentials: "include",
});
if (userdata_req.status == 404) {
console.error("invalid user");
console.log("invalid user");
return;
}
let userdata = await userdata_req.json();
@ -106,16 +106,16 @@ export default class extends Aview {
if (delete_req.status == 200)
navigationManager("/");
else
console.error("xd"); // xd?????????????
console.log("xd"); // xd?????????????
});
const upload = document.getElementById("upload-file") as HTMLInputElement;
upload.addEventListener("change", () => {
const fileList: FileList | null = upload.files;
if (!fileList)
return console.error("empty");
return console.log("empty");
if (!fileList[0].type.startsWith("image/")) {
console.error("invalid file");
console.log("invalid file");
return;
}

View File

@ -307,18 +307,18 @@ export default class extends Aview {
) as HTMLCanvasElement | null;
this.canvas = el;
if (!this.canvas)
throw console.error("no canvas :c");
throw console.log("no canvas :c");
this.canvas.width = COLS * BLOCK;
this.canvas.height = ROWS * BLOCK;
const ctx = this.canvas.getContext("2d");
this.ctx = ctx;
if (!this.ctx)
throw console.error("no ctx D:");
throw console.log("no ctx D:");
this.holdCanvas = document.getElementById("hold") as HTMLCanvasElement;
this.queueCanvas = document.getElementById("queue") as HTMLCanvasElement;
if (!this.holdCanvas || !this.queueCanvas)
throw console.error("no canvas :c");
throw console.log("no canvas :c");
this.holdCtx = this.holdCanvas.getContext("2d");
this.queueCtx = this.queueCanvas.getContext("2d");
if (!this.holdCtx || !this.queueCtx)

View File

@ -332,18 +332,18 @@ export default class extends Aview {
) as HTMLCanvasElement | null;
this.canvas = el;
if (!this.canvas)
throw console.error("no canvas :c");
throw console.log("no canvas :c");
this.canvas.width = COLS * BLOCK;
this.canvas.height = ROWS * BLOCK;
const ctx = this.canvas.getContext("2d");
this.ctx = ctx;
if (!this.ctx)
throw console.error("no ctx D:");
throw console.log("no ctx D:");
this.holdCanvas = document.getElementById(canvasId + "-hold") as HTMLCanvasElement;
this.queueCanvas = document.getElementById(canvasId + "-queue") as HTMLCanvasElement;
if (!this.holdCanvas || !this.queueCanvas)
throw console.error("no canvas :c");
throw console.log("no canvas :c");
this.holdCtx = this.holdCanvas.getContext("2d");
this.queueCtx = this.queueCanvas.getContext("2d");
if (!this.holdCtx || !this.queueCtx)

View File

@ -77,6 +77,6 @@ async function start() {
}
start().catch((err) => {
console.error(err);
console.log(err);
process.exit(1);
});