mirror of https://github.com/deavminet/dnetd-ng
Added entry-point initialization for a server instance
This commit is contained in:
parent
f9c93d17c1
commit
8703cdc74d
|
@ -4,6 +4,10 @@
|
|||
module dnetd.app;
|
||||
|
||||
import dlog;
|
||||
import dnetd.exceptions : GeneralException;
|
||||
import std.json : JSONValue;
|
||||
import dnetd.config : readConfig, Configuration;
|
||||
import dnetd.server : Server;
|
||||
|
||||
public Logger logger;
|
||||
string VERSION = "v0.0.1";
|
||||
|
@ -14,4 +18,19 @@ void main()
|
|||
logger = new DefaultLogger();
|
||||
|
||||
logger.log("Welcome to dnetd v"~VERSION);
|
||||
|
||||
/* TODO: Add jcli handling here */
|
||||
|
||||
try
|
||||
{
|
||||
JSONValue jsonConfig = readConfig("config.json");
|
||||
Configuration config = Configuration.fromJSON(jsonConfig);
|
||||
|
||||
/* TODO: Server init with config here */
|
||||
Server server = new Server(config);
|
||||
|
||||
}
|
||||
catch(GeneralException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,12 +5,16 @@ module dnetd.config;
|
|||
|
||||
import dnetd.app : logger;
|
||||
import std.json : JSONValue, JSONException;
|
||||
import dnetd.exceptions;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public final class Configuration
|
||||
{
|
||||
/**
|
||||
* Load the configuration from a JSON source, returning the
|
||||
* configuration as a Configuration object, on error, null
|
||||
* configuration as a Configuration object, on error, null (TODO: Throw exception rather)
|
||||
*
|
||||
* @param jsonConfig the JSONValue configuration
|
||||
*/
|
||||
|
@ -41,3 +45,28 @@ public final class Configuration
|
|||
return config;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads in the JSON from the given path to the configuration
|
||||
* file
|
||||
*
|
||||
* On error throws TODO
|
||||
*/
|
||||
public JSONValue readConfig(string path)
|
||||
{
|
||||
JSONValue config;
|
||||
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Configuration error
|
||||
*/
|
||||
public final class ConfigurationError : GeneralException
|
||||
{
|
||||
this()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
/**
|
||||
* Exceptions sub-system
|
||||
*/
|
||||
module dnetd.exceptions;
|
||||
|
||||
import std.exception;
|
||||
|
||||
/**
|
||||
* Base class for all DNETD exceptions
|
||||
*/
|
||||
public class GeneralException : Exception
|
||||
{
|
||||
this()
|
||||
{
|
||||
}
|
||||
}
|
|
@ -6,3 +6,18 @@
|
|||
* relates to it, such as users, server links and processing/handling
|
||||
* of messages and commands.
|
||||
*/
|
||||
module dnetd.server;
|
||||
|
||||
import dnetd.app : logger;
|
||||
import dnetd.config : Configuration;
|
||||
|
||||
/**
|
||||
* Represents an instance of a dnet server
|
||||
*/
|
||||
public final class Server
|
||||
{
|
||||
this(Configuration config)
|
||||
{
|
||||
logger.log("Server instance '"~"PUT ID HERE"~"' starting up...");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue