diff --git a/src/connection.cpp b/src/connection.cpp index e8582c6..6944503 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -10,6 +10,7 @@ #include "../lib/silentdragonlitelib.h" #include "precompiled.h" #include +#include "sdl.h" using json = nlohmann::json; @@ -357,15 +358,39 @@ QString litelib_process_response(char* resp) ************************************************************************************/ void Executor::run() { - char* resp = litelib_execute(this->cmd.toStdString().c_str(), this->args.toStdString().c_str()); - QString reply = litelib_process_response(resp); + auto config = std::shared_ptr(new ConnectionConfig()); + DEBUG("cmd=" << cmd << " args=" << args << " server=" << config->server); + QString response = ""; + try { + char* resp = litelib_execute(this->cmd.toStdString().c_str(), this->args.toStdString().c_str()); + response = litelib_process_response(resp); + } catch (const std::exception& e) { + DEBUG("ignoring exception: " << e.what() ); + } + + if (response.toUpper().trimmed() != "OK") { + config->server = Settings::getRandomServer(); + + try { + char* resp = litelib_initialize_existing( + config->dangerous, + config->server.toStdString().c_str() + ); + response = litelib_process_response(resp); + resp = litelib_execute(this->cmd.toStdString().c_str(), this->args.toStdString().c_str()); + response = litelib_process_response(resp); + } catch (const std::exception& e) { + DEBUG("server= " << config->server << " gave exception: " << e.what() ); + emit handleError(response); + } + } auto parsed = json::parse( - reply.toStdString().c_str(), + response.toStdString().c_str(), nullptr, false ); if (parsed.is_discarded() || parsed.is_null()) { - emit handleError(reply); + emit handleError(response); } else { emit responseReady(parsed); }