MCPcopy Create free account
hub / github.com/NoMercy-ac/NoMercy / InitializeClientSocket

Method InitializeClientSocket

Source/Client/NM_Engine/ClientSocketMain.cpp:9–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7#include "ExceptionHandlers.h"
8
9bool CNetwork::InitializeClientSocket()
10{
11 NETWORK_LOG(LL_SYS, "Network client initialize has been started!");
12
13 bool bRet = false;
14
15 m_pNetClient = std::make_shared<CNetworkClient>(m_NetService);
16 if (!m_pNetClient || !m_pNetClient.get())
17 {
18 NETWORK_LOG(LL_ERR, "m_pNetClient can NOT allocated! Last error: %u", g_winapiApiTable->GetLastError());
19 return bRet;
20 }
21
22 try
23 {
24 bRet = m_pNetClient->Connect(m_szIPAddress, m_wPort);
25 if (bRet == false)
26 {
27 NETWORK_LOG(LL_ERR, "m_pNetClient->Connect(m_wPort) fail! Last error: %u", g_winapiApiTable->GetLastError());
28
29 bRet = m_pNetClient->Connect(m_szIPAddress, m_wPort2);
30 }
31
32 if (bRet == false)
33 {
34 NETWORK_LOG(LL_ERR, "m_pNetClient->Connect(m_wPort2) fail! Last error: %u", g_winapiApiTable->GetLastError());
35 return bRet;
36 }
37
38 m_bIsInitialized = true;
39
40 m_NetService.Run();
41 }
42 catch (std::exception& e)
43 {
44#ifdef _DEBUG
45 NETWORK_LOG(LL_ERR, "Exception handled: %s", e.what());
46 CExceptionHandlers::OnExceptionThrowed(nullptr);
47#else
48 UNREFERENCED_PARAMETER(e);
49#endif
50 }
51 catch (DWORD dwNumber)
52 {
53#ifdef _DEBUG
54 NETWORK_LOG(LL_ERR, "Exception handled: %p", dwNumber);
55 CExceptionHandlers::OnExceptionThrowed(nullptr);
56#else
57 UNREFERENCED_PARAMETER(dwNumber);
58#endif
59 }
60 catch (...)
61 {
62#ifdef _DEBUG
63 NETWORK_LOG(LL_ERR, "Unhandled exception!");
64 CExceptionHandlers::OnExceptionThrowed(nullptr);
65#endif
66 }

Callers 1

NetworkRoutineFunction · 0.80

Calls 3

getMethod · 0.45
ConnectMethod · 0.45
RunMethod · 0.45

Tested by

no test coverage detected