Fixed critical bug with server-side commandPreprocessor
This commit is contained in:
parent
f8a6e00345
commit
4c1d3c9db5
|
|
@ -32,84 +32,87 @@ module.exports = class commandPreprocessor{
|
|||
}
|
||||
|
||||
async preprocess(socket, data){
|
||||
//Set socket, data, and sendFlag
|
||||
this.socket = socket;
|
||||
this.sendFlag = true;
|
||||
this.rawData = data;
|
||||
this.chatType = 'chat';
|
||||
//Set command object
|
||||
let commandObj = {
|
||||
socket,
|
||||
sendFlag: true,
|
||||
rawData: data,
|
||||
chatType: 'chat'
|
||||
}
|
||||
|
||||
//If we don't pass sanatization/validation turn this car around
|
||||
if(!this.sanatizeCommand()){
|
||||
if(!this.sanatizeCommand(commandObj)){
|
||||
return;
|
||||
}
|
||||
|
||||
//split the command
|
||||
this.splitCommand();
|
||||
this.splitCommand(commandObj);
|
||||
|
||||
//Process the command
|
||||
await this.processServerCommand();
|
||||
await this.processServerCommand(commandObj);
|
||||
|
||||
//If we're going to relay this command as a message, continue on to chat processing
|
||||
if(this.sendFlag){
|
||||
if(commandObj.sendFlag){
|
||||
//Prep the message
|
||||
await this.prepMessage();
|
||||
await this.prepMessage(commandObj);
|
||||
|
||||
//Send the chat
|
||||
this.sendChat();
|
||||
this.sendChat(commandObj);
|
||||
}
|
||||
}
|
||||
|
||||
sanatizeCommand(){
|
||||
sanatizeCommand(commandObj){
|
||||
//Trim and Sanatize for XSS
|
||||
this.command = validator.trim(validator.escape(this.rawData.msg));
|
||||
commandObj.command = validator.trim(validator.escape(commandObj.rawData.msg));
|
||||
|
||||
//nuke the message if its empty or huge
|
||||
return (validator.isLength(this.command, {min: 1, max: 255}));
|
||||
//Return whether or not the shit was long enough
|
||||
return (validator.isLength(commandObj.rawData.msg, {min: 1, max: 255}));
|
||||
}
|
||||
|
||||
splitCommand(){
|
||||
splitCommand(commandObj){
|
||||
//Split string by words
|
||||
this.commandArray = this.command.split(/\b/g);//Split by word-borders
|
||||
this.argumentArray = this.command.match(/\b\w+\b/g);//Match by words surrounded by borders
|
||||
commandObj.commandArray = commandObj.command.split(/\b/g);//Split by word-borders
|
||||
commandObj.argumentArray = commandObj.command.match(/\b\w+\b/g);//Match by words surrounded by borders
|
||||
}
|
||||
|
||||
async processServerCommand(){
|
||||
async processServerCommand(commandObj){
|
||||
//If the raw message starts with '!' (skip commands that start with whitespace so people can send example commands in chat)
|
||||
if(this.rawData.msg[0] == '!'){
|
||||
if(commandObj.rawData.msg[0] == '!'){
|
||||
//if it isn't just an exclimation point, and we have a real command
|
||||
if(this.argumentArray != null){
|
||||
if(this.commandProcessor[this.argumentArray[0].toLowerCase()] != null){
|
||||
if(commandObj.argumentArray != null){
|
||||
if(this.commandProcessor[commandObj.argumentArray[0].toLowerCase()] != null){
|
||||
//Process the command and use the return value to set the sendflag (true if command valid)
|
||||
this.sendFlag = await this.commandProcessor[this.argumentArray[0].toLowerCase()](this);
|
||||
commandObj.sendFlag = await this.commandProcessor[commandObj.argumentArray[0].toLowerCase()](commandObj);
|
||||
}else{
|
||||
//Process as toke command if we didnt get a match from the standard server-side command processor
|
||||
this.sendFlag = await this.tokebot.tokeProcessor(this);
|
||||
commandObj.sendFlag = await this.tokebot.tokeProcessor(commandObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async markLinks(){
|
||||
//Empty out the links array
|
||||
this.links = [];
|
||||
async markLinks(commandObj){
|
||||
//Setup the links array
|
||||
commandObj.links = [];
|
||||
|
||||
//For each link sent from the client
|
||||
//this.rawData.links.forEach((link) => {
|
||||
for (const link of this.rawData.links){
|
||||
for (const link of commandObj.rawData.links){
|
||||
//Add a marked link object to our links array
|
||||
this.links.push(await linkUtils.markLink(link));
|
||||
commandObj.links.push(await linkUtils.markLink(link));
|
||||
}
|
||||
}
|
||||
|
||||
async prepMessage(){
|
||||
async prepMessage(commandObj){
|
||||
//Create message from commandArray
|
||||
this.message = this.commandArray.join('').trimStart();
|
||||
commandObj.message = commandObj.commandArray.join('').trimStart();
|
||||
//Validate links and mark them by embed type
|
||||
await this.markLinks();
|
||||
await this.markLinks(commandObj);
|
||||
}
|
||||
|
||||
sendChat(){
|
||||
sendChat(commandObj){
|
||||
//FUCKIN' SEND IT!
|
||||
this.chatHandler.relayUserChat(this.socket, this.message, this.chatType, this.links);
|
||||
this.chatHandler.relayUserChat(commandObj.socket, commandObj.message, commandObj.chatType, commandObj.links);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue