Skip to content

Commit

Permalink
Fix potential bug with some games when typing the exit keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
radj307 committed Jan 23, 2022
1 parent f5b334b commit a8d0f44
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 3 additions & 3 deletions ARRCON/mode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ namespace mode {
std::string command;
std::getline(std::cin, command);

if (Global.allow_exit && str::tolower(command) == "exit")
break;

if (Global.connected && !command.empty()) {
rcon::command(sd, command);
std::this_thread::sleep_for(std::chrono::milliseconds(50));
}

if (Global.allow_exit && str::tolower(command) == "exit")
break;
}
// Flush & reset colors once done.
(std::cout << Global.palette.reset()).flush();
Expand Down
8 changes: 5 additions & 3 deletions ARRCON/network/net.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,12 @@ namespace net {

if (auto ret{ recv(sd, (char*)&psize, sizeof(int), 0) }; ret == 0)
throw make_exception("Connection Lost! Last Error: (", LAST_SOCKET_ERROR_CODE(), ") ", getLastSocketErrorMessage());
else if (ret != sizeof(int)) {
std::cerr << term::get_warn(!Global.no_color) << "Received a corrupted packet! Code " << ret << '\n';
return{};
else if (ret == -1) { // throw if -1
std::cerr << "Connection Closed." << std::endl;
std::exit(EXIT_SUCCESS);
}
else if (ret != sizeof(int))
throw make_exception("Received a corrupted packet! Receive returned: ", ret, "! Last Socket Error: (", LAST_SOCKET_ERROR_CODE(), ") ", getLastSocketErrorMessage());

if (psize < packet::PSIZE_MIN) {
std::cerr << term::get_warn(!Global.no_color) << "Received unexpectedly small packet size: " << psize << std::endl;
Expand Down

0 comments on commit a8d0f44

Please sign in to comment.