private void HandleNewSocket(Socket socket) { if (socket == null) { return; } var remoteEndPoint = socket.RemoteEndPoint; this.Log(l => l.DebugFormat($"Game Client connected, Address {remoteEndPoint}")); ushort newPlayerId; var playerIdEventArgs = new RequestPlayerIdEventArgs(); if (!this.OnRequestPlayerId(playerIdEventArgs)) { // No Free Id, so disconnect the client this.Log(l => l.DebugFormat($"out of free id's... disconnecting the game client {remoteEndPoint}")); // MAYBE TODO: wait until an id is free? socket.Dispose(); } else { newPlayerId = playerIdEventArgs.PlayerId; this.Log(l => l.DebugFormat($"new player id {newPlayerId} for game client {remoteEndPoint}")); var connection = new Connection(socket, new Encryptor(), new Decryptor()); var remotePlayer = new RemotePlayer(newPlayerId, this.gameContext, this.mainPacketHandler, connection); this.OnPlayerConnected(remotePlayer); connection.Disconnected += (sender, e) => remotePlayer.Disconnect(); connection.BeginReceive(); } }
private void HandleNewSocket(Socket socket) { if (socket == null) { return; } var remoteEndPoint = socket.RemoteEndPoint; this.Log(l => l.DebugFormat($"Game Client connected, Address {remoteEndPoint}")); if (this.gameContext.PlayerList.Count >= this.gameContext.ServerConfiguration.MaximumPlayers) { this.Log(l => l.DebugFormat($"The server is full... disconnecting the game client {remoteEndPoint}")); // MAYBE TODO: wait until another player disconnects? socket.Dispose(); } else { var connection = new Connection(socket, new Encryptor(), new Decryptor()); var remotePlayer = new RemotePlayer(this.gameContext, this.mainPacketHandler, connection); this.OnPlayerConnected(remotePlayer); connection.Disconnected += (sender, e) => remotePlayer.Disconnect(); connection.BeginReceive(); } }
private void HandleNewSocket(Socket socket) { if (socket == null) { return; } var remoteEndPoint = socket.RemoteEndPoint; this.Log(l => l.DebugFormat($"Game Client connected, Address {remoteEndPoint}")); if (this.gameContext.PlayerList.Count >= this.gameContext.ServerConfiguration.MaximumPlayers) { this.Log(l => l.DebugFormat($"The server is full... disconnecting the game client {remoteEndPoint}")); // MAYBE TODO: wait until another player disconnects? socket.Dispose(); } else { socket.NoDelay = true; var socketConnection = SocketConnection.Create(socket); var connection = new Connection(socketConnection, new PipelinedDecryptor(socketConnection.Input), new PipelinedEncryptor(socketConnection.Output)); var remotePlayer = new RemotePlayer(this.gameContext, connection, new ClientVersion(this.endPoint.Client.Season, this.endPoint.Client.Episode, this.endPoint.Client.Language)); this.OnPlayerConnected(remotePlayer); connection.Disconnected += (sender, e) => remotePlayer.Disconnect(); // we don't want to await the call. connection.BeginReceive(); } }