| 37 | } |
| 38 | |
| 39 | int 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 | |
| 82 | void CServer::Update() |
| 83 | { |
nothing calls this directly
no test coverage detected