Skip to content

Commit

Permalink
Added checking, parsing and displaying server & RPC statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
KimihikoAkayasaki committed Nov 4, 2022
1 parent 00fc4b9 commit 44af41f
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 91 deletions.
13 changes: 7 additions & 6 deletions Amethyst/Assets/Strings/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,13 @@
"/SharedStrings/Updates/Statuses/Downloading": "Herunterladen - 0%",
"/SharedStrings/Updates/Statuses/Error": "Fehler beim Herunterladen!",

"/ServerStatuses/Success": "Erfolg! (Code 1)\nI_OK\nAlles ist gut!",
"/ServerStatuses/WTF": "KONNTE NICHT ÜBERPRÜFEN (Code -12)\nE_WTF\nEtwas ist komplett schief gelaufen.",
"/ServerStatuses/Exception": "FEHLER BEIM ÜBERPRÜFEN (Code -10)\nE_EXCEPTION_WHILE_CHECKING\nÜberprüfe die SteamVR-Add-Ons (NICHT die Overlays) und aktiviere Amethyst.",
"/ServerStatuses/ConnectionError": "SERVERVERBINDUNGSFEHLER (Code -1)\nE_CONNECTION_ERROR\nDein Amethyst SteamVR treiber ist möglicherweise defekt oder veraltet.",
"/ServerStatuses/ServerFailure": "FATALER SERVERFEHLER (Code 10)\nE_FATAL_SERVER_FAILURE\nStarte Amethyst bitte neu, überprüfe die Logs und schreibe uns auf Discord.",
"/ServerStatuses/APIFailure": "AUSFALL DER K2API VERBINDUNG (Code -11)\nE_K2API_FAILURE\nDieser Fehler sollte eigentlich nicht auftreten. Irgendetwas stimmt gar nicht.",
"/ServerStatuses/WTF": "COULD NOT CHECK STATUS (\u15dc\u02ec\u15dc)\nE_WTF\nSomething's fucked a really big time.",
"/ServerStatuses/Success": "Success! (Code 1:0)\nI_OK\nEverything's good!",
"/ServerStatuses/ConnectionError": "SERVER CONNECTION ERROR (Code -1:{0})\nE_CONNECTION_ERROR\nCheck SteamVR add-ons (NOT overlays) and enable Amethyst.",
"/ServerStatuses/RPCChannelFailure": "RPC CHANNEL FAILURE (Code -2:{0})\nE_RPC_CHAN_FAILURE\nCould not connect to localhost:7135, is it already taken?",
"/ServerStatuses/RPCStubFailure": "RPC/API STUB FAILURE (Code -3:{0})\nE_RPC_STUB_FAILURE\nCould not derive IK2DriverService! Is the protocol valid?",
"/ServerStatuses/Exception": "EXCEPTION WHILE CHECKING (Code -10:{0})\nE_EXCEPTION_WHILE_CHECKING\nYour Amethyst SteamVR driver may be broken or outdated.",
"/ServerStatuses/ServerFailure": "FATAL SERVER FAILURE (Code 10)\nE_FATAL_SERVER_FAILURE\nPlease restart, check logs and write to us on Discord.",

"/CrashHandler/Content/AlreadyRunning": "Anscheinend läuft die App bereits\nund du hast versucht, eine zweite Instanz von Amethyst zu starten.\nDiese Aktion wird derzeit nicht unterstützt.\n\nÜberprüfe, dass die App nicht geöffnet ist.\nSollte das Problem weiterhin bestehen bleiben, klicke auf 'Beenden erzwingen'.",
"/CrashHandler/Content/Crash/NoDevices": "Es sind keine geeigneten Geräte (Plugins) zum Laden und Verwenden für das Körper-Tracking verfügbar.\n\nStelle sicher, dass alle Abhängigkeiten (dependencies) installiert sind (z.B. die richtigen Kinect SDK / Runtime und andere Abhängigkeitsbibliotheken, die von Ihren Geräten benötigt werden.",
Expand Down
11 changes: 6 additions & 5 deletions Amethyst/Assets/Strings/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,13 @@
"/SharedStrings/Updates/Statuses/Downloading": "Downloading - 0%",
"/SharedStrings/Updates/Statuses/Error": "Error downloading!",

