Beispiel #1
0
 public PackedFrame(ArraySegment <byte> bytes, SignalMap map)
 {
     (dstid, bytes) = VarInt.Take(bytes);
     (srcid, bytes) = VarInt.Take(bytes);
     payload        = VarInt.TakeAll(bytes).ToArray();
     this.map       = map;
 }
Beispiel #2
0
        public static IEnumerable <VarInt> TakeAll(ArraySegment <byte> data)
        {
            while (data.Count > 0)
            {
                VarInt val = 0;
                (val, data) = VarInt.Take(data);
                if (val == 0)
                {
                    yield break;
                }

                yield return(val);
            }
        }
Beispiel #3
0
        async void ReceiveTask()
        {
            while (rconAlive)
            {
                await Task.Delay(20);

                var packets = new ArraySegment <byte>(await rcon.SendCommandAsync(Encoding.UTF8.GetBytes("/RoutingTXBuff\0")));

                VarInt size;

                while (packets.Count() > 2)
                {
                    (size, packets) = VarInt.Take(packets);

                    var packet = new ArraySegment <byte>(packets.Array, packets.Offset, size);

                    var packetframe = new PackedFrame(packet, Map).Unpack();
                    packetframe.origin = this;
                    OnReceive?.Invoke(packetframe);

                    packets = new ArraySegment <byte>(packets.Array, packets.Offset + size, packets.Count - size);
                }
            }
        }