public DicePacketFactoryTest()
        {
            var sequence = new DicePacketSequence(458u, PacketType.Request, PacketOrigin.Client);
            var words = new List<IDiceWord> { new DiceWord("listPlayers"), new DiceWord("all") };
            this.expectedPacket = new DicePacket(sequence, words);

            dicePacketFactory = new DicePacketFactory();
        }
Example #2
0
        private async void SocketOnDataReceived(object sender, SocketDataReceivedEventArgs socketDataReceivedEventArgs)
        {
            var packetReceivedEventHandler = this.PacketReceived;
            if (packetReceivedEventHandler == null)
            {
                return;
            }

            var packetFactory = new DicePacketFactory();
            var packets = packetFactory.FromBytes(socketDataReceivedEventArgs.DataReceived);
            var maxSequenceId = this.sequenceId;
            foreach (var packet in packets)
            {
                maxSequenceId = packet.Sequence.Id > maxSequenceId ? packet.Sequence.Id : maxSequenceId;
                await packetReceivedEventHandler.InvokeAllAsync(this, new DicePacketEventArgs(packet));
            }

            await this.UpdateSequenceIdAsync(maxSequenceId);
        }