Пример #1
0
        /// <summary>
        /// Register a new console command.
        /// </summary>
        /// <param name="name">Command name.</param>
        /// <param name="func">Delegate to the console command function to be called when command is invoked.</param>
        /// <param name="comment">Help string, will be displayed when typing in console "command ?".</param>
        /// <param name="flags">Bitfield consist of VF_ flags (e.g. VF_CHEAT)</param>
        public static void Register(string name, ConsoleCommandDelegate func, string comment = "", CVarFlags flags = CVarFlags.None)
        {
            if (!commands.ContainsKey(name))
            {
                NativeCVarMethods.RegisterCommand(name, comment, flags);

                commands.Add(name, func);
            }
        }
Пример #2
0
        public ConsoleCommand(ConsoleCommandDelegate cmd, params string[] cmdNames)
        {
            if (cmdNames == null || cmdNames.Length < 1)
                throw new NotSupportedException();

            Command = cmd;
            Names = new List<string>(cmdNames);
            Arguments = new List<ConsoleCommandArgument>();
        }
Пример #3
0
        public ConsoleCommand(ConsoleCommandDelegate cmd, params string[] cmdNames)
        {
            if (cmdNames == null || cmdNames.Length < 1)
            {
                throw new NotSupportedException();
            }

            this.Command   = cmd;
            this.Names     = new List <string>(cmdNames);
            this.Arguments = new List <ConsoleCommandArgument>();
        }
Пример #4
0
        /// <summary>
        /// Register a new console command.
        /// </summary>
        /// <param name="name">Command name.</param>
        /// <param name="func">Delegate to the console command function to be called when command is invoked.</param>
        /// <param name="comment">Help string, will be displayed when typing in console "command ?".</param>
        /// <param name="flags">Bitfield consist of VF_ flags (e.g. VF_CHEAT)</param>
        public static void Register(string name, ConsoleCommandDelegate func, string comment = "", CVarFlags flags = CVarFlags.None)
        {
            if (!commands.ContainsKey(name))
            {
                NativeCVarMethods.RegisterCommand(name, comment, flags);

                commands.Add(name, func);
            }
            else
            {
                throw new DuplicateConsoleCommandException(string.Format("The console command {0} was already registered", name));
            }
        }
Пример #5
0
        /// <summary>
        /// Registers a console command to the console command list.
        /// </summary>
        /// <param name="alias"></param>
        /// <param name="description"></param>
        /// <param name="callback"></param>
        /// <returns></returns>
        public static bool AddCommnd(List<string> alias, string description, ConsoleCommandDelegate callback)
        {
            // Validate the parameters..
            if (alias.Count == 0 || string.IsNullOrEmpty(description) || callback == null)
                return false;

            // Ensure no other command has any alias defined..
            if (ConsoleCommands.Commands.Any(c => alias.Any(c.HasAlias)))
                return false;

            // Add the new command..
            var cmd = new ConsoleCommand(alias, callback) { Description = description };
            ConsoleCommands.Commands.Add(cmd);
            return true;
        }
        /// <summary>
        /// Register a new console command.
        /// </summary>
        /// <param name="name">Command name.</param>
        /// <param name="func">Delegate to the console command function to be called when command is invoked.</param>
        /// <param name="comment">Help string, will be displayed when typing in console "command ?".</param>
        /// <param name="flags">Bitfield consist of VF_ flags (e.g. VF_CHEAT)</param>
        public static void Register(string name, ConsoleCommandDelegate func, string comment = "", CVarFlags flags = CVarFlags.None, bool overwrite = false)
        {
            bool containsKey = Commands.ContainsKey(name);
            if (containsKey && overwrite)
            {
                Unregister(name);
                containsKey = false;
            }

            if (!containsKey)
            {
                NativeCVarMethods.RegisterCommand(name, comment, flags);

                Commands.Add(name, func);
            }
            else
                throw new DuplicateConsoleCommandException(string.Format("The console command {0} was already registered", name));
        }
Пример #7
0
        /// <summary>
        /// Register a new console command.
        /// </summary>
        /// <param name="name">Command name.</param>
        /// <param name="func">
        /// Delegate to the console command function to be called when command is invoked.
        /// </param>
        /// <param name="comment">
        /// Help string, will be displayed when typing in console "command ?".
        /// </param>
        /// <param name="flags">Bitfield consist of VF_ flags (e.g. VF_CHEAT)</param>
        public static void Register(string name, ConsoleCommandDelegate func, string comment = "", CVarFlags flags = CVarFlags.None, bool overwrite = false)
        {
            bool containsKey = Commands.ContainsKey(name);

            if (containsKey && overwrite)
            {
                Unregister(name);
                containsKey = false;
            }

            if (!containsKey)
            {
                Native.ConsoleInterop.RegisterCommand(name, comment, flags);

                Commands.Add(name, func);
            }
            else
            {
                throw new DuplicateConsoleCommandException(string.Format("The console command {0} was already registered", name));
            }
        }
