From 8742700404a932e8639296ded6f2b8a820ae7dce Mon Sep 17 00:00:00 2001 From: ThiML10 <157675695+ThiML10@users.noreply.github.com> Date: Fri, 26 Apr 2024 21:42:50 +0000 Subject: [PATCH 1/9] just a try to seperate pages --- html/index.html | 350 +++---------------------------------- html/index_1.html | 430 ++++++++++++++++++++++++++++++++++++++++++++++ html/lobby.js | 75 ++++++++ html/welcome.js | 65 +++++++ 4 files changed, 590 insertions(+), 330 deletions(-) create mode 100644 html/index_1.html create mode 100644 html/lobby.js create mode 100644 html/welcome.js diff --git a/html/index.html b/html/index.html index bd50e28..1b2fb45 100644 --- a/html/index.html +++ b/html/index.html @@ -5,15 +5,33 @@ The Word Search Game Lobby + + +
+

Welcome to The Word Search Game

+
+ + + + +
+
+ + +
+ + +
+ + + +
+ + + +
+
+ + + + + +
+ + +
+
+ + +
+ +

The Word Search Game

+ + + +
+
+ +
+ + + + +
+

Leaderboard

+ + + + + + + + + + + +
RankNicknameScore
+
+ + +
+

Timer: 30 seconds

