mirror of
https://github.com/AlecM33/Werewolf.git
synced 2025-12-26 15:57:50 +01:00
some game joining logic
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { UserUtility } from "../modules/UserUtility.js";
|
||||
import { globals } from "../config/globals.js";
|
||||
|
||||
export const game = () => {
|
||||
let userId = UserUtility.validateAnonUserSignature();
|
||||
const splitUrl = window.location.href.split('/game/');
|
||||
const accessCode = splitUrl[1];
|
||||
if (/^[a-zA-Z0-9]+$/.test(accessCode) && accessCode.length === globals.ACCESS_CODE_LENGTH) {
|
||||
socket.emit(globals.COMMANDS.FETCH_GAME_STATE, accessCode, userId, function (gameState) {
|
||||
if (gameState === null) {
|
||||
window.location.replace('/not-found');
|
||||
} else {
|
||||
console.log(gameState);
|
||||
userId = gameState.id;
|
||||
UserUtility.setAnonymousUserId(userId);
|
||||
// processGameState(gameState, userId, socket);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
window.location.replace('/not-found');
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user