forked from GTACoop/GTACoop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bec6f49
commit ea17b27
Showing
6 changed files
with
108 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Security.Cryptography.X509Certificates; | ||
using System.Threading.Tasks; | ||
using GTAServer.ProtocolMessages; | ||
|
||
namespace GTAServer.PluginAPI | ||
{ | ||
public interface ICommand | ||
{ | ||
/// <summary> | ||
/// Name of the command | ||
/// </summary> | ||
string CommandName { get; } | ||
/// <summary> | ||
/// What shows in the help text for the command | ||
/// </summary> | ||
string HelpText { get; } | ||
|
||
/// <summary> | ||
/// List of permissions needed to run the command | ||
/// </summary> | ||
List<string> RequiredPermissions { get; } | ||
/// <summary> | ||
/// If every permission listed in RequiredPermissions is needed. | ||
/// </summary> | ||
bool AllPermissionsRequired { get; } | ||
|
||
/// <summary> | ||
/// Called when a command is being executed. | ||
/// </summary> | ||
/// <param name="caller">Person who called the command</param> | ||
/// <param name="chatData">Chat data object from the message command</param> | ||
void OnCommandExec(Client caller, ChatData chatData); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
namespace GTAServer.PluginAPI | ||
{ | ||
public interface IPlugin | ||
{ | ||
/// <summary> | ||
/// Name of the plugin | ||
/// </summary> | ||
string Name { get; } | ||
/// <summary> | ||
/// Description of the plugin | ||
/// </summary> | ||
string Description { get; } | ||
/// <summary> | ||
/// Name of the plugin author. | ||
/// </summary> | ||
string Author { get; } | ||
|
||
/// <summary> | ||
/// Plugin entry point, called when a plugin is being enabled. | ||
/// Use this to register any necessary hooks and commands. | ||
/// </summary> | ||
/// <param name="gameServer">Game server object.</param> | ||
/// <param name="isAfterServerLoad">If the plugin is being started after the server has started.</param> | ||
/// <returns>If the plugin successfully loaded</returns> | ||
bool OnEnable(GameServer gameServer, bool isAfterServerLoad); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace GTAServer.PluginAPI | ||
{ | ||
public static class PluginLoader | ||
{ | ||
public static string Location = System.AppContext.BaseDirectory; | ||
private static ILogger _logger; | ||
public static List<IPlugin> LoadPlugin(string targetAssemblyName) | ||
{ | ||
_logger = Util.LoggerFactory.CreateLogger<GameServer>(); | ||
var assemblyName = targetAssemblyName; | ||
var pluginList = new List<IPlugin>(); | ||
|
||
|
||
var pluginAssembly = Assembly.Load(new AssemblyName(assemblyName)); | ||
var types = pluginAssembly.GetExportedTypes(); | ||
var validTypes = types.Where(t => typeof(IPlugin).IsAssignableFrom(t)).ToArray(); | ||
if (!validTypes.Any()) | ||
{ | ||
_logger.LogError("No classes found that extend IPlugin in assembly " + assemblyName); | ||
return new List<IPlugin>(); | ||
} | ||
foreach (var plugin in validTypes) | ||
{ | ||
var curPlugin = Activator.CreateInstance(plugin) as IPlugin; | ||
if (curPlugin == null) _logger.LogWarning("Could not create instance of " + plugin.Name + " (returned null after Activator.CreateInstance)"); | ||
} | ||
|
||
return pluginList; | ||
} | ||
} | ||
} |