public bool AddNewConnection(ServerClientConnection conn) { Monitor.Enter(newConnections); try { newConnections.Add(conn); return true; } finally { Monitor.Exit(newConnections); } }
protected void threadMain() { while (true) { Socket newClientSocket = null; try { newClientSocket = serverSocket.Accept(); Logger.LogProgress(LogSource.Listener, "Accepted connection from IP: " + (newClientSocket.RemoteEndPoint as IPEndPoint).Address + ", Port: " + (newClientSocket.RemoteEndPoint as IPEndPoint).Port); } catch (Exception ex) { Logger.LogError(LogSource.Listener, "Failed to accept connection.", ex); continue; } try { // Creating a new connection ServerClientConnection conn = new ServerClientConnection(newClientSocket, serverConfiguration.ConnectionReadBufferSize); conn.Logger = Logger; conn.LogNormalOperation = serverConfiguration.LogNormalOperation; // Creating a new player PlayerCharacter pc = new PlayerCharacter(conn); // Adding a new connection serverCommunicationManager.AddNewConnection(conn); // Adding a new player serverWorldSimulation.AddNewPlayer(pc); } catch (Exception ex) { Logger.LogError(LogSource.Listener, "Failed to add new connection or player", ex); } } }