1
0
mirror of https://github.com/deavminet/dnetd synced 2024-09-21 17:53:39 +02:00
dnetd_old/source/app.d

94 lines
2.0 KiB
D
Raw Normal View History

2020-09-23 09:37:18 +02:00
import std.stdio;
import std.socket : parseAddress;
import dnetd.dserver : DServer;
2021-01-29 14:28:52 +02:00
import dnetd.dconfig : DConfig, DLinkConfig;
import std.json;
import std.exception;
2020-10-29 11:23:25 +02:00
import gogga;
2020-09-23 09:37:18 +02:00
void main(string[] args)
2020-09-23 09:37:18 +02:00
{
/* Configuration file */
string configFilename;
/* If there are no arguments */
if(args.length == 1)
{
/* Use the default file */
configFilename = "config.json";
}
/* If there is one argument */
else if(args.length == 2)
{
/* use the specified one */
2020-10-16 17:15:08 +02:00
configFilename = args[1];
}
/* 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);
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);
return;
}
2020-09-23 09:37:18 +02:00
/* The JSON */
JSONValue json;
try
{
/* Parse the configuration file */
json = parseJSON(cast(string)data);
}
catch(JSONException e)
{
2020-10-29 11:23:25 +02:00
gprintln("Failure to parse configuration file'"~configFilename~"' with error:\n\n"~e.toString(), DebugType.ERROR);
return;
}
/* Create a new configuration file and check configuration parameters */
DConfig config = DConfig.getConfig(json);
/* If the configuration reading was successful (valid JSON) */
if(config)
{
2021-01-29 14:30:02 +02:00
/* Create a new server */
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"]);
/* TODO: COnfigure here */
/* TODO: Start meyer here (remove from inside DServer) */
2021-01-29 14:30:02 +02:00
/* Start the server */
dserver.startServer();
}
else
{
2020-10-29 11:23:25 +02:00
gprintln("Failure to read a valid dnetd configuration file'"~configFilename~"'", DebugType.ERROR);
}
2020-09-23 09:37:18 +02:00
}