From 9f71cc05ca1bbbde7990bb6bffb7b6784023e0ad Mon Sep 17 00:00:00 2001 From: githuberuser Date: Sat, 12 Dec 2020 16:51:13 -0500 Subject: [PATCH] If this username has been taken then show a reminder and avoid this operation. --- nginx/public/officeHours.js | 2 ++ src/main/scala/model/OfficeHoursServer.scala | 13 +++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/nginx/public/officeHours.js b/nginx/public/officeHours.js index 3514c14..5357673 100644 --- a/nginx/public/officeHours.js +++ b/nginx/public/officeHours.js @@ -3,6 +3,8 @@ const socket = io.connect("http://localhost:8080", {transports: ['websocket']}); socket.on('queue', displayQueue); socket.on('message', displayMessage); + + function displayMessage(newMessage) { document.getElementById("message").innerHTML = newMessage; } diff --git a/src/main/scala/model/OfficeHoursServer.scala b/src/main/scala/model/OfficeHoursServer.scala index 09ef61b..b2cd3b9 100644 --- a/src/main/scala/model/OfficeHoursServer.scala +++ b/src/main/scala/model/OfficeHoursServer.scala @@ -60,10 +60,15 @@ class DisconnectionListener(server: OfficeHoursServer) extends DisconnectListene class EnterQueueListener(server: OfficeHoursServer) extends DataListener[String] { override def onData(socket: SocketIOClient, username: String, ackRequest: AckRequest): Unit = { - server.database.addStudentToQueue(StudentInQueue(username, System.nanoTime())) - server.socketToUsername += (socket -> username) - server.usernameToSocket += (username -> socket) - server.server.getBroadcastOperations.sendEvent("queue", server.queueJSON()) + var usernameList=server.usernameToSocket.keySet + if (usernameList.contains(username)) { + server.usernameToSocket(username).sendEvent("message","This username has been taken, plz change a username!! ") + }else { + server.database.addStudentToQueue(StudentInQueue(username, System.nanoTime())) + server.socketToUsername += (socket -> username) + server.usernameToSocket += (username -> socket) + server.server.getBroadcastOperations.sendEvent("queue", server.queueJSON()) + } } }