MCPcopy Create free account
hub / github.com/cppla/ServerStatus / Init

Method Init

server/src/server.cpp:39–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37}
38
39int CServer::Init(CMain *pMain, const char *Bind, int Port)
40{
41 m_pMain = pMain;
42 m_NetBan.Init();
43
44 for(int i = 0; i < NET_MAX_CLIENTS; i++)
45 m_aClients[i].m_State = CClient::STATE_EMPTY;
46
47 m_Ready = false;
48
49 if(Port == 0)
50 {
51 dbg_msg("server", "Will not bind to port 0.");
52 return 1;
53 }
54
55 NETADDR BindAddr;
56 if(Bind[0] && net_host_lookup(Bind, &BindAddr, NETTYPE_ALL) == 0)
57 {
58 // got bindaddr
59 BindAddr.type = NETTYPE_ALL;
60 BindAddr.port = Port;
61 }
62 else
63 {
64 mem_zero(&BindAddr, sizeof(BindAddr));
65 BindAddr.type = NETTYPE_ALL;
66 BindAddr.port = Port;
67 }
68
69 if(m_Network.Open(BindAddr, &m_NetBan))
70 {
71 m_Network.SetCallbacks(NewClientCallback, DelClientCallback, this);
72 m_Ready = true;
73 dbg_msg("server", "Bound to %s:%d", Bind, Port);
74 return 0;
75 }
76 else
77 dbg_msg("server", "Couldn't open socket. Port (%d) might already be in use.", Port);
78
79 return 1;
80}
81
82void CServer::Update()
83{

Callers

nothing calls this directly

Calls 5

dbg_msgFunction · 0.85
net_host_lookupFunction · 0.85
mem_zeroFunction · 0.85
OpenMethod · 0.80
SetCallbacksMethod · 0.80

Tested by

no test coverage detected