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

            newData[1] = (byte)family;
            return(new PacketBuilder(newData));
        }
Example #4
0
 public PacketBuilder(PacketFamily family, PacketAction action)
 {
     _data = new List <byte> {
         (byte)action, (byte)family
     };
     _encoderService = new NumberEncoderService();
 }
Example #5
0
 public OldPacket(PacketFamily family, PacketAction action)
 {
     data = new List <byte>(2)
     {
         (byte)action, (byte)family
     };
 }
Example #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));
        }
Example #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);
        }
Example #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);
                }
            }
        }
Example #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);
        }
Example #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 };
 }
Example #11
0
 public FamilyActionPair(PacketFamily family, PacketAction action)
 {
     fam = family;
     act = action;
 }
Example #12
0
 public static ushort PID(PacketFamily family, PacketAction action)
 {
     return((ushort)((ushort)family | (ushort)action << 8));
 }
 public EOPacketHandler(PacketFamily family, PacketAction action, EOPacketChannel channel)
 {
     this.Family  = family;
     this.Action  = action;
     this.Channel = channel;
 }
Example #14
0
 public static ushort PID(PacketFamily family, PacketAction action)
 {
     return (ushort)((ushort)family | (ushort)action << 8);
 }
Example #15
0
 public Packet(PacketFamily family, PacketAction action)
 {
     data = new List<byte>(2) {(byte) action, (byte) family};
 }
Example #16
0
 // ReSharper disable once UnusedMember.Global
 public void SetID(PacketFamily family, PacketAction action)
 {
     data[0] = (byte)action;
     data[1] = (byte)family;
 }
Example #17
0
 public FamilyActionPair(PacketFamily family, PacketAction action)
 {
     fam = family;
     act = action;
 }
Example #18
0
// ReSharper disable once UnusedMember.Global
        public void SetID(PacketFamily family, PacketAction action)
        {
            data[0] = (byte)action;
            data[1] = (byte)family;
        }
 public IPacketHandler FindHandler(PacketFamily family, PacketAction action)
 {
     return(_handlers[new FamilyActionPair(family, action)]);
 }
 public bool HandlerExists(PacketFamily family, PacketAction action)
 {
     return(_handlers.ContainsKey(new FamilyActionPair(family, action)));
 }