Пример #1
0
        public void SetUp()
        {
            data = new SceneMessage();
            mockTransportConnection = Substitute.For <IConnection>();

            void ParsePacket(ArraySegment <byte> data)
            {
                var reader = new NetworkReader(data);

                _        = MessagePacker.UnpackId(reader);
                lastSent = reader.ReadNotifyPacket();

                lastSerializedPacket = new byte[data.Count];
                Array.Copy(data.Array, data.Offset, lastSerializedPacket, 0, data.Count);
            }

            mockTransportConnection.Send(
                Arg.Do <ArraySegment <byte> >(ParsePacket), Channel.Unreliable);

            connection = new NetworkPlayer(mockTransportConnection);

            serializedMessage = MessagePacker.Pack(new ReadyMessage());
            connection.RegisterHandler <ReadyMessage>(message => { });

            delivered = Substitute.For <Action <INetworkPlayer, object> >();
            lost      = Substitute.For <Action <INetworkPlayer, object> >();

            connection.NotifyDelivered += delivered;
            connection.NotifyLost      += lost;
        }
Пример #2
0
 public void RemoveContact(GGContact contact)
 {
     if (this.State == State.Connected)
     {
         NotifyPacket notify = new NotifyPacket(PacketType.NotifyRemove);
         notify.Contacts.Add(contact);
         this.packetManager.AddPacket(notify);
     }
     this.contacts.Remove(contact.Number);
 }
Пример #3
0
 public void AddContact(GGContact contact)
 {
     this.contacts.Add(contact.Number, contact);
     if (this.State == State.Connected)
     {
         NotifyPacket notify = new NotifyPacket(PacketType.NotifyAdd);
         notify.Contacts.Add(contact);
         this.packetManager.AddPacket(notify);
     }
 }
Пример #4
0
        public void BlockContact(GGContact contact)
        {
            NotifyPacket notifyRemove = new NotifyPacket(PacketType.NotifyRemove);

            notifyRemove.Contacts.Add(contact);
            this.packetManager.AddPacket(notifyRemove);

            contact.ContactType = ContactType.Blocked;
            NotifyPacket notifyAdd = new NotifyPacket(PacketType.NotifyAdd);

            notifyRemove.Contacts.Add(contact);
            this.packetManager.AddPacket(notifyAdd);
        }
Пример #5
0
 private void SendContactList()
 {
     if (this.contacts.Count == 0)
     {
         this.packetManager.AddPacket(new Packet(PacketType.EmptyContactList));
     }
     else
     {
         int countPackets = (int)Math.Ceiling(this.contacts.Count / 400.0);
         for (int i = 0; i < countPackets; ++i)
         {
             PacketType type = PacketType.NotifyFirst;
             if (i == (countPackets - 1))
             {
                 type = PacketType.NotifyLast;
             }
             NotifyPacket packet = new NotifyPacket(type);
             packet.Contacts.AddRange(this.contacts.Values.Skip(i * 400).Take(400));
             this.packetManager.AddPacket(packet);
         }
     }
 }
Пример #6
0
 public static void WriteNotifyPacket(this NetworkWriter writer, NotifyPacket packet)
 {
     writer.WriteUInt16(packet.Sequence);
     writer.WriteUInt16(packet.ReceiveSequence);
     writer.WriteUInt64(packet.AckMask);
 }