+
+ + + +
+ + + +
+
+ + + diff --git a/html/lobby.js b/html/lobby.js new file mode 100644 index 0000000..a5b4c60 --- /dev/null +++ b/html/lobby.js @@ -0,0 +1,75 @@ +document.addEventListener("DOMContentLoaded", function() { + const socket = new WebSocket("ws://" + window.location.hostname + ":9105"); + const gameSelect = document.getElementById("gameSelect"); + const modeSelect = document.getElementById("modeSelect"); + const confirmButton = document.getElementById("confirmButton"); + const startButton = document.getElementById("startButton"); + const leaveButton = document.getElementById("leaveButton"); + const refreshButton = document.getElementById("refreshButton"); + const gameTable = document.getElementById("gameListSection"); + + socket.onopen = function() { + console.log("WebSocket connection opened."); + requestGameList(); + }; + + socket.onmessage = function(event) { + const data = JSON.parse(event.data); + if (data.type === "gameListUpdate") { + updateGameList(data.games); + } + }; + + socket.onerror = function(error) { + console.error("WebSocket error:", error); + }; + + socket.onclose = function() { + console.log("WebSocket connection closed."); + }; + + confirmButton.addEventListener('click', function() { + const gameIndex = gameSelect.selectedIndex; + const modeIndex = modeSelect.selectedIndex; + if (gameIndex >= 0 && modeIndex >= 0) { + joinGame(gameSelect.value, modeSelect.options[modeSelect.selectedIndex].text); + } else { + alert('Please select both a game and a mode.'); + } + }); + + refreshButton.addEventListener('click', function() { + requestGameList(); + }); + + function requestGameList() { + socket.send(JSON.stringify({ type: "requestGameList" })); + } + + function joinGame(gameId, mode) { + const message = { + type: "joinGame", + gameId: gameId, + mode: mode + }; + socket.send(JSON.stringify(message)); + } + + function updateGameList(games) { + while (gameTable.rows.length > 1) { + gameTable.deleteRow(1); + } + + // Add new rows for each game + games.forEach(function(game) { + let row = gameTable.insertRow(); + let nameCell = row.insertCell(0); + let joinCell = row.insertCell(1); + let playersCell = row.insertCell(2); + + nameCell.textContent = game.name; + joinCell.innerHTML = ``; + playersCell.textContent = game.players.join(", "); + }); + } +}); diff --git a/html/welcome.js b/html/welcome.js new file mode 100644 index 0000000..1f82d72 --- /dev/null +++ b/html/welcome.js @@ -0,0 +1,65 @@ +document.addEventListener("DOMContentLoaded", function() { + const nickInput = document.getElementById("nickInput"); + const nickForm = document.getElementById("nickForm"); + const errorElement = document.getElementById("error"); + const welcomeContainer = document.getElementById("welcomeContainer"); + const lobbyContainer = document.getElementById("lobbyContainer"); + + // Setup WebSocket connection + const connection = new WebSocket("ws://" + window.location.hostname + ":9105"); + + connection.onopen = function () { + console.log('WebSocket connection established!'); + }; + + connection.onerror = function (error) { + console.error('WebSocket Error:', error); + }; + + connection.onmessage = function (e) { + console.log('Server:', e.data); + const response = JSON.parse(e.data); + handleServerResponse(response); + }; + + nickForm.addEventListener('submit', function(event) { + event.preventDefault(); + validateNickname(nickInput.value.trim()); + }); + + function validateNickname(nickname) { + if (!nickname) { + showError("Please enter a nickname."); + return; + } + + let message = { + screen: "welcome", + type: "validateNickname", + nickname: nickname + }; + + // Send the message object as a string via WebSocket + connection.send(JSON.stringify(message)); + } + + function handleServerResponse(response) { + if (response.type === "validateNicknameResponse") { + if (response.isValid) { + enterLobby(); + } else { + showError("Your nick is already taken, please reenter."); + } + } + } + + function enterLobby() { + welcomeContainer.style.display = 'none'; + lobbyContainer.style.display = 'block'; + } + + function showError(message) { + errorElement.textContent = message; + errorElement.style.display = 'block'; + } +}); From 981f40598acb234c3bb3ec073536bdd3fd51ef0a Mon Sep 17 00:00:00 2001 From: ThiML10 <157675695+ThiML10@users.noreply.github.com> Date: Fri, 26 Apr 2024 21:49:35 +0000 Subject: [PATCH 2/9] index --- html/index.html | 330 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 330 insertions(+) diff --git a/html/index.html b/html/index.html index 1b2fb45..162b24d 100644 --- a/html/index.html +++ b/html/index.html @@ -98,3 +98,333 @@

Timer: 30 seconds

+ + From 9aae55f1f2a80d8cffeb15a61d54800f6a33c6f7 Mon Sep 17 00:00:00 2001 From: ThiML10 <157675695+ThiML10@users.noreply.github.com> Date: Sat, 27 Apr 2024 02:20:01 +0000 Subject: [PATCH 3/9] commit1 --- html/index.html | 30 ++++++++++++++++++++++++++++++ html/lobby.js | 4 ++++ 2 files changed, 34 insertions(+) diff --git a/html/index.html b/html/index.html index 162b24d..8038d50 100644 --- a/html/index.html +++ b/html/index.html @@ -4,8 +4,16 @@ The Word Search Game Lobby + + + +
@@ -99,6 +107,7 @@

Timer: 30 seconds

diff --git a/html/lobby.js b/html/lobby.js index a5b4c60..677ecd5 100644 --- a/html/lobby.js +++ b/html/lobby.js @@ -73,3 +73,7 @@ document.addEventListener("DOMContentLoaded", function() { }); } }); + + + + From c6749df21e058b34224ba62055a82a4a607f67be Mon Sep 17 00:00:00 2001 From: ThiML10 <157675695+ThiML10@users.noreply.github.com> Date: Sat, 27 Apr 2024 02:53:13 +0000 Subject: [PATCH 4/9] commit2 --- html/index.html | 136 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 116 insertions(+), 20 deletions(-) diff --git a/html/index.html b/html/index.html index 8038d50..559946f 100644 --- a/html/index.html +++ b/html/index.html @@ -9,6 +9,15 @@ #lobbyContainer { display: none; } + table { + width: 100%; + border-collapse: collapse; + } + th, td { + border: 1px solid black; + padding: 8px; + text-align: left; + } @@ -68,11 +77,23 @@

The Word Search Game

+ + +
+ + + + + + + + + +
Game NameSlots Filled/NeededPlayers
-
-
+ @@ -133,6 +154,9 @@

Timer: 30 seconds

