Skip to content

Commit 23dacaa

Browse files
author
Kaizen Conroy
committed
create random name for lobby rooms
1 parent 6f6cf75 commit 23dacaa

File tree

5 files changed

+13
-3
lines changed

5 files changed

+13
-3
lines changed

app.js

+3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ app.use('/room', async function (req, res, next) {
5656
alert = alertMessage.CREATE_ALREADY_EXISTS;
5757
res.redirect('/');
5858
return;
59+
} else if (action == "create" && roomname.includes('lobbyroom')) {
60+
alert = alertMessage.CREATE_RESERVED;
61+
res.redirect('/');
5962
} else if (action == "join" && !exists) {
6063
alert = alertMessage.JOIN_DOES_NOT_EXIST;
6164
res.redirect('/');

public/display.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ socket.on('show-current-sidekick', (data)=>{
296296
setIdleClue("");
297297
if (data.username === username){
298298
showFormDisplay();
299-
startSidekickStorageClickStats();
299+
//startSidekickStorageClickStats();
300300
broadcastYourTurn(data.turn);
301301
} else {
302302
turnOffButtons();

public/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const alertMessage = {
44
JOIN_DOES_NOT_EXIST: 'join-does-not-exist',
55
JOIN_USERNAME_EXISTS: 'join-username-exists',
66
CREATE_ALREADY_EXISTS: 'create-already-exists',
7+
CREATE_RESERVED: 'create-reserved',
78
BAD_USERNAME: 'bad-username',
89
BAD_ROOMNAME: 'bad-roomname',
910
}
@@ -31,6 +32,9 @@ function displayAlert() {
3132
} else if (name == alertMessage.CREATE_ALREADY_EXISTS) {
3233
alert.style.display = "block";
3334
alert.innerHTML = "Room already exists";
35+
} else if (name == alertMessage.CREATE_RESERVED){
36+
alert.style.display = "block";
37+
alert.innerHTML = "Roomname is reserved";
3438
} else if (name == alertMessage.BAD_USERNAME){
3539
alert.style.display = "block";
3640
alert.innerHTML = "Username has profanity";

utils/messages.js

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const alertMessage = {
44
JOIN_DOES_NOT_EXIST: 'join-does-not-exist',
55
JOIN_USERNAME_EXISTS: 'join-username-exists',
66
CREATE_ALREADY_EXISTS: 'create-already-exists',
7+
CREATE_RESERVED: 'create-reserved',
78
BAD_USERNAME: 'bad-username',
89
BAD_ROOMNAME: 'bad-roomname',
910
}

utils/socket.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ function sleep(ms) {
1818
});
1919
}
2020

21-
playersInLobby = [];
21+
var playersInLobby = [];
22+
var roomnumber = 1;
2223

2324
// Socket connection.
2425
function socket(io) {
@@ -55,9 +56,10 @@ function socket(io) {
5556
console.log(playersInLobby[0]);
5657
io.to('lobby').emit('enter-room', {
5758
players: playersInLobby,
58-
roomname: "lobbyroom1",
59+
roomname: `lobbyroom${roomnumber}`,
5960
});
6061
playersInLobby = [];
62+
roomnumber +=1;
6163
}
6264
io.to('lobby').emit('display-lobby', {players: playersInLobby});
6365
}

0 commit comments

Comments
 (0)