| 62 | } |
| 63 | |
| 64 | int CNetConsole::AcceptClient(NETSOCKET Socket, const NETADDR *pAddr) |
| 65 | { |
| 66 | const auto &DropClient = [&](const char *pError) { |
| 67 | net_tcp_send(Socket, pError, str_length(pError)); |
| 68 | net_tcp_close(Socket); |
| 69 | }; |
| 70 | |
| 71 | // check if address is banned |
| 72 | char aBanMessage[256]; |
| 73 | if(NetBan() && NetBan()->IsBanned(pAddr, aBanMessage, sizeof(aBanMessage))) |
| 74 | { |
| 75 | DropClient(aBanMessage); |
| 76 | return -1; |
| 77 | } |
| 78 | |
| 79 | // look for free slot or multiple clients with same address |
| 80 | int FreeSlot = -1; |
| 81 | for(int i = 0; i < NET_MAX_CONSOLE_CLIENTS; i++) |
| 82 | { |
| 83 | if(m_aSlots[i].m_Connection.State() == CConsoleNetConnection::EState::OFFLINE) |
| 84 | { |
| 85 | if(FreeSlot == -1) |
| 86 | { |
| 87 | FreeSlot = i; |
| 88 | } |
| 89 | } |
| 90 | else if(net_addr_comp_noport(pAddr, m_aSlots[i].m_Connection.PeerAddress()) == 0) |
| 91 | { |
| 92 | DropClient("only one client per IP allowed"); |
| 93 | return -1; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | if(FreeSlot == -1) |
| 98 | { |
| 99 | DropClient("no free slot available"); |
| 100 | return -1; |
| 101 | } |
| 102 | |
| 103 | // accept client |
| 104 | if(m_aSlots[FreeSlot].m_Connection.Init(Socket, pAddr) != 0) |
| 105 | { |
| 106 | DropClient("failed to initialize client connection"); |
| 107 | return -1; |
| 108 | } |
| 109 | if(m_pfnNewClient) |
| 110 | { |
| 111 | m_pfnNewClient(FreeSlot, m_pUser); |
| 112 | } |
| 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | void CNetConsole::Update() |
| 117 | { |
nothing calls this directly
no test coverage detected