2020-09-23 09:37:18 +02:00
|
|
|
import std.stdio;
|
|
|
|
import std.socket : parseAddress;
|
|
|
|
import dnetd.dserver : DServer;
|
2021-01-29 16:44:31 +02:00
|
|
|
import dnetd.dconfig : DGeneralConfig, DLinkConfig;
|
2020-10-02 16:11:27 +02:00
|
|
|
import std.json;
|
|
|
|
import std.exception;
|
2020-10-29 11:23:25 +02:00
|
|
|
import gogga;
|
2021-01-29 15:00:56 +02:00
|
|
|
import dnetd.dlink : DLink, DMeyer;
|
2020-09-23 09:37:18 +02:00
|
|
|
|
2020-10-02 16:11:27 +02:00
|
|
|
void main(string[] args)
|
2020-09-23 09:37:18 +02:00
|
|
|
{
|
2020-10-02 16:11:27 +02:00
|
|
|
/* Configuration file */
|
|
|
|
string configFilename;
|
|
|
|
|
|
|
|
/* If there are no arguments */
|
2020-10-02 17:08:35 +02:00
|
|
|
if(args.length == 1)
|
2020-10-02 16:11:27 +02:00
|
|
|
{
|
|
|
|
/* Use the default file */
|
|
|
|
configFilename = "config.json";
|
|
|
|
}
|
|
|
|
/* If there is one argument */
|
2020-10-02 17:08:35 +02:00
|
|
|
else if(args.length == 2)
|
2020-10-02 16:11:27 +02:00
|
|
|
{
|
|
|
|
/* use the specified one */
|
2020-10-16 17:15:08 +02:00
|
|
|
configFilename = args[1];
|
2020-10-02 16:11:27 +02:00
|
|
|
}
|
|
|
|
/* Illegal amount of guns in one household (no such thing) */
|
|
|
|
else
|
|
|
|
{
|
2020-10-29 11:23:25 +02:00
|
|
|
gprintln("Invalid number of arguments", DebugType.ERROR);
|
2020-10-02 16:11:27 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Configuration file contents */
|
|
|
|
byte[] data;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
/* Open the file for reading */
|
|
|
|
File config;
|
|
|
|
config.open(configFilename, "r");
|
|
|
|
|
|
|
|
/* Read the configuration file data */
|
|
|
|
data.length = config.size();
|
|
|
|
data = config.rawRead(data);
|
|
|
|
config.close();
|
|
|
|
}
|
|
|
|
catch(ErrnoException e)
|
|
|
|
{
|
2020-10-29 11:23:25 +02:00
|
|
|
gprintln("Failure to use configuration file'"~configFilename~"' with error:\n\n"~e.toString(), DebugType.ERROR);
|
2020-10-02 16:11:27 +02:00
|
|
|
return;
|
|
|
|
}
|
2020-09-23 09:37:18 +02:00
|
|
|
|
2021-01-29 17:00:22 +02:00
|
|
|
|
2020-10-02 16:11:27 +02:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2021-01-29 17:00:22 +02:00
|
|
|
/* The JSON */
|
|
|
|
JSONValue json;
|
|
|
|
|
2020-10-02 16:11:27 +02:00
|
|
|
/* Parse the configuration file */
|
|
|
|
json = parseJSON(cast(string)data);
|
|
|
|
|
2021-01-29 17:00:22 +02:00
|
|
|
/* Create a new configuration file and check configuration parameters */
|
|
|
|
DGeneralConfig config = DGeneralConfig.getConfig(json["general"]);
|
2020-10-02 16:11:27 +02:00
|
|
|
|
2021-01-29 14:30:02 +02:00
|
|
|
/* Create a new server */
|
2020-10-02 16:11:27 +02:00
|
|
|
DServer dserver = new DServer(config);
|
2021-01-29 14:28:52 +02:00
|
|
|
|
|
|
|
/* Now configure the the linking */
|
|
|
|
DLinkConfig linkConfig = DLinkConfig.getConfig(dserver, json["links"]);
|
|
|
|
|
2021-01-29 15:00:56 +02:00
|
|
|
/* Get all server links */
|
|
|
|
DLink[] serverLinks = linkConfig.getLinks();
|
2021-01-29 20:48:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
import std.conv : to;
|
|
|
|
gprintln("Links I will be opening: " ~to!(string)(serverLinks));
|
2021-01-29 14:28:52 +02:00
|
|
|
|
2021-01-29 16:44:31 +02:00
|
|
|
/* Create a new Meyer (link manager) and attach the links to it */
|
|
|
|
DMeyer meyer = new DMeyer(dserver, serverLinks);
|
2021-01-29 15:00:56 +02:00
|
|
|
|
|
|
|
/* Attach the Meyer to the server */
|
2021-01-29 17:09:15 +02:00
|
|
|
dserver.attachLinkManager(meyer);
|
2021-01-29 16:44:31 +02:00
|
|
|
|
2021-01-29 15:00:56 +02:00
|
|
|
/* Start the server (TODO: This should start Meyer) */
|
2021-01-29 14:30:02 +02:00
|
|
|
dserver.startServer();
|
2020-10-02 16:11:27 +02:00
|
|
|
}
|
2021-01-29 17:00:22 +02:00
|
|
|
catch(JSONException e)
|
2020-10-02 16:11:27 +02:00
|
|
|
{
|
2021-01-29 17:00:22 +02:00
|
|
|
gprintln("Failure to parse configuration file'"~configFilename~"' with error:\n\n"~e.toString(), DebugType.ERROR);
|
|
|
|
return;
|
2020-10-02 16:11:27 +02:00
|
|
|
}
|
2020-09-23 09:37:18 +02:00
|
|
|
}
|