"/ServerStatuses/Success": "Success! (Code 1)\nI_OK\nEverything's good!",
"/ServerStatuses/WTF": "COULD NOT CHECK STATUS (Code -12)\nE_WTF\nSomething's fucked a really big time.",
"/ServerStatuses/Exception": "EXCEPTION WHILE CHECKING (Code -10)\nE_EXCEPTION_WHILE_CHECKING\nCheck SteamVR add-ons (NOT overlays) and enable Amethyst.",
"/ServerStatuses/ConnectionError": "SERVER CONNECTION ERROR (Code -1)\nE_CONNECTION_ERROR\nYour Amethyst SteamVR driver may be broken or outdated.",
"/ServerStatuses/WTF": "COULD NOT CHECK STATUS (\u15dc\u02ec\u15dc)\nE_WTF\nSomething's fucked a really big time.",
"/ServerStatuses/Success": "Success! (Code 1:0)\nI_OK\nEverything's good!",
"/ServerStatuses/ConnectionError": "SERVER CONNECTION ERROR (Code -1:{0})\nE_CONNECTION_ERROR\nCheck SteamVR add-ons (NOT overlays) and enable Amethyst.",
"/ServerStatuses/RPCChannelFailure": "RPC CHANNEL FAILURE (Code -2:{0})\nE_RPC_CHAN_FAILURE\nCould not connect to localhost:7135, is it already taken?",
"/ServerStatuses/RPCStubFailure": "RPC/API STUB FAILURE (Code -3:{0})\nE_RPC_STUB_FAILURE\nCould not derive IK2DriverService! Is the protocol valid?",
"/ServerStatuses/Exception": "EXCEPTION WHILE CHECKING (Code -10:{0})\nE_EXCEPTION_WHILE_CHECKING\nYour Amethyst SteamVR driver may be broken or outdated.",
"/ServerStatuses/ServerFailure": "FATAL SERVER FAILURE (Code 10)\nE_FATAL_SERVER_FAILURE\nPlease restart, check logs and write to us on Discord.",
"/ServerStatuses/APIFailure": "COULD NOT CONNECT TO K2API (Code -11)\nE_K2API_FAILURE\nThis error shouldn't occur, actually. Something's wrong a big part.",

"/CrashHandler/Content/AlreadyRunning": "Looks like the app is already running\nand you've tried to launch a second instance,\nthis action is not currently supported.\n\nPlease check if the app isn't opened.\nIf problem persists, press the 'Force Exit' button.",
"/CrashHandler/Content/Crash/NoDevices": "There were no appropriate devices (plugins) available to load and use for body tracking.\n\nPlease check if you have all dependencies installed, like proper Kinect SDK / Runtime and other dependency libraries needed by your devices.",
Expand Down
13 changes: 7 additions & 6 deletions Amethyst/Assets/Strings/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,13 @@
"/SharedStrings/Updates/Statuses/Downloading": "Téléchargement - 0%",
"/SharedStrings/Updates/Statuses/Error": "Erreur de téléchargement !",

"/ServerStatuses/Success": "Succès! (Code 1)\nI_OK\nTout fonctionne!",
"/ServerStatuses/WTF": "STATUT INACCESSIBLE (Code -12)\nE_WTF\nQuelque chose de grave s'est produit.",
"/ServerStatuses/Exception": "UNE EXCEPTION EST SURVENUE (Code -10)\nE_EXCEPTION_WHILE_CHECKING\nVérifiez qu'Amethyst est activé dans les extensions (PAS les overlays) de SteamVR.",
"/ServerStatuses/ConnectionError": "ERREUR DE CONNEXION (Code -1)\nE_CONNECTION_ERROR\nLa version de L'extension SteamVR n'est probablement pas à jour.",
"/ServerStatuses/ServerFailure": "ERREUR FATALE (Code 10)\nE_FATAL_SERVER_FAILURE\nRelancez Amethyst. Si le problème persiste contactez-nous sur Discord.",
"/ServerStatuses/APIFailure": "CONNEXION A K4API IMPOSSIBLE (Code -11)\nE_K2API_FAILURE\nÇa devrait vraiment pas arriver. En fait, quelque chose est foutu grave.",
"/ServerStatuses/WTF": "COULD NOT CHECK STATUS (\u15dc\u02ec\u15dc)\nE_WTF\nSomething's fucked a really big time.",
"/ServerStatuses/Success": "Success! (Code 1:0)\nI_OK\nEverything's good!",
"/ServerStatuses/ConnectionError": "SERVER CONNECTION ERROR (Code -1:{0})\nE_CONNECTION_ERROR\nCheck SteamVR add-ons (NOT overlays) and enable Amethyst.",
"/ServerStatuses/RPCChannelFailure": "RPC CHANNEL FAILURE (Code -2:{0})\nE_RPC_CHAN_FAILURE\nCould not connect to localhost:7135, is it already taken?",
"/ServerStatuses/RPCStubFailure": "RPC/API STUB FAILURE (Code -3:{0})\nE_RPC_STUB_FAILURE\nCould not derive IK2DriverService! Is the protocol valid?",
"/ServerStatuses/Exception": "EXCEPTION WHILE CHECKING (Code -10:{0})\nE_EXCEPTION_WHILE_CHECKING\nYour Amethyst SteamVR driver may be broken or outdated.",
"/ServerStatuses/ServerFailure": "FATAL SERVER FAILURE (Code 10)\nE_FATAL_SERVER_FAILURE\nPlease restart, check logs and write to us on Discord.",

