From 7bb5ec2ba68b63b02ba379c2fa4ac10644aa6dee Mon Sep 17 00:00:00 2001 From: staphen Date: Sat, 22 Nov 2025 12:52:22 -0500 Subject: [PATCH] Improve error messages when joining ZT games --- Source/dvlnet/base_protocol.h | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/Source/dvlnet/base_protocol.h b/Source/dvlnet/base_protocol.h index 3f0c69c74..9e51528be 100644 --- a/Source/dvlnet/base_protocol.h +++ b/Source/dvlnet/base_protocol.h @@ -76,7 +76,7 @@ private: bool is_recognized(endpoint_t sender); tl::expected wait_network(); - bool wait_firstpeer(); + tl::expected wait_firstpeer(); tl::expected wait_join(); }; @@ -114,8 +114,9 @@ void base_protocol

::DisconnectNet(plr_t plr) } template -bool base_protocol

::wait_firstpeer() +tl::expected base_protocol

::wait_firstpeer() { + firstpeer = {}; // wait for peer for 5 seconds for (auto i = 0; i < 500; ++i) { auto it = game_list.find(gamename); @@ -127,7 +128,9 @@ bool base_protocol

::wait_firstpeer() recv(); SDL_Delay(10); } - return bool { firstpeer }; + if (!firstpeer) + return tl::make_unexpected("Timeout waiting for response from game host"); + return {}; } template @@ -206,13 +209,17 @@ int base_protocol

::join(std::string_view addrstr) SDL_SetError("%.*s", static_cast(message.size()), message.data()); return -1; } - if (wait_firstpeer()) { - tl::expected result = wait_join(); - if (!result.has_value()) { - const std::string_view message = result.error().what(); - SDL_SetError("%.*s", static_cast(message.size()), message.data()); - return -1; - } + tl::expected isPeerReady = wait_firstpeer(); + if (!isPeerReady.has_value()) { + const std::string_view message = isPeerReady.error().what(); + SDL_SetError("%.*s", static_cast(message.size()), message.data()); + return -1; + } + tl::expected isJoined = wait_join(); + if (!isJoined.has_value()) { + const std::string_view message = isJoined.error().what(); + SDL_SetError("%.*s", static_cast(message.size()), message.data()); + return -1; } return (plr_self == PLR_BROADCAST ? -1 : plr_self); }