public static void AddBan(int plr)
        {
            RemoteAddress remoteAddress = Netplay.Clients[plr].Socket.GetRemoteAddress();

            using (StreamWriter streamWriter = new StreamWriter(Netplay.BanFilePath, true))
            {
                streamWriter.WriteLine("//" + Main.player[plr].name);
                streamWriter.WriteLine(remoteAddress.ToString());
            }
        }
Exemple #2
0
 /// <summary>
 /// A friendly representation of this object.
 /// </summary>
 /// <returns>The remote's user nick and his IP address, e.g. [email protected]</returns>
 public override string ToString()
 {
     if (RemoteAddress == null)
     {
         return(Nick);
     }
     else
     {
         return(Nick + "@" + RemoteAddress.ToString());
     }
 }
Exemple #3
0
 /// <summary>
 /// This method is called by the <see cref="M:AppenderSkeleton.DoAppend(LoggingEvent)" /> method.
 /// </summary>
 /// <param name="loggingEvent">The event to log.</param>
 /// <remarks>
 /// <para>
 /// Sends the event using an UDP datagram.
 /// </para>
 /// <para>
 /// Exceptions are passed to the <see cref="P:log4net.Appender.AppenderSkeleton.ErrorHandler" />.
 /// </para>
 /// </remarks>
 protected override void Append(LoggingEvent loggingEvent)
 {
     try
     {
         byte[] bytes = m_encoding.GetBytes(RenderLoggingEvent(loggingEvent).ToCharArray());
         Client.SendAsync(bytes, bytes.Length, RemoteEndPoint).Wait();
     }
     catch (Exception e)
     {
         ErrorHandler.Error("Unable to send logging event to remote host " + RemoteAddress.ToString() + " on port " + RemotePort + ".", e, ErrorCode.WriteFailure);
     }
 }
Exemple #4
0
        public Connection(TcpConnectionInformation info)
        {
            this.RemoteAddress = info.RemoteEndPoint.Address;
            this.LocalAddress  = info.LocalEndPoint.Address;
            this.LocalPort     = info.LocalEndPoint.Port;
            this.RemotePort    = info.RemoteEndPoint.Port;
            this.State         = info.State;
            double?a, b;

            GeoDatabase.GetPosition(RemoteAddress.ToString(), out a, out b);
            this.Longitude = a;
            this.Latitude  = b;
        }
Exemple #5
0
 public override System.String ToString()
 {
     System.Text.StringBuilder buf = new System.Text.StringBuilder();
     buf.Append(System.Net.Dns.GetHostEntry(RemoteAddress.ToString()).HostName);
     buf.Append(":");
     for (int i = 0; i < sockets.Count; i++)
     {
         System.Net.IPEndPoint end = ((System.Net.Sockets.TcpClient)sockets[i]).Client.RemoteEndPoint as System.Net.IPEndPoint;
         buf.Append(end.Port);
         if (i + 1 < sockets.Count)
         {
             buf.Append(",");
         }
     }
     return(buf.ToString());
 }
Exemple #6
0
        public override void Start()
        {
            ServerSocket = true;

            SetBlocking(false);

            var ipAddress = RemoteAddress.ToString();

            Console.WriteLine("Connection from {0}:{1} accepted", ipAddress, RemotePort);

            Session = new AuthSession(this);
            World.AddSession(Session);

            _authCrypt.Init("key", Shared.Keys.ServerEncryptionKey, Shared.Keys.ClientEncryptionKey, ServerSocket);

            AsyncRead();
        }
        /// <summary>
        /// This method is called by the <see cref="AppenderSkeleton.DoAppend(LoggingEvent)"/> method.
        /// </summary>
        /// <param name="loggingEvent">The event to log.</param>
        /// <remarks>
        /// <para>
        /// Writes the event to a remote syslog daemon.
        /// </para>
        /// <para>
        /// The format of the output will depend on the appender's layout.
        /// </para>
        /// </remarks>
        protected override void Append(LoggingEvent loggingEvent)
        {
            try
            {
                StringWriter writer = new StringWriter(CultureInfo.InvariantCulture);

                // Priority
                int priority = GeneratePriority(m_facility, GetSeverity(loggingEvent.Level));
                writer.Write('<');
                writer.Write(priority);
                writer.Write('>');

                // Identity
                if (m_identity != null)
                {
                    m_identity.Format(writer, loggingEvent);
                }
                else
                {
                    writer.Write(loggingEvent.Domain);
                }
                writer.Write(": ");

                // Message. The message goes after the tag/identity
                RenderLoggingEvent(writer, loggingEvent);

                // Grab as a byte array
                string  fullMessage = writer.ToString();
                Byte [] buffer      = Encoding.GetBytes(fullMessage.ToCharArray());

                Client.Send(buffer, buffer.Length, RemoteEndPoint);
            }
            catch (Exception e)
            {
                ErrorHandler.Error(
                    "Unable to send logging event to remote syslog " +
                    RemoteAddress.ToString() +
                    " on port " +
                    RemotePort + ".",
                    e,
                    ErrorCode.WriteFailure);
            }
        }
