Implement messages on Linux

This commit is contained in:
Substitute 2021-02-12 12:42:47 -05:00
parent 36ea06260f
commit 18ea465b93

View File

@ -26,25 +26,18 @@ auto onClientConnected(networked& client)
} }
auto onClientMessaged(networked& client, std::string& message) auto onClientMessaged(networked& client, std::string& message)
{ {
//TODO vm_stat -> vmstat
std::string commands[6] = {"date", "uptime", "vm_stat", "netstat -ant", "who", "ps"};
auto badOperand = []() {sscout << "Invalid OPCode, Ignored.\n";};
try try
{ {
int operation = std::stoi(message); int operation = std::stoi(message);
sscout << "OPCode is " << operation << ".\n"; sscout << "OPCode is " << operation << ".\n";
switch(operation) if (math::is_between<0,7>(operation))
{ client.send_message(net::system(commands[operation]));
case 1: else
client.send_message(net::system("date")); badOperand();
break; }catch(std::invalid_argument& invalid_number) { badOperand(); }
case 4:
client.send_message(net::system("netstat -ant"));
break;
default:
break;
}
}catch(std::invalid_argument& invalid_number)
{
sscout << "Invalid OPCode, Ignored.\n";
}
client.disconnect(); client.disconnect();
return true; return true;
} }