From 83afaa06816af548c75363ea5008214a59b6aada Mon Sep 17 00:00:00 2001 From: Guillaume Meunier Date: Fri, 9 Feb 2024 11:15:58 +0100 Subject: [PATCH] Show tooltip when the server version is incompatible --- client/scenes/lobby.cpp | 29 +++++++++++++++++++++++------ client/scenes/lobby.h | 1 + client/scenes/lobby_gui.cpp | 8 +++++++- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/client/scenes/lobby.cpp b/client/scenes/lobby.cpp index 80e5a293..6e3ce28e 100644 --- a/client/scenes/lobby.cpp +++ b/client/scenes/lobby.cpp @@ -197,6 +197,7 @@ scenes::lobby::lobby() .autoconnect = i["autoconnect"].get_bool(), .manual = i["manual"].get_bool(), .visible = false, + .compatible = true, .service = { .name = (std::string)i["pretty_name"], .hostname = (std::string)i["hostname"], @@ -411,15 +412,30 @@ void scenes::lobby::update_server_list() data.visible = false; } + char protocol_string[17]; + sprintf(protocol_string, "%016lx", xrt::drivers::wivrn::protocol_version); + for(auto& service: discovered_services) { - if (service.txt.find("cookie") == service.txt.end()) - { - spdlog::info("Ignored {} because there is no cookie field", service.name); - continue; - } + std::string cookie; + bool compatible = true; + + auto it = service.txt.find("cookie"); + if (it == service.txt.end()) + { + cookie = service.hostname; + compatible = false; + } + else + cookie = it->second; + + auto protocol = service.txt.find("protocol"); + if (protocol == service.txt.end()) + compatible = false; + + if (protocol->second != protocol_string) + compatible = false; - auto cookie = service.txt.at("cookie"); auto server = servers.find(cookie); if (server == servers.end()) { @@ -428,6 +444,7 @@ void scenes::lobby::update_server_list() .autoconnect = false, .manual = false, .visible = true, + .compatible = compatible, .service = service }); } diff --git a/client/scenes/lobby.h b/client/scenes/lobby.h index 41044710..bcb19ca5 100644 --- a/client/scenes/lobby.h +++ b/client/scenes/lobby.h @@ -47,6 +47,7 @@ class lobby : public scene_impl bool autoconnect; bool manual; bool visible; + bool compatible; wivrn_discover::service service; }; diff --git a/client/scenes/lobby_gui.cpp b/client/scenes/lobby_gui.cpp index a6aae762..07923608 100644 --- a/client/scenes/lobby_gui.cpp +++ b/client/scenes/lobby_gui.cpp @@ -245,7 +245,7 @@ void scenes::lobby::gui_server_list() button_position.x -= button_size.x + style.WindowPadding.x; ImGui::SetCursorPos(button_position); - bool enable_connect_button = data.visible || data.manual; + bool enable_connect_button = (data.visible || data.manual) && data.compatible; ImGui::BeginDisabled(!enable_connect_button); if (enable_connect_button) { @@ -266,6 +266,12 @@ void scenes::lobby::gui_server_list() } vibrate_on_hover(); + if (ImGui::IsItemHovered()) + { + if (!data.compatible) + ImGui::SetTooltip("Incompatible server version"); + } + ImGui::PopStyleColor(3); ImGui::EndDisabled();