Ejemplo n.º 1
0
 /// <summary>
 /// Creates a new player instance
 /// </summary>
 public Player(BinaryReader binaryReader)
 {
     ID             = binaryReader.ReadInt64();
     LastActionMS   = binaryReader.ReadInt64();
     Name           = new Username(binaryReader);
     ConnecToken    = new Token(binaryReader);
     RemoteEndPoint = IPEndPointExtension.FromBytes(binaryReader);
 }
        public void TestInvalidIpAddress()
        {
            IPEndPoint endPoint;

            foreach (var ip in _invalidInputs)
            {
                Assert.IsFalse(IPEndPointExtension.TryParse(ip, out endPoint));
            }
        }
        public void TestValidIpAddresses()
        {
            IPEndPoint endpoint;

            foreach (var ip in _validInputs)
            {
                Assert.IsTrue(IPEndPointExtension.TryParse(ip, out endpoint));
            }
        }
        public void TestInvalidDomains()
        {
            HostEndPoint endpoint;

            foreach (var domain in _invalidDomains)
            {
                Assert.IsFalse(IPEndPointExtension.TryParse(domain, out endpoint));
            }
        }
        private void SetEndPointOrDefault(string daemonAddress)
        {
            IPEndPoint daemonEndPoint;

            if (!IPEndPointExtension.TryParse(daemonAddress, out daemonEndPoint))
            {
                _logger.InfoFormat("The given daemonAddress ({0}) is invalid, using default daemon address.", daemonEndPoint);
                daemonEndPoint = new IPEndPoint(_defaultDaemonAddress, _defaultDaemonPort);
            }

            _logger.InfoFormat("Set daemon address: {0}:{1}", daemonEndPoint.Address.ToString(), daemonEndPoint.Port);
            EndPoint = daemonEndPoint;
        }
        private void SetEndPointOrDefault(string daemonAddress)
        {
            IPEndPoint daemonEndPoint;

            if (string.IsNullOrEmpty(daemonAddress))
            {
                daemonEndPoint = new IPEndPoint(_defaultDaemonAddress, _defaultDaemonPort);
                _logger.InfoFormat("Using default daemon address: {0}:{1}", daemonEndPoint.Address.ToString(), daemonEndPoint.Port);
            }
            else if (!IPEndPointExtension.TryParse(daemonAddress, out daemonEndPoint))
            {
                daemonEndPoint = new IPEndPoint(_defaultDaemonAddress, _defaultDaemonPort);
                _logger.InfoFormat("The given daemonAddress ({0}) is invalid, using default daemon address {1}:{2}.", daemonAddress, daemonEndPoint.Address.ToString(), daemonEndPoint.Port);
            }

            EndPoint = daemonEndPoint;
        }
        public void ByteConversion(IPEndPoint value)
        {
            var bytes    = new byte[IPEndPointExtension.ByteSize];
            var newValue = value;

            using (var memoryStream = new MemoryStream(bytes))
            {
                using (var binaryWriter = new BinaryWriter(memoryStream))
                {
                    value.ToBytes(binaryWriter);
                    Assert.AreEqual(IPEndPointExtension.ByteSize, memoryStream.Position);

                    binaryWriter.Seek(0, SeekOrigin.Begin);

                    using (var binaryReader = new BinaryReader(memoryStream))
                    {
                        newValue = IPEndPointExtension.FromBytes(binaryReader);
                        Assert.AreEqual(IPEndPointExtension.ByteSize, memoryStream.Position);
                    }
                }
            }

            Assert.AreEqual(value, newValue);
        }