using System; using System.Collections.Generic; using System.Linq; using System.Text; using ProxyCore.Output; using System.Text.RegularExpressions; using ProxyCore.Input; namespace ProxyCore.Scripting { public class Plugin { protected Plugin(string keyword, string name) { Keyword = keyword; Name = name; } /// /// Set this to be your configuration file if you want your plugin to have one. This is optional. /// public ConfigFile Config { get; protected set; } /// /// Name of your plugin. You must set this or your plugin will not be loaded. /// public readonly string Name; /// /// This is the keyword for your plugin. You must set this or your plugin will not be loaded. /// This must be unique. If two or more plugins with the same keyword are found then the plugin /// with the highest version number is loaded. /// public readonly string Keyword; /// /// Creator of the plugin, this is your name / character's name. This is optional. /// public string Author { get; protected set; } /// /// Version of your plugin. This is optional. /// public int Version { get; protected set; } /// /// Description about your plugin. You should explain here what it does and how to handle it. /// This will be displayed if user requests information about your plugin. This is optional. /// public string Description { get; protected set; } /// /// Enter a website for this plugin if you wish. Mostly used to see documentation and updates. /// public string Website { get; protected set; } /// /// Enter the URL for update checking txt file. For example "www.duckbat.com/plugins/update.moons.txt". /// In the text file enter the number of last version. For example whole contents of the txt file can be "3". /// Indicating that the last version for this plugin is 3. If version is greater than user's version and /// they have update checking on then they will be notified that there is a more up to date version out there. /// public string UpdateUrl { get; protected set; } /// /// Does this plugin require a certain version of core? Set this if there was an update and your plugin requires it. /// Plugin is not loaded if an older version core than this is used and user will be notified. /// public int RequiredCoreVersion { get; protected set; } /// /// Register a new trigger. /// /// Unique identifier for the trigger. /// Regex pattern for the trigger. /// Function that will be called if this trigger fires. protected void RegisterTrigger(string Name, string Pattern, TriggerFunction Function) { RegisterTrigger(Name, Pattern, Function, TriggerFlags.None); } /// /// Register a new trigger. /// /// Unique identifier for the trigger. /// Regex pattern for the trigger. /// Function that will be called if this trigger fires. /// Options for the trigger. protected void RegisterTrigger(string Name, string Pattern, TriggerFunction Function, TriggerFlags Flags) { RegisterTrigger(Name, Pattern, Function, Flags, 1000); } /// /// Register a new trigger. /// /// Unique identifier for the trigger. /// Regex pattern for the trigger. /// Function that will be called if this trigger fires. /// Options for the trigger. /// Lower priority triggers get matched first. protected void RegisterTrigger(string Name, string Pattern, TriggerFunction Function, TriggerFlags Flags, int Priority) { RegisterTrigger(Name, Pattern, Function, Flags, Priority, 0); } /// /// Register a new trigger. /// /// Unique identifier for the trigger. /// Regex pattern for the trigger. /// Function that will be called if this trigger fires. /// Options for the trigger. /// Lower priority triggers get matched first. /// Custom argument that will be passed to trigger data. protected void RegisterTrigger(string Name, string Pattern, TriggerFunction Function, TriggerFlags Flags, int Priority, int Arg) { TriggerHandler.RegisterTrigger(Keyword.ToLower().Trim() + "." + Name, Pattern, Function, Flags, Priority, Arg, Keyword.ToLower().Trim()); } /// /// Unregister a trigger by name. /// /// Name of the trigger you wish to unregister. protected void UnregisterTrigger(string Name) { TriggerHandler.UnregisterTrigger(Keyword.ToLower().Trim() + "." + Name); } /// /// Register a new command or overwrite a previous one. /// /// Command to register. /// Arguments to match (regex pattern). This can be set to null or empty string /// if you don't want to capture anything or plan to do so in the function yourself. /// Function of command. protected void RegisterCommand(string Cmd, string Args, CmdFunction f) { RegisterCommand(Cmd, Args, f, 0); } /// /// Register a new command or overwrite a previous one. /// /// Command to register. /// Arguments to match (regex pattern). This can be set to null or empty string /// if you don't want to capture anything or plan to do so in the function yourself. /// Function of command. /// Minimum length of command typed required to activate. For example if command is "plugins" and this is 6 then "plugin" and "plugins" both activate this command but "plugi" won't. Enter 0 to disable this behaviour. protected void RegisterCommand(string Cmd, string Args, CmdFunction f, int MinLength) { RegisterCommand(Cmd, Args, f, MinLength, CMDFlags.None); } /// /// Register a new command or overwrite a previous one. /// /// Command to register. /// Arguments to match (regex pattern). This can be set to null or empty string /// if you don't want to capture anything or plan to do so in the function yourself. /// Function of command. /// Minimum length of command typed required to activate. For example if command is "plugins" and this is 6 then "plugin" and "plugins" both activate this command but "plugi" won't. Enter 0 to disable this behaviour. /// Options for command. protected void RegisterCommand(string Cmd, string Args, CmdFunction f, int MinLength, CMDFlags flags) { RegisterCommand(Cmd, Args, f, MinLength, flags, null); } /// /// Register a new command or overwrite a previous one. /// /// Command to register. /// Arguments to match (regex pattern). This can be set to null or empty string /// if you don't want to capture anything or plan to do so in the function yourself. /// Function of command. /// Minimum length of command typed required to activate. For example if command is "plugins" and this is 6 then "plugin" and "plugins" both activate this command but "plugi" won't. Enter 0 to disable this behaviour. /// Options for command. /// Parent command (if you want to create a subcommand). You can enter commands separated with space if it's nested. protected void RegisterCommand(string Cmd, string Args, CmdFunction f, int MinLength, CMDFlags flags, string parent) { RegisterCommand(Cmd, Args, f, MinLength, flags, parent, 0); } /// /// Register a new command or overwrite a previous one. /// /// Command to register. /// Arguments to match (regex pattern). This can be set to null or empty string /// if you don't want to capture anything or plan to do so in the function yourself. /// Function of command. /// Minimum length of command typed required to activate. For example if command is "plugins" and this is 6 then "plugin" and "plugins" both activate this command but "plugi" won't. Enter 0 to disable this behaviour. /// Options for command. /// Parent command (if you want to create a subcommand). You can enter commands separated with space if it's nested. /// Custom argument to pass to function handler. This way you can register multiple commands to a same /// function handler only differentiating them with this custom argument. protected void RegisterCommand(string Cmd, string Args, CmdFunction f, int MinLength, CMDFlags flags, string parent, int Arg) { RegisterCommand(Cmd, Args, f, MinLength, flags, parent, Arg, ulong.MaxValue); } /// /// Register a new command or overwrite a previous one. /// /// Command to register. /// Arguments to match (regex pattern). This can be set to null or empty string /// if you don't want to capture anything or plan to do so in the function yourself. /// Function of command. /// Options for command. /// Parent command (if you want to create a subcommand). You can enter commands separated with space if it's nested. /// Custom argument to pass to function handler. This way you can register multiple commands to a same /// function handler only differentiating them with this custom argument. /// Mask of allowed auth levels to access this command. Default ulong.MaxValue (meaning all auth levels are allowed). /// Enter 3 for example to allow only auth level 1 and 2 to access this command. /// Minimum length of command typed required to activate. For example if command is "plugins" and this is 6 then "plugin" and "plugins" both activate this command but "plugi" won't. Enter 0 to disable this behaviour. protected void RegisterCommand(string Cmd, string Args, CmdFunction f, int MinLength, CMDFlags flags, string parent, int Arg, ulong AuthMask) { InputHandler.RegisterCommand(Cmd, Args, f, flags, parent, Arg, AuthMask, Keyword.ToLower().Trim(), MinLength); } /// /// Unregister a command. /// /// Command to unregister. If you want to unregister a nested command /// separate commands with a space. protected void UnregisterCommand(string Cmd) { InputHandler.UnregisterCommand(Cmd); } /// /// This will be called when character enters the game. Either by log in or reconnect. /// public virtual void OnLogin() { } /// /// This will be called when we disconnect from Aardwolf. /// public virtual void OnDisconnect() { } /// /// This will be called when we connect to Aardwolf. /// public virtual void OnConnect() { } /// /// This is called when program shuts down. Write any code you need to shut down your plugin. /// public virtual void Shutdown() { } /// /// This is called on every loop of world update. You can use it as your main loop for /// the plugin if you need one. /// /// Current time since program startup. public virtual void Update(long msTime) { } /// /// This is called when we receive a line from MUD. It is called AFTER triggers are done with it. If /// a trigger gagged the line this will not be called. /// /// public virtual void OnReceivedLineAfter(Messages.Message Msg) { } /// /// This is called when we receive a line from MUD. It is called BEFORE triggers are done with it. /// /// public virtual void OnReceivedLineBefore(Messages.Message Msg) { } /// /// This is called when user enters a command and inputhandler did not handle the command. So it /// is called AFTER we check for aliases and commands and we are about to send command to MUD. /// /// Command that was entered. You can change this in the function. If you set null /// then nothing will be sent to MUD. /// Client who entered the command. If this is 0 it was executed from a plugin. /// Auth level of who entered the command. public virtual void OnEnteredCommandAfter(ref string Msg, uint ClientId, int AuthLevel) { } /// /// This is called when user enters a command. It is called BEFORE we check for aliases and commands. /// /// Command that was entered. You can change this in the function. If you set null /// then nothing will be sent to MUD and nothing will be checked for aliases or commands. /// Client who entered the command. If this is 0 it was executed from a plugin. /// Auth level of who entered the command. public virtual void OnEnteredCommandBefore(ref string Msg, uint ClientId, int AuthLevel) { } /// /// Enter required player config options here. This will be displayed if user requests info about a plugin. /// For example you may enter here "echocommands ON" and "statmon ON" etc. Whatever your plugin requires. /// This doesn't actually change the settings in game it is only for plugin info command. /// public readonly List RequiredPlayerConfig = new List(); /// /// This is the class name of script. For example moons has this set to "MoonScript.MoonScript". /// Only needed by developers who want to use another plugin in their plugin. /// internal string ClassName; /// /// Called when we load a configuration file. /// /// Did the loading succeed? If not then the config file wasn't present and we created a new one. public virtual void OnLoadedConfig(bool Success) { } /// /// Disable all triggers with this priority. Disabling triggers from a plugin will make them not work until /// you enable them from the same plugin again. If triggers have been disabled from multiple plugins then /// all plugins will have to enable them again until they start working. Disabling triggers will make all /// triggers with this priority to not work not only triggers in current plugin! /// /// Priority of triggers to disable. protected void DisableTriggers(int Priority) { DisableTriggers(Priority, Priority); } /// /// Disable all triggers with this priority. Disabling triggers from a plugin will make them not work until /// you enable them from the same plugin again. If triggers have been disabled from multiple plugins then /// all plugins will have to enable them again until they start working. Disabling triggers will make all /// triggers with this priority to not work not only triggers in current plugin! /// /// Minimum priority of triggers to disable. /// Maximum priority of triggers to disable. protected void DisableTriggers(int MinPriority, int MaxPriority) { TriggerHandler.DisableTriggers(Keyword, MinPriority, MaxPriority); } /// /// Enable all previously disabled triggers with this priority. /// /// Priority of triggers to enable. protected void EnableTriggers(int Priority) { EnableTriggers(Priority, Priority); } /// /// Enable all previously disabled triggers with this priority. /// /// Minimum priority of triggers to enable. /// Maximum priority of triggers to enable. protected void EnableTriggers(int MinPriority, int MaxPriority) { TriggerHandler.EnableTriggers(Keyword, MinPriority, MaxPriority); } } }