Added basic serverside command logic (no commands yet)

This commit is contained in:
rainbow napkin 2024-12-08 08:55:49 -05:00
parent 358d01d730
commit 4c1f0f10a7
3 changed files with 58 additions and 3 deletions

View file

@ -0,0 +1,48 @@
module.exports = class commandPreprocessor{
constructor(server){
this.server = server;
this.commandProcessor = new commandProcessor(server);
}
preprocess(socket, data){
//Set command, socket and sendFlag
this.command = data.msg;
this.socket = socket;
this.sendFlag = true;
this.splitBody();
this.processServerCommand();
this.sendChat();
}
splitBody(){
//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
}
processServerCommand(){
if(this.commandArray[0] == '!'){
if(this.argumentArray != null && this.commandProcessor[this.argumentArray[0]] != null){
this.sendFlag = false;
this.commandProcessor[this.argumentArray[0]](this.socket, this.argumentArray);
}
}
}
sendChat(){
if(this.sendFlag){
this.server.chatHandler.relayChat(this.socket, this.commandArray.join(''));
}
}
}
class commandProcessor{
constructor(server){
this.server = server;
}
whisper(socket, argumentArray){
console.log(argumentArray);
}
}