"/CrashHandler/Content/AlreadyRunning": "Il semble que l'application est déjà\nlancée. Une seule instance d'Amethyst peut être\nouverte à la fois.\n\nAssurez vous d'avoir quitté l'application correctement.\nSi le problème persiste, cliquez sur \"Quitter de force.\"",
"/CrashHandler/Content/Crash/NoDevices": "Aucun plug-in ou appareil est disponible à charger et utiliser pour le full-body tracking.\n\nAssurez vous que tous les pré-requis pour l'appareil de votre choix sont bien installés. (Par example: SDK et pilotes pour Kinect)",
Expand Down
13 changes: 7 additions & 6 deletions Amethyst/Assets/Strings/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,13 @@
"/SharedStrings/Updates/Statuses/Downloading": "Скачивание - 0%",
"/SharedStrings/Updates/Statuses/Error": "Ошибка при скачивании!",

"/ServerStatuses/Success": "Успешно! (Код 1)\nI_OK\nВсе работает!",
"/ServerStatuses/WTF": "НЕВОЗМОЖНО ПРОВЕРИТЬ СТАТУС (Код -12)\nE_WTF\nЧто-то пошло очень не так на этот раз.",
"/ServerStatuses/Exception": "ИСКЛЮЧЕНИЕ ПРИ ПРОВЕРКЕ (Код -10)\nE_EXCEPTION_WHILE_CHECKING\nПроверьте модули (не оверлеи) SteamVR и включите Amethyst.",
"/ServerStatuses/ConnectionError": "ОШИБКА ПОДКЛЮЧЕНИЯ К СЕРВЕРУ (Код -1)\nE_CONNECTION_ERROR\nВозможно ваша версия драйвера Amethyst для SteamVR устарела или повреждена.",
"/ServerStatuses/ServerFailure": "КРИТИЧЕСКАЯ ОШИБКА СЕРВЕРА (Код 10)\nE_FATAL_SERVER_FAILURE\nПожалуйста перезагрузите Amethyst, проверьте журнал событий и напишите нам в Discord.",
"/ServerStatuses/APIFailure": "НЕВОЗМОЖНО ПОДКЛЮЧИТЬСЯ К K2API (Код -11)\nE_K2API_FAILURE\nЭтой ошибки вообще не должно быть. Что-то совсем все плохо.",
"/ServerStatuses/WTF": "COULD NOT CHECK STATUS (\u15dc\u02ec\u15dc)\nE_WTF\nSomething's fucked a really big time.",
"/ServerStatuses/Success": "Success! (Code 1:0)\nI_OK\nEverything's good!",
"/ServerStatuses/ConnectionError": "SERVER CONNECTION ERROR (Code -1:{0})\nE_CONNECTION_ERROR\nCheck SteamVR add-ons (NOT overlays) and enable Amethyst.",
"/ServerStatuses/RPCChannelFailure": "RPC CHANNEL FAILURE (Code -2:{0})\nE_RPC_CHAN_FAILURE\nCould not connect to localhost:7135, is it already taken?",
"/ServerStatuses/RPCStubFailure": "RPC/API STUB FAILURE (Code -3:{0})\nE_RPC_STUB_FAILURE\nCould not derive IK2DriverService! Is the protocol valid?",
"/ServerStatuses/Exception": "EXCEPTION WHILE CHECKING (Code -10:{0})\nE_EXCEPTION_WHILE_CHECKING\nYour Amethyst SteamVR driver may be broken or outdated.",
"/ServerStatuses/ServerFailure": "FATAL SERVER FAILURE (Code 10)\nE_FATAL_SERVER_FAILURE\nPlease restart, check logs and write to us on Discord.",

