From a855cde6512b690dd0c28d743f2f34508a4f5d96 Mon Sep 17 00:00:00 2001 From: Mr_Goldberg Date: Tue, 29 Jun 2021 11:53:40 -0400 Subject: [PATCH] Add relay init callback. --- dll/steam_networking_utils.h | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/dll/steam_networking_utils.h b/dll/steam_networking_utils.h index 0143f5f1..4fcb8a2c 100644 --- a/dll/steam_networking_utils.h +++ b/dll/steam_networking_utils.h @@ -30,6 +30,7 @@ public ISteamNetworkingUtils std::chrono::time_point initialized_time = std::chrono::steady_clock::now(); FSteamNetworkingSocketsDebugOutput debug_function; bool relay_initialized = false; + bool init_relay = false; public: static void steam_callback(void *object, Common_Message *msg) @@ -95,8 +96,19 @@ SteamNetworkingMessage_t *AllocateMessage( int cbAllocateBuffer ) bool InitializeRelayAccess() { PRINT_DEBUG("Steam_Networking_Utils::InitializeRelayAccess\n"); - relay_initialized = true; - return true; + init_relay = true; + return relay_initialized; +} + +SteamRelayNetworkStatus_t get_network_status() +{ + SteamRelayNetworkStatus_t data = {}; + data.m_eAvail = k_ESteamNetworkingAvailability_Current; + data.m_bPingMeasurementInProgress = 0; + data.m_eAvailAnyRelay = k_ESteamNetworkingAvailability_Current; + data.m_eAvailNetworkConfig = k_ESteamNetworkingAvailability_Current; + strcpy(data.m_debugMsg, "OK"); + return data; } /// Fetch current status of the relay network. @@ -115,11 +127,7 @@ ESteamNetworkingAvailability GetRelayNetworkStatus( SteamRelayNetworkStatus_t *p //TODO: check if this is how real steam returns it SteamRelayNetworkStatus_t data = {}; if (relay_initialized) { - data.m_eAvail = k_ESteamNetworkingAvailability_Current; - data.m_bPingMeasurementInProgress = 0; - data.m_eAvailAnyRelay = k_ESteamNetworkingAvailability_Current; - data.m_eAvailNetworkConfig = k_ESteamNetworkingAvailability_Current; - strcpy(data.m_debugMsg, "OK"); + data = get_network_status(); } if (pDetails) { @@ -173,8 +181,8 @@ bool ParsePingLocationString( const char *pszString, SteamNetworkPingLocation_t bool CheckPingDataUpToDate( float flMaxAgeSeconds ) { PRINT_DEBUG("Steam_Networking_Utils::CheckPingDataUpToDate %f\n", flMaxAgeSeconds); - relay_initialized = true; - return true; + init_relay = true; + return relay_initialized; } @@ -628,6 +636,11 @@ bool SteamNetworkingIdentity_ParseString( SteamNetworkingIdentity *pIdentity, co void RunCallbacks() { + if (init_relay && !relay_initialized) { + relay_initialized = true; + SteamRelayNetworkStatus_t data = get_network_status(); + callbacks->addCBResult(data.k_iCallback, &data, sizeof(data)); + } } void Callback(Common_Message *msg)