Files
Commonwealth-Online-Server/server/native_transport/co_gns_server_endpoint.cpp

35 lines
919 B
C++

#include "co_gns_server_bridge.h"
#include <steam/steamnetworkingsockets.h>
extern "C"
{
int co_gns_server_remote_ipv4(
co_gns_server_handle handle,
uint32_t connection_id,
uint32_t* out_ipv4_host_order,
uint16_t* out_port)
{
if (handle == nullptr || connection_id == 0 || out_ipv4_host_order == nullptr || out_port == nullptr) {
return 0;
}
auto* networking = SteamNetworkingSockets();
if (networking == nullptr) {
return 0;
}
SteamNetConnectionInfo_t info{};
if (!networking->GetConnectionInfo(static_cast<HSteamNetConnection>(connection_id), &info)) {
return 0;
}
if (!info.m_addrRemote.IsIPv4()) {
return 0;
}
*out_ipv4_host_order = info.m_addrRemote.GetIPv4();
*out_port = info.m_addrRemote.m_port;
return 1;
}
}