From 39e28db261bc7e57eb3ca04f09382c8633a6e267 Mon Sep 17 00:00:00 2001 From: Marius Kiefer Date: Wed, 13 Sep 2023 23:37:01 +0200 Subject: [PATCH 1/5] Add option to allow all posts --- config.template.js | 1 + public/js/client.js | 20 +++++++++++++++++++- server.js | 8 ++++++-- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/config.template.js b/config.template.js index 76f6d8f..3b9fbf7 100644 --- a/config.template.js +++ b/config.template.js @@ -29,5 +29,6 @@ Config.privateMessaging = true; //Connect 4 URL: If you would prefer to host it yourself, https://github.com/tannerkrewson/connect4lansite Config.connectFourUrl = 'https://kevinshannon.dev/connect4/'; +Config.allowAllPosts = true; module.exports = Config; diff --git a/public/js/client.js b/public/js/client.js index 3122fdf..4cd400c 100644 --- a/public/js/client.js +++ b/public/js/client.js @@ -13,6 +13,7 @@ var socket = io(); // if the user is OP. this flag is just for cosmetics, which won't // do anything if the user isn't OP, because the server won't allow it. var isThisUserOP = false; +var allPostsAreAllowed= false; //will contain all the loaded client boxes var BoxNames = []; @@ -282,13 +283,18 @@ SendToServer.areWeOP = function(){ SendToServer.generic('areWeOP', {}); } +SendToServer.areAllPostsAllowed = function(){ + SendToServer.generic('areAllPostsAllowed', {}); +} function Popup() {} Popup.requestSent = function() { //don't annoy the admins with constant popups if (!isThisUserOP) { - swal("Request sent!", "Now, wait for the admin to respond.", "success"); + if(!allPostsAreAllowed) { + swal("Request sent!", "Now, wait for the admin to respond.", "success"); + } } } @@ -345,6 +351,9 @@ socket.on('newStream', function(msg) { //see if we are op SendToServer.areWeOP(); + SendToServer.areAllPostsAllowed(); + + //deletes all boxes currently in the array mainStream.clearArray(); @@ -390,6 +399,15 @@ socket.on('areWeOP', function(msg) { } }); +socket.on('areAllPostsAllowed', function(msg) { + allowCheck = msg && true; + //if we're not already OP + + if (!allPostsAreAllowed && allowCheck){ + allPostsAreAllowed = true; + } +}); + //shows a popup to inform the user if there request was accepted or denied socket.on('requestAccepted', function(msg) { Popup.requestAccepted(msg); diff --git a/server.js b/server.js index 07c9a79..aa2bcf2 100644 --- a/server.js +++ b/server.js @@ -762,8 +762,8 @@ function RequestManager() { } RequestManager.prototype.addRequest = function(userThatMadeRequest, requestString, acceptFunction, denyFunction){ - //if the user is op, accept the request, no questions asked - if (userThatMadeRequest.isOp) { + //if the user is op or the config is set to allow all posts, accept the request, no questions asked + if (userThatMadeRequest.isOp||Config.allowAllPosts) { //I bypass adding the request and using the handler here // the true tells the function to supress the usual popup // that users receive when their popup is accepted @@ -971,6 +971,10 @@ io.on('connection', function(socket) { } }); + socket.on('areAllPostsAllowed', function(msg) { + socket.emit('areAllPostsAllowed', Config.allowAllPosts); + }); + socket.on('disconnect', function() { //console.log('Unauthenticated user disconnected'); //mainStream.users.removeUser(user); From 27fc4af3687aecaf47e8e7b3db795049123c084e Mon Sep 17 00:00:00 2001 From: Marius Kiefer Date: Wed, 13 Sep 2023 23:39:03 +0200 Subject: [PATCH 2/5] fix comment for disabling popup on post request --- public/js/client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/js/client.js b/public/js/client.js index 4cd400c..a5b8697 100644 --- a/public/js/client.js +++ b/public/js/client.js @@ -290,7 +290,7 @@ SendToServer.areAllPostsAllowed = function(){ function Popup() {} Popup.requestSent = function() { - //don't annoy the admins with constant popups + //don't show popup when user is admin or all posts are allowed if (!isThisUserOP) { if(!allPostsAreAllowed) { swal("Request sent!", "Now, wait for the admin to respond.", "success"); From 167d1d5a9f64e42a270ce201b74bf6a4dae7da96 Mon Sep 17 00:00:00 2001 From: Marius Kiefer Date: Wed, 13 Sep 2023 23:40:14 +0200 Subject: [PATCH 3/5] add description to new config option --- config.template.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config.template.js b/config.template.js index 3b9fbf7..881df33 100644 --- a/config.template.js +++ b/config.template.js @@ -29,6 +29,7 @@ Config.privateMessaging = true; //Connect 4 URL: If you would prefer to host it yourself, https://github.com/tannerkrewson/connect4lansite Config.connectFourUrl = 'https://kevinshannon.dev/connect4/'; -Config.allowAllPosts = true; +//Automatically accept all posts +Config.allowAllPosts = false; module.exports = Config; From c02cfcc7f99d138de1d2a71362c6d20f9462fb19 Mon Sep 17 00:00:00 2001 From: Marius Kiefer Date: Wed, 13 Sep 2023 23:42:49 +0200 Subject: [PATCH 4/5] remove unnecessary newline --- public/js/client.js | 1 - 1 file changed, 1 deletion(-) diff --git a/public/js/client.js b/public/js/client.js index a5b8697..7faad2c 100644 --- a/public/js/client.js +++ b/public/js/client.js @@ -353,7 +353,6 @@ socket.on('newStream', function(msg) { SendToServer.areAllPostsAllowed(); - //deletes all boxes currently in the array mainStream.clearArray(); From 1155b03e4c0785245d85d8c07bea8c7918f241bc Mon Sep 17 00:00:00 2001 From: Marius Kiefer Date: Wed, 13 Sep 2023 23:48:32 +0200 Subject: [PATCH 5/5] add webstorm IDE files to .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index a4c57d4..414d20c 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,6 @@ build/Release # Dependency directory # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git node_modules + +# Webstorm project files +.idea \ No newline at end of file