move to public repo

This commit is contained in:
Nathaniel Tampus
2023-01-03 15:47:30 +08:00
commit 17ce3cf4c4
58 changed files with 2430 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
import type { Socket } from "socket.io";
import { io } from "../server";
import { joinLobby, leaveLobby, getLatestGame, sendMove, joinAsPlayer, chat } from "./game.socket";
const socketConnect = (socket: Socket) => {
const req = socket.request;
// re-analyze if this is necessary, or if io.use will handle logout
socket.use((__, next) => {
req.session.reload((err) => {
if (err) {
console.log("reload: disconnecting socket.");
console.log(err);
socket.disconnect();
} else {
next();
}
});
});
socket.on("disconnect", leaveLobby);
socket.on("joinLobby", joinLobby);
socket.on("leaveLobby", leaveLobby);
socket.on("getLatestGame", getLatestGame);
socket.on("sendMove", sendMove);
socket.on("joinAsPlayer", joinAsPlayer);
socket.on("chat", chat);
};
export const init = () => {
io.on("connection", socketConnect);
};