添加连接类型列到用户列表,优化连接信息显示逻辑

This commit is contained in:
Ayndpa
2025-11-19 21:07:48 +08:00
parent 47943a0052
commit 94d3445cd2
3 changed files with 35 additions and 1 deletions

View File

@@ -209,10 +209,11 @@ int main()
{ {
ImGui::Begin("房间状态"); ImGui::Begin("房间状态");
ImGui::Text("用户列表:"); ImGui::Text("用户列表:");
if (ImGui::BeginTable("UserTable", 2, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg)) if (ImGui::BeginTable("UserTable", 3, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg))
{ {
ImGui::TableSetupColumn("名称"); ImGui::TableSetupColumn("名称");
ImGui::TableSetupColumn("延迟 (ms)"); ImGui::TableSetupColumn("延迟 (ms)");
ImGui::TableSetupColumn("连接类型");
ImGui::TableHeadersRow(); ImGui::TableHeadersRow();
{ {
std::vector<CSteamID> members = roomManager.getLobbyMembers(); std::vector<CSteamID> members = roomManager.getLobbyMembers();
@@ -227,10 +228,13 @@ int main()
if (memberID == mySteamID) if (memberID == mySteamID)
{ {
ImGui::Text("-"); ImGui::Text("-");
ImGui::TableNextColumn();
ImGui::Text("-");
} }
else else
{ {
int ping = 0; int ping = 0;
std::string relayInfo = "N/A";
if (steamManager.isHost()) if (steamManager.isHost())
{ {
// Find connection for this member // Find connection for this member
@@ -243,6 +247,7 @@ int main()
if (info.m_identityRemote.GetSteamID() == memberID) if (info.m_identityRemote.GetSteamID() == memberID)
{ {
ping = steamManager.getConnectionPing(conn); ping = steamManager.getConnectionPing(conn);
relayInfo = steamManager.getConnectionRelayInfo(conn);
break; break;
} }
} }
@@ -252,8 +257,14 @@ int main()
{ {
// Client shows ping to host // Client shows ping to host
ping = steamManager.getHostPing(); ping = steamManager.getHostPing();
if (steamManager.getConnection() != k_HSteamNetConnection_Invalid)
{
relayInfo = steamManager.getConnectionRelayInfo(steamManager.getConnection());
}
} }
ImGui::Text("%d", ping); ImGui::Text("%d", ping);
ImGui::TableNextColumn();
ImGui::Text("%s", relayInfo.c_str());
} }
} }
} }

View File

@@ -211,6 +211,28 @@ int SteamNetworkingManager::getConnectionPing(HSteamNetConnection conn) const
return 0; 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) void SteamNetworkingManager::handleConnectionStatusChanged(SteamNetConnectionStatusChangedCallback_t *pInfo)
{ {
std::lock_guard<std::mutex> lock(connectionsMutex); std::lock_guard<std::mutex> lock(connectionsMutex);

View File

@@ -45,6 +45,7 @@ public:
int getConnectionPing(HSteamNetConnection conn) const; int getConnectionPing(HSteamNetConnection conn) const;
HSteamNetConnection getConnection() const { return g_hConnection; } HSteamNetConnection getConnection() const { return g_hConnection; }
ISteamNetworkingSockets* getInterface() const { return m_pInterface; } ISteamNetworkingSockets* getInterface() const { return m_pInterface; }
std::string getConnectionRelayInfo(HSteamNetConnection conn) const;
// For SteamRoomManager access // For SteamRoomManager access
std::unique_ptr<TCPServer>*& getServer() { return server_; } std::unique_ptr<TCPServer>*& getServer() { return server_; }