Skip to content

Extensible C# server using MEF for dynamic functionality and LUA for internal scripting. Ideal for creating flexible, extendable server applications

Notifications You must be signed in to change notification settings

nakira974/Lkhsoft.Dring

Repository files navigation

Extensible Server with MEF

Overview

This project demonstrates how to create an extensible server using the Managed Extensibility Framework (MEF). The server is designed to be highly extensible, allowing developers to easily add new functionalities through MEF. Additionally, the server supports the use of LUA as its internal language for creating batch scripts and other automation tasks.

Features

  • Extensibility with MEF: The server leverages MEF to allow for the dynamic discovery and composition of parts. This makes it easy to add new features and commands without modifying the core server code.
  • LUA Scripting: The server uses LUA as its internal scripting language. This allows users to create batch scripts, automate tasks, and extend the server's functionality using LUA scripts.
  • Command-Line Interface (CLI): The server includes a robust CLI for interacting with the server, executing commands, and managing tasks.

Create a configuration file

To configure the server, you need to create an app.config file with the following structure:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <appSettings>
        <add key="CertificatePath" value="C:\\Users\\octocat\\.ssl\\server_certificate.pfx" />
        <add key="CertificatePassword" value="passwd" />
        <add key="PluginsPath" value="C:\\Users\\octocat\\Server\\Plugins" />
        <add key="CommandsPath" value="C:\\Users\\octocat\\Server\\Plugins\\Commands" />
        <add key="UdpPort" value="60500" />
        <add key="TcpPort" value="9091" />
        <add key="BatchConfigPath" value="batch.config.yaml"/>
        <add key="BatchDefaultLaunchTime" value="0"/>
        <add key="BatchOutputAllowed" value="False"/>
    </appSettings>
    <connectionStrings>
        <add name="ServerDB" connectionString="Data Source=users.db;Version=3;" providerName="System.Data.SqlClient"/>
    </connectionStrings>
</configuration>
  • CertificatePath: The path to the server certificate file.
  • CertificatePassword: The password for the server certificate.
  • PluginsPath: The path to the directory containing the server plugins.
  • CommandsPath: The path to the directory containing the command plugins.
  • UdpPort: The UDP port number for the server.
  • TcpPort: The TCP port number for the server.
  • BatchConfigPath: The path to the batch configuration file.
  • BatchDefaultLaunchTime: The default launch time for batch jobs.
  • BatchOutputAllowed: A flag indicating whether Lua batch output is allowed.
  • ServerDB: The datasource for the server database.

Extending the Server with MEF

To add new commands or functionalities to the server, you can create new classes that implement the ICommand interface and export them using MEF. Here is an example of how to create a new command:

using System;
using System.ComponentModel.Composition;

[Export(typeof(ICommand))]
[ExportMetadata("CommandName", "MYCOMMAND")]
public class MyCommand : ICommand
{
    public void Execute(params object[] args)
    {
        Console.WriteLine("MyCommand executed.");
        // Add your command logic here
    }
}

Using LUA Scripting

The server supports LUA as its internal scripting language. You can use the CLI command called 'LUA' to launch an interpreter. Using the server's LUA API (which you can extend by implementing cs public interface ILuaDelegate), you can create batch scripts, automate tasks, and enhance the server's functionality. Here is an example of a simple LUA command:

print("Hello, world!")

About

Extensible C# server using MEF for dynamic functionality and LUA for internal scripting. Ideal for creating flexible, extendable server applications

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published