Modules

A module is a small class that can be used to bundle up a set of related components behind a ‘facade’ to simplify configuration and deployment.

In FigNet Modules implement FigNet.Core.IModule & it is used to add your custom logic to fignet application as a plugin.

//IModule
namespace FigNet.Core
{
    public interface IModule
    {
        void Load(IServer server);
        void Process(float deltaTime);  // gets call per frame
        void UnLoad();
    }
}

How to create a Module

public class TestModule : IModule
{
     // here define your properties & logic
     public void Load(IServer server)
      {
          FN.Logger.Info("test loaded");
          FN.HandlerCollection.RegisterHandler(new TestHandler());
      }
 
      public void Process(float deltaTime)
      {
      }
 
      public void UnLoad()
      {   
      }
}

How to load a Module

Open ServerConfig.xml and add Module tag and under that tag add assemblyName & Type tags AssemblyName is the name of the dll or solution whereas Type name is the class name including namespace.

<Modules>
      <Module>
        <AssemblyName>FigNetTemplate</AssemblyName>
        <Type>FigNetTemplate.Modules.FolderName.TestModule</Type>
        <Dependencies>
          <Package>
            <AssemblyName>LiteNetLib</AssemblyName>
          </Package>
        </Dependencies>
       </Module>
</Modules>

Tag

Description

Module

define an instance of module

AssemblyName

assembly name (dll) without extension

Type

name of module including complete namespace

Dependencies

addition assemblies a module depends on

Package

dependency

Modules use reflection to create instances if you are using Unity IL2CPP load module manually instead of using config.

How to manually load the module

static void Main(string[] args)
{
    IServer serverApp = new ServerApplication();
    serverApp.SetUp();
    serverApp.AddModule(new TestModule());
    Run(serverApp);
    serverApp.TearDown();
}

AddModule method also calls the Load method of Module internally. There is no need to call Load method of Module explicitly

Last updated

Was this helpful?