| 51 | } |
| 52 | |
| 53 | void CEcon::Init(CConfig *pConfig, IConsole *pConsole, CNetBan *pNetBan) |
| 54 | { |
| 55 | m_pConfig = pConfig; |
| 56 | m_pConsole = pConsole; |
| 57 | |
| 58 | for(auto &Client : m_aClients) |
| 59 | Client.m_State = CClient::STATE_EMPTY; |
| 60 | |
| 61 | m_Ready = false; |
| 62 | m_UserClientId = -1; |
| 63 | |
| 64 | if(g_Config.m_EcPort == 0) |
| 65 | return; |
| 66 | |
| 67 | if(g_Config.m_EcPassword[0] == 0) |
| 68 | { |
| 69 | Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "econ", "ec_password is required to be set for econ to be enabled."); |
| 70 | return; |
| 71 | } |
| 72 | |
| 73 | NETADDR BindAddr; |
| 74 | if(g_Config.m_EcBindaddr[0] && net_host_lookup(g_Config.m_EcBindaddr, &BindAddr, NETTYPE_ALL) == 0) |
| 75 | { |
| 76 | // got bindaddr |
| 77 | BindAddr.port = g_Config.m_EcPort; |
| 78 | } |
| 79 | else |
| 80 | { |
| 81 | char aBuf[256]; |
| 82 | str_format(aBuf, sizeof(aBuf), "The configured bindaddr '%s' cannot be resolved.", g_Config.m_EcBindaddr); |
| 83 | Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "econ", aBuf); |
| 84 | return; |
| 85 | } |
| 86 | |
| 87 | if(m_NetConsole.Open(BindAddr, pNetBan)) |
| 88 | { |
| 89 | m_NetConsole.SetCallbacks(NewClientCallback, DelClientCallback, this); |
| 90 | m_Ready = true; |
| 91 | char aBuf[128]; |
| 92 | str_format(aBuf, sizeof(aBuf), "bound to %s:%d", g_Config.m_EcBindaddr, g_Config.m_EcPort); |
| 93 | Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "econ", aBuf); |
| 94 | Console()->Register("logout", "", CFGFLAG_ECON, ConLogout, this, "Logout of econ"); |
| 95 | } |
| 96 | else |
| 97 | Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "econ", "couldn't open socket. port might already be in use"); |
| 98 | } |
| 99 | |
| 100 | void CEcon::Update() |
| 101 | { |
nothing calls this directly
no test coverage detected