Example #1
0
        public static PacketData Execute(Command command, Packet packet)
        {
            var executeMethod = GetExecutingMethod(command, packet);
            var mnemonic = executeMethod.GetCustomAttribute<ExecuteAttribute>().Mnemonic;
            var parsingContext = new ParsingContext(packet, mnemonic.Length);
            var parameters = executeMethod.GetParameters().Select(x => HandleArgumentNotResolved(parsingContext, x)).ToArray();

            return (PacketData)executeMethod.Invoke(command, parameters);
        }
Example #2
0
        private static MethodInfo GetExecutingMethod(Command command, Packet packet)
        {
            var interestingMethods = GetExecutingMethods(command.GetType());
            if(!interestingMethods.Any())
            {
                return null;
            }

            return interestingMethods.SingleOrDefault(x => packet.Data.DataAsString.StartsWith(x.GetCustomAttribute<ExecuteAttribute>().Mnemonic, StringComparison.Ordinal));
        }
Example #3
0
        public bool TryGetCommand(Packet packet, out Command command)
        {
            var commandDescriptor = availableCommands.SingleOrDefault(x => packet.Data.DataAsString.StartsWith(x.Mnemonic, StringComparison.Ordinal));
            if(commandDescriptor == null)
            {
                command = null;
                return false;
            }

            command = GetOrCreateCommand(commandDescriptor.Method.DeclaringType);
            return true;
        }