Initial repository 1.0.0
This commit is contained in:
commit
d8b1275884
1861 files changed
+66342
No files matched your search
@@ -0,0 +1,114 @@
|
||||
#include "ConsoleSession.h"
|
||||
|
||||
namespace core {
|
||||
|
||||
ConsoleSession::ConsoleSession(EPoll &ePoll, ConsoleServer &server) : TerminalSession(ePoll, server) {
|
||||
}
|
||||
|
||||
ConsoleSession::~ConsoleSession() {
|
||||
}
|
||||
|
||||
void ConsoleSession::output(std::stringstream &out) {
|
||||
// socket->output(out);
|
||||
}
|
||||
|
||||
void ConsoleSession::protocol(std::string data = "") {
|
||||
|
||||
switch (status) {
|
||||
|
||||
case WELCOME:
|
||||
setBackColor(BG_BLACK);
|
||||
clear();
|
||||
setCursorLocation(1, 1);
|
||||
setBackColor(BG_BLUE);
|
||||
clearEOL();
|
||||
out << "ConsoleSession";
|
||||
setCursorLocation(2, 1);
|
||||
setBackColor(BG_BLACK);
|
||||
status = LOGIN;
|
||||
protocol();
|
||||
break;
|
||||
|
||||
case LOGIN:
|
||||
setCursorLocation(3, 3);
|
||||
out << "Enter User Profile: ";
|
||||
send();
|
||||
status = WAIT_USER_PROFILE;
|
||||
break;
|
||||
|
||||
case WAIT_USER_PROFILE:
|
||||
status = PASSWORD;
|
||||
protocol();
|
||||
break;
|
||||
|
||||
case PASSWORD:
|
||||
setCursorLocation(4, 7);
|
||||
out << "Enter Password: ";
|
||||
send();
|
||||
status = WAIT_PASSWORD;
|
||||
break;
|
||||
|
||||
case WAIT_PASSWORD:
|
||||
setBackColor(BG_BLACK);
|
||||
clear();
|
||||
setCursorLocation(1, 1);
|
||||
setBackColor(BG_BLUE);
|
||||
clearEOL();
|
||||
out << "ConsoleSession";
|
||||
setCursorLocation(2, 1);
|
||||
setBackColor(BG_BLACK);
|
||||
scrollArea(2, 16);
|
||||
status = PROMPT;
|
||||
protocol();
|
||||
break;
|
||||
|
||||
case PROMPT:
|
||||
Log(LOG_DEBUG_1) << "Lines is " << getLines() << ".";
|
||||
setCursorLocation(17, 1);
|
||||
clearEOL();
|
||||
out << ("--> ");
|
||||
send();
|
||||
status = INPUT;
|
||||
break;
|
||||
|
||||
case INPUT:
|
||||
command = std::string(data);
|
||||
command.erase(command.find_last_not_of("\r\n\t") + 1);
|
||||
status = PROCESS;
|
||||
protocol();
|
||||
break;
|
||||
|
||||
case PROCESS:
|
||||
doCommand(command);
|
||||
status = (command == "exit")? DONE: PROMPT;
|
||||
protocol();
|
||||
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);
|
||||
out << data;
|
||||
restoreCursor();
|
||||
send();
|
||||
}
|
||||
|
||||
void ConsoleSession::doCommand(std::string request) {
|
||||
saveCursor();
|
||||
setCursorLocation(16, 1);
|
||||
out << "--> " << request << std::endl;
|
||||
server.commands.processRequest(request, this);
|
||||
restoreCursor();
|
||||
send();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user