2017-03-11 06:14:48 +01:00
|
|
|
module ircd.app;
|
|
|
|
|
2017-12-29 14:38:13 +01:00
|
|
|
import std.algorithm;
|
|
|
|
import std.traits;
|
|
|
|
import std.string;
|
|
|
|
|
|
|
|
import sdlang;
|
|
|
|
|
2017-03-11 17:45:49 +01:00
|
|
|
import ircd.server;
|
2017-03-11 06:14:48 +01:00
|
|
|
|
2017-12-29 14:38:13 +01:00
|
|
|
static T tagValueOrNull(T)(Tag tag, string childName)
|
|
|
|
{
|
2020-02-12 13:59:41 +01:00
|
|
|
if (childName !in tag.tags)
|
2020-02-11 15:01:08 +01:00
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return tagValue!T(tag, childName);
|
|
|
|
}
|
2017-12-29 14:38:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static T tagValue(T)(Tag tag, string childName)
|
|
|
|
{
|
2020-02-12 13:59:41 +01:00
|
|
|
static if (isArray!T && !isSomeString!T)
|
2020-02-11 15:01:08 +01:00
|
|
|
{
|
|
|
|
template U(T : T[])
|
|
|
|
{
|
|
|
|
alias U = T;
|
|
|
|
}
|
2017-12-29 14:38:13 +01:00
|
|
|
|
2020-02-11 15:01:08 +01:00
|
|
|
T array = [];
|
2017-12-29 14:38:13 +01:00
|
|
|
|
2020-02-12 13:59:41 +01:00
|
|
|
foreach (value; tag.tags[childName][0].values)
|
2020-02-11 15:01:08 +01:00
|
|
|
{
|
|
|
|
array ~= value.get!(U!T);
|
|
|
|
}
|
2017-12-29 14:38:13 +01:00
|
|
|
|
2020-02-11 15:01:08 +01:00
|
|
|
return array;
|
|
|
|
}
|
2020-02-12 13:59:41 +01:00
|
|
|
else static if (isIntegral!T && !is(T == int))
|
2020-02-11 15:01:08 +01:00
|
|
|
{
|
2020-02-12 13:59:41 +01:00
|
|
|
return cast(T) tagValue!int(tag, childName);
|
2020-02-11 15:01:08 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return tag.tags[childName][0].values[0].get!T;
|
|
|
|
}
|
2017-12-29 14:38:13 +01:00
|
|
|
}
|
|
|
|
|
2017-03-11 06:14:48 +01:00
|
|
|
shared static this()
|
|
|
|
{
|
2020-02-11 15:01:08 +01:00
|
|
|
auto server = new Server();
|
2017-12-29 14:38:13 +01:00
|
|
|
|
2020-02-11 15:01:08 +01:00
|
|
|
auto config = parseFile("config.sdl");
|
2017-12-29 14:38:13 +01:00
|
|
|
|
2020-02-11 15:01:08 +01:00
|
|
|
auto pass = config.tagValue!string("pass");
|
|
|
|
server.setPass(pass.empty ? null : pass);
|
2017-12-29 14:38:13 +01:00
|
|
|
|
2020-02-12 13:59:41 +01:00
|
|
|
foreach (listenBlock; config.tags.filter!(t => t.getFullName.toString == "listen"))
|
2020-02-11 15:01:08 +01:00
|
|
|
{
|
|
|
|
assert(listenBlock.tagValue!string("type") == "plaintext");
|
2017-12-29 14:38:13 +01:00
|
|
|
|
2020-02-11 15:01:08 +01:00
|
|
|
auto addresses = listenBlock.tagValue!(string[])("address");
|
|
|
|
auto port = listenBlock.tagValue!ushort("port");
|
2017-12-29 14:38:13 +01:00
|
|
|
|
2020-02-12 13:59:41 +01:00
|
|
|
foreach (address; addresses)
|
2020-02-11 15:01:08 +01:00
|
|
|
{
|
|
|
|
server.listen(port, address);
|
|
|
|
}
|
|
|
|
}
|
2017-03-11 06:14:48 +01:00
|
|
|
}
|