Exemplo n.º 1
0
 public DataTransferEventArgs(TransferType type, PacketFamily family, PacketAction action, byte[] rawData)
 {
     Type = type;
     PacketFamily = family;
     PacketAction = action;
     RawByteData = rawData;
 }
Exemplo n.º 2
0
 public DataTransferEventArgs(TransferType type, PacketFamily family, PacketAction action, byte[] rawData)
 {
     Type         = type;
     PacketFamily = family;
     PacketAction = action;
     RawByteData  = rawData;
 }
Exemplo n.º 3
0
        public IPacketBuilder WithFamily(PacketFamily family)
        {
            var newData = new List <byte>(_data);

            newData[1] = (byte)family;
            return(new PacketBuilder(newData));
        }
Exemplo n.º 4
0
 public PacketBuilder(PacketFamily family, PacketAction action)
 {
     _data = new List <byte> {
         (byte)action, (byte)family
     };
     _encoderService = new NumberEncoderService();
 }
Exemplo n.º 5
0
 public OldPacket(PacketFamily family, PacketAction action)
 {
     data = new List <byte>(2)
     {
         (byte)action, (byte)family
     };
 }
Exemplo n.º 6
0
        /// <summary>
        /// Setup the PacketSendService mock to return a packet with the specified family/action/data from SendEncodedPacketAndWaitAsync
        /// </summary>
        /// <param name="packetSendServiceMock">The mocked packet send service</param>
        /// <param name="family">Packet family for the "received" packet</param>
        /// <param name="action">Packet action for the "received" packet</param>
        /// <param name="data">Packet data payload (any additional data that should be in the packet)</param>
        internal static void SetupReceivedPacketHasHeader(this Mock <IPacketSendService> packetSendServiceMock,
                                                          PacketFamily family,
                                                          PacketAction action,
                                                          params byte[] data)
        {
            var receivedPacket = new PacketBuilder(family, action)
                                 .AddBytes(data)
                                 .Build();

            packetSendServiceMock.Setup(x => x.SendEncodedPacketAndWaitAsync(It.IsAny <IPacket>()))
            .Returns(Task.FromResult(receivedPacket));
        }
Exemplo n.º 7
0
        public PacketHandlingType FindHandlingType(PacketFamily family, PacketAction action)
        {
            var fap = new FamilyActionPair(family, action);

            if (_inBandPackets.Contains(fap))
            {
                return(PacketHandlingType.InBand);
            }

            if (_outOfBandPackets.Contains(fap))
            {
                return(PacketHandlingType.OutOfBand);
            }

            return(PacketHandlingType.NotHandled);
        }
Exemplo n.º 8
0
        public static void Handle(NetIncomingMessage message, NetServer server, NetConnection client)
        {
            PacketFamily family  = (PacketFamily)message.ReadByte();
            PacketAction action  = (PacketAction)message.ReadByte();
            Handler      handler = handlers[(byte)family, (byte)action];

            if (handler == null)
            {
                System.Diagnostics.Debug.WriteLine("No handler set for " + family + "_" + action);
            }
            else
            {
                lock (client)
                {
                    handler(message, server, client);
                }
            }
        }
Exemplo n.º 9
0
        private static Handler[,] InitializeHandlers()
        {
            handlers = new Handler[256, 256];

            foreach (var type in Assembly.GetCallingAssembly().GetTypes())
            {
                if (type.Namespace == typeof(Handler).Namespace + ".Handlers" && type.Name.EndsWith("Handler"))
                {
                    PacketFamily family = (PacketFamily)Enum.Parse(typeof(PacketFamily), type.Name.Substring(0, type.Name.Length - 7));

                    foreach (MethodInfo method in type.GetMethods())
                    {
                        if (method.IsStatic && method.Name.StartsWith("Handle"))
                        {
                            PacketAction action = (PacketAction)Enum.Parse(typeof(PacketAction), method.Name.Substring(6));

                            handlers[(byte)family, (byte)action] = (Handler)Delegate.CreateDelegate(typeof(Handler), method);
                        }
                    }
                }
            }

            return(handlers);
        }
Exemplo n.º 10
0
 /// <summary>
 /// initiate a packet builder with pre-defined family and actions
 /// </summary>
 /// <param name="family"></param>
 /// <param name="action"></param>
 public PacketBuilder(PacketFamily family, PacketAction action)
 {
     _data = new byte[] { (byte)family, (byte)action };
 }
Exemplo n.º 11
0
 public FamilyActionPair(PacketFamily family, PacketAction action)
 {
     fam = family;
     act = action;
 }
Exemplo n.º 12
0
 public static ushort PID(PacketFamily family, PacketAction action)
 {
     return((ushort)((ushort)family | (ushort)action << 8));
 }
Exemplo n.º 13
0
 public EOPacketHandler(PacketFamily family, PacketAction action, EOPacketChannel channel)
 {
     this.Family  = family;
     this.Action  = action;
     this.Channel = channel;
 }
Exemplo n.º 14
0
 public static ushort PID(PacketFamily family, PacketAction action)
 {
     return (ushort)((ushort)family | (ushort)action << 8);
 }
Exemplo n.º 15
0
 public Packet(PacketFamily family, PacketAction action)
 {
     data = new List<byte>(2) {(byte) action, (byte) family};
 }
Exemplo n.º 16
0
 // ReSharper disable once UnusedMember.Global
 public void SetID(PacketFamily family, PacketAction action)
 {
     data[0] = (byte)action;
     data[1] = (byte)family;
 }
Exemplo n.º 17
0
 public FamilyActionPair(PacketFamily family, PacketAction action)
 {
     fam = family;
     act = action;
 }
Exemplo n.º 18
0
// ReSharper disable once UnusedMember.Global
        public void SetID(PacketFamily family, PacketAction action)
        {
            data[0] = (byte)action;
            data[1] = (byte)family;
        }
Exemplo n.º 19
0
 public IPacketHandler FindHandler(PacketFamily family, PacketAction action)
 {
     return(_handlers[new FamilyActionPair(family, action)]);
 }
Exemplo n.º 20
0
 public bool HandlerExists(PacketFamily family, PacketAction action)
 {
     return(_handlers.ContainsKey(new FamilyActionPair(family, action)));
 }