Server Plugins
Contents
Introduction
It is possible to write plugins in C# and use these from Lua.
These plugins must implement a certain Interface to be usable.
In the moment there is no extensive written documentation, but there exists a tutorial plugin which is well commented and which can be used as a starting point.
CAVEAT: Server plugins are officially not supported and you can seriously shoot yourself in the foot with them. You need to know what you are doing to really use them.
Compiled plugins need to be placed into
\build\base\plugins
API Overview
Synchronous Requests
Server Plugins can take requests from Lua and answer them directly, like any other synchronous function. Your Lua script will wait until the call returns. The engine function for that is
Lua Code: SendRequestToPlugin("TutorialPlugin", "GimmeFive")
Where "Tutorialpligin" is the name of the plugin as returned by the function string GetPluginName();
in the IPlugin interface you implemented and "GimmeFive" is just a piece of data.
You can add any number or type of arguments to the request after specifying the plugin name.
These arguments find their way into the IPlugin function:
object[] DirectRequestFromLua(object[] _requestData);
Your arguments end up as elements of the _requestData array. In our example the string "GimmeFive" ends up in _requestData[0]
Asynchronous Requests
TBD
Returning Lua Tables
If you use LuaTableProxy types to return Lua tables your plugin also must be linked against Shardsserver.exe, which means you probably have to update it a lot.
Helper Functions
TBD
IPlugin
Every plugin must implement this interface. Check out the Tutorial Plugin to see how it is done.
using System.Collections.Concurrent; namespace Gameplay.Plugin { public class LuaRequest { public string EventId; public object[] Data; } public class LuaResponse { public string EventId; public ulong DestinationObjectId; public object[] Data; } public interface IPlugin { void Init(ConcurrentQueue<LuaResponse> _responseQueue); void Start(); bool IsReadyForServerStartup(); void Shutdown(); bool IsShutDown(); void MessageFromLua(LuaRequest _request); object[] DirectRequestFromLua(object[] _requestData); string GetPluginName(); } }
Related Engine Functions
These are the engine functions which can be used to interact with your plugin from Lua. There is example Lua code in the Tutorial plugin you can use.
SendMessageToPlugin(...) Description: Sends a message to a C# gameplay plugin. Params: (string) - Plug-in name to send to. (string) - EventId name. (...) One or more object arguments to be passed to the plug-in. Returns: None ----------------------------------
SendRequestToPlugin(...) Description: Sends a direct request to a C# gameplay plugin. Params: (string) - Plug-in name to send to. (...) One or more object arguments to be passed to the plug-in. Returns: A single value, or an array of values. ----------------------------------
IsPluginLoaded(...) Description: Ask if a c# gameplay plug-in has been loaded or not Params: (string) - Plug-in name to send to. Returns: true or false ----------------------------------
Tutorial Plugin Download Link
https://www.legendsofaria.com/downloads/u3d2bdea/LoA_TutorialPlugin.zip