diff --git a/src/app/auxServer.js b/src/app/auxServer.js deleted file mode 100644 index 3a66337..0000000 --- a/src/app/auxServer.js +++ /dev/null @@ -1,79 +0,0 @@ -/*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 5e16ffc..b783be8 100644 --- a/src/app/pm/pmHandler.js +++ b/src/app/pm/pmHandler.js @@ -14,25 +14,44 @@ 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 extends auxServer{ +class pmHandler{ /** * 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){ - super(io, chanServer, "/pm"); + /** + * 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'); this.chatPreprocessor = new chatPreprocessor(null, null); + + //Handle connections from private messaging namespace + this.namespace.on("connection", this.handleConnection.bind(this) ); } /** @@ -40,21 +59,31 @@ class pmHandler extends auxServer{ * @param {Socket} socket - Requesting Socket */ async handleConnection(socket){ - //Check if we're properly authorized - const authorized = await super.handleConnection(socket, "${user}"); + try{ + //ensure unbanned ip and valid CSRF token + if(!(await socketUtils.validateSocket(socket))){ + socket.disconnect(); + return; + } - //If we're authorized - if(authorized){ - //Throw the user into their own unique channel + //If the socket wasn't authorized + if(await socketUtils.authSocketLite(socket) == null){ + socket.disconnect(); + return; + } + + //Throw socket into room named after it's user socket.join(socket.user.user); - //Define listeners + //Define network related event listeners against socket 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 aaab30b..7751d59 100644 --- a/www/js/channel/panels/pmPanel.js +++ b/www/js/channel/panels/pmPanel.js @@ -369,6 +369,7 @@ 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); }