Compare commits

...

7 Commits

Author SHA1 Message Date
Mr_Goldberg 44305a0068
Implement steamnetworkingsockets ip/port connections.
Note: clients need to know each other already or it won't work.
2021-03-07 19:06:05 -05:00
Mr_Goldberg 3f06dd8576
Call GameLobbyJoinRequested_t if a lobby exists when joining with rich presence. 2021-03-07 19:04:01 -05:00
Mr_Goldberg 8785ae568c
Allow "hidden" achievement property to be an int in the json config. 2021-03-07 19:03:24 -05:00
Mr_Goldberg 992e5c3faa
Properly initialize user_achievements so functions like
getachievementandunlocktime work properly.
2021-02-28 19:26:29 -05:00
Mr_Goldberg 58a57cc91b
Fix coding mistake in networking socket receive functions. 2021-02-27 16:29:40 -05:00
Mr_Goldberg 8e9d3e8f3a
Add force_listen_port.txt 2021-02-27 16:28:59 -05:00
Mr_Goldberg 8e1be658e9
Networking messages improvements. 2021-02-21 11:13:43 -05:00
8 changed files with 140 additions and 52 deletions

View File

@ -29,7 +29,7 @@ Note that these are global so you won't have to change them for each game. For g
If you want to change your steam_id on a per game basis, simply create a settings folder in the game unique directory (Full path: C:\Users\<Your windows user name>\AppData\Roaming\Goldberg SteamEmu Saves\<appid>\settings) If you want to change your steam_id on a per game basis, simply create a settings folder in the game unique directory (Full path: C:\Users\<Your windows user name>\AppData\Roaming\Goldberg SteamEmu Saves\<appid>\settings)
In that settings folder create a user_steam_id.txt file that contains the valid steam id that you want to use for that game only. In that settings folder create a user_steam_id.txt file that contains the valid steam id that you want to use for that game only.
You can also make the emu ignore certain global settings by using a force_account_name.txt, force_language.txt or force_steamid.txt that you put in the <path where my emu lib is>\steam_settings\ folder. You can also make the emu ignore certain global settings by using a force_account_name.txt, force_language.txt, force_listen_port.txt or force_steamid.txt that you put in the <path where my emu lib is>\steam_settings\ folder.
See the steam_settings.EXAMPLE folder for an example. See the steam_settings.EXAMPLE folder for an example.
If for some reason you want it to save in the game directory you can create a file named local_save.txt right beside steam_api(64).dll (libsteam_api.so on linux) If for some reason you want it to save in the game directory you can create a file named local_save.txt right beside steam_api(64).dll (libsteam_api.so on linux)

View File

@ -119,7 +119,8 @@ message Networking_Sockets {
} }
Types type = 1; Types type = 1;
uint32 port = 2; int32 virtual_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

@ -286,6 +286,10 @@ uint32 create_localstorage_settings(Settings **settings_client_out, Settings **s
} else if (p == "force_account_name.txt") { } else if (p == "force_account_name.txt") {
int len = Local_Storage::get_file_data(steam_settings_path + "force_account_name.txt", name, sizeof(name) - 1); int len = Local_Storage::get_file_data(steam_settings_path + "force_account_name.txt", name, sizeof(name) - 1);
if (len > 0) name[len] = 0; if (len > 0) name[len] = 0;
} else if (p == "force_listen_port.txt") {
char array_port[10] = {};
int len = Local_Storage::get_file_data(steam_settings_path + "force_listen_port.txt", array_port, sizeof(array_port) - 1);
if (len > 0) port = std::stoi(array_port);
} }
} }
} }

View File

