From a0b66407bf2b8da686a708802cbc412f9cd386ca Mon Sep 17 00:00:00 2001 From: Mr_Goldberg Date: Tue, 3 Mar 2020 09:04:04 -0500 Subject: [PATCH] Some networking/matchmaking improvements. --- dll/network.cpp | 10 ++++++++++ dll/network.h | 1 + dll/steam_matchmaking.h | 9 ++++++--- dll/steam_networking.h | 7 +++---- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/dll/network.cpp b/dll/network.cpp index 38306da8..4a8d8f26 100644 --- a/dll/network.cpp +++ b/dll/network.cpp @@ -1141,6 +1141,16 @@ bool Networking::sendToIPPort(Common_Message *msg, uint32 ip, uint16 port, bool return true; } +uint32 Networking::getIP(CSteamID id) +{ + Connection *conn = find_connection(id, this->appid); + if (conn) { + return ntohl(conn->tcp_ip_port.ip); + } + + return 0; +} + bool Networking::sendTo(Common_Message *msg, bool reliable, Connection *conn) { if (!enabled) return false; diff --git a/dll/network.h b/dll/network.h index 1d6119aa..793b0f44 100644 --- a/dll/network.h +++ b/dll/network.h @@ -135,6 +135,7 @@ public: bool sendToIPPort(Common_Message *msg, uint32 ip, uint16 port, bool reliable); bool setCallback(Callback_Ids id, CSteamID steam_id, void (*message_callback)(void *object, Common_Message *msg), void *object); + uint32 getIP(CSteamID id); uint32 getOwnIP(); void shutDown(); diff --git a/dll/steam_matchmaking.h b/dll/steam_matchmaking.h index 10315405..91227555 100644 --- a/dll/steam_matchmaking.h +++ b/dll/steam_matchmaking.h @@ -113,7 +113,7 @@ void send_lobby_data() } } -void trigger_lobby_dataupdate(CSteamID lobby, CSteamID member, bool success, double cb_timeout=0.0, bool send_changed_lobby=true) +void trigger_lobby_dataupdate(CSteamID lobby, CSteamID member, bool success, double cb_timeout=0.005, bool send_changed_lobby=true) { PRINT_DEBUG("Lobby dataupdate %llu %llu\n", lobby.ConvertToUint64(), member.ConvertToUint64()); LobbyDataUpdate_t data; @@ -1092,9 +1092,12 @@ CSteamID GetLobbyOwner( CSteamID steamIDLobby ) PRINT_DEBUG("GetLobbyOwner %llu\n", steamIDLobby.ConvertToUint64()); std::lock_guard lock(global_mutex); Lobby *lobby = get_lobby(steamIDLobby); + if (!lobby || lobby->deleted()) return k_steamIDNil; + + Lobby_Member *member = get_lobby_member(lobby, settings->get_local_steam_id()); CSteamID id = k_steamIDNil; - if (lobby) id = (uint64)lobby->owner(); - + if (member) id = (uint64)lobby->owner(); + return id; } diff --git a/dll/steam_networking.h b/dll/steam_networking.h index 64ed48ee..180214d8 100644 --- a/dll/steam_networking.h +++ b/dll/steam_networking.h @@ -453,9 +453,8 @@ bool GetP2PSessionState( CSteamID steamIDRemote, P2PSessionState_t *pConnectionS pConnectionState->m_bUsingRelay = false; pConnectionState->m_nBytesQueuedForSend = 0; pConnectionState->m_nPacketsQueuedForSend = 0; - //TODO ip? - pConnectionState->m_nRemoteIP = 0; - pConnectionState->m_nRemotePort = 0; + pConnectionState->m_nRemoteIP = network->getIP(steamIDRemote); + pConnectionState->m_nRemotePort = 12345; } PRINT_DEBUG("Connection\n"); @@ -470,7 +469,7 @@ bool GetP2PSessionState( CSteamID steamIDRemote, P2PSessionState_t *pConnectionS // P2P packet relay is allowed by default bool AllowP2PPacketRelay( bool bAllow ) { - PRINT_DEBUG("Steam_Networking::AllowP2PPacketRelay\n"); + PRINT_DEBUG("Steam_Networking::AllowP2PPacketRelay %u\n", bAllow); return true; }