Beispiel #1
0
        private void OnAccept(IAsyncResult result)
        {
            if (!_isServerRunning)
            {
                return;
            }

            try
            {
                _listener.BeginAccept(OnAccept, null);

                var handler    = _listener.EndAccept(result);
                var connection = new ServerConnection(handler, _api.Name, _logger, OnPackageReceived);

                connection.SendInfo();

                lock (_connections)
                {
                    connection.Id = string.Format("{0}{1}", Connection.TempConnectionPrefix, _lastTempId++);
                    _connections.Add(connection.Id, connection);
                }

                _notifier.ConnectionOpened(new ConnectionEventArgs(connection.Id));
            }
            catch (Exception e)
            {
                _logger.Write(e);
            }
        }
        private void OnAccept(IAsyncResult result)
        {
            if (!_isServerRunning)
            {
                return;
            }

            try
            {
                _listener.BeginAccept(OnAccept, null);

                var handler  = _listener.EndAccept(result);
                var endPoint = (IPEndPoint)handler.RemoteEndPoint;

                if (_bans.IsBanned(endPoint.Address))
                {
                    handler.Disconnect(false);
                    handler.Dispose();
                }
                else
                {
                    var connection = new ServerConnection(handler, _certificate, _api.Name, _logger, OnPackageReceived);
                    connection.SendServerInfo();

                    lock (_connections)
                    {
                        connection.Id = new UserId(_lastTempId++, "<not_registered>");
                        _connections.Add(connection.Id, connection);
                    }

                    _notifier.ConnectionOpened(new ConnectionEventArgs(connection.Id));
                }
            }
            catch (Exception e)
            {
                _logger.Write(e);
            }
        }