| 53 | } |
| 54 | |
| 55 | int CNetwork::AcceptClient(NETSOCKET Socket, const NETADDR *pAddr) |
| 56 | { |
| 57 | char aError[256] = { 0 }; |
| 58 | int FreeSlot = -1; |
| 59 | |
| 60 | // look for free slot or multiple client |
| 61 | for(int i = 0; i < NET_MAX_CLIENTS; i++) |
| 62 | { |
| 63 | if(FreeSlot == -1 && m_aSlots[i].m_Connection.State() == NET_CONNSTATE_OFFLINE) |
| 64 | FreeSlot = i; |
| 65 | if(m_aSlots[i].m_Connection.State() != NET_CONNSTATE_OFFLINE) |
| 66 | { |
| 67 | if(net_addr_comp(pAddr, m_aSlots[i].m_Connection.PeerAddress()) == 0) |
| 68 | { |
| 69 | str_copy(aError, "Only one client per IP allowed.", sizeof(aError)); |
| 70 | break; |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | // accept client |
| 76 | if(!aError[0] && FreeSlot != -1) |
| 77 | { |
| 78 | m_aSlots[FreeSlot].m_Connection.Init(Socket, pAddr); |
| 79 | if(m_pfnNewClient) |
| 80 | m_pfnNewClient(FreeSlot, m_UserPtr); |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | // reject client |
| 85 | if(!aError[0]) |
| 86 | str_copy(aError, "No free slot available.", sizeof(aError)); |
| 87 | |
| 88 | net_tcp_send(Socket, aError, str_length(aError)); |
| 89 | net_tcp_close(Socket); |
| 90 | |
| 91 | return -1; |
| 92 | } |
| 93 | |
| 94 | int CNetwork::Update() |
| 95 | { |
nothing calls this directly
no test coverage detected