ServerCore/ConsoleSession.cpp
2021-08-10 14:07:50 -07:00

86 lines
2.0 KiB
C++

#include "ConsoleSession.h"
#include "TCPServer.h"
#include "Log.h"
namespace core {
ConsoleSession::ConsoleSession(EPoll &ePoll, TCPServer &server) : TCPSession(ePoll, server) {
coreutils::Log(coreutils::LOG_DEBUG_2) << "Constructing ConsoleSession...";
}
ConsoleSession::~ConsoleSession() {}
void ConsoleSession::protocol(coreutils::ZString &data) {
coreutils::ZString blank("");
coreutils::Log(coreutils::LOG_DEBUG_1) << "ConsoleSession protocol " << status;
switch (status) {
case WELCOME:
status = LOGIN;
protocol(blank);
break;
case LOGIN:
out << "User: ";
status = WAIT_USER_PROFILE;
break;
case WAIT_USER_PROFILE:
status = PASSWORD;
protocol(blank);
break;
case PASSWORD:
out << "Password: ";
status = WAIT_PASSWORD;
break;
case WAIT_PASSWORD:
status = PROMPT;
protocol(blank);
break;
case PROMPT:
out << (": ");
status = INPUT;
break;
case INPUT:
command = data;
status = PROCESS;
protocol(blank);
break;
case PROCESS:
doCommand(command);
status = command.equals((char *)"exit") ? DONE: PROMPT;
protocol(blank);
break;
case DONE:
out << "Done." << std::endl;
break;
default:
out << "Unrecognized status code: ERROR.";
break;
}
}
void ConsoleSession::writeLog(std::string data) {
// saveCursor();
// setCursorLocation(16, 1);
// restoreCursor();
}
void ConsoleSession::doCommand(coreutils::ZString request) {
// saveCursor();
// setCursorLocation(16, 1);
// out << "--> " << request << std::endl;
server.commands.processRequest(request, *this);
// restoreCursor();
}
}