salty-ircd/source/ircd/app.d

73 lines
1.4 KiB
D
Raw Normal View History

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