| 297 | |
| 298 | |
| 299 | void cServer::OnConnectionAccepted(cSocket & a_Socket) |
| 300 | { |
| 301 | if (!a_Socket.IsValid()) |
| 302 | { |
| 303 | return; |
| 304 | } |
| 305 | |
| 306 | const AString & ClientIP = a_Socket.GetIPString(); |
| 307 | if (ClientIP.empty()) |
| 308 | { |
| 309 | LOGWARN("cServer: A client connected, but didn't present its IP, disconnecting."); |
| 310 | a_Socket.CloseSocket(); |
| 311 | return; |
| 312 | } |
| 313 | |
| 314 | LOGD("Client \"%s\" connected!", ClientIP.c_str()); |
| 315 | |
| 316 | cClientHandle * NewHandle = new cClientHandle(&a_Socket, m_ClientViewDistance); |
| 317 | if (!m_SocketThreads.AddClient(a_Socket, NewHandle)) |
| 318 | { |
| 319 | // For some reason SocketThreads have rejected the handle, clean it up |
| 320 | LOGERROR("Client \"%s\" cannot be handled, server probably unstable", ClientIP.c_str()); |
| 321 | a_Socket.CloseSocket(); |
| 322 | delete NewHandle; |
| 323 | return; |
| 324 | } |
| 325 | |
| 326 | cCSLock Lock(m_CSClients); |
| 327 | m_Clients.push_back(NewHandle); |
| 328 | } |
| 329 | |
| 330 | |
| 331 | |