예제 #1
0
        public static bool SimpleUnitTest()
        {
            // encryption test
            NetEncryption enc = new NetEncryption();

            byte[] key = new byte[16];
            NetRandom.Default.NextBytes(key);
            enc.SetSymmetricKey(key);

            byte[] data    = Encoding.ASCII.GetBytes("Michael");          // 7 bytes
            byte[] correct = new byte[data.Length];
            data.CopyTo(correct, 0);

            NetBuffer buf = new NetBuffer(data);

            enc.EncryptSymmetric(buf);

            bool ok = enc.DecryptSymmetric(buf);

            if (!ok)
            {
                return(false);
            }

            // compare
            if (buf.LengthBytes != correct.Length)
            {
                return(false);
            }

            for (int i = 0; i < correct.Length; i++)
            {
                if (buf.Data[i] != correct[i])
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #2
0
 internal NetConnection(NetBase parent, IPEndPoint remote)
 {
     m_parent                = parent;
     m_remoteEndpoint        = remote;
     m_nextSequenceNumber    = new ushort[NetConstants.NumSequenceChannels];
     m_sequenceHandler       = new NetSequenceHandler();
     m_unsentMessages        = new Queue <NetMessage>(10);
     m_receivedMessages      = new Queue <NetMessage>(10);
     m_withheldMessages      = new List <NetMessage>();
     m_unsentAcknowledges    = new Queue <NetMessage>(10);
     m_lastHeardFromRemote   = (float)NetTime.Now;
     m_reusedAckMessage      = new NetMessage(NetMessageType.Acknowledge, null);
     m_savedReliableMessages = new List <NetMessage> [NetConstants.NumSequenceChannels];
     Configuration           = new NetConnectionConfiguration(this);
     m_ping        = new NetPing(this);
     Statistics    = new NetStatistics(this);
     m_stringTable = new NetStringTable();
     m_encryption  = new NetEncryption();
     if (parent.Configuration.UsesEncryption)
     {
         m_encryption.SetRSAKey(parent.Configuration.ServerPublicKeyBytes, parent.Configuration.ServerPrivateKeyBytes);
     }
 }
예제 #3
0
		internal NetConnection(NetBase parent, IPEndPoint remote)
		{
			m_parent = parent;
			m_remoteEndpoint = remote;
			m_nextSequenceNumber = new ushort[NetConstants.NumSequenceChannels];
			m_sequenceHandler = new NetSequenceHandler();
			m_unsentMessages = new Queue<NetMessage>(10);
			m_receivedMessages = new Queue<NetMessage>(10);
			m_withheldMessages = new List<NetMessage>();
			m_unsentAcknowledges = new Queue<NetMessage>(10);
			m_lastHeardFromRemote = (float)NetTime.Now;
			m_reusedAckMessage = new NetMessage(NetMessageType.Acknowledge, null);
			m_savedReliableMessages = new List<NetMessage>[NetConstants.NumSequenceChannels];
			Configuration = new NetConnectionConfiguration(this);
			m_ping = new NetPing(this);
			Statistics = new NetStatistics(this);
			m_stringTable = new NetStringTable();
			m_encryption = new NetEncryption();
			if (parent.Configuration.UsesEncryption)
				m_encryption.SetRSAKey(parent.Configuration.ServerPublicKeyBytes, parent.Configuration.ServerPrivateKeyBytes);
		}
예제 #4
0
		public static bool SimpleUnitTest()
		{
			// encryption test
			NetEncryption enc = new NetEncryption();
			byte[] key = new byte[16];
			NetRandom.Default.NextBytes(key);
			enc.SetSymmetricKey(key);

			byte[] data = Encoding.ASCII.GetBytes("Michael"); // 7 bytes
			byte[] correct = new byte[data.Length];
			data.CopyTo(correct, 0);

			NetBuffer buf = new NetBuffer(data);

			enc.EncryptSymmetric(buf);

			bool ok = enc.DecryptSymmetric(buf);
			if (!ok)
				return false;

			// compare
			if (buf.LengthBytes != correct.Length)
				return false;

			for (int i = 0; i < correct.Length; i++)
				if (buf.Data[i] != correct[i])
					return false;

			return true;
		}