"/CrashHandler/Content/AlreadyRunning": "Похоже программа уже запущена.\nНа данный момент запуск еще одного процесса\nне поддерживается.\n\nПожалуйста убедитесь, что программа не запущена.\nЕсли проблема не устранена, нажмите кнопку \"Принудительный выход\".",
"/CrashHandler/Content/Crash/NoDevices": "Подходящих устройств (модулей) доступных для загрузки и использования трекинга не обнаружено.\n\nУбедитесь, установлены ли все зависимости такие как Kinect SDK / Runtime и прочие библиотеки требуемые вашими устройствами.",
Expand Down
104 changes: 69 additions & 35 deletions Amethyst/K2Interfacing.h
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,8 @@ namespace k2app::interfacing

// Server interfacing data
inline int serverDriverStatusCode = 0;
inline int serverRPCStatusCode = 0;

inline uint32_t pingTime = 0, parsingTime = 0;
inline bool isServerDriverPresent = false,
serverDriverFailure = false;
Expand Down Expand Up @@ -752,7 +754,7 @@ namespace k2app::interfacing
* \brief This will init K2API and server driver
* \return Success?
*/
inline bool TestK2ServerConnection()
inline grpc::Status TestK2ServerConnection()
{
// Do not spawn 1000 voids, check how many do we have
if (pingCheckingThreadsNumber <= maxPingCheckingThreads)
Expand All @@ -763,7 +765,7 @@ namespace k2app::interfacing
try
{
// Send a ping message and capture the data
const auto [success, send_time,
const auto [status, send_time,
receive_time, full_time] = ktvr::test_connection();

// Dump data to variables
Expand All @@ -773,7 +775,7 @@ namespace k2app::interfacing
// Log ?success
LOG(INFO) <<
"Connection test has ended, [result: " <<
(success ? "success" : "fail") << "]";
(status.ok() ? "success" : "fail") << "]";

// Log some data if needed
LOG(INFO) << "\n" <<
Expand All @@ -787,7 +789,7 @@ namespace k2app::interfacing
static_cast<int>(maxPingCheckingThreads) + 1);

// Return the result
return success;
return status;
}
catch (const std::exception& e)
{
Expand All @@ -799,20 +801,21 @@ namespace k2app::interfacing
pingCheckingThreadsNumber = std::clamp(
static_cast<int>(pingCheckingThreadsNumber) - 1, 0,
static_cast<int>(maxPingCheckingThreads) + 1);
return false;

return grpc::Status(grpc::UNKNOWN, "An exception occurred.");
}
}

// else
LOG(ERROR) << "Connection checking threads exceeds 3, aborting...";
return false;
return grpc::Status(grpc::UNAVAILABLE, "Too many simultaneous checking threads.");
}

/**
* \brief This will check K2API and server driver
* \return Success?
*/
inline int CheckK2ServerStatus()
inline std::pair<int, int> CheckK2ServerStatus()
{
if (!isServerDriverPresent)
{
Expand All @@ -823,7 +826,7 @@ namespace k2app::interfacing
LOG(INFO) << "AME_API version name: " << ktvr::IAME_API_Version;

const auto init_code = ktvr::init_ame_api();
bool server_connected = false;
grpc::Status server_status;

LOG(INFO) << "Server IPC initialization " <<
(init_code == 0 ? "succeed" : "failed") << ", exit code: " << init_code;
Expand All @@ -837,28 +840,36 @@ namespace k2app::interfacing
for (int i = 0; i < 3; i++)
{
LOG(INFO) << "Starting the test no " << i + 1 << "...";
server_connected = TestK2ServerConnection();
server_status = TestK2ServerConnection();
// Not direct assignment since it's only a one-way check
if (server_connected)isServerDriverPresent = true;
if (server_status.ok())isServerDriverPresent = true;
}
}

return init_code == 0
? (server_connected ? 1 : -1)
: -10;
}
catch (const std::exception& e) { return -10; }
// If the API is ok
? (server_status.ok()
// If the server is/isn't ok
? std::make_pair(1, server_status.error_code())
: std::make_pair(-1, server_status.error_code()))
// If the API is not ok
: std::make_pair(init_code, grpc::UNKNOWN);
}
catch (const std::exception& e) { return {-10, grpc::UNKNOWN}; }
}