var nick=""; var grid; var clicked=0; + + + socket.onopen = function(evt) { console.log("Open"); requestGameList(); @@ -205,7 +229,7 @@

Timer: 30 seconds

}; - +/* function requestGameList() { var data = { type: "RequestGameList" }; socket.send(JSON.stringify(data)); @@ -277,8 +301,97 @@

Timer: 30 seconds

document.getElementById('refreshButton').addEventListener('click', function() { requestGameList(); }); + */ + + ////////////////////////////////////////////// + //Welcome and Lobby + document.getElementById('nickForm').addEventListener('submit', function(event) { + event.preventDefault(); + var nick = document.getElementById('nickInput').value.trim(); + if (nick) { + socket.send(JSON.stringify({ type: "CheckNick", nick: nick })); + } + }); + + document.getElementById('confirmButton').addEventListener('click', function() { + var game = document.getElementById('gameSelect').value; + var mode = document.getElementById('modeSelect').value; + socket.send(JSON.stringify({ type: "JoinGame", game: game, mode: mode })); + }); + + socket.onmessage = function(event) { + var data = JSON.parse(event.data); + switch (data.type) { + case "NickChecked": + if (data.isUnique) { + document.getElementById('welcomeContainer').style.display = 'none'; + document.getElementById('lobbyContainer').style.display = 'block'; + } else { + document.getElementById('error').style.display = 'block'; + document.getElementById('error').textContent = 'Nickname already taken, please try another one.'; + } + break; + case "UpdateGameList": + updateGameList(data.games); + break; + case "GameReady": + document.getElementById('startButton').disabled = false; + break; + } + }; + + function updateGameList(games) { + var tbody = document.getElementById('gameListBody'); + tbody.innerHTML = ''; + games.forEach(function(game) { + var row = '' + + '' + game.gameName + '' + + '' + game.filledSlots + '/' + game.maxSlots + '' + + '' + game.players.join(', ') + '' + + ''; + tbody.innerHTML += row; + }); + } + + document.getElementById('startButton').addEventListener('click', function() { + if (!this.disabled) { + socket.send(JSON.stringify({ type: "StartGame" })); + } + }); + + document.getElementById('leaveButton').addEventListener('click', function() { + var nick = document.getElementById('nickInput').value; + socket.send(JSON.stringify({ type: "LeaveGame", nick: nick })); + }); + + document.getElementById('refreshButton').addEventListener('click', function() { + socket.send(JSON.stringify({ type: "RequestGameList" })); + }); + +/* + +document.getElementById('nickForm').addEventListener('submit', function(event) { + event.preventDefault(); // Prevent the default form submission + var nickInput = document.getElementById('nickInput').value.trim(); + // Simulate a check for nickname uniqueness + if (nickInput && isNickUnique(nickInput)) { // Implement isNickUnique() to check the nickname + document.getElementById('welcomeContainer').style.display = 'none'; + document.getElementById('lobbyContainer').style.display = 'block'; + } else { + document.getElementById('error').style.display = 'block'; + document.getElementById('error').textContent = 'Nickname already taken, please try another one.'; + } +}); + +function isNickUnique(nick) { + // This function should ideally make an AJAX call to the server to check nickname uniqueness + return true; // Placeholder return +} +*/ + +/////////////////////////////////////////////////////////////////////////////// //generate 25*25 grid //too big may have to do smaller grid or smaller cells @@ -435,24 +548,7 @@

