Implement messages on Linux
This commit is contained in:
parent
36ea06260f
commit
18ea465b93
23
main.cpp
23
main.cpp
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user