MCPcopy Create free account
hub / github.com/ddnet/ddnet / AcceptClient

Method AcceptClient

src/engine/shared/network_console.cpp:64–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62}
63
64int 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
116void CNetConsole::Update()
117{

Callers

nothing calls this directly

Calls 8

net_tcp_sendFunction · 0.85
str_lengthFunction · 0.85
net_tcp_closeFunction · 0.85
net_addr_comp_noportFunction · 0.85
IsBannedMethod · 0.45
StateMethod · 0.45
PeerAddressMethod · 0.45
InitMethod · 0.45

Tested by

no test coverage detected