Skip to content

Commit 75cd76e

Browse files
author
a
committed
allow changing packet sharing behavior in old p2p networking via ini config
1 parent e88797f commit 75cd76e

File tree

6 files changed

+255
-90
lines changed

6 files changed

+255
-90
lines changed

dll/dll/p2p_manager.hpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#pragma once
1919

2020
#include "base.h"
21+
#include <tuple>
2122

2223

2324
class P2p_Manager
@@ -31,8 +32,15 @@ class P2p_Manager
3132

3233
struct Packet_t
3334
{
35+
private:
36+
std::chrono::high_resolution_clock::time_point time_created = std::chrono::high_resolution_clock::now();
37+
38+
public:
3439
bool is_processed = false;
3540
std::vector<char> data{};
41+
EP2PSend send_type = EP2PSend::k_EP2PSendUnreliable;
42+
43+
const std::chrono::high_resolution_clock::time_point& get_time_created() const;
3644
};
3745

3846
struct Channel_t
@@ -69,7 +77,17 @@ class P2p_Manager
6977

7078
// true if the connection was already accepted,
7179
// false otherwise.
72-
bool store_packet(CSteamID my_id, CSteamID steamIDRemote, const void *pubData, uint32 cubData, int nChannel);
80+
bool store_packet(
81+
CSteamID my_id, CSteamID steamIDRemote,
82+
const void *pubData, uint32 cubData, int nChannel,
83+
EP2PSend send_type
84+
);
85+
86+
std::optional<std::tuple<
87+
decltype(connections)::iterator,
88+
decltype(Connection_t::channels)::iterator,
89+
decltype(Channel_t::packets)::iterator
90+
>> get_next_packet(CSteamID my_id, int nChannel);
7391

7492
void periodic_handle_connections(const std::chrono::high_resolution_clock::time_point &now);
7593
void periodic_handle_channels(const std::chrono::high_resolution_clock::time_point &now);

dll/dll/settings.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,32 @@ struct Branch_Info {
200200
bool active = false;
201201
};
202202

203+
struct OldP2pBehavior {
204+
enum class EPacketShareMode {
205+
// if the sending type is unreliable (UDP), share packets between gameserver and client
206+
// otherwise, don't share packets
207+
DEFAULT,
208+
209+
// always share packets between gameserver and client
210+
ALWAYS_SHARE,
211+
212+
// never share packets between gameserver and client
213+
NEVER_SHARE,
214+
215+
_LAST,
216+
};
217+
218+
static EPacketShareMode to_share_mode(int val) {
219+
if (val < 0 || val >= (unsigned)EPacketShareMode::_LAST) {
220+
return EPacketShareMode::DEFAULT;
221+
}
222+
223+
return (EPacketShareMode)val;
224+
}
225+
226+
EPacketShareMode mode = EPacketShareMode::DEFAULT;
227+
};
228+
203229
class Settings {
204230
private:
205231
CSteamID steam_id{}; // user id
@@ -373,6 +399,9 @@ class Settings {
373399
// free weekend
374400
bool free_weekend = false;
375401

402+
// old P2P (ISteamNetworking) behavior
403+
OldP2pBehavior old_p2p_behavior{};
404+
376405
// voice chat
377406
bool enable_voice_chat = false;
378407

dll/net.proto

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ message Low_Level {
8181
}
8282

8383
message Network_pb {
84-
int32 channel = 1;
85-
bytes data = 2;
86-
8784
enum Types {
8885
DATA = 0;
8986
FAILED_CONNECT = 1;
9087
}
9188

92-
Types type = 3;
89+
Types type = 1;
90+
int32 channel = 2;
91+
bytes data = 3;
92+
uint32 send_type = 4; // EP2PSend
9393
}
9494

9595
message Network_Old {

0 commit comments

Comments
 (0)