diff --git a/server/native_transport/co_gns_server_endpoint.cpp b/server/native_transport/co_gns_server_endpoint.cpp new file mode 100644 index 0000000..5428ee0 --- /dev/null +++ b/server/native_transport/co_gns_server_endpoint.cpp @@ -0,0 +1,34 @@ +#include "co_gns_server_bridge.h" + +#include + +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(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; + } +}