/*
* codes:
codes:
-10: driver is disabled
-1: driver is workin but outdated or doomed
10: ur pc brokey, cry about it
1: ok
all ok: 1
server could not be reached: -1
exception when trying to reach: -10
could not create rpc channel: -2
could not create rpc stub: -3
fatal run-time failure: 10
*/
return 1; //don't check if it was already working
return {1, grpc::OK}; // Don't check if already ok
}

/**
Expand All @@ -869,8 +880,8 @@ namespace k2app::interfacing
{
if (!serverDriverFailure)
{
// Backup the status
serverDriverStatusCode = CheckK2ServerStatus();
// Backup the server and RPC status
std::tie(serverDriverStatusCode, serverRPCStatusCode) = CheckK2ServerStatus();
}
else
{
Expand All @@ -880,30 +891,53 @@ namespace k2app::interfacing

isServerDriverPresent = false; // Assume fail
serverStatusString = LocalizedJSONString(L"/ServerStatuses/WTF");
//L"COULD NOT CHECK STATUS (Code -12)\nE_WTF\nSomething's fucked a really big time.";
//L"COULD NOT CHECK STATUS (\u15dc\u02ec\u15dc)\nE_WTF\nSomething's fucked a really big time.";

using namespace std::string_literals;
switch (serverDriverStatusCode)
{
case -10:
serverStatusString = LocalizedJSONString(L"/ServerStatuses/Exception");
//L"EXCEPTION WHILE CHECKING (Code -10)\nE_EXCEPTION_WHILE_CHECKING\nCheck SteamVR add-ons (NOT overlays) and enable Amethyst.";
case 1:
serverStatusString = LocalizedJSONString(L"/ServerStatuses/Success");
//L"Success! (Code 1)\nI_OK\nEverything's good!";
isServerDriverPresent = true; // Change to success
break;

case -1:
serverStatusString = LocalizedJSONString(L"/ServerStatuses/ConnectionError");
//L"SERVER CONNECTION ERROR (Code -1)\nE_CONNECTION_ERROR\nYour Amethyst SteamVR driver may be broken or outdated.";
serverStatusString = stringReplaceAll_R(
LocalizedJSONString(L"/ServerStatuses/ConnectionError"),
L"{0}"s, std::to_wstring(serverRPCStatusCode));
//L"SERVER CONNECTION ERROR (Code -1:{0})\nE_CONNECTION_ERROR\nCheck SteamVR add-ons (NOT overlays) and enable Amethyst.";
break;

case -10:
serverStatusString = stringReplaceAll_R(
LocalizedJSONString(L"/ServerStatuses/Exception"),
L"{0}"s, std::to_wstring(serverRPCStatusCode));
//L"EXCEPTION WHILE CHECKING (Code -10)\nE_EXCEPTION_WHILE_CHECKING\nCheck SteamVR add-ons (NOT overlays) and enable Amethyst.";
break;

case -2:
serverStatusString = stringReplaceAll_R(
LocalizedJSONString(L"/ServerStatuses/RPCChannelFailure"),
L"{0}"s, std::to_wstring(serverRPCStatusCode));
//L"RPC CHANNEL FAILURE (Code -2:{0})\nE_RPC_CHAN_FAILURE\nCould not connect to localhost:7135, is it already taken?";
break;

case -3:
serverStatusString = stringReplaceAll_R(
LocalizedJSONString(L"/ServerStatuses/RPCStubFailure"),
L"{0}"s, std::to_wstring(serverRPCStatusCode));
//L"RPC/API STUB FAILURE (Code -3:{0})\nE_RPC_STUB_FAILURE\nCould not derive IK2DriverService! Is the protocol valid?";
break;

case 10:
serverStatusString = LocalizedJSONString(L"/ServerStatuses/ServerFailure");
//L"FATAL SERVER FAILURE (Code 10)\nE_FATAL_SERVER_FAILURE\nPlease restart, check logs and write to us on Discord.";
break;
case 1:
serverStatusString = LocalizedJSONString(L"/ServerStatuses/Success");
//L"Success! (Code 1)\nI_OK\nEverything's good!";
isServerDriverPresent = true; // Change to success