Skip to content

Commit

Permalink
add logger
Browse files Browse the repository at this point in the history
  • Loading branch information
nil1729 committed Sep 14, 2023
1 parent 71b6874 commit c1a9b6f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 8 additions & 1 deletion frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ const App = () => {
const joinGame = (e) => {
e.preventDefault();
socket.emit("join_game", game_id_input, (cb) => {
if (cb && cb.error) alert(cb.error);
if (cb && cb.error) {
console.error("join_game", { game_id: game_id_input, cb });
alert(cb.error);
}
});
history.push(`/play/${game_id_input}`);
set_game_id_input("");
Expand All @@ -55,6 +58,7 @@ const App = () => {
const joinOwnGame = (game_id) => {
socket.emit("join_game", game_id, (cb) => {
if (cb && cb.error) {
console.error("join_game", { game_id, cb });
alert(cb.error);
history.push("/");
}
Expand All @@ -65,6 +69,7 @@ const App = () => {
const startGame = (game_id) => {
socket.emit("start_game", game_id, (cb) => {
if (cb && cb.error) {
console.error("start_game", { game_id, cb });
alert(cb.error);
}
});
Expand All @@ -73,6 +78,7 @@ const App = () => {
const playGame = (game_id, board_index) => {
socket.emit("play_game", game_id, board_index, (cb) => {
if (cb && cb.error) {
console.error("play_game", { game_id, board_index, cb });
alert(cb.error);
}
});
Expand All @@ -81,6 +87,7 @@ const App = () => {
const restartGame = (game_id) => {
socket.emit("restart_game", game_id, (cb) => {
if (cb && cb.error) {
console.error("restart_game", { game_id, cb });
alert(cb.error);
}
});
Expand Down
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ io.on("connection", (socket) => {
(game_object && game_object.users[socket.id].user_type !== "player") ||
(game_object && game_object.playing)
) {
console.error("start_game", { game_id, board_index, cb });
cb({
error: "Invalid Command",
});
Expand All @@ -226,6 +227,7 @@ io.on("connection", (socket) => {
(game_object && !game_object.playing) ||
(game_object && game_object.board_state[board_index] !== 0)
) {
console.error("play_game", { game_id, board_index, cb });
cb({
error: "Invalid Command",
});
Expand Down Expand Up @@ -254,6 +256,7 @@ io.on("connection", (socket) => {
(game_object && game_object.users[socket.id].user_type !== "player") ||
(game_object && !game_object.playing && !game_object.winner)
) {
console.error("restart_game", { game_id, board_index, cb });
cb({
error: "Invalid Command",
});
Expand Down

0 comments on commit c1a9b6f

Please sign in to comment.