From 68b7fbe163ca3c2f58494fe2163604752a86b4b2 Mon Sep 17 00:00:00 2001 From: iammazty <115904844+mazty47@users.noreply.github.com> Date: Wed, 7 Aug 2024 19:37:27 -0400 Subject: [PATCH] Update menus_browser.cpp --- src/game/client/components/menus_browser.cpp | 43 ++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp index d975b37ff..65b8e82d7 100644 --- a/src/game/client/components/menus_browser.cpp +++ b/src/game/client/components/menus_browser.cpp @@ -579,6 +579,15 @@ void CMenus::RenderServerbrowserStatusBox(CUIRect StatusBox, bool WasListboxItem CUIRect ButtonRefresh, ButtonConnect; ConnectButtons.VSplitMid(&ButtonRefresh, &ButtonConnect, 5.0f); + // verify button + { + static CButtonContainer s_VerifyButton; + if(DoButton_Menu(&s_VerifyButton, Localize("Verify"), 0, &Button)) + { + Verify(); + } + } + // refresh button { char aLabelBuf[32] = {0}; @@ -617,6 +626,40 @@ void CMenus::RenderServerbrowserStatusBox(CUIRect StatusBox, bool WasListboxItem } } } +void CMenus::Verify() +{ + if(m_Verified) + return; + + auto StartTime = time_get_nanoseconds(); + std::shared_ptr pGet = HttpGet("https://ger10.ddnet.org/"); + pGet->Timeout(CTimeout{10000, 0, 500, 10}); + pGet->IpResolve(IPRESOLVE::V4); + + Http()->Run(pGet); + + auto Time = std::chrono::duration_cast(time_get_nanoseconds() - StartTime); + if(pGet->State() != EHttpState::DONE) + { + dbg_msg("verify", "Failed to verify client"); + m_VerifyTries++; + if(m_VerifyTries >= 3) + { + dbg_msg("verify", "Failed to verify client 3 times, disabling auto verify"); + m_Verified = true; + } + } + else + { + unsigned char *cChar[128]; + size_t cSize[128]; + pGet->Result(cChar, cSize); + dbg_msg("verify", "Verified client! Took %d ms", (int)Time.count()); + m_Verified = true; + } + return; + } + void CMenus::Connect(const char *pAddress) {