Skip to content

Commit 03ea476

Browse files
committed
simulated packet loss/delay for steam sockets
1 parent 827d201 commit 03ea476

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
strategy:
99
fail-fast: false
1010
matrix:
11-
os-version: [2022, 2025]
11+
os-version: [2025]
1212
build-arch: [Win32, x64]
1313
build-config: [debug, release, relwithdebinfo]
1414
build-tool: ["", "-T ClangCL"]

sources/include/cage-core/networkGinnel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace cage
99
// Northern English: A narrow passage between buildings; an alley.
1010
// Origin: Early 17th century perhaps from French chenel ‘channel’.
1111

12-
// low latency, connection-oriented, sequenced and optionally reliable datagram protocol on top of udp
12+
// low latency, connection-oriented, sequenced, and optionally reliable, datagram protocol on top of udp
1313
// messages are sequenced within each channel only; reliable and unreliable messages are not sequenced with each other
1414

1515
struct CAGE_CORE_API GinnelStatistics

sources/include/cage-core/networkSteam.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace cage
1010
uint64 sendingBytesPerSecond = 0;
1111
uint64 receivingBytesPerSecond = 0;
1212
uint64 estimatedBandwidth = 0; // bytes per second
13-
uint64 ping = 0;
13+
uint64 ping = 0; // microseconds (round-trip)
1414
float quality = 0; // 0 = bad, 1 = good
1515
};
1616

sources/libcore/network/steam.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ namespace cage
2121
namespace
2222
{
2323
const ConfigSint32 confDebugLogLevel("cage/steamsocks/logLevel", k_ESteamNetworkingSocketsDebugOutputType_Msg);
24+
const ConfigFloat confSimulatedPacketLoss("cage/steamsocks/simulatedPacketLoss", 0); // 0 .. 1
25+
const ConfigFloat confSimulatedPacketDelay("cage/steamsocks/simulatedPacketDelay", 0); // ms
2426

2527
constexpr uint32 LanesCount = 4;
2628

@@ -144,11 +146,18 @@ namespace cage
144146
CAGE_ASSERT(utils);
145147
}
146148

147-
struct InitializerDebugOutput
149+
struct InitializerConfiguration
148150
{
149-
InitializerDebugOutput() { utils->SetDebugOutputFunction((ESteamNetworkingSocketsDebugOutputType)(sint32)confDebugLogLevel, &debugOutputHandler); }
151+
InitializerConfiguration()
152+
{
153+
utils->SetDebugOutputFunction((ESteamNetworkingSocketsDebugOutputType)(sint32)confDebugLogLevel, &debugOutputHandler);
154+
float packetLoss = confSimulatedPacketLoss * 100;
155+
utils->SetConfigValue(k_ESteamNetworkingConfig_FakePacketLoss_Send, k_ESteamNetworkingConfig_Global, 0, k_ESteamNetworkingConfig_Float, &packetLoss);
156+
sint32 packetDelay = confSimulatedPacketDelay;
157+
utils->SetConfigValue(k_ESteamNetworkingConfig_FakePacketLag_Send, k_ESteamNetworkingConfig_Global, 0, k_ESteamNetworkingConfig_Int32, &packetDelay);
158+
}
150159
};
151-
static InitializerDebugOutput initializerDebugOutput;
160+
static InitializerConfiguration initializerConfiguration;
152161

153162
#if defined(CAGE_USE_STEAM_SDK)
154163
struct InitializerSdk
@@ -159,7 +168,7 @@ namespace cage
159168
ESteamNetworkingAvailability a = sockets->InitAuthentication();
160169
while (!networkingAvailable(a))
161170
{
162-
threadSleep(5000);
171+
threadSleep(5'000);
163172
SteamAPI_RunCallbacks();
164173
SteamGameServer_RunCallbacks();
165174
a = sockets->GetAuthenticationStatus(nullptr);
@@ -183,7 +192,7 @@ namespace cage
183192
ESteamNetworkingAvailability a = utils->GetRelayNetworkStatus(nullptr);
184193
if (networkingAvailable(a))
185194
break;
186-
threadSleep(5000);
195+
threadSleep(5'000);
187196
SteamAPI_RunCallbacks();
188197
}
189198
}

0 commit comments

Comments
 (0)