Add a longer delay to P2PSessionRequest_t callback.

Don't fire it if packet is sent before it is fired.
merge-requests/30/head
Mr_Goldberg 2020-01-26 17:25:41 -05:00
parent 39d1d8dcdf
commit b1206b0fa2
No known key found for this signature in database
GPG Key ID: 8597D87419DEF278
1 changed files with 24 additions and 4 deletions

View File

@ -21,6 +21,9 @@
#define ORPHANED_PACKET_TIMEOUT (20) #define ORPHANED_PACKET_TIMEOUT (20)
#define NEW_CONNECTION_TIMEOUT (20.0) #define NEW_CONNECTION_TIMEOUT (20.0)
//kingdom 2 crowns doesn't work with a 0.3 delay or lower
#define NEW_CONNECTION_DELAY (0.4)
#define OLD_CHANNEL_NUMBER 1 #define OLD_CHANNEL_NUMBER 1
struct Steam_Networking_Connection { struct Steam_Networking_Connection {
@ -78,6 +81,7 @@ public ISteamNetworking
std::vector<struct steam_connection_socket> connection_sockets; std::vector<struct steam_connection_socket> connection_sockets;
std::map<CSteamID, std::chrono::high_resolution_clock::time_point> new_connection_times; std::map<CSteamID, std::chrono::high_resolution_clock::time_point> new_connection_times;
std::queue<CSteamID> new_connections_to_call_cb;
bool connection_exists(CSteamID id) bool connection_exists(CSteamID id)
{ {
@ -819,10 +823,7 @@ void RunCallbacks()
if (!msg.network().processed()) { if (!msg.network().processed()) {
if (!connection_exists(source_id)) { if (!connection_exists(source_id)) {
if (new_connection_times.find(source_id) == new_connection_times.end()) { if (new_connection_times.find(source_id) == new_connection_times.end()) {
P2PSessionRequest_t data; new_connections_to_call_cb.push(source_id);
memset(&data, 0, sizeof(data));
data.m_steamIDRemote = CSteamID(source_id);
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data), 0.1);
new_connection_times[source_id] = std::chrono::high_resolution_clock::now(); new_connection_times[source_id] = std::chrono::high_resolution_clock::now();
} }
} else { } else {
@ -855,6 +856,25 @@ void RunCallbacks()
} }
while (!new_connections_to_call_cb.empty()) {
CSteamID source_id = new_connections_to_call_cb.front();
auto t = new_connection_times.find(source_id);
if (t == new_connection_times.end()) {
new_connections_to_call_cb.pop();
continue;
}
if (!check_timedout(t->second, NEW_CONNECTION_DELAY)) {
break;
}
P2PSessionRequest_t data;
memset(&data, 0, sizeof(data));
data.m_steamIDRemote = source_id;
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data));
new_connections_to_call_cb.pop();
}
//TODO: not sure if sockets should be wiped right away //TODO: not sure if sockets should be wiped right away
remove_killed_connection_sockets(); remove_killed_connection_sockets();