Add example of hello world plugin

This commit is contained in:
ChronosX88 2020-07-19 14:47:38 +04:00
parent 1133ca8a76
commit 0f15340065
2 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,44 @@
using Newtonsoft.Json;
using Zirconium.Core.Logging;
using Zirconium.Core.Models;
using Zirconium.Core.Modules.Interfaces;
namespace HelloWorldPlugin
{
internal class HelloWorldPlugin : IModuleAPI
{
public string GetModuleUniqueName() => "HelloWorldPlugin";
public void Initialize(IHostModuleAPI hostModuleAPI)
{
var handler = new C2SHandler(hostModuleAPI);
hostModuleAPI.Hook(handler);
Log.Debug("plugin is initialized");
}
}
internal class C2SHandler : IC2SMessageHandler
{
private IHostModuleAPI hostModuleAPI;
public C2SHandler(IHostModuleAPI hostModuleAPI) {
this.hostModuleAPI = hostModuleAPI;
}
public string GetHandlerUniqueID() => "test";
public string GetHandlingMessageType() => "test";
public void HandleMessage(ConnectionInfo connInfo, BaseMessage message)
{
BaseMessage msg = new BaseMessage(message, true);
msg.Payload["testProp"] = "hello world";
msg.Ok = true;
msg.From = hostModuleAPI.GetServerID();
string strMsg = JsonConvert.SerializeObject(msg);
connInfo.ConnectionHandler.SendMessage(strMsg);
}
public bool IsAuthorizationRequired() => false;
}
}

View File

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../../Zirconium/Zirconium.csproj" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>
</Project>