game transition lobby
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
const Logger = require('./logger.js');
|
||||
const Server = require('./webserver.js');
|
||||
|
||||
const Crypto = require("crypto");
|
||||
const Crypto = require('crypto');
|
||||
|
||||
/*
|
||||
USER OBJECT
|
||||
@@ -27,6 +27,8 @@ let OnlineUsers = [];
|
||||
|
||||
|
||||
// TODO: This won't scale very well lol
|
||||
// FIXME: There is a potential bug where the username will be free
|
||||
// during gametransition intents
|
||||
function CheckUsernameAvailability(username)
|
||||
{
|
||||
// un-reserve username if original owner has disconnected
|
||||
|
||||
@@ -74,7 +74,8 @@ function IsLobbyReady(lobbyuid)
|
||||
if (!Lobbies[lobbyuid]) return false;
|
||||
// only support 2-4 players
|
||||
// https://en.wikipedia.org/wiki/Scrabble
|
||||
if (Lobbies[lobbyuid].players.length <= 1) return false;
|
||||
// TODO: ADD THIS BACK - REMOVED FOR TESTING
|
||||
// if (Lobbies[lobbyuid].players.length <= 1) return false;
|
||||
if (Lobbies[lobbyuid].players.length > 4) return false;
|
||||
|
||||
return Lobbies[lobbyuid].players.every(e => e.ready);
|
||||
|
||||
@@ -24,6 +24,8 @@ let io = {};
|
||||
* sort of communication they will be recieving
|
||||
*/
|
||||
|
||||
// TODO: stop trusting the users UID, lookup with their connection ID
|
||||
|
||||
function init()
|
||||
{
|
||||
io = require('socket.io')(WebServer.Server);
|
||||
@@ -95,6 +97,7 @@ function ClientIdentify(socket, args)
|
||||
if (status === true)
|
||||
{
|
||||
socket.emit('identify-success', {connected: true, user: user});
|
||||
Game.Registrar.ChangeUserIntent(user.uid, intent);
|
||||
return;
|
||||
}
|
||||
else if (status === 'error-taken-user-connection')
|
||||
@@ -110,9 +113,13 @@ function ClientIdentify(socket, args)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: add checks to all these functions
|
||||
function UpdateIntent(socket, args)
|
||||
{
|
||||
|
||||
const user = Game.Registrar.GetUserbyConnection(socket.id);
|
||||
|
||||
const intent = args.intent;
|
||||
Game.Registrar.ChangeUserIntent(user.uid, intent);
|
||||
}
|
||||
|
||||
|
||||
@@ -285,7 +292,23 @@ function LobbyUserUnReady(socket, args)
|
||||
|
||||
function LobbyGameBegin(socket, args)
|
||||
{
|
||||
|
||||
const user = Game.Registrar.GetUserbyConnection(socket.id);
|
||||
const lobby = Game.Lobbies.GetLobbyByUserUID(user.uid);
|
||||
// TODO: Maybe only the owner of the lobby should be able to start the game
|
||||
|
||||
// Tells all other clients in the lobby to change intent to transition
|
||||
// the clients don't need to request the server change their intent
|
||||
// except the host that started the transition
|
||||
for (const user of lobby.players)
|
||||
{
|
||||
Game.Registrar.ChangeUserIntent(user.uid, 'GAMETRANSITION');
|
||||
}
|
||||
for (const user of lobby.spectators)
|
||||
{
|
||||
Game.Registrar.ChangeUserIntent(user.uid, 'GAMETRANSITION');
|
||||
}
|
||||
|
||||
io.to(lobby.uid).emit('request-intent-change', { intent: 'GAMETRANSITION', lobby: lobby });
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user