Skip to content

Commit

Permalink
Merge pull request #88 from La-404-Devinci/dev
Browse files Browse the repository at this point in the history
🚑 Fix missing callback and handle missing email in placePixel
  • Loading branch information
Kan-A-Pesh authored Mar 28, 2024
2 parents 3eca559 + 058cd1e commit 2f84a06
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 33 deletions.
9 changes: 9 additions & 0 deletions backend/controllers/Canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@ class CanvasController {
* @param data The payload
*/
public static async placePixel(socket: SocketIO.Socket, [x, y, palette, callback]: [number, number, number, (timer: number) => void]) {
if (!callback) {
console.error("Missing callback");
return;
}

if (!socket.data.email) {
return callback(-1);
}

// Get the user
const user = await prisma.account.findFirst({
where: {
Expand Down
41 changes: 8 additions & 33 deletions backend/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,51 +66,26 @@ WSS.io.on("connection", (socket: Socket) => {
});

socket.on("auth", (...data) => {
try {
const [token, email] = data;
AccountController.authSocket(socket, [token, email]);
} catch (e) {
console.error("SCKT-ERR:", e);
console.log("SCKT-ERR: place-pixel email", socket.data.email);
}
const [token, email] = data;
AccountController.authSocket(socket, [token, email]);
});

socket.on("place-pixel", (...data) => {
try {
const [x, y, color, callback] = data;
CanvasController.placePixel(socket, [x, y, color, callback]);
} catch (e) {
console.error("SCKT-ERR:", e);
console.log("SCKT-ERR: place-pixel email", socket.data.email);
}
const [x, y, color, callback] = data;
CanvasController.placePixel(socket, [x, y, color, callback]);
});

socket.on("message", (...data) => {
try {
const [message, callback] = data;
ChatController.broadcastMessage(socket, [message, callback]);
} catch (e) {
console.error("SCKT-ERR:", e);
console.log("SCKT-ERR: place-pixel email", socket.data.email);
}
const [message, callback] = data;
ChatController.broadcastMessage(socket, [message, callback]);
});

socket.on("get-stats", () => {
try {
AccountController.getStats(socket);
} catch (e) {
console.error("SCKT-ERR:", e);
console.log("SCKT-ERR: place-pixel email", socket.data.email);
}
AccountController.getStats(socket);
});

socket.on("get-classement", () => {
try {
WSS.updateClassement(socket);
} catch (e) {
console.error("SCKT-ERR:", e);
console.log("SCKT-ERR: place-pixel email", socket.data.email);
}
WSS.updateClassement(socket);
});
} catch (e) {
socket.emit("error", "An error occurred");
Expand Down

0 comments on commit 2f84a06

Please sign in to comment.