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

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