From f73af8d4164d00248b0922deaac67073b2240664 Mon Sep 17 00:00:00 2001 From: Shingo INADA Date: Sun, 13 Aug 2023 20:52:16 +0900 Subject: [PATCH 1/2] add network jam simulation --- core/deps/ggpo/lib/ggpo/network/udp_proto.cpp | 16 ++++++++++++++++ core/deps/ggpo/lib/ggpo/network/udp_proto.h | 2 ++ run.py | 4 +++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/core/deps/ggpo/lib/ggpo/network/udp_proto.cpp b/core/deps/ggpo/lib/ggpo/network/udp_proto.cpp index 441f7540e..738e183e1 100644 --- a/core/deps/ggpo/lib/ggpo/network/udp_proto.cpp +++ b/core/deps/ggpo/lib/ggpo/network/udp_proto.cpp @@ -62,6 +62,7 @@ UdpProtocol::UdpProtocol() : _oo_packet.msg = NULL; _send_latency = GGPOPlatform::GetConfigInt("GGPO_NETWORK_DELAY"); + _jam_latency = GGPOPlatform::GetConfigInt("GGPO_NETWORK_JAM_DELAY"); _oop_percent = GGPOPlatform::GetConfigInt("GGPO_OOP_PERCENT"); } @@ -822,6 +823,21 @@ UdpProtocol::PumpSendQueue() break; } } + + // simulate temporary packet jam + if (_jam_latency) { + if (!_enable_jam && (rand() % 600 == 0)) { + _enable_jam = true; + LogInfo("Jam!"); + } + if (_enable_jam) { + if ((int)GGPOPlatform::GetCurrentTimeMS() < entry.queue_time + _jam_latency) { + break; + } + _enable_jam = false; + } + } + if (_oop_percent && !_oo_packet.msg && ((rand() % 100) < _oop_percent)) { int delay = rand() % (_send_latency * 10 + 1000); Log("udpproto%d | creating rogue oop (seq: %d delay: %d)", _queue, entry.msg->hdr.sequence_number, delay); diff --git a/core/deps/ggpo/lib/ggpo/network/udp_proto.h b/core/deps/ggpo/lib/ggpo/network/udp_proto.h index c6b8a4c63..8198f0d03 100644 --- a/core/deps/ggpo/lib/ggpo/network/udp_proto.h +++ b/core/deps/ggpo/lib/ggpo/network/udp_proto.h @@ -151,6 +151,8 @@ class UdpProtocol : public IPollSink uint16 _remote_magic_number; bool _connected; int _send_latency; + int _jam_latency; + bool _enable_jam; int _oop_percent; struct { int send_time; diff --git a/run.py b/run.py index e9c714690..25b252e64 100644 --- a/run.py +++ b/run.py @@ -100,7 +100,9 @@ def run(idx, *arg_list) -> subprocess.Popen: print(cmd) new_env = os.environ.copy() new_env["GGPO_NETWORK_DELAY"] = "16" - new_env["GGPO_OOP_PERCENT"] = "1" + # new_env["GGPO_OOP_PERCENT"] = "1" + if idx == 0: + new_env["GGPO_NETWORK_JAM_DELAY"] = "500" # else: new_env["GGPO_NETWORK_DELAY"] = "100" return subprocess.Popen(cmd, shell=True, env=new_env) From 41fc183750ccc48f7e7c57597df892170d63ec1f Mon Sep 17 00:00:00 2001 From: Shingo INADA Date: Wed, 16 Aug 2023 07:26:46 +0900 Subject: [PATCH 2/2] Fix to write loginkey --- core/gdxsv/gdxsv.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/gdxsv/gdxsv.cpp b/core/gdxsv/gdxsv.cpp index a045bd543..47b2c1cc4 100644 --- a/core/gdxsv/gdxsv.cpp +++ b/core/gdxsv/gdxsv.cpp @@ -6,7 +6,6 @@ #include #include -#include "cfg/cfg.h" #include "cfg/option.h" #include "emulator.h" #include "gdx_rpc.h" @@ -117,6 +116,10 @@ void Gdxsv::Reset() { config::GdxLocalPort = get_random_port_number(); } + if (config::GdxLoginKey.get().empty()) { + config::GdxLoginKey = GenerateLoginKey(); + } + NOTICE_LOG(COMMON, "gdxsv disk:%d server:%s loginkey:%s udp_port:%d", (int)disk_, config::GdxLobbyServer.get().c_str(), config::GdxLoginKey.get().c_str(), config::GdxLocalPort.get());