Refactoring and updating

Fix bug, when steps = 0, but player didn't lose
This commit is contained in:
2025-04-30 19:36:14 +03:00
parent 7f0e023e0c
commit d905c1a3f9
7 changed files with 85 additions and 65 deletions

View File

@@ -3,10 +3,11 @@
int main(int argc, char **argv) {
int opt;
std::string host = "localhost";
int steps = 10;
bool service_mode = false;
short unsigned port = 1024u;
while ((opt = getopt(argc, argv, "h:p:s:")) != -1) {
while ((opt = getopt(argc, argv, "h:p:sn:")) != -1) {
switch (opt) {
case 'h':
host = optarg;
@@ -14,8 +15,16 @@ int main(int argc, char **argv) {
case 'p':
port = static_cast<unsigned short>(atoi(optarg));
break;
case 'n':
steps = atoi(optarg);
if(steps <= 0) {
std::cerr << "Invalid steps" << std::endl;
return 1;
}
break;
case 's':
service_mode = true;
break;
default:
break;
}
@@ -23,7 +32,7 @@ int main(int argc, char **argv) {
try {
Server server(host, port, service_mode);
server.start();
server.start(steps);
} catch (const std::runtime_error& e){
std::cerr << "Server application error: " << e.what() << std::endl;
return 1;