@ -236,7 +236,7 @@ int ReceiveMessagesOnChannel( int nLocalChannel, SteamNetworkingMessage_t **ppOu
for (auto & conn : connections) { for (auto & conn : connections) {
auto chan = conn.second.data.find(nLocalChannel); auto chan = conn.second.data.find(nLocalChannel);
if (chan != conn.second.data.end()) { if (chan != conn.second.data.end()) {
while (!chan->second.empty() && message_counter <= nMaxMessages) { while (!chan->second.empty() && message_counter < nMaxMessages) {
SteamNetworkingMessage_t *pMsg = new SteamNetworkingMessage_t(); //TODO size is wrong SteamNetworkingMessage_t *pMsg = new SteamNetworkingMessage_t(); //TODO size is wrong
unsigned long size = chan->second.front().size(); unsigned long size = chan->second.front().size();
pMsg->m_pData = malloc(size); pMsg->m_pData = malloc(size);
@ -323,6 +323,7 @@ bool CloseChannelWithUser( const SteamNetworkingIdentity &identityRemote, int nL
{ {
PRINT_DEBUG("Steam_Networking_Messages::CloseChannelWithUser\n"); PRINT_DEBUG("Steam_Networking_Messages::CloseChannelWithUser\n");
std::lock_guard<std::recursive_mutex> lock(global_mutex); std::lock_guard<std::recursive_mutex> lock(global_mutex);
//TODO
return false; return false;
} }
@ -344,22 +345,29 @@ ESteamNetworkingConnectionState GetSessionConnectionInfo( const SteamNetworkingI
return k_ESteamNetworkingConnectionState_None; return k_ESteamNetworkingConnectionState_None;
} }
ESteamNetworkingConnectionState state = k_ESteamNetworkingConnectionState_Connected;
if (conn->second.remote_id == 0 || !conn->second.accepted) {
state = k_ESteamNetworkingConnectionState_Connecting;
} else if (conn->second.dead) {
state = k_ESteamNetworkingConnectionState_ClosedByPeer;
}
if (pConnectionInfo) { if (pConnectionInfo) {
memset(pConnectionInfo, 0, sizeof(SteamNetConnectionInfo_t));
pConnectionInfo->m_eState = state;
pConnectionInfo->m_identityRemote = conn->second.remote_identity;
//TODO //TODO
} }
if (pQuickStatus) { if (pQuickStatus) {
memset(pQuickStatus, 0, sizeof(SteamNetworkingQuickConnectionStatus));
pQuickStatus->m_eState = state;
pQuickStatus->m_nPing = 10; //TODO: calculate real numbers?
pQuickStatus->m_flConnectionQualityLocal = 1.0;
pQuickStatus->m_flConnectionQualityRemote = 1.0;
//TODO //TODO
} }
if (conn->second.remote_id == 0 || !conn->second.accepted) {
return k_ESteamNetworkingConnectionState_Connecting;
}
if (conn->second.dead) {
return k_ESteamNetworkingConnectionState_ClosedByPeer;
}
return k_ESteamNetworkingConnectionState_Connected; return k_ESteamNetworkingConnectionState_Connected;
} }

View File

@ -21,6 +21,7 @@ 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 {
@ -34,6 +35,7 @@ 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;
@ -69,6 +71,8 @@ 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)
{ {
@ -114,7 +118,7 @@ static unsigned long get_socket_id()
return socket_id; return socket_id;
} }
HSteamListenSocket new_listen_socket(int nSteamConnectVirtualPort) HSteamListenSocket new_listen_socket(int nSteamConnectVirtualPort, int real_port)
{ {
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;
@ -125,6 +129,7 @@ HSteamListenSocket new_listen_socket(int nSteamConnectVirtualPort)
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;
} }
@ -145,7 +150,6 @@ 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);
@ -153,17 +157,31 @@ 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_port(connect_socket->second.virtual_port); msg.mutable_networking_sockets()->set_virtual_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);
} }
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) const SteamNetworkingIPAddr *ip_addr = connect_socket->second.remote_identity.GetIPAddr();
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;
@ -237,7 +255,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); return new_listen_socket(nSteamConnectVirtualPort, nPort);
} }
/// Creates a "server" socket that listens for clients to connect to by /// Creates a "server" socket that listens for clients to connect to by
@ -257,19 +275,22 @@ 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");
return k_HSteamListenSocket_Invalid; std::lock_guard<std::recursive_mutex> lock(global_mutex);
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");
return k_HSteamListenSocket_Invalid; std::lock_guard<std::recursive_mutex> lock(global_mutex);
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");
return k_HSteamListenSocket_Invalid; std::lock_guard<std::recursive_mutex> lock(global_mutex);
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
@ -293,19 +314,34 @@ 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");
return k_HSteamNetConnection_Invalid; std::lock_guard<std::recursive_mutex> lock(global_mutex);
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");
return k_HSteamNetConnection_Invalid; std::lock_guard<std::recursive_mutex> lock(global_mutex);
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");
return k_HSteamNetConnection_Invalid; std::lock_guard<std::recursive_mutex> lock(global_mutex);
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
@ -322,7 +358,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); return new_listen_socket(nVirtualPort, SNS_DISABLED_PORT);
} }
HSteamListenSocket CreateListenSocketP2P( int nVirtualPort, int nOptions, const SteamNetworkingConfigValue_t *pOptions ) HSteamListenSocket CreateListenSocketP2P( int nVirtualPort, int nOptions, const SteamNetworkingConfigValue_t *pOptions )
@ -330,7 +366,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); return new_listen_socket(nVirtualPort, SNS_DISABLED_PORT);
} }
/// 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.
@ -361,7 +397,7 @@ HSteamNetConnection ConnectP2P( const SteamNetworkingIdentity &identityRemote, i
return k_HSteamNetConnection_Invalid; return k_HSteamNetConnection_Invalid;
} }
HSteamNetConnection socket = new_connect_socket(identityRemote, nVirtualPort); HSteamNetConnection socket = new_connect_socket(identityRemote, nVirtualPort, SNS_DISABLED_PORT);
send_packet_new_connection(socket); send_packet_new_connection(socket);
return socket; return socket;
} }
@ -487,7 +523,8 @@ 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_port(connect_socket->second.virtual_port); msg.mutable_networking_sockets()->set_virtual_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);
@ -665,7 +702,8 @@ 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_port(connect_socket->second.virtual_port); msg.mutable_networking_sockets()->set_virtual_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);
@ -793,7 +831,7 @@ int ReceiveMessagesOnConnection( HSteamNetConnection hConn, SteamNetworkingMessa
std::lock_guard<std::recursive_mutex> lock(global_mutex); std::lock_guard<std::recursive_mutex> lock(global_mutex);
SteamNetworkingMessage_t *msg = NULL; SteamNetworkingMessage_t *msg = NULL;
int messages = 0; int messages = 0;
while ((msg = get_steam_message_connection(hConn)) && messages < nMaxMessages) { while (messages < nMaxMessages && (msg = get_steam_message_connection(hConn))) {
ppOutMessages[messages] = msg; ppOutMessages[messages] = msg;
++messages; ++messages;
} }
@ -821,7 +859,7 @@ int ReceiveMessagesOnListenSocket( HSteamListenSocket hSocket, SteamNetworkingMe
auto socket_conn = std::begin(connect_sockets); auto socket_conn = std::begin(connect_sockets);
while (socket_conn != std::end(connect_sockets) && messages < nMaxMessages) { while (socket_conn != std::end(connect_sockets) && messages < nMaxMessages) {
if (socket_conn->second.listen_socket_id == hSocket) { if (socket_conn->second.listen_socket_id == hSocket) {
while ((msg = get_steam_message_connection(socket_conn->first)) && messages < nMaxMessages) { while (messages < nMaxMessages && (msg = get_steam_message_connection(socket_conn->first))) {
ppOutMessages[messages] = msg; ppOutMessages[messages] = msg;
++messages; ++messages;
} }
@ -1021,8 +1059,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, CONNECT_SOCKET_CONNECTED, k_HSteamListenSocket_Invalid, k_HSteamNetConnection_Invalid); HSteamNetConnection con1 = new_connect_socket(remote_identity, 0, SNS_DISABLED_PORT, CONNECT_SOCKET_CONNECTED, k_HSteamListenSocket_Invalid, k_HSteamNetConnection_Invalid);
HSteamNetConnection con2 = new_connect_socket(remote_identity, 0, CONNECT_SOCKET_CONNECTED, k_HSteamListenSocket_Invalid, con1); HSteamNetConnection con2 = new_connect_socket(remote_identity, 0, SNS_DISABLED_PORT, 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;
@ -1197,7 +1235,7 @@ int ReceiveMessagesOnPollGroup( HSteamNetPollGroup hPollGroup, SteamNetworkingMe
int messages = 0; int messages = 0;
for (auto c : group->second) { for (auto c : group->second) {
while ((msg = get_steam_message_connection(c)) && messages < nMaxMessages) { while (messages < nMaxMessages && (msg = get_steam_message_connection(c))) {
ppOutMessages[messages] = msg; ppOutMessages[messages] = msg;
++messages; ++messages;
} }
@ -1383,7 +1421,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); return new_listen_socket(nVirtualPort, SNS_DISABLED_PORT);
} }
/// 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
@ -1400,7 +1438,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); return new_listen_socket(nVirtualPort, SNS_DISABLED_PORT);
} }
@ -1670,19 +1708,29 @@ 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().port(); int virtual_port = msg->networking_sockets().virtual_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, CONNECT_SOCKET_NOT_ACCEPTED, conn->socket_id, msg->networking_sockets().connection_id_from()); HSteamNetConnection new_connection = new_connect_socket(identity, virtual_port, real_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

@ -94,6 +94,20 @@ Steam_User_Stats(Settings *settings, Local_Storage *local_storage, class SteamCa
{ {
load_achievements_db(); // achievements db load_achievements_db(); // achievements db
load_achievements(); // achievements per user load_achievements(); // achievements per user
for (auto & it : defined_achievements) {
try {
std::string name = static_cast<std::string const&>(it["name"]);
if (user_achievements.find(name) == user_achievements.end()) {
user_achievements[name]["earned"] = false;
user_achievements[name]["earned_time"] = static_cast<uint32>(0);
}
} catch (...) {}
try {
it["hidden"] = std::to_string(it["hidden"].get<int>());
} catch (...) {}
}
} }
// Ask the server to send down this user's data and achievements for this game // Ask the server to send down this user's data and achievements for this game

View File

@ -0,0 +1 @@
47584

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,6 +805,18 @@ 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;
} }
} }