Beispiel #1
0
        public CreatorCommands()
        {
            RaceCommandDefinition cmdCreatorStart = RC.Commands.Create()
                                                    .AddCommandName("creator", "start")
                                                    .AddSuccessCallback(new Action <string>(OnCreatorStart))
                                                    .AddFailedCallback(new Action <string, string>(OnCommandFailed))
                                                    .AddParam <string>("track_name", new RaceCommandCheckArgs {
                Min = 3, Max = 32
            });

            RaceCommandDefinition cmdCreatorCheckpoint = RC.Commands.Create()
                                                         .AddCommandName("creator", "cp")
                                                         .AddSuccessCallback(new Action(OnCreatorAddCheckpoint))
                                                         .AddFailedCallback(new Action <string, string>(OnCommandFailed));

            RaceCommandDefinition cmdCreatorOption = RC.Commands.Create()
                                                     .AddCommandName("creator", "option")
                                                     .AddSuccessCallback(new Action <string, bool>(OnCreatorOption))
                                                     .AddFailedCallback(new Action <string, string>(OnCommandFailed))
                                                     .AddParam <string>("option", new RaceCommandCheckArgs())
                                                     .AddParam <bool>("option_value", new RaceCommandCheckArgs());

            RC.Commands.Register(cmdCreatorStart);
            RC.Commands.Register(cmdCreatorCheckpoint);
            RC.Commands.Register(cmdCreatorOption);
        }
Beispiel #2
0
        public DevToolboxCommands()
        {
            RaceCommandDefinition dvtCar = RC.Commands.Create()
                                           .AddCommandName("dvt", "car")
                                           .AddSuccessCallback(new Action <string>(OnCarSpawn))
                                           .AddFailedCallback(new Action <string, string>(OnCommandFailed))
                                           .AddParam <string>("vehicle_model", new RaceCommandCheckArgs {
                Min = 3, Max = 20
            });

            RC.Commands.Register(dvtCar);
        }
Beispiel #3
0
        public CreatorCommands()
        {
            RaceCommandCollection cc = RaceClient.Instance.CommandCollection;

            RaceCommandDefinition cmdCreatorStart = cc.Create()
                                                    .AddCommandName("creator", "start")
                                                    .AddSuccessCallback(new Action <string>(OnCreatorStart))
                                                    .AddFailedCallback(new Action <string>(OnCreatorStartFailed))
                                                    .AddParam <string>("track_name", new RaceCommandCheckArgs {
                Min = 3, Max = 32
            });

            cc.Register(cmdCreatorStart);
        }
Beispiel #4
0
        private void ProcessCommandInvoke(int source, List <object> args, string raw)
        {
            if (string.IsNullOrEmpty(raw))
            {
                logger.Log("Invalid command? How did you even manage this?");
                return;
            }

            string baseCommand = raw.Split(' ')[0].Replace("/", "");

            if (args.Count < 1)
            {
                PrintCommandUsage(baseCommand);
                return;
            }

            string subCommand = (string)args[0];

            RaceCommandDefinition currentDefinition = null;

            //Lookup the definition from all the definitions we have registered.
            foreach (RaceCommandDefinition def in commandDefinitions)
            {
                if (string.Compare(baseCommand, def.BaseCommand, true) == 0 &&
                    string.Compare(subCommand, def.SubCommand, true) == 0)
                {
                    currentDefinition = def;
                    break;
                }
            }

            if (currentDefinition == null)
            {
                logger.LogToChat("CommandCollection", $"Command /{baseCommand} {subCommand} was not found", 255, 0, 0);
                return;
            }

            List <object> paramList = new List <object>();

            if (currentDefinition.Parameters.Count != (args.Count - 1))
            {
                currentDefinition.InvokeFailed($"Mismatch parameter(s), expected: {currentDefinition.Parameters.Count} param(s), got: {args.Count - 1} param(s)");
                return;
            }

            int  paramCounter            = 1;
            bool wasOneOfTheParamInvalid = false;

            foreach (var paramKvp in currentDefinition.Parameters)
            {
                var    paramName = paramKvp.Key;
                var    param     = paramKvp.Value;
                object arg       = args[paramCounter];

                //Exception to attach the player source and fill in the param..
                if (string.Compare("player", param.Name) == 0)
                {
                    paramList.Add(source);
                }
                else
                {
                    param.ParseParam(arg);

                    if (!param.Error)
                    {
                        paramList.Add(param.Param);
                        paramCounter++;
                    }
                    else
                    {
                        logger.LogToChat("CommandCollection", $"Error?: {param.Error}, Reason: {param.CheckError}");
                        currentDefinition.InvokeFailed(param.CheckError);
                        wasOneOfTheParamInvalid = true;
                        break;
                    }
                }
            }

            if (!wasOneOfTheParamInvalid)
            {
                currentDefinition.InvokeSuccess(paramList.ToArray());
            }
        }
Beispiel #5
0
 public void Register(RaceCommandDefinition definition)
 {
     //TODO: Set the restricted/permissions parameter.
     registerProxy?.Invoke(definition.BaseCommand, new RaceCommandInvokable(ProcessCommandInvoke), false);
     commandDefinitions.Add(definition);
 }