MCPcopy Create free account
hub / github.com/ddnet/ddnet / Init

Method Init

src/engine/shared/econ.cpp:53–98  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51}
52
53void 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
100void CEcon::Update()
101{

Callers

nothing calls this directly

Calls 6

net_host_lookupFunction · 0.85
str_formatFunction · 0.85
PrintMethod · 0.45
OpenMethod · 0.45
SetCallbacksMethod · 0.45
RegisterMethod · 0.45

Tested by

no test coverage detected