Exemple #8
0
        public override void Start()
        {
            SetBlocking(false);

            var ipAddress = RemoteAddress.ToString();

            Console.WriteLine("Connected to server {0}:{1}", ipAddress, RemotePort);

            Session = new ClientSession(this);

            _authCrypt.Init("key", Shared.Keys.ServerEncryptionKey, Shared.Keys.ClientEncryptionKey, ServerSocket);

            var loginPacket = new Shared.ClientPackets.Login {
                Username = "******", Password = "******"
            };

            SendPacket(loginPacket);

            AsyncRead();
        }
 /// <summary>
 /// String representation of the proxy socket.
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     return("Proxy connection to: " + RemoteAddress.ToString());
 }
        protected internal override async Task OnOpenAsync(TimeSpan timeout)
        {
            TimeoutHelper helper = new TimeoutHelper(timeout);

            bool success = false;

            try
            {
                if (WcfEventSource.Instance.WebSocketConnectionRequestSendStartIsEnabled())
                {
                    WcfEventSource.Instance.WebSocketConnectionRequestSendStart(
                        EventTraceActivity,
                        RemoteAddress != null ? RemoteAddress.ToString() : string.Empty);
                }

                ChannelParameterCollection channelParameterCollection = new ChannelParameterCollection();

                if (HttpChannelFactory <IDuplexSessionChannel> .MapIdentity(this.RemoteAddress, _channelFactory.AuthenticationScheme))
                {
                    lock (ThisLock)
                    {
                        _cleanupIdentity = HttpTransportSecurityHelpers.AddIdentityMapping(Via, RemoteAddress);
                    }
                }

                X509Certificate2 clientCertificate = null;
                HttpsChannelFactory <IDuplexSessionChannel> httpsChannelFactory = _channelFactory as HttpsChannelFactory <IDuplexSessionChannel>;
                if (httpsChannelFactory != null && httpsChannelFactory.RequireClientCertificate)
                {
                    var certificateProvider    = httpsChannelFactory.CreateAndOpenCertificateTokenProvider(RemoteAddress, Via, channelParameterCollection, helper.RemainingTime());
                    var clientCertificateToken = httpsChannelFactory.GetCertificateSecurityToken(certificateProvider, RemoteAddress, Via, channelParameterCollection, ref helper);
                    var x509Token = (X509SecurityToken)clientCertificateToken.Token;
                    clientCertificate = x509Token.Certificate;
                }

                try
                {
                    WebSocket = await CreateWebSocketWithFactoryAsync(clientCertificate, helper);
                }
                finally
                {
                    if (WebSocket != null && _cleanupStarted)
                    {
                        WebSocket.Abort();
                        CommunicationObjectAbortedException communicationObjectAbortedException = new CommunicationObjectAbortedException(
                            new WebSocketException(WebSocketError.ConnectionClosedPrematurely).Message);
                        FxTrace.Exception.AsWarning(communicationObjectAbortedException);
                        throw communicationObjectAbortedException;
                    }
                }

                bool inputUseStreaming = TransferModeHelper.IsResponseStreamed(TransferMode);

                SetMessageSource(new WebSocketMessageSource(
                                     this,
                                     WebSocket,
                                     inputUseStreaming,
                                     this));

                success = true;

                if (WcfEventSource.Instance.WebSocketConnectionRequestSendStopIsEnabled())
                {
                    WcfEventSource.Instance.WebSocketConnectionRequestSendStop(
                        EventTraceActivity,
                        WebSocket != null ? WebSocket.GetHashCode() : -1);
                }
            }
            catch (WebSocketException ex)
            {
                if (WcfEventSource.Instance.WebSocketConnectionFailedIsEnabled())
                {
                    WcfEventSource.Instance.WebSocketConnectionFailed(EventTraceActivity, ex.Message);
                }

                TryConvertAndThrow(ex);
            }
            finally
            {
                CleanupTokenProviders();
                if (!success)
                {
                    CleanupOnError();
                }
            }
        }