diff --git a/src/app/auxServer.js b/src/app/auxServer.js new file mode 100644 index 0000000..3a66337 --- /dev/null +++ b/src/app/auxServer.js @@ -0,0 +1,79 @@ +/*Canopy - The next generation of stoner streaming software +Copyright (C) 2024-2025 Rainbownapkin and the TTN Community + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see .*/ + +//local includes +const loggerUtils = require("../utils/loggerUtils"); +const socketUtils = require("../utils/socketUtils"); + +/** + * Class containg global server-side logic for handling namespaces outside of the main one + */ +class auxServer{ + /** + * Instantiates object containing global server-side private message relay logic + * @param {Socket.io} io - Socket.io server instanced passed down from server.js + * @param {channelManager} chanServer - Sister channel management server object + */ + constructor(io, chanServer, namespace){ + /** + * Socket.io server instance passed down from server.js + */ + this.io = io; + + /** + * Sister channel management server object + */ + this.chanServer = chanServer; + + /** + * Socket.io server namespace for handling messaging + */ + this.namespace = io.of(namespace); + + //Handle connections from private messaging namespace + this.namespace.on("connection", this.handleConnection.bind(this) ); + } + + /** + * Handles global server-side initialization for new connections to aux server + * @param {Socket} socket - Requesting Socket + */ + async handleConnection(socket){ + try{ + //ensure unbanned ip and valid CSRF token + if(!(await socketUtils.validateSocket(socket))){ + socket.disconnect(); + return false; + } + + //If the socket wasn't authorized + if(await socketUtils.authSocketLite(socket) == null){ + socket.disconnect(); + return false; + } + + return true; + }catch(err){ + //Flip a table if something fucks up + return loggerUtils.socketCriticalExceptionHandler(socket, err); + } + } + + defineListeners(socket){ + } +} + +module.exports = auxServer; \ No newline at end of file diff --git a/src/app/pm/pmHandler.js b/src/app/pm/pmHandler.js index b783be8..5e16ffc 100644 --- a/src/app/pm/pmHandler.js +++ b/src/app/pm/pmHandler.js @@ -14,44 +14,25 @@ GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see .*/ -//NPM Imports -const validator = require('validator');//No express here, so regular validator it is! - //local includes +const auxServer = require('../auxServer'); const chatPreprocessor = require('../chatPreprocessor'); const loggerUtils = require("../../utils/loggerUtils"); -const socketUtils = require("../../utils/socketUtils"); const message = require("./message"); /** * Class containg global server-side private message relay logic */ -class pmHandler{ +class pmHandler extends auxServer{ /** * Instantiates object containing global server-side private message relay logic * @param {Socket.io} io - Socket.io server instanced passed down from server.js * @param {channelManager} chanServer - Sister channel management server object */ constructor(io, chanServer){ - /** - * Socket.io server instance passed down from server.js - */ - this.io = io; - - /** - * Sister channel management server object - */ - this.chanServer = chanServer; - - /** - * Socket.io server namespace for handling messaging - */ - this.namespace = io.of('/pm'); + super(io, chanServer, "/pm"); this.chatPreprocessor = new chatPreprocessor(null, null); - - //Handle connections from private messaging namespace - this.namespace.on("connection", this.handleConnection.bind(this) ); } /** @@ -59,31 +40,21 @@ class pmHandler{ * @param {Socket} socket - Requesting Socket */ async handleConnection(socket){ - try{ - //ensure unbanned ip and valid CSRF token - if(!(await socketUtils.validateSocket(socket))){ - socket.disconnect(); - return; - } + //Check if we're properly authorized + const authorized = await super.handleConnection(socket, "${user}"); - //If the socket wasn't authorized - if(await socketUtils.authSocketLite(socket) == null){ - socket.disconnect(); - return; - } - - //Throw socket into room named after it's user + //If we're authorized + if(authorized){ + //Throw the user into their own unique channel socket.join(socket.user.user); - //Define network related event listeners against socket + //Define listeners this.defineListeners(socket); - }catch(err){ - //Flip a table if something fucks up - return loggerUtils.socketCriticalExceptionHandler(socket, err); - } + } } defineListeners(socket){ + super.defineListeners(socket); socket.on("pm", (data)=>{this.handlePM(data, socket)}); } diff --git a/www/js/channel/panels/pmPanel.js b/www/js/channel/panels/pmPanel.js index 7751d59..aaab30b 100644 --- a/www/js/channel/panels/pmPanel.js +++ b/www/js/channel/panels/pmPanel.js @@ -369,7 +369,6 @@ class pmPanel extends panelObj{ handleAutoScroll(){ //If autoscroll is enabled if(this.autoScroll){ - console.log("SCROLLME"); //Set seshBuffer scrollTop to the difference between scrollHeight and buffer height (scroll to the bottom) this.seshBuffer.scrollTop = this.seshBuffer.scrollHeight - Math.round(this.seshBuffer.getBoundingClientRect().height); }