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

Method AcceptClient

server/src/network.cpp:55–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53}
54
55int 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
94int CNetwork::Update()
95{

Callers

nothing calls this directly

Calls 8

net_addr_compFunction · 0.85
str_copyFunction · 0.85
net_tcp_sendFunction · 0.85
str_lengthFunction · 0.85
net_tcp_closeFunction · 0.85
StateMethod · 0.80
PeerAddressMethod · 0.80
InitMethod · 0.45

Tested by

no test coverage detected