Timer: 30 seconds

} -document.getElementById('nickForm').addEventListener('submit', function(event) { - event.preventDefault(); // Prevent the default form submission - var nickInput = document.getElementById('nickInput').value.trim(); - - // Simulate a check for nickname uniqueness - if (nickInput && isNickUnique(nickInput)) { // Implement isNickUnique() to check the nickname - document.getElementById('welcomeContainer').style.display = 'none'; - document.getElementById('lobbyContainer').style.display = 'block'; - } else { - document.getElementById('error').style.display = 'block'; - document.getElementById('error').textContent = 'Nickname already taken, please try another one.'; - } -}); -function isNickUnique(nick) { - // This function should ideally make an AJAX call to the server to check nickname uniqueness - return true; // Placeholder return -} From 42af49fceccd9618855d625a3e4d0b76f8d2d3cc Mon Sep 17 00:00:00 2001 From: ThiML10 <157675695+ThiML10@users.noreply.github.com> Date: Sat, 27 Apr 2024 02:56:44 +0000 Subject: [PATCH 5/9] commit3 --- html/index.html | 112 ++++++++++++++++++++++++------------------------ 1 file changed, 57 insertions(+), 55 deletions(-) diff --git a/html/index.html b/html/index.html index 559946f..2299ef0 100644 --- a/html/index.html +++ b/html/index.html @@ -306,68 +306,70 @@

Timer: 30 seconds

////////////////////////////////////////////// //Welcome and Lobby - document.getElementById('nickForm').addEventListener('submit', function(event) { - event.preventDefault(); - var nick = document.getElementById('nickInput').value.trim(); - if (nick) { - socket.send(JSON.stringify({ type: "CheckNick", nick: nick })); - } - }); + // var socket = new WebSocket("ws://" + window.location.hostname + ":9105"); - document.getElementById('confirmButton').addEventListener('click', function() { - var game = document.getElementById('gameSelect').value; - var mode = document.getElementById('modeSelect').value; - socket.send(JSON.stringify({ type: "JoinGame", game: game, mode: mode })); - }); +document.getElementById('nickForm').addEventListener('submit', function(event) { + event.preventDefault(); // Prevent the default form submission + var nick = document.getElementById('nickInput').value.trim(); + if (nick) { + // Send nickname to the server for uniqueness check + socket.send(JSON.stringify({type: "CheckNick", nick: nick})); + } +}); - socket.onmessage = function(event) { - var data = JSON.parse(event.data); - switch (data.type) { - case "NickChecked": - if (data.isUnique) { - document.getElementById('welcomeContainer').style.display = 'none'; - document.getElementById('lobbyContainer').style.display = 'block'; - } else { - document.getElementById('error').style.display = 'block'; - document.getElementById('error').textContent = 'Nickname already taken, please try another one.'; - } - break; - case "UpdateGameList": - updateGameList(data.games); - break; - case "GameReady": - document.getElementById('startButton').disabled = false; - break; +// Handling messages from the server +socket.onmessage = function(event) { + var data = JSON.parse(event.data); + switch (data.type) { + case "NickResponse": + if (data.isUnique) { + // If the nickname is unique, display the lobby + document.getElementById('welcomeContainer').style.display = 'none'; + document.getElementById('lobbyContainer').style.display = 'block'; + } else { + // If the nickname is not unique, show an error message + document.getElementById('error').style.display = 'block'; + document.getElementById('error').textContent = 'Nickname already taken, please try another one.'; } - }; + break; + case "UpdateGameList": + updateGameList(data.games); + break; + case "GameReady": + // Enable the start button if the game is ready + document.getElementById('startButton').disabled = false; + break; + } +}; + +function updateGameList(games) { + var tbody = document.getElementById('gameListBody'); + tbody.innerHTML = ''; + games.forEach(function(game) { + var row = '' + + '' + game.gameName + '' + + '' + game.filledSlots + '/' + game.maxSlots + '' + + '' + game.players.join(', ') + '' + + ''; + tbody.innerHTML += row; + }); +} - function updateGameList(games) { - var tbody = document.getElementById('gameListBody'); - tbody.innerHTML = ''; - games.forEach(function(game) { - var row = '' + - '' + game.gameName + '' + - '' + game.filledSlots + '/' + game.maxSlots + '' + - '' + game.players.join(', ') + '' + - ''; - tbody.innerHTML += row; - }); - } +document.getElementById('startButton').addEventListener('click', function() { + if (!this.disabled) { + socket.send(JSON.stringify({ type: "StartGame" })); + } +}); - document.getElementById('startButton').addEventListener('click', function() { - if (!this.disabled) { - socket.send(JSON.stringify({ type: "StartGame" })); - } - }); +document.getElementById('leaveButton').addEventListener('click', function() { + var nick = document.getElementById('nickInput').value; + socket.send(JSON.stringify({ type: "LeaveGame", nick: nick })); +}); - document.getElementById('leaveButton').addEventListener('click', function() { - var nick = document.getElementById('nickInput').value; - socket.send(JSON.stringify({ type: "LeaveGame", nick: nick })); - }); +document.getElementById('refreshButton').addEventListener('click', function() { + socket.send(JSON.stringify({ type: "RequestGameList" })); +}); - document.getElementById('refreshButton').addEventListener('click', function() { - socket.send(JSON.stringify({ type: "RequestGameList" })); - }); /* From aeb555889fc568565b4804a5174b60e622ccae5f Mon Sep 17 00:00:00 2001 From: ThiML10 <157675695+ThiML10@users.noreply.github.com> Date: Sat, 27 Apr 2024 02:59:40 +0000 Subject: [PATCH 6/9] commit2 --- html/index.html | 138 +++++++----------------------------------------- 1 file changed, 20 insertions(+), 118 deletions(-) diff --git a/html/index.html b/html/index.html index 2299ef0..8038d50 100644 --- a/html/index.html +++ b/html/index.html @@ -9,15 +9,6 @@ #lobbyContainer { display: none; } - table { - width: 100%; - border-collapse: collapse; - } - th, td { - border: 1px solid black; - padding: 8px; - text-align: left; - } @@ -77,22 +68,10 @@

The Word Search Game

- - -
- - - - - - - - - -
Game NameSlots Filled/NeededPlayers
-
+
+
@@ -154,9 +133,6 @@

Timer: 30 seconds

var nick=""; var grid; var clicked=0; - - - socket.onopen = function(evt) { console.log("Open"); requestGameList(); @@ -229,7 +205,7 @@

Timer: 30 seconds

}; -/* + function requestGameList() { var data = { type: "RequestGameList" }; socket.send(JSON.stringify(data)); @@ -301,99 +277,8 @@

Timer: 30 seconds

document.getElementById('refreshButton').addEventListener('click', function() { requestGameList(); }); - */ - - ////////////////////////////////////////////// - //Welcome and Lobby - // var socket = new WebSocket("ws://" + window.location.hostname + ":9105"); - -document.getElementById('nickForm').addEventListener('submit', function(event) { - event.preventDefault(); // Prevent the default form submission - var nick = document.getElementById('nickInput').value.trim(); - if (nick) { - // Send nickname to the server for uniqueness check - socket.send(JSON.stringify({type: "CheckNick", nick: nick})); - } -}); - -// Handling messages from the server -socket.onmessage = function(event) { - var data = JSON.parse(event.data); - switch (data.type) { - case "NickResponse": - if (data.isUnique) { - // If the nickname is unique, display the lobby - document.getElementById('welcomeContainer').style.display = 'none'; - document.getElementById('lobbyContainer').style.display = 'block'; - } else { - // If the nickname is not unique, show an error message - document.getElementById('error').style.display = 'block'; - document.getElementById('error').textContent = 'Nickname already taken, please try another one.'; - } - break; - case "UpdateGameList": - updateGameList(data.games); - break; - case "GameReady": - // Enable the start button if the game is ready - document.getElementById('startButton').disabled = false; - break; - } -}; - -function updateGameList(games) { - var tbody = document.getElementById('gameListBody'); - tbody.innerHTML = ''; - games.forEach(function(game) { - var row = '' + - '' + game.gameName + '' + - '' + game.filledSlots + '/' + game.maxSlots + '' + - '' + game.players.join(', ') + '' + - ''; - tbody.innerHTML += row; - }); -} - -document.getElementById('startButton').addEventListener('click', function() { - if (!this.disabled) { - socket.send(JSON.stringify({ type: "StartGame" })); - } -}); - -document.getElementById('leaveButton').addEventListener('click', function() { - var nick = document.getElementById('nickInput').value; - socket.send(JSON.stringify({ type: "LeaveGame", nick: nick })); -}); - -document.getElementById('refreshButton').addEventListener('click', function() { - socket.send(JSON.stringify({ type: "RequestGameList" })); -}); - - -/* - -document.getElementById('nickForm').addEventListener('submit', function(event) { - event.preventDefault(); // Prevent the default form submission - var nickInput = document.getElementById('nickInput').value.trim(); - // Simulate a check for nickname uniqueness - if (nickInput && isNickUnique(nickInput)) { // Implement isNickUnique() to check the nickname - document.getElementById('welcomeContainer').style.display = 'none'; - document.getElementById('lobbyContainer').style.display = 'block'; - } else { - document.getElementById('error').style.display = 'block'; - document.getElementById('error').textContent = 'Nickname already taken, please try another one.'; - } -}); - -function isNickUnique(nick) { - // This function should ideally make an AJAX call to the server to check nickname uniqueness - return true; // Placeholder return -} -*/ - -/////////////////////////////////////////////////////////////////////////////// //generate 25*25 grid //too big may have to do smaller grid or smaller cells @@ -550,7 +435,24 @@

Timer: 30 seconds

} +document.getElementById('nickForm').addEventListener('submit', function(event) { + event.preventDefault(); // Prevent the default form submission + var nickInput = document.getElementById('nickInput').value.trim(); + + // Simulate a check for nickname uniqueness + if (nickInput && isNickUnique(nickInput)) { // Implement isNickUnique() to check the nickname + document.getElementById('welcomeContainer').style.display = 'none'; + document.getElementById('lobbyContainer').style.display = 'block'; + } else { + document.getElementById('error').style.display = 'block'; + document.getElementById('error').textContent = 'Nickname already taken, please try another one.'; + } +}); +function isNickUnique(nick) { + // This function should ideally make an AJAX call to the server to check nickname uniqueness + return true; // Placeholder return +} From e444af2adfac0e3e0f3b70c75cc74f33424c58c4 Mon Sep 17 00:00:00 2001 From: ThiML10 <157675695+ThiML10@users.noreply.github.com> Date: Sat, 27 Apr 2024 03:02:46 +0000 Subject: [PATCH 7/9] commit2 --- html/index.html | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/html/index.html b/html/index.html index 8038d50..9b0d0c1 100644 --- a/html/index.html +++ b/html/index.html @@ -436,10 +436,9 @@

Timer: 30 seconds

document.getElementById('nickForm').addEventListener('submit', function(event) { - event.preventDefault(); // Prevent the default form submission + event.preventDefault(); var nickInput = document.getElementById('nickInput').value.trim(); - // Simulate a check for nickname uniqueness if (nickInput && isNickUnique(nickInput)) { // Implement isNickUnique() to check the nickname document.getElementById('welcomeContainer').style.display = 'none'; document.getElementById('lobbyContainer').style.display = 'block'; @@ -450,7 +449,6 @@

Timer: 30 seconds

}); function isNickUnique(nick) { - // This function should ideally make an AJAX call to the server to check nickname uniqueness return true; // Placeholder return } From 2c9b8de6c5c461b6473bc0db9bba0c4b47b813b6 Mon Sep 17 00:00:00 2001 From: ThiML10 <157675695+ThiML10@users.noreply.github.com> Date: Sat, 27 Apr 2024 03:40:00 +0000 Subject: [PATCH 8/9] commit1 --- html/index.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/html/index.html b/html/index.html index 9b0d0c1..1f7bcc3 100644 --- a/html/index.html +++ b/html/index.html @@ -72,6 +72,8 @@

The Word Search Game

+ + From 044fc9646a5e7fbd66a57381b361fe3d1270cb9e Mon Sep 17 00:00:00 2001 From: ThiML10 <157675695+ThiML10@users.noreply.github.com> Date: Sat, 27 Apr 2024 03:42:40 +0000 Subject: [PATCH 9/9] commit1 --- html/welcome.js | 65 ------------------------------------------------- 1 file changed, 65 deletions(-) delete mode 100644 html/welcome.js diff --git a/html/welcome.js b/html/welcome.js deleted file mode 100644 index 1f82d72..0000000 --- a/html/welcome.js +++ /dev/null @@ -1,65 +0,0 @@ -document.addEventListener("DOMContentLoaded", function() { - const nickInput = document.getElementById("nickInput"); - const nickForm = document.getElementById("nickForm"); - const errorElement = document.getElementById("error"); - const welcomeContainer = document.getElementById("welcomeContainer"); - const lobbyContainer = document.getElementById("lobbyContainer"); - - // Setup WebSocket connection - const connection = new WebSocket("ws://" + window.location.hostname + ":9105"); - - connection.onopen = function () { - console.log('WebSocket connection established!'); - }; - - connection.onerror = function (error) { - console.error('WebSocket Error:', error); - }; - - connection.onmessage = function (e) { - console.log('Server:', e.data); - const response = JSON.parse(e.data); - handleServerResponse(response); - }; - - nickForm.addEventListener('submit', function(event) { - event.preventDefault(); - validateNickname(nickInput.value.trim()); - }); - - function validateNickname(nickname) { - if (!nickname) { - showError("Please enter a nickname."); - return; - } - - let message = { - screen: "welcome", - type: "validateNickname", - nickname: nickname - }; - - // Send the message object as a string via WebSocket - connection.send(JSON.stringify(message)); - } - - function handleServerResponse(response) { - if (response.type === "validateNicknameResponse") { - if (response.isValid) { - enterLobby(); - } else { - showError("Your nick is already taken, please reenter."); - } - } - } - - function enterLobby() { - welcomeContainer.style.display = 'none'; - lobbyContainer.style.display = 'block'; - } - - function showError(message) { - errorElement.textContent = message; - errorElement.style.display = 'block'; - } -});