mirror of
https://github.com/cadmium-im/zirconium-sharp.git
synced 2024-11-08 11:41:04 +00:00
Add example of hello world plugin
This commit is contained in:
parent
1133ca8a76
commit
0f15340065
@ -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;
|
||||
}
|
||||
}
|
@ -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>
|
Loading…
Reference in New Issue
Block a user