fixed issues with certain characters in user names

This commit is contained in:
Samuel Kent
2024-02-03 09:58:56 +11:00
parent 42cf703556
commit d03d5b0fd9
5 changed files with 25 additions and 7 deletions
+7
View File
@@ -94,12 +94,19 @@ io.on("connection", (socket) => {
teamName: teamName, teamName: teamName,
buzzerId: buzzerId buzzerId: buzzerId
} }
console.log(userInfo);
io.emit("userInfoToClient", userInfo);
});
//used by the host when they refresh the page.
socket.on("refreshUserInfo", () => {
io.emit("userInfoToClient", userInfo); io.emit("userInfoToClient", userInfo);
}); });
socket.on("unregisterUsers", () => { socket.on("unregisterUsers", () => {
userInfo = new Object(); userInfo = new Object();
io.emit("userInfoToClient", userInfo); io.emit("userInfoToClient", userInfo);
io.emit("reconnectUsers");
}); });
socket.on("objectionToServer", (userName) => { socket.on("objectionToServer", (userName) => {
+2 -1
View File
@@ -1,6 +1,7 @@
function userInfoToClient(userInfo) { function userInfoToClient(userInfo) {
for (const user in userInfo) { for (const user in userInfo) {
const userId = user.replaceAll(" ","_"); re = new RegExp("\\W","g");
const userId = user.replaceAll(re,"_");
if ($("#userListPanel").find("#"+userId).length >= 1) { if ($("#userListPanel").find("#"+userId).length >= 1) {
//update buzzer icon of existing user //update buzzer icon of existing user
$("#userListPanel").find("#"+userId).find("img").attr("data-buzzerId",userInfo[user].buzzerId); $("#userListPanel").find("#"+userId).find("img").attr("data-buzzerId",userInfo[user].buzzerId);
+6 -3
View File
@@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<title>No, you do not need to mute this site anymore.</title> <title>You may now put weird characters in your name.</title>
<link rel="stylesheet" href="styleMain.css"> <link rel="stylesheet" href="styleMain.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script> <script>
@@ -10,10 +10,13 @@
const egg = new Audio('Egg.wav'); const egg = new Audio('Egg.wav');
$("#userName").change(function() { $("#userName").change(function() {
okSsuka.play(); okSsuka.play();
$("#playerLink").attr("href", "/play?user="+this.value+"&team=Players");
re = new RegExp("\\#|\\&","g");
const userName = this.value.replaceAll(re,">:(");
$("#playerLink").attr("href", "/play?user="+userName+"&team=Players");
$("#playerLink").html("Players"); $("#playerLink").html("Players");
$("#chaserLink").attr("href", "/play?user="+this.value+"&team=Chasers"); $("#chaserLink").attr("href", "/play?user="+userName+"&team=Chasers");
$("#chaserLink").html("Chasers"); $("#chaserLink").html("Chasers");
}); });
$("#egg").click(function() { $("#egg").click(function() {
+5 -2
View File
@@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<title>No, you do not need to mute this site anymore.</title> <title>No, you do not need to mute this site anymore. (yes, even on firefox)</title>
<link rel="stylesheet" href="styleMain.css"> <link rel="stylesheet" href="styleMain.css">
<script src="browserFunctions.js"></script> <script src="browserFunctions.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
@@ -10,6 +10,8 @@
$(document).ready(function() { $(document).ready(function() {
var socket = io(); var socket = io();
socket.emit("refreshUserInfo");
socket.on("userInfoToClient", (userInfo) => { socket.on("userInfoToClient", (userInfo) => {
userInfoToClient(userInfo); userInfoToClient(userInfo);
}); });
@@ -46,6 +48,7 @@
$("#unregisterUsers").click(function() { $("#unregisterUsers").click(function() {
socket.emit("unregisterUsers"); socket.emit("unregisterUsers");
location.reload();
}); });
socket.on("objectionToClient", (userName) => { socket.on("objectionToClient", (userName) => {
@@ -80,7 +83,7 @@
<br> <br>
<br> <br>
<br> <br>
<button id="unregisterUsers" type="button" style="height: 30px;">Remove all players</button> <button id="unregisterUsers" type="button" style="height: 30px;">Remove/Reconnect all players</button>
</div> </div>
<div id="userListPanel"> <div id="userListPanel">
<div id="PlayersList"> <div id="PlayersList">
+5 -1
View File
@@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<title>No, you do not need to mute this site anymore.</title> <title>No, you do not need to mute this site anymore. (yes, even on firefox)</title>
<link rel="stylesheet" href="styleMain.css"> <link rel="stylesheet" href="styleMain.css">
<script src="browserFunctions.js"></script> <script src="browserFunctions.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
@@ -150,6 +150,10 @@
userInfoToClient(userInfo); userInfoToClient(userInfo);
}); });
socket.on("reconnectUsers", () => {
location.reload();
});
socket.on("gameStateToClient", (currentTeam, currentScore) => { socket.on("gameStateToClient", (currentTeam, currentScore) => {
gameStateToClient(currentTeam, currentScore); gameStateToClient(currentTeam, currentScore);
}); });