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; }
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); }
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); } }
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); }
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); } } }
public static void WriteNotifyPacket(this NetworkWriter writer, NotifyPacket packet) { writer.WriteUInt16(packet.Sequence); writer.WriteUInt16(packet.ReceiveSequence); writer.WriteUInt64(packet.AckMask); }