Beispiel #1
0
        public override void HandleCommand(ICommandPayload payload, string result, ulong sourceChannelId)
        {
            result = result.Replace("</br>", "\n");
            result = result.Replace("</b>", "**");
            result = result.Replace("</i>", "*");
            result = result.Replace("</code>", "`");
            result = result.Replace("</box>", "```");
            result = result.Replace("</quote>", "> ");

            messageQueue.QueueMessage(sourceChannelId, result);
        }
 /// <summary>
 /// Receives raw input from the game and checks whether it has an associated command. If it does, it checks if the user has permission to run it.
 /// </summary>
 /// <param name="payload">Command payload containing which command to run, as well as all necessary data to run it.</param>
 /// <returns>If successful, returns a response from the command's executor. If no permission, returns a message indicating so.</returns>
 public string ExecuteCommand(ICommandPayload payload)
 {
     if (payload.UserExecutor.PermissionLevel >= payload.Command.DefaultPermissionLevel)
     {
         return(payload.Command.Execute(payload.Parameters, payload.UserExecutor));
     }
     else
     {
         return("You don't have permission to use this command!");
     }
 }
Beispiel #3
0
        public void ExecuteCommandPayload(ICommandPayload commandPayload, Action onCompleteCallback)
        {
            var commandPayloadType = commandPayload.GetType();

            foreach (var methodHandlersPair in _methodHandlersByContextType)
            {
                if (!methodHandlersPair.Value.ContainsKey(commandPayloadType))
                {
                    continue;
                }
                if (!_invocationTargets.TryGetValue(methodHandlersPair.Key, out ICommandHandlerContext handlerContext) || handlerContext == null)
                {
                    continue;
                }
                ExecuteCommandPayload(handlerContext, commandPayload, methodHandlersPair.Value[commandPayloadType], onCompleteCallback);
                return;
            }
            throw new Exception($"No command handler for command payload: {commandPayloadType.Name}.");
        }
Beispiel #4
0
        private void ExecuteCommandPayload(ICommandHandlerContext handlerContext, ICommandPayload commandPayload, MethodInfo methodHandler, Action onCompleteCallback)
        {
            var handlerContextType = handlerContext.GetType();
            var commandPayloadType = commandPayload.GetType();
            var commandType        = typeof(Command <>);

            Type[] typeArgs = { commandPayloadType };
            commandType = commandType.MakeGenericType(typeArgs);
            var command = (ICommand)Activator.CreateInstance(
                commandType,
                new object[] {
                commandPayload,
                CreateQueuedCompletionCallback(
                    $"{handlerContextType.Name}.{methodHandler.Name}",
                    onCompleteCallback
                    )
            });

            command.Execute(handlerContext, methodHandler);
        }
Beispiel #5
0
        public void ExecuteCommandPayload(ICommandHandlerContext handlerContext, ICommandPayload commandPayload, Action onCompleteCallback)
        {
            var handlerContextType = handlerContext.GetType();

            if (_methodHandlersByContextType.TryGetValue(handlerContextType, out Dictionary <Type, MethodInfo> methodHandlers))
            {
                var commandPayloadType = commandPayload.GetType();
                if (methodHandlers.ContainsKey(commandPayloadType))
                {
                    ExecuteCommandPayload(handlerContext, commandPayload, methodHandlers[commandPayloadType], onCompleteCallback);
                }
                else
                {
                    throw new Exception($"No command handler for command payload: {commandPayloadType.Name} on type: {handlerContextType.Name}");
                }
            }
            else
            {
                throw new Exception($"No command handlers registered for type: {handlerContextType.Name}");
            }
        }
 internal void ExecuteCommandPayload(ICommandHandlerContext handlerContext, ICommandPayload commandPayload, Action onCompleteCallback)
 {
     _commandManager.ExecuteCommandPayload(handlerContext, commandPayload, onCompleteCallback);
 }
 internal void ExecuteCommandPayload(ICommandPayload commandPayload, Action onCompleteCallback)
 {
     ExecuteCommandPayload(this, commandPayload, onCompleteCallback);
 }
Beispiel #8
0
 /// <summary>
 /// Parses incoming result messages from already executed commands for the client to handle.
 /// </summary>
 /// <param name="payload">The payload that was ran before being sent to this handler. Boolean Executed updated to reflect whether it successfully executed or not.</param>
 /// <param name="msg">The output message from the command execution detailing the status of the command.</param>
 /// <param name="sourceChannelId">Optional id for clients that require id's to send to channels. Id of the channel the message originated from.</param>
 public abstract void HandleCommand(ICommandPayload payload, string msg, ulong sourceChannelId = 0);