diff --git a/main.cpp b/main.cpp index 8c98d6f..488e1d4 100644 --- a/main.cpp +++ b/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; }