コード例 #1
0
 public void Init()
 {
     Provider       = new LidgrenClient(this);
     IsSinglePlayer = true;
     _server.OpenGameServer(true);
     _server.SinglePlayerConnection = this;
     ClientName = "Player";
     ClientID   = new IPIdentity(0);
     ServerID   = ClientID;
     ConnectToServer();
 }
コード例 #2
0
 public void isPublicTest()
 {
     Assert.IsTrue(IPIdentity.isPublic("badipaddress") == null);
     Assert.IsTrue(IPIdentity.isPublic("123.255.255.000") == true);
     Assert.IsTrue(IPIdentity.isPublic("192.168.254.000") == false);
     Assert.IsTrue(IPIdentity.isPublic("10.789.1.255") == false);
     Assert.IsTrue(IPIdentity.isPublic("172.16.1.212") == false);
     Assert.IsTrue(IPIdentity.isPublic("172.15.1.212") == true);
     Assert.IsTrue(IPIdentity.isPublic("172.31.1.212") == false);
     Assert.IsTrue(IPIdentity.isPublic("172.32.1.212") == true);
     Assert.IsTrue(IPIdentity.isPublic("fd20:4a55:d0f1:94b7:xxxx:xxxx:xxxx:xxxx") == false);
     Assert.IsTrue(IPIdentity.isPublic("2001:db8::211:22ff:fe33:4455") == true);
     Assert.IsTrue(IPIdentity.isPublic("2001:db8:0000:211:22ff:fe33:4455:0000") == true);
 }
コード例 #3
0
        public static IPIdentity GetIdentFromConnection(NetConnection senderConnection, Dictionary <ulong, NetConnection> peers)
        {
            foreach (ulong ident in peers.Keys)
            {
                if (Equals(peers[ident].RemoteEndPoint, senderConnection.RemoteEndPoint))
                {
                    return(new IPIdentity(ident));
                }
            }

            //IPIdentity newIdent = new IPIdentity(senderConnection.RemoteEndPoint.Address);
            IPIdentity newIdent = new IPIdentity((ulong)new Random().Next(1, int.MaxValue));

            peers.Add(newIdent.Serialize(), senderConnection);
            return(newIdent);
        }
コード例 #4
0
        public override void AttemptConnect(string ip, ushort port, string password)
        {
            _ip   = ip;
            _port = port;

            NetPeerConfiguration config = new NetPeerConfiguration(GameInfo.NAME)
            {
                Port = new Random().Next(1024, 65535)
            };

            _client = new NetClient(config);
            _client.Start();
            NetConnection conn = _client.Connect(_ip, _port);

            _listen = true;
            LogUtils.Debug("Adding server connection");
            var servIdent = new IPIdentity(0);

            _peers.Add(servIdent.Serialize(), conn);
        }
コード例 #5
0
 public override void SetIdentity(ulong serializedIdent)
 {
     _ident = new IPIdentity(serializedIdent);
 }