ServerCore/CommandList.cpp
2020-04-13 09:40:58 -07:00

52 lines
1.3 KiB
C++

#include "CommandList.h"
#include "Log.h"
namespace core {
void CommandList::add(Command &command, std::string name) {
command.setName(name);
commands.push_back(&command);
}
void CommandList::remove(Command &command) {
}
bool CommandList::processRequest(std::string request, TCPSession *session, std::stringstream &data) {
std::stringstream input = std::stringstream(request);
while(!input.eof()) {
std::string requests;
std::getline(input, requests);
if(session->grab != NULL)
session->grab->processCommand(requests, session, data);
else {
int pos = requests.find(" ");
std::string function = pos == requests.npos ? requests: requests.substr(0, pos);
for(auto *command : commands)
if(command->check(function))
command->processCommand(requests, session, data);
}
}
return true;
}
bool CommandList::grabInput(TCPSession *session, Command &command) {
session->grab = &command;
return true;
}
void CommandList::clearGrab(TCPSession *session) {
session->grab = NULL;
}
int CommandList::processCommand(std::string request, TCPSession *session, std::stringstream &data) {
for(Command *command : commands)
data << command->getName() << std::endl;
return true;
}
}