From 94d3445cd2cbe334ad29ed2e0d85da57980658cf Mon Sep 17 00:00:00 2001 From: Ayndpa Date: Wed, 19 Nov 2025 21:07:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=BF=9E=E6=8E=A5=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E5=88=97=E5=88=B0=E7=94=A8=E6=88=B7=E5=88=97=E8=A1=A8?= =?UTF-8?q?=EF=BC=8C=E4=BC=98=E5=8C=96=E8=BF=9E=E6=8E=A5=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- online_game_tool.cpp | 13 ++++++++++++- steam/steam_networking_manager.cpp | 22 ++++++++++++++++++++++ steam/steam_networking_manager.h | 1 + 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/online_game_tool.cpp b/online_game_tool.cpp index e5bd347..dc4014d 100644 --- a/online_game_tool.cpp +++ b/online_game_tool.cpp @@ -209,10 +209,11 @@ int main() { ImGui::Begin("房间状态"); ImGui::Text("用户列表:"); - if (ImGui::BeginTable("UserTable", 2, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg)) + if (ImGui::BeginTable("UserTable", 3, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg)) { ImGui::TableSetupColumn("名称"); ImGui::TableSetupColumn("延迟 (ms)"); + ImGui::TableSetupColumn("连接类型"); ImGui::TableHeadersRow(); { std::vector members = roomManager.getLobbyMembers(); @@ -227,10 +228,13 @@ int main() if (memberID == mySteamID) { ImGui::Text("-"); + ImGui::TableNextColumn(); + ImGui::Text("-"); } else { int ping = 0; + std::string relayInfo = "N/A"; if (steamManager.isHost()) { // Find connection for this member @@ -243,6 +247,7 @@ int main() if (info.m_identityRemote.GetSteamID() == memberID) { ping = steamManager.getConnectionPing(conn); + relayInfo = steamManager.getConnectionRelayInfo(conn); break; } } @@ -252,8 +257,14 @@ int main() { // Client shows ping to host ping = steamManager.getHostPing(); + if (steamManager.getConnection() != k_HSteamNetConnection_Invalid) + { + relayInfo = steamManager.getConnectionRelayInfo(steamManager.getConnection()); + } } ImGui::Text("%d", ping); + ImGui::TableNextColumn(); + ImGui::Text("%s", relayInfo.c_str()); } } } diff --git a/steam/steam_networking_manager.cpp b/steam/steam_networking_manager.cpp index 0b7f5c6..fbd84cf 100644 --- a/steam/steam_networking_manager.cpp +++ b/steam/steam_networking_manager.cpp @@ -211,6 +211,28 @@ int SteamNetworkingManager::getConnectionPing(HSteamNetConnection conn) const return 0; } +std::string SteamNetworkingManager::getConnectionRelayInfo(HSteamNetConnection conn) const +{ + SteamNetConnectionInfo_t info; + if (m_pInterface->GetConnectionInfo(conn, &info)) + { + // Check if connection is using relay + if (info.m_nFlags & k_nSteamNetworkConnectionInfoFlags_Relayed) + { + return "中继"; + } + else if (info.m_nFlags & k_nSteamNetworkConnectionInfoFlags_Fast) + { + return "直连"; + } + else + { + return "未知"; + } + } + return "N/A"; +} + void SteamNetworkingManager::handleConnectionStatusChanged(SteamNetConnectionStatusChangedCallback_t *pInfo) { std::lock_guard lock(connectionsMutex); diff --git a/steam/steam_networking_manager.h b/steam/steam_networking_manager.h index 94b5eeb..e0e3a36 100644 --- a/steam/steam_networking_manager.h +++ b/steam/steam_networking_manager.h @@ -45,6 +45,7 @@ public: int getConnectionPing(HSteamNetConnection conn) const; HSteamNetConnection getConnection() const { return g_hConnection; } ISteamNetworkingSockets* getInterface() const { return m_pInterface; } + std::string getConnectionRelayInfo(HSteamNetConnection conn) const; // For SteamRoomManager access std::unique_ptr*& getServer() { return server_; }