2021-08-15 07:54:25 +02:00
using System ;
2021-08-14 21:49:23 +02:00
2022-06-04 18:09:42 +08:00
namespace RageCoop.Server.Scripting
2021-08-14 21:49:23 +02:00
{
2022-06-12 15:39:32 +08:00
/// <summary>
/// Inherit from this class, constructor will be called automatically, but other scripts might have yet been loaded, you should use <see cref="OnStart"/>. to initiate your script.
/// </summary>
2022-06-11 18:41:10 +08:00
public abstract class ServerScript : Core . Scripting . IScriptable
2021-11-27 22:44:00 +01:00
{
2022-06-12 15:39:32 +08:00
/// <summary>
/// This method would be called from main thread after all scripts have been loaded.
/// </summary>
2022-06-11 18:41:10 +08:00
public abstract void OnStart ( ) ;
2021-08-18 11:47:59 +02:00
2022-04-12 06:04:02 +02:00
/// <summary>
2022-06-12 15:39:32 +08:00
/// This method would be called from main thread when the server is shutting down, you MUST terminate all background jobs/threads in this method.
2022-04-12 06:04:02 +02:00
/// </summary>
2022-06-12 15:39:32 +08:00
public abstract void OnStop ( ) ;
2022-04-12 06:04:02 +02:00
/// <summary>
2022-06-12 15:39:32 +08:00
/// Get the resource directory this script belongs to.
2022-04-12 06:04:02 +02:00
/// </summary>
2022-06-12 15:39:32 +08:00
public string CurrentDirectory { get ; internal set ; }
2022-04-12 06:04:02 +02:00
}
[AttributeUsage(AttributeTargets.Method, Inherited = false)]
2021-12-02 23:05:22 +01:00
public class Command : Attribute
2021-08-18 11:47:59 +02:00
{
/// <summary>
/// Sets name of the command
/// </summary>
public string Name { get ; set ; }
2021-12-16 14:52:48 +01:00
/// <summary>
/// Set the Usage (Example: "Please use "/help"". ArgsLength required!)
/// </summary>
2021-12-02 23:05:22 +01:00
public string Usage { get ; set ; }
2021-12-16 14:52:48 +01:00
/// <summary>
/// Set the length of arguments (Example: 2 for "/message USERNAME MESSAGE". Usage required!)
/// </summary>
2021-12-02 23:05:22 +01:00
public short ArgsLength { get ; set ; }
public Command ( string name )
2021-08-15 07:54:25 +02:00
{
2021-08-18 11:47:59 +02:00
Name = name ;
2021-08-15 07:54:25 +02:00
}
2021-08-14 21:49:23 +02:00
}
2021-08-18 11:47:59 +02:00
public class CommandContext
{
/// <summary>
/// Gets the client which executed the command
/// </summary>
2021-08-26 17:01:32 +02:00
public Client Client { get ; internal set ; }
2021-08-18 11:47:59 +02:00
/// <summary>
2021-12-16 14:52:48 +01:00
/// Gets the arguments (Example: "/message USERNAME MESSAGE", Args[0] for USERNAME)
2021-08-18 11:47:59 +02:00
/// </summary>
public string [ ] Args { get ; internal set ; }
}
2021-08-14 21:49:23 +02:00
}