mirror of
https://github.com/deavminet/dnetd
synced 2024-09-21 09:43:37 +02:00
Restructured configuration sub-system
This commit is contained in:
parent
a75afc5528
commit
fa15d5cb08
@ -1,7 +1,7 @@
|
||||
import std.stdio;
|
||||
import std.socket : parseAddress;
|
||||
import dnetd.dserver : DServer;
|
||||
import dnetd.dconfig : DConfig, DLinkConfig;
|
||||
import dnetd.dconfig : DGeneralConfig, DLinkConfig;
|
||||
import std.json;
|
||||
import std.exception;
|
||||
import gogga;
|
||||
@ -66,7 +66,7 @@ void main(string[] args)
|
||||
}
|
||||
|
||||
/* 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(config)
|
||||
@ -80,10 +80,11 @@ void main(string[] args)
|
||||
/* Get all server links */
|
||||
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 */
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -12,63 +12,6 @@ import gogga;
|
||||
import dnetd.dlink : DLink;
|
||||
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
|
||||
{
|
||||
|
@ -644,7 +644,7 @@ public class DConnection : Thread
|
||||
bool status = true;
|
||||
|
||||
/* Get the message of the day */
|
||||
string motd = server.getConfig().getGeneral().getMotd();
|
||||
string motd = server.getGeneralConfig().getMotd();
|
||||
|
||||
/* Encode the reply */
|
||||
reply ~= [status];
|
||||
|
@ -106,7 +106,7 @@ public final class DMeyer
|
||||
/* Associated server */
|
||||
private DServer server;
|
||||
|
||||
this(DServer server, DLinkConfig linkConfig)
|
||||
this(DServer server, DLink[] links)
|
||||
{
|
||||
this.server = server;
|
||||
|
||||
|
@ -26,7 +26,7 @@ import gogga;
|
||||
public class DServer : Thread
|
||||
{
|
||||
/* Server configuration */
|
||||
private DConfig config;
|
||||
private DGeneralConfig generalConfig;
|
||||
|
||||
/**
|
||||
* Connection queue
|
||||
@ -51,16 +51,16 @@ public class DServer : Thread
|
||||
private DListener[] listeners;
|
||||
|
||||
/* TODO: Implement new constructor */
|
||||
this(DConfig config)
|
||||
this(DGeneralConfig generalConfig)
|
||||
{
|
||||
/* Set the function to be called on thread start */
|
||||
super(&startListeners);
|
||||
|
||||
/* Set the server's config */
|
||||
this.config = config;
|
||||
/* Set the server's general config */
|
||||
this.generalConfig = generalConfig;
|
||||
|
||||
/* Construct the listeners */
|
||||
initListeners(config.getGeneral().getAddresses());
|
||||
initListeners(generalConfig.getAddresses());
|
||||
|
||||
/* Initialize the server */
|
||||
init();
|
||||
@ -111,9 +111,9 @@ public class DServer : Thread
|
||||
}
|
||||
}
|
||||
|
||||
public DConfig getConfig()
|
||||
public DGeneralConfig getGeneralConfig()
|
||||
{
|
||||
return config;
|
||||
return generalConfig;
|
||||
}
|
||||
|
||||
private void init()
|
||||
@ -148,11 +148,18 @@ public class DServer : Thread
|
||||
return meyerSS;
|
||||
}
|
||||
|
||||
public DMeyer getLinkManager()
|
||||
{
|
||||
return getMeyer();
|
||||
}
|
||||
|
||||
public void attachLinkManager(DMeyer linkManager)
|
||||
{
|
||||
meyerSS = linkManager;
|
||||
}
|
||||
|
||||
public void startServer()
|
||||
{
|
||||
// /* Initialize the Meyer linking sub-system */
|
||||
// meyerSS = new DMeyer(this, config.getLinks());
|
||||
|
||||
/* Start the listener starter */
|
||||
start();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user