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