public DataTransferEventArgs(TransferType type, PacketFamily family, PacketAction action, byte[] rawData) { Type = type; PacketFamily = family; PacketAction = action; RawByteData = rawData; }
public IPacketBuilder WithFamily(PacketFamily family) { var newData = new List <byte>(_data); newData[1] = (byte)family; return(new PacketBuilder(newData)); }
public PacketBuilder(PacketFamily family, PacketAction action) { _data = new List <byte> { (byte)action, (byte)family }; _encoderService = new NumberEncoderService(); }
public OldPacket(PacketFamily family, PacketAction action) { data = new List <byte>(2) { (byte)action, (byte)family }; }
/// <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)); }
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); }
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); } } }
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); }
/// <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 }; }
public FamilyActionPair(PacketFamily family, PacketAction action) { fam = family; act = action; }
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; }
public static ushort PID(PacketFamily family, PacketAction action) { return (ushort)((ushort)family | (ushort)action << 8); }
public Packet(PacketFamily family, PacketAction action) { data = new List<byte>(2) {(byte) action, (byte) family}; }
// 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))); }