diff --git a/Anit-Cheat_EXE/server_pipe.cpp b/Anit-Cheat_EXE/server_pipe.cpp index 1216b50..4ec9036 100644 --- a/Anit-Cheat_EXE/server_pipe.cpp +++ b/Anit-Cheat_EXE/server_pipe.cpp @@ -19,7 +19,7 @@ static LONG g_seen_client = 0; static LONG64 g_session_id = 0; static std::mutex g_clients_mutex; static std::vector> g_clients; -static constexpr DWORD kFirstClientTimeoutMs = 3000; +static constexpr DWORD kFirstClientTimeoutMs = 30000; static void ExitServerProcess(UINT exit_code) @@ -335,18 +335,36 @@ static bool DispatchCommand(HANDLE pipe, const std::shared_ptr& clie static DWORD WINAPI FirstClientTimeoutProc(LPVOID) { - DWORD wait = WaitForSingleObject(g_exit_event, kFirstClientTimeoutMs); - if (wait == WAIT_TIMEOUT && - InterlockedCompareExchange(&g_seen_client, 0, 0) == 0) + if (kFirstClientTimeoutMs != INFINITE) { - //printf("[server] no client connected in %lu ms, server shutdown\n", kFirstClientTimeoutMs); - fflush(stdout); - RequestShutdown("first client timeout"); + DWORD wait = WaitForSingleObject( + g_exit_event, + kFirstClientTimeoutMs); + + if (wait == WAIT_TIMEOUT && + InterlockedCompareExchange(&g_seen_client, 0, 0) == 0) + { + RequestShutdown("first client timeout"); + } } return 0; } +//static DWORD WINAPI FirstClientTimeoutProc(LPVOID) +//{ +// DWORD wait = WaitForSingleObject(g_exit_event, kFirstClientTimeoutMs); +// if (wait == WAIT_TIMEOUT && +// InterlockedCompareExchange(&g_seen_client, 0, 0) == 0) +// { +// //printf("[server] no client connected in %lu ms, server shutdown\n", kFirstClientTimeoutMs); +// fflush(stdout); +// RequestShutdown("first client timeout"); +// } +// +// return 0; +//} + static DWORD WINAPI MonitorThreadProc(LPVOID) { while (WaitForSingleObject(g_exit_event, kHeartbeatIntervalMs) == WAIT_TIMEOUT) @@ -477,6 +495,37 @@ static DWORD WINAPI AcceptThreadProc(LPVOID) if (WaitForSingleObject(g_exit_event, 0) == WAIT_OBJECT_0) return 0; + //HANDLE pipe = CreateNamedPipeW( + // kPipeName, + // PIPE_ACCESS_DUPLEX, + // PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, + // PIPE_UNLIMITED_INSTANCES, + // sizeof(Msg), + // sizeof(Msg), + // 0, + // nullptr); + + PSECURITY_DESCRIPTOR security_descriptor = nullptr; + + if (!ConvertStringSecurityDescriptorToSecurityDescriptorW( + L"D:P" + L"(A;;GA;;;SY)" + L"(A;;GA;;;BA)" + L"(A;;GRGW;;;AU)" + L"S:(ML;;NW;;;ME)", + SDDL_REVISION_1, + &security_descriptor, + nullptr)) + { + Sleep(1000); + continue; + } + + SECURITY_ATTRIBUTES security_attributes{}; + security_attributes.nLength = sizeof(security_attributes); + security_attributes.lpSecurityDescriptor = security_descriptor; + security_attributes.bInheritHandle = FALSE; + HANDLE pipe = CreateNamedPipeW( kPipeName, PIPE_ACCESS_DUPLEX, @@ -485,11 +534,24 @@ static DWORD WINAPI AcceptThreadProc(LPVOID) sizeof(Msg), sizeof(Msg), 0, - nullptr); + &security_attributes); + + LocalFree(security_descriptor); + + if (pipe == INVALID_HANDLE_VALUE) { - //printf("[server] CreateNamedPipeW failed: %lu\n", GetLastError()); + DWORD error = GetLastError(); + + char buffer[128]{}; + sprintf_s( + buffer, + "[server] CreateNamedPipeW failed: %lu\n", + error); + + OutputDebugStringA(buffer); + Sleep(1000); continue; }