mirror of
https://github.com/deavminet/dnetd
synced 2024-09-21 17:53:39 +02:00
Restructured configuration sub-system
This commit is contained in:
parent
a75afc5528
commit
fa15d5cb08
@ -1,7 +1,7 @@
|
|||||||
import std.stdio;
|
import std.stdio;
|
||||||
import std.socket : parseAddress;
|
import std.socket : parseAddress;
|
||||||
import dnetd.dserver : DServer;
|
import dnetd.dserver : DServer;
|
||||||
import dnetd.dconfig : DConfig, DLinkConfig;
|
import dnetd.dconfig : DGeneralConfig, DLinkConfig;
|
||||||
import std.json;
|
import std.json;
|
||||||
import std.exception;
|
import std.exception;
|
||||||
import gogga;
|
import gogga;
|
||||||
@ -66,7 +66,7 @@ void main(string[] args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Create a new configuration file and check configuration parameters */
|
/* Create a new configuration file and check configuration parameters */
|
||||||
DConfig config = DConfig.getConfig(json);
|
DGeneralConfig config = DGeneralConfig.getConfig(json["general"]);
|
||||||
|
|
||||||
/* If the configuration reading was successful (valid JSON) */
|
/* If the configuration reading was successful (valid JSON) */
|
||||||
if(config)
|
if(config)
|
||||||
@ -80,13 +80,14 @@ void main(string[] args)
|
|||||||
/* Get all server links */
|
/* Get all server links */
|
||||||
DLink[] serverLinks = linkConfig.getLinks();
|
DLink[] serverLinks = linkConfig.getLinks();
|
||||||
|
|
||||||
/* Create a new Meyer */
|
/* Create a new Meyer (link manager) and attach the links to it */
|
||||||
|
DMeyer meyer = new DMeyer(dserver, serverLinks);
|
||||||
|
|
||||||
/* Attach the Meyer to the server */
|
/* Attach the Meyer to the server */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Start the server (TODO: This should start Meyer) */
|
/* Start the server (TODO: This should start Meyer) */
|
||||||
dserver.startServer();
|
dserver.startServer();
|
||||||
}
|
}
|
||||||
|
@ -12,63 +12,6 @@ import gogga;
|
|||||||
import dnetd.dlink : DLink;
|
import dnetd.dlink : DLink;
|
||||||
import dnetd.dserver : DServer;
|
import dnetd.dserver : DServer;
|
||||||
|
|
||||||
public final class DConfig
|
|
||||||
{
|
|
||||||
/* General configuration */
|
|
||||||
private DGeneralConfig generalConfig;
|
|
||||||
|
|
||||||
/* Link configuration */
|
|
||||||
private DLinkConfig linksConfig;
|
|
||||||
|
|
||||||
private this()
|
|
||||||
{
|
|
||||||
/* TODO: */
|
|
||||||
}
|
|
||||||
|
|
||||||
public DGeneralConfig getGeneral()
|
|
||||||
{
|
|
||||||
return generalConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DLinkConfig getLinks()
|
|
||||||
{
|
|
||||||
return linksConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static DConfig getConfig(JSONValue json)
|
|
||||||
{
|
|
||||||
/* The newly created configuration */
|
|
||||||
DConfig config = new DConfig();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
/* TODO: Parse */
|
|
||||||
|
|
||||||
/* Get the `general` block */
|
|
||||||
JSONValue generalBlock = json["general"];
|
|
||||||
config.generalConfig = DGeneralConfig.getConfig(generalBlock);
|
|
||||||
|
|
||||||
/* Get the `links` block */
|
|
||||||
JSONValue linksBlock = json["links"];
|
|
||||||
config.linksConfig = DLinkConfig.getConfig(linksBlock);
|
|
||||||
}
|
|
||||||
catch(JSONException e)
|
|
||||||
{
|
|
||||||
/* Set config to null (signals an error) */
|
|
||||||
config = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JSONValue saveConfig()
|
|
||||||
{
|
|
||||||
JSONValue config;
|
|
||||||
|
|
||||||
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public final class DGeneralConfig
|
public final class DGeneralConfig
|
||||||
{
|
{
|
||||||
|
@ -644,7 +644,7 @@ public class DConnection : Thread
|
|||||||
bool status = true;
|
bool status = true;
|
||||||
|
|
||||||
/* Get the message of the day */
|
/* Get the message of the day */
|
||||||
string motd = server.getConfig().getGeneral().getMotd();
|
string motd = server.getGeneralConfig().getMotd();
|
||||||
|
|
||||||
/* Encode the reply */
|
/* Encode the reply */
|
||||||
reply ~= [status];
|
reply ~= [status];
|
||||||
|
@ -106,7 +106,7 @@ public final class DMeyer
|
|||||||
/* Associated server */
|
/* Associated server */
|
||||||
private DServer server;
|
private DServer server;
|
||||||
|
|
||||||
this(DServer server, DLinkConfig linkConfig)
|
this(DServer server, DLink[] links)
|
||||||
{
|
{
|
||||||
this.server = server;
|
this.server = server;
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ import gogga;
|
|||||||
public class DServer : Thread
|
public class DServer : Thread
|
||||||
{
|
{
|
||||||
/* Server configuration */
|
/* Server configuration */
|
||||||
private DConfig config;
|
private DGeneralConfig generalConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connection queue
|
* Connection queue
|
||||||
@ -51,16 +51,16 @@ public class DServer : Thread
|
|||||||
private DListener[] listeners;
|
private DListener[] listeners;
|
||||||
|
|
||||||
/* TODO: Implement new constructor */
|
/* TODO: Implement new constructor */
|
||||||
this(DConfig config)
|
this(DGeneralConfig generalConfig)
|
||||||
{
|
{
|
||||||
/* Set the function to be called on thread start */
|
/* Set the function to be called on thread start */
|
||||||
super(&startListeners);
|
super(&startListeners);
|
||||||
|
|
||||||
/* Set the server's config */
|
/* Set the server's general config */
|
||||||
this.config = config;
|
this.generalConfig = generalConfig;
|
||||||
|
|
||||||
/* Construct the listeners */
|
/* Construct the listeners */
|
||||||
initListeners(config.getGeneral().getAddresses());
|
initListeners(generalConfig.getAddresses());
|
||||||
|
|
||||||
/* Initialize the server */
|
/* Initialize the server */
|
||||||
init();
|
init();
|
||||||
@ -111,9 +111,9 @@ public class DServer : Thread
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public DConfig getConfig()
|
public DGeneralConfig getGeneralConfig()
|
||||||
{
|
{
|
||||||
return config;
|
return generalConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init()
|
private void init()
|
||||||
@ -148,11 +148,18 @@ public class DServer : Thread
|
|||||||
return meyerSS;
|
return meyerSS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DMeyer getLinkManager()
|
||||||
|
{
|
||||||
|
return getMeyer();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void attachLinkManager(DMeyer linkManager)
|
||||||
|
{
|
||||||
|
meyerSS = linkManager;
|
||||||
|
}
|
||||||
|
|
||||||
public void startServer()
|
public void startServer()
|
||||||
{
|
{
|
||||||
// /* Initialize the Meyer linking sub-system */
|
|
||||||
// meyerSS = new DMeyer(this, config.getLinks());
|
|
||||||
|
|
||||||
/* Start the listener starter */
|
/* Start the listener starter */
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user