Add relay init callback.

This commit is contained in:
Mr_Goldberg 2021-06-29 11:53:40 -04:00
parent f4cd015701
commit a855cde651
No known key found for this signature in database
GPG key ID: 8597D87419DEF278

View file

@ -30,6 +30,7 @@ public ISteamNetworkingUtils
std::chrono::time_point<std::chrono::steady_clock> initialized_time = std::chrono::steady_clock::now(); std::chrono::time_point<std::chrono::steady_clock> initialized_time = std::chrono::steady_clock::now();
FSteamNetworkingSocketsDebugOutput debug_function; FSteamNetworkingSocketsDebugOutput debug_function;
bool relay_initialized = false; bool relay_initialized = false;
bool init_relay = false;
public: public:
static void steam_callback(void *object, Common_Message *msg) static void steam_callback(void *object, Common_Message *msg)
@ -95,8 +96,19 @@ SteamNetworkingMessage_t *AllocateMessage( int cbAllocateBuffer )
bool InitializeRelayAccess() bool InitializeRelayAccess()
{ {
PRINT_DEBUG("Steam_Networking_Utils::InitializeRelayAccess\n"); PRINT_DEBUG("Steam_Networking_Utils::InitializeRelayAccess\n");
relay_initialized = true; init_relay = true;
return 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. /// 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 //TODO: check if this is how real steam returns it
SteamRelayNetworkStatus_t data = {}; SteamRelayNetworkStatus_t data = {};
if (relay_initialized) { if (relay_initialized) {
data.m_eAvail = k_ESteamNetworkingAvailability_Current; data = get_network_status();
data.m_bPingMeasurementInProgress = 0;
data.m_eAvailAnyRelay = k_ESteamNetworkingAvailability_Current;
data.m_eAvailNetworkConfig = k_ESteamNetworkingAvailability_Current;
strcpy(data.m_debugMsg, "OK");
} }
if (pDetails) { if (pDetails) {
@ -173,8 +181,8 @@ bool ParsePingLocationString( const char *pszString, SteamNetworkPingLocation_t
bool CheckPingDataUpToDate( float flMaxAgeSeconds ) bool CheckPingDataUpToDate( float flMaxAgeSeconds )
{ {
PRINT_DEBUG("Steam_Networking_Utils::CheckPingDataUpToDate %f\n", flMaxAgeSeconds); PRINT_DEBUG("Steam_Networking_Utils::CheckPingDataUpToDate %f\n", flMaxAgeSeconds);
relay_initialized = true; init_relay = true;
return true; return relay_initialized;
} }
@ -628,6 +636,11 @@ bool SteamNetworkingIdentity_ParseString( SteamNetworkingIdentity *pIdentity, co
void RunCallbacks() 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) void Callback(Common_Message *msg)