Implement configuration API for plugins

This commit is contained in:
ChronosX88 2020-09-06 14:16:13 +04:00
parent 48d27401ae
commit 01a7589417
Signed by: ChronosXYZ
GPG Key ID: 085A69A82C8C511A
5 changed files with 34 additions and 4 deletions

View File

@ -15,3 +15,11 @@ ServerID = ""
Host = "localhost" Host = "localhost"
Port = 8000 Port = 8000
Endpoint = "" Endpoint = ""
# Here you can specify settings that is exposed by plugins
# For example - [Plugins.HelloWorld] is the settings for plugin called HelloWorld
[Plugins]
[Plugins.HelloWorld]
text = "123"
[Plugins.HelloWorld.Test]
modes = ["abc"]

View File

@ -1,3 +1,5 @@
using System.Collections.Generic;
namespace Zirconium.Core namespace Zirconium.Core
{ {
public class Config public class Config
@ -16,6 +18,9 @@ namespace Zirconium.Core
// Websocket server settings // Websocket server settings
public Websocket Websocket { get; set; } public Websocket Websocket { get; set; }
// Configurations of plugins
public Dictionary<string, dynamic> Plugins { get; set; }
} }
public class Websocket public class Websocket

View File

@ -1,3 +1,4 @@
using System.Collections.Generic;
using System; using System;
using Newtonsoft.Json; using Newtonsoft.Json;
using Zirconium.Core.Models; using Zirconium.Core.Models;
@ -36,6 +37,16 @@ namespace Zirconium.Core.Modules
return _app.Config.ServerID; return _app.Config.ServerID;
} }
public dynamic GetSettings(IModuleAPI plugin)
{
return _app.Config.Plugins.GetValueOrDefault(plugin.GetModuleUniqueName(), null);
}
public dynamic GetSettings(string pluginName)
{
return _app.Config.Plugins.GetValueOrDefault(pluginName, null);
}
public void Hook(IC2SMessageHandler handler) public void Hook(IC2SMessageHandler handler)
{ {
_router.AddC2SHandler(handler.GetHandlingMessageType(), handler); _router.AddC2SHandler(handler.GetHandlingMessageType(), handler);

View File

@ -13,5 +13,7 @@ namespace Zirconium.Core.Modules.Interfaces
string[] GetServerDomains(); string[] GetServerDomains();
string GetServerID(); string GetServerID();
void SendMessage(ConnectionInfo connInfo, BaseMessage message); void SendMessage(ConnectionInfo connInfo, BaseMessage message);
dynamic GetSettings(IModuleAPI plugin);
dynamic GetSettings(string pluginName);
} }
} }

View File

@ -2,11 +2,15 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>
<BuildProjectReferences>false</BuildProjectReferences>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="../../Zirconium/Zirconium.csproj" /> <ProjectReference Include="../../Zirconium/Zirconium.csproj">
<ExcludeAssets>runtime</ExcludeAssets>
</ProjectReference>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup> </ItemGroup>
</Project> </Project>