Compare commits

..

No commits in common. "44305a0068df6a97cb3db352652f24430f4f27aa" and "992e5c3faabb2616f3039c4f0301552da89a4fb6" have entirely different histories.

4 changed files with 39 additions and 104 deletions

View File

@ -119,8 +119,7 @@ message Networking_Sockets {
} }
Types type = 1; Types type = 1;
int32 virtual_port = 2; uint32 port = 2;
int32 real_port = 6;
uint64 connection_id = 3; uint64 connection_id = 3;
uint64 connection_id_from = 4; uint64 connection_id_from = 4;
bytes data = 5; bytes data = 5;

View File

@ -21,7 +21,6 @@ struct Listen_Socket {
HSteamListenSocket socket_id; HSteamListenSocket socket_id;
int virtual_port; int virtual_port;
int real_port;
}; };
enum connect_socket_status { enum connect_socket_status {
@ -35,7 +34,6 @@ enum connect_socket_status {
struct Connect_Socket { struct Connect_Socket {
int virtual_port; int virtual_port;
int real_port;
SteamNetworkingIdentity remote_identity; SteamNetworkingIdentity remote_identity;
HSteamNetConnection remote_id; HSteamNetConnection remote_id;
@ -71,8 +69,6 @@ public ISteamNetworkingSockets
std::map<HSteamNetPollGroup, std::list<HSteamNetConnection>> poll_groups; std::map<HSteamNetPollGroup, std::list<HSteamNetConnection>> poll_groups;
std::chrono::steady_clock::time_point created; std::chrono::steady_clock::time_point created;
static const int SNS_DISABLED_PORT = -1;
public: public:
static void steam_callback(void *object, Common_Message *msg) static void steam_callback(void *object, Common_Message *msg)
{ {
@ -118,7 +114,7 @@ static unsigned long get_socket_id()
return socket_id; return socket_id;
} }
HSteamListenSocket new_listen_socket(int nSteamConnectVirtualPort, int real_port) HSteamListenSocket new_listen_socket(int nSteamConnectVirtualPort)
{ {
HSteamListenSocket socket_id = get_socket_id(); HSteamListenSocket socket_id = get_socket_id();
if (socket_id == k_HSteamListenSocket_Invalid) ++socket_id; if (socket_id == k_HSteamListenSocket_Invalid) ++socket_id;
@ -129,7 +125,6 @@ HSteamListenSocket new_listen_socket(int nSteamConnectVirtualPort, int real_port
struct Listen_Socket listen_socket; struct Listen_Socket listen_socket;
listen_socket.socket_id = socket_id; listen_socket.socket_id = socket_id;
listen_socket.virtual_port = nSteamConnectVirtualPort; listen_socket.virtual_port = nSteamConnectVirtualPort;
listen_socket.real_port = real_port;
listen_sockets.push_back(listen_socket); listen_sockets.push_back(listen_socket);
return socket_id; return socket_id;
} }
@ -150,6 +145,7 @@ bool send_packet_new_connection(HSteamNetConnection m_hConn)
Common_Message msg; Common_Message msg;
msg.set_source_id(settings->get_local_steam_id().ConvertToUint64()); msg.set_source_id(settings->get_local_steam_id().ConvertToUint64());
msg.set_dest_id(connect_socket->second.remote_identity.GetSteamID64());
msg.set_allocated_networking_sockets(new Networking_Sockets); msg.set_allocated_networking_sockets(new Networking_Sockets);
if (connect_socket->second.status == CONNECT_SOCKET_CONNECTING) { if (connect_socket->second.status == CONNECT_SOCKET_CONNECTING) {
msg.mutable_networking_sockets()->set_type(Networking_Sockets::CONNECTION_REQUEST); msg.mutable_networking_sockets()->set_type(Networking_Sockets::CONNECTION_REQUEST);
@ -157,31 +153,17 @@ bool send_packet_new_connection(HSteamNetConnection m_hConn)
msg.mutable_networking_sockets()->set_type(Networking_Sockets::CONNECTION_ACCEPTED); msg.mutable_networking_sockets()->set_type(Networking_Sockets::CONNECTION_ACCEPTED);
} }
msg.mutable_networking_sockets()->set_virtual_port(connect_socket->second.virtual_port); msg.mutable_networking_sockets()->set_port(connect_socket->second.virtual_port);
msg.mutable_networking_sockets()->set_real_port(connect_socket->second.real_port);
msg.mutable_networking_sockets()->set_connection_id_from(connect_socket->first); msg.mutable_networking_sockets()->set_connection_id_from(connect_socket->first);
msg.mutable_networking_sockets()->set_connection_id(connect_socket->second.remote_id); msg.mutable_networking_sockets()->set_connection_id(connect_socket->second.remote_id);
uint64_t steam_id = connect_socket->second.remote_identity.GetSteamID64();
if (steam_id) {
msg.set_dest_id(steam_id);
return network->sendTo(&msg, true); return network->sendTo(&msg, true);
} }
const SteamNetworkingIPAddr *ip_addr = connect_socket->second.remote_identity.GetIPAddr(); HSteamNetConnection new_connect_socket(SteamNetworkingIdentity remote_identity, int virtual_port, enum connect_socket_status status=CONNECT_SOCKET_CONNECTING, HSteamListenSocket listen_socket_id=k_HSteamListenSocket_Invalid, HSteamNetConnection remote_id=k_HSteamNetConnection_Invalid)
if (ip_addr) {
return network->sendToIPPort(&msg, ip_addr->GetIPv4(), ip_addr->m_port, true);
}
return false;
}
HSteamNetConnection new_connect_socket(SteamNetworkingIdentity remote_identity, int virtual_port, int real_port, enum connect_socket_status status=CONNECT_SOCKET_CONNECTING, HSteamListenSocket listen_socket_id=k_HSteamListenSocket_Invalid, HSteamNetConnection remote_id=k_HSteamNetConnection_Invalid)
{ {
Connect_Socket socket = {}; Connect_Socket socket = {};
socket.remote_identity = remote_identity; socket.remote_identity = remote_identity;
socket.virtual_port = virtual_port; socket.virtual_port = virtual_port;
socket.real_port = real_port;
socket.listen_socket_id = listen_socket_id; socket.listen_socket_id = listen_socket_id;
socket.remote_id = remote_id; socket.remote_id = remote_id;
socket.status = status; socket.status = status;
@ -255,7 +237,7 @@ HSteamListenSocket CreateListenSocket( int nSteamConnectVirtualPort, uint32 nIP,
{ {
PRINT_DEBUG("Steam_Networking_Sockets::CreateListenSocket %i %u %u\n", nSteamConnectVirtualPort, nIP, nPort); PRINT_DEBUG("Steam_Networking_Sockets::CreateListenSocket %i %u %u\n", nSteamConnectVirtualPort, nIP, nPort);
std::lock_guard<std::recursive_mutex> lock(global_mutex); std::lock_guard<std::recursive_mutex> lock(global_mutex);
return new_listen_socket(nSteamConnectVirtualPort, nPort); return new_listen_socket(nSteamConnectVirtualPort);
} }
/// Creates a "server" socket that listens for clients to connect to by /// Creates a "server" socket that listens for clients to connect to by
@ -275,22 +257,19 @@ HSteamListenSocket CreateListenSocket( int nSteamConnectVirtualPort, uint32 nIP,
HSteamListenSocket CreateListenSocketIP( const SteamNetworkingIPAddr &localAddress ) HSteamListenSocket CreateListenSocketIP( const SteamNetworkingIPAddr &localAddress )
{ {
PRINT_DEBUG("Steam_Networking_Sockets::CreateListenSocketIP old\n"); PRINT_DEBUG("Steam_Networking_Sockets::CreateListenSocketIP old\n");
std::lock_guard<std::recursive_mutex> lock(global_mutex); return k_HSteamListenSocket_Invalid;
return new_listen_socket(SNS_DISABLED_PORT, localAddress.m_port);
} }
HSteamListenSocket CreateListenSocketIP( const SteamNetworkingIPAddr *localAddress ) HSteamListenSocket CreateListenSocketIP( const SteamNetworkingIPAddr *localAddress )
{ {
PRINT_DEBUG("Steam_Networking_Sockets::CreateListenSocketIP old1\n"); PRINT_DEBUG("Steam_Networking_Sockets::CreateListenSocketIP old1\n");
std::lock_guard<std::recursive_mutex> lock(global_mutex); return k_HSteamListenSocket_Invalid;
return new_listen_socket(SNS_DISABLED_PORT, localAddress->m_port);
} }
HSteamListenSocket CreateListenSocketIP( const SteamNetworkingIPAddr &localAddress, int nOptions, const SteamNetworkingConfigValue_t *pOptions ) HSteamListenSocket CreateListenSocketIP( const SteamNetworkingIPAddr &localAddress, int nOptions, const SteamNetworkingConfigValue_t *pOptions )
{ {
PRINT_DEBUG("Steam_Networking_Sockets::CreateListenSocketIP\n"); PRINT_DEBUG("Steam_Networking_Sockets::CreateListenSocketIP\n");
std::lock_guard<std::recursive_mutex> lock(global_mutex); return k_HSteamListenSocket_Invalid;
return new_listen_socket(SNS_DISABLED_PORT, localAddress.m_port);
} }
/// Creates a connection and begins talking to a "server" over UDP at the /// Creates a connection and begins talking to a "server" over UDP at the
@ -314,34 +293,19 @@ HSteamListenSocket CreateListenSocketIP( const SteamNetworkingIPAddr &localAddre
HSteamNetConnection ConnectByIPAddress( const SteamNetworkingIPAddr &address ) HSteamNetConnection ConnectByIPAddress( const SteamNetworkingIPAddr &address )
{ {
PRINT_DEBUG("Steam_Networking_Sockets::ConnectByIPAddress old\n"); PRINT_DEBUG("Steam_Networking_Sockets::ConnectByIPAddress old\n");
std::lock_guard<std::recursive_mutex> lock(global_mutex); return k_HSteamNetConnection_Invalid;
SteamNetworkingIdentity ip_id;
ip_id.SetIPAddr(address);
HSteamNetConnection socket = new_connect_socket(ip_id, SNS_DISABLED_PORT, address.m_port);
send_packet_new_connection(socket);
return socket;
} }
HSteamNetConnection ConnectByIPAddress( const SteamNetworkingIPAddr *address ) HSteamNetConnection ConnectByIPAddress( const SteamNetworkingIPAddr *address )
{ {
PRINT_DEBUG("Steam_Networking_Sockets::ConnectByIPAddress old1\n"); PRINT_DEBUG("Steam_Networking_Sockets::ConnectByIPAddress old1\n");
std::lock_guard<std::recursive_mutex> lock(global_mutex); return k_HSteamNetConnection_Invalid;
SteamNetworkingIdentity ip_id;
ip_id.SetIPAddr(*address);
HSteamNetConnection socket = new_connect_socket(ip_id, SNS_DISABLED_PORT, address->m_port);
send_packet_new_connection(socket);
return socket;
} }
HSteamNetConnection ConnectByIPAddress( const SteamNetworkingIPAddr &address, int nOptions, const SteamNetworkingConfigValue_t *pOptions ) HSteamNetConnection ConnectByIPAddress( const SteamNetworkingIPAddr &address, int nOptions, const SteamNetworkingConfigValue_t *pOptions )
{ {
PRINT_DEBUG("Steam_Networking_Sockets::ConnectByIPAddress\n"); PRINT_DEBUG("Steam_Networking_Sockets::ConnectByIPAddress\n");
std::lock_guard<std::recursive_mutex> lock(global_mutex); return k_HSteamNetConnection_Invalid;
SteamNetworkingIdentity ip_id;
ip_id.SetIPAddr(address);
HSteamNetConnection socket = new_connect_socket(ip_id, SNS_DISABLED_PORT, address.m_port);
send_packet_new_connection(socket);
return socket;
} }
/// Like CreateListenSocketIP, but clients will connect using ConnectP2P /// Like CreateListenSocketIP, but clients will connect using ConnectP2P
@ -358,7 +322,7 @@ HSteamListenSocket CreateListenSocketP2P( int nVirtualPort )
{ {
PRINT_DEBUG("Steam_Networking_Sockets::CreateListenSocketP2P old %i\n", nVirtualPort); PRINT_DEBUG("Steam_Networking_Sockets::CreateListenSocketP2P old %i\n", nVirtualPort);
std::lock_guard<std::recursive_mutex> lock(global_mutex); std::lock_guard<std::recursive_mutex> lock(global_mutex);
return new_listen_socket(nVirtualPort, SNS_DISABLED_PORT); return new_listen_socket(nVirtualPort);
} }
HSteamListenSocket CreateListenSocketP2P( int nVirtualPort, int nOptions, const SteamNetworkingConfigValue_t *pOptions ) HSteamListenSocket CreateListenSocketP2P( int nVirtualPort, int nOptions, const SteamNetworkingConfigValue_t *pOptions )
@ -366,7 +330,7 @@ HSteamListenSocket CreateListenSocketP2P( int nVirtualPort, int nOptions, const
PRINT_DEBUG("Steam_Networking_Sockets::CreateListenSocketP2P %i\n", nVirtualPort); PRINT_DEBUG("Steam_Networking_Sockets::CreateListenSocketP2P %i\n", nVirtualPort);
//TODO config options //TODO config options
std::lock_guard<std::recursive_mutex> lock(global_mutex); std::lock_guard<std::recursive_mutex> lock(global_mutex);
return new_listen_socket(nVirtualPort, SNS_DISABLED_PORT); return new_listen_socket(nVirtualPort);
} }
/// Begin connecting to a server that is identified using a platform-specific identifier. /// Begin connecting to a server that is identified using a platform-specific identifier.
@ -397,7 +361,7 @@ HSteamNetConnection ConnectP2P( const SteamNetworkingIdentity &identityRemote, i
return k_HSteamNetConnection_Invalid; return k_HSteamNetConnection_Invalid;
} }
HSteamNetConnection socket = new_connect_socket(identityRemote, nVirtualPort, SNS_DISABLED_PORT); HSteamNetConnection socket = new_connect_socket(identityRemote, nVirtualPort);
send_packet_new_connection(socket); send_packet_new_connection(socket);
return socket; return socket;
} }
@ -523,8 +487,7 @@ bool CloseConnection( HSteamNetConnection hPeer, int nReason, const char *pszDeb
msg.set_dest_id(connect_socket->second.remote_identity.GetSteamID64()); msg.set_dest_id(connect_socket->second.remote_identity.GetSteamID64());
msg.set_allocated_networking_sockets(new Networking_Sockets); msg.set_allocated_networking_sockets(new Networking_Sockets);
msg.mutable_networking_sockets()->set_type(Networking_Sockets::CONNECTION_END); msg.mutable_networking_sockets()->set_type(Networking_Sockets::CONNECTION_END);
msg.mutable_networking_sockets()->set_virtual_port(connect_socket->second.virtual_port); msg.mutable_networking_sockets()->set_port(connect_socket->second.virtual_port);
msg.mutable_networking_sockets()->set_real_port(connect_socket->second.real_port);
msg.mutable_networking_sockets()->set_connection_id_from(connect_socket->first); msg.mutable_networking_sockets()->set_connection_id_from(connect_socket->first);
msg.mutable_networking_sockets()->set_connection_id(connect_socket->second.remote_id); msg.mutable_networking_sockets()->set_connection_id(connect_socket->second.remote_id);
network->sendTo(&msg, true); network->sendTo(&msg, true);
@ -702,8 +665,7 @@ EResult SendMessageToConnection( HSteamNetConnection hConn, const void *pData, u
msg.set_dest_id(connect_socket->second.remote_identity.GetSteamID64()); msg.set_dest_id(connect_socket->second.remote_identity.GetSteamID64());
msg.set_allocated_networking_sockets(new Networking_Sockets); msg.set_allocated_networking_sockets(new Networking_Sockets);
msg.mutable_networking_sockets()->set_type(Networking_Sockets::DATA); msg.mutable_networking_sockets()->set_type(Networking_Sockets::DATA);
msg.mutable_networking_sockets()->set_virtual_port(connect_socket->second.virtual_port); msg.mutable_networking_sockets()->set_port(connect_socket->second.virtual_port);
msg.mutable_networking_sockets()->set_real_port(connect_socket->second.real_port);
msg.mutable_networking_sockets()->set_connection_id_from(connect_socket->first); msg.mutable_networking_sockets()->set_connection_id_from(connect_socket->first);
msg.mutable_networking_sockets()->set_connection_id(connect_socket->second.remote_id); msg.mutable_networking_sockets()->set_connection_id(connect_socket->second.remote_id);
msg.mutable_networking_sockets()->set_data(pData, cbData); msg.mutable_networking_sockets()->set_data(pData, cbData);
@ -1059,8 +1021,8 @@ bool CreateSocketPair( HSteamNetConnection *pOutConnection1, HSteamNetConnection
SteamNetworkingIdentity remote_identity; SteamNetworkingIdentity remote_identity;
remote_identity.SetSteamID(settings->get_local_steam_id()); remote_identity.SetSteamID(settings->get_local_steam_id());
HSteamNetConnection con1 = new_connect_socket(remote_identity, 0, SNS_DISABLED_PORT, CONNECT_SOCKET_CONNECTED, k_HSteamListenSocket_Invalid, k_HSteamNetConnection_Invalid); HSteamNetConnection con1 = new_connect_socket(remote_identity, 0, CONNECT_SOCKET_CONNECTED, k_HSteamListenSocket_Invalid, k_HSteamNetConnection_Invalid);
HSteamNetConnection con2 = new_connect_socket(remote_identity, 0, SNS_DISABLED_PORT, CONNECT_SOCKET_CONNECTED, k_HSteamListenSocket_Invalid, con1); HSteamNetConnection con2 = new_connect_socket(remote_identity, 0, CONNECT_SOCKET_CONNECTED, k_HSteamListenSocket_Invalid, con1);
connect_sockets[con1].remote_id = con2; connect_sockets[con1].remote_id = con2;
*pOutConnection1 = con1; *pOutConnection1 = con1;
*pOutConnection2 = con2; *pOutConnection2 = con2;
@ -1421,7 +1383,7 @@ HSteamListenSocket CreateHostedDedicatedServerListenSocket( int nVirtualPort )
{ {
PRINT_DEBUG("Steam_Networking_Sockets::CreateHostedDedicatedServerListenSocket old %i\n", nVirtualPort); PRINT_DEBUG("Steam_Networking_Sockets::CreateHostedDedicatedServerListenSocket old %i\n", nVirtualPort);
std::lock_guard<std::recursive_mutex> lock(global_mutex); std::lock_guard<std::recursive_mutex> lock(global_mutex);
return new_listen_socket(nVirtualPort, SNS_DISABLED_PORT); return new_listen_socket(nVirtualPort);
} }
/// Create a listen socket on the specified virtual port. The physical UDP port to use /// Create a listen socket on the specified virtual port. The physical UDP port to use
@ -1438,7 +1400,7 @@ HSteamListenSocket CreateHostedDedicatedServerListenSocket( int nVirtualPort, in
PRINT_DEBUG("Steam_Networking_Sockets::CreateHostedDedicatedServerListenSocket old %i\n", nVirtualPort); PRINT_DEBUG("Steam_Networking_Sockets::CreateHostedDedicatedServerListenSocket old %i\n", nVirtualPort);
//TODO config options //TODO config options
std::lock_guard<std::recursive_mutex> lock(global_mutex); std::lock_guard<std::recursive_mutex> lock(global_mutex);
return new_listen_socket(nVirtualPort, SNS_DISABLED_PORT); return new_listen_socket(nVirtualPort);
} }
@ -1708,29 +1670,19 @@ void Callback(Common_Message *msg)
if (msg->has_networking_sockets()) { if (msg->has_networking_sockets()) {
PRINT_DEBUG("Steam_Networking_Sockets: got network socket msg %u\n", msg->networking_sockets().type()); PRINT_DEBUG("Steam_Networking_Sockets: got network socket msg %u\n", msg->networking_sockets().type());
if (msg->networking_sockets().type() == Networking_Sockets::CONNECTION_REQUEST) { if (msg->networking_sockets().type() == Networking_Sockets::CONNECTION_REQUEST) {
int virtual_port = msg->networking_sockets().virtual_port(); int virtual_port = msg->networking_sockets().port();
int real_port = msg->networking_sockets().real_port();
std::vector<Listen_Socket>::iterator conn;
if (virtual_port == SNS_DISABLED_PORT) {
conn = std::find_if(listen_sockets.begin(), listen_sockets.end(), [&real_port](struct Listen_Socket const& conn) { return conn.real_port == real_port;});
} else {
conn = std::find_if(listen_sockets.begin(), listen_sockets.end(), [&virtual_port](struct Listen_Socket const& conn) { return conn.virtual_port == virtual_port;});
}
auto conn = std::find_if(listen_sockets.begin(), listen_sockets.end(), [&virtual_port](struct Listen_Socket const& conn) { return conn.virtual_port == virtual_port;});
if (conn != listen_sockets.end()) { if (conn != listen_sockets.end()) {
SteamNetworkingIdentity identity; SteamNetworkingIdentity identity;
identity.SetSteamID64(msg->source_id()); identity.SetSteamID64(msg->source_id());
HSteamNetConnection new_connection = new_connect_socket(identity, virtual_port, real_port, CONNECT_SOCKET_NOT_ACCEPTED, conn->socket_id, msg->networking_sockets().connection_id_from()); HSteamNetConnection new_connection = new_connect_socket(identity, virtual_port, CONNECT_SOCKET_NOT_ACCEPTED, conn->socket_id, msg->networking_sockets().connection_id_from());
launch_callback(new_connection, CONNECT_SOCKET_NO_CONNECTION); launch_callback(new_connection, CONNECT_SOCKET_NO_CONNECTION);
} }
} else if (msg->networking_sockets().type() == Networking_Sockets::CONNECTION_ACCEPTED) { } else if (msg->networking_sockets().type() == Networking_Sockets::CONNECTION_ACCEPTED) {
auto connect_socket = connect_sockets.find(msg->networking_sockets().connection_id()); auto connect_socket = connect_sockets.find(msg->networking_sockets().connection_id());
if (connect_socket != connect_sockets.end()) { if (connect_socket != connect_sockets.end()) {
if (connect_socket->second.remote_identity.GetSteamID64() == 0) {
connect_socket->second.remote_identity.SetSteamID64(msg->source_id());
}
if (connect_socket->second.remote_identity.GetSteamID64() == msg->source_id() && connect_socket->second.status == CONNECT_SOCKET_CONNECTING) { if (connect_socket->second.remote_identity.GetSteamID64() == msg->source_id() && connect_socket->second.status == CONNECT_SOCKET_CONNECTING) {
connect_socket->second.remote_id = msg->networking_sockets().connection_id_from(); connect_socket->second.remote_id = msg->networking_sockets().connection_id_from();
connect_socket->second.status = CONNECT_SOCKET_CONNECTED; connect_socket->second.status = CONNECT_SOCKET_CONNECTED;

View File

@ -103,10 +103,6 @@ Steam_User_Stats(Settings *settings, Local_Storage *local_storage, class SteamCa
user_achievements[name]["earned_time"] = static_cast<uint32>(0); user_achievements[name]["earned_time"] = static_cast<uint32>(0);
} }
} catch (...) {} } catch (...) {}
try {
it["hidden"] = std::to_string(it["hidden"].get<int>());
} catch (...) {}
} }
} }

View File

@ -787,7 +787,7 @@ void Steam_Overlay::RunCallbacks()
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data)); callbacks->addCBResult(data.k_iCallback, &data, sizeof(data));
friend_info->second.window_state &= ~window_state_lobby_invite; friend_info->second.window_state &= ~window_state_lobby_invite;
} else { } else
// The user got a rich presence invite and accepted it // The user got a rich presence invite and accepted it
if (friend_info->second.window_state & window_state_rich_invite) if (friend_info->second.window_state & window_state_rich_invite)
{ {
@ -805,18 +805,6 @@ void Steam_Overlay::RunCallbacks()
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data)); callbacks->addCBResult(data.k_iCallback, &data, sizeof(data));
} }
//Not sure about this but it fixes sonic racing transformed invites
FriendGameInfo_t friend_game_info = {};
steamFriends->GetFriendGamePlayed(friend_id, &friend_game_info);
uint64 lobby_id = friend_game_info.m_steamIDLobby.ConvertToUint64();
if (lobby_id) {
GameLobbyJoinRequested_t data;
data.m_steamIDLobby.SetFromUint64(lobby_id);
data.m_steamIDFriend.SetFromUint64(friend_id);
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data));
}
}
friend_info->second.window_state &= ~window_state_join; friend_info->second.window_state &= ~window_state_join;
} }
} }