Added code so players can't vote for their own submissions
This commit is contained in:
parent
4953f1e685
commit
14d00a407a
|
@ -188,6 +188,7 @@ socket.on("PICK", function(data){
|
|||
|
||||
page += "<div id='pick_buttons'>";
|
||||
page += "<p>Select the line you prefer.</p>";
|
||||
page += "<p id='text_read_error' style='display: none; color: #BB2266; '></p>";
|
||||
for(y=0; y<data.submissions.length; y++){
|
||||
page += "<div class='row'>";
|
||||
page += "<div class='ten columns'>";
|
||||
|
@ -208,19 +209,39 @@ socket.on("PICK", function(data){
|
|||
}
|
||||
page += "</div>";
|
||||
|
||||
page += "<div id='pick_ok_button' style='display: none;'>";
|
||||
page += "</div>";
|
||||
|
||||
|
||||
// Show page
|
||||
document.getElementById("main").innerHTML = page;
|
||||
});
|
||||
|
||||
// PICK button
|
||||
function button_pick(id){
|
||||
// Disable all buttons and show waiting text
|
||||
document.getElementById("pick_buttons").innerHTML = "<button class='button' id='button_ok' disabled>Loading...</button>";
|
||||
// Hide layout and show OK button
|
||||
document.getElementById("pick_buttons").style.display = "none";
|
||||
document.getElementById("text_read_error").style.display = "none";
|
||||
document.getElementById("pick_ok_button").style.display = "block";
|
||||
document.getElementById("pick_ok_button").innerHTML = "<button class='button' id='button_ok' disabled>Loading...</button>";
|
||||
|
||||
// Send to server
|
||||
socket.emit("PICK", id);
|
||||
}
|
||||
|
||||
// PICK_REPLY
|
||||
socket.on("PICK_REPLY", function(data){
|
||||
// When something wrong with pick
|
||||
// Make layout visible again
|
||||
document.getElementById("pick_buttons").style.display = "block";
|
||||
document.getElementById("pick_ok_button").style.display = "none";
|
||||
|
||||
// Show message
|
||||
document.getElementById("text_read_error").innerHTML = "<i class='fas fa-exclamation-triangle'></i> "+data.error;
|
||||
document.getElementById("text_read_error").style.display = "block";
|
||||
});
|
||||
|
||||
|
||||
// ANSWER
|
||||
socket.on("ANSWER", function(data){
|
||||
// Received answer
|
||||
|
|
8
main.js
8
main.js
|
@ -183,6 +183,14 @@ io.on("connection", (socket) => {
|
|||
// PICK
|
||||
socket.on("PICK", (id) => {
|
||||
// When received pick form player
|
||||
|
||||
// Check if not my entry
|
||||
if(userWrite[userSockets.indexOf(socket)] == submissions[id]){
|
||||
socket.emit("PICK_REPLY", {error:"You can't vote for your own submission!"});
|
||||
return;
|
||||
}
|
||||
|
||||
// Add to list
|
||||
userPick[userSockets.indexOf(socket)] = id;
|
||||
|
||||
// Perform ok
|
||||
|
|
Loading…
Reference in New Issue