Пример #8
0
        /// <summary>
        /// Registers a console command to the console command list.
        /// </summary>
        /// <param name="alias"></param>
        /// <param name="description"></param>
        /// <param name="callback"></param>
        /// <returns></returns>
        public static bool AddCommnd(List <string> alias, string description, ConsoleCommandDelegate callback)
        {
            // Validate the parameters..
            if (alias.Count == 0 || string.IsNullOrEmpty(description) || callback == null)
            {
                return(false);
            }

            // Ensure no other command has any alias defined..
            if (ConsoleCommands.Commands.Any(c => alias.Any(c.HasAlias)))
            {
                return(false);
            }

            // Add the new command..
            var cmd = new ConsoleCommand(alias, callback)
            {
                Description = description
            };

            ConsoleCommands.Commands.Add(cmd);
            return(true);
        }
Пример #9
0
 internal static extern void CSharpResource_SetMain(IntPtr resourcePointer, MainDelegate mainDelegate,
                                                    StopDelegate stopDelegate,
                                                    TickDelegate tickDelegate, ServerEventDelegate serverEventDelegate,
                                                    CheckpointDelegate checkpointDelegate,
                                                    ClientEventDelegate clientEventDelegate, PlayerDamageDelegate playerDamageDelegate,
                                                    PlayerConnectDelegate playerConnectDelegate, PlayerDeathDelegate playerDeathDelegate,
                                                    PlayerDisconnectDelegate playerDisconnectDelegate, PlayerRemoveDelegate playerRemoveDelegate,
                                                    VehicleRemoveDelegate vehicleRemoveDelegate,
                                                    PlayerChangeVehicleSeatDelegate playerChangeVehicleSeatDelegate,
                                                    PlayerEnterVehicleDelegate playerEnterVehicleDelegate,
                                                    PlayerLeaveVehicleDelegate playerLeaveVehicleDelegate,
                                                    CreatePlayerDelegate createPlayerDelegate, RemovePlayerDelegate removePlayerDelegate,
                                                    CreateVehicleDelegate createVehicleDelegate, RemoveVehicleDelegate removeVehicleDelegate,
                                                    CreateBlipDelegate createBlipDelegate, RemoveBlipDelegate removeBlipDelegate,
                                                    CreateCheckpointDelegate createCheckpointDelegate, RemoveCheckpointDelegate removeCheckpointDelegate,
                                                    CreateVoiceChannelDelegate createVoiceChannelDelegate,
                                                    RemoveVoiceChannelDelegate removeVoiceChannelDelegate,
                                                    ConsoleCommandDelegate consoleCommandDelegate,
                                                    MetaDataChange metaDataChange,
                                                    MetaDataChange syncedMetaDataChange,
                                                    CreateColShapeDelegate createColShapeDelegate,
                                                    RemoveColShapeDelegate removeColShapeDelegate,
                                                    ColShapeDelegate colShapeDelegate
                                                    );
Пример #10
0
 internal static extern void CSharpResourceImpl_SetConsoleCommandDelegate(IntPtr resource,
                                                                          ConsoleCommandDelegate @delegate);
Пример #11
0
 public ConsoleCommand(string name, ConsoleCommandDelegate command)
 {
     Name    = name;
     Command = command;
 }
Пример #12
0
 /// <summary>
 /// Binds a command to a command handler. A command cannot contain spaces. When the handler
 /// is executed the first parameter is the command, the following parameters were parsed
 /// by splitting on the space.
 /// </summary>
 /// <param name="commandName">Name of the command. Spaces are not permitted. Case sensitive</param>
 /// <param name="description">Description of the command.</param>
 /// <param name="handler">Handler for the command.</param>
 /// <returns>A command binding instance.</returns>
 public CommandBinding Bind(string commandName, string description, ConsoleCommandDelegate handler)
 {
     var binding = Bind(commandName, description);
     binding.CommandHandlers += handler;
     return binding;
 }
Пример #13
0
 public void AddConsoleCommand(string Command, ConsoleCommandDelegate MethodToBindTo)
 {
     BindConsoleCommand(Command, MethodToBindTo);
 }
Пример #14
0
 public void AddConsoleCommand(string Command, ConsoleCommandDelegate MethodToBindTo)
 {
     BindConsoleCommand(Command, MethodToBindTo);
 }