Parse new listener blocks

This commit is contained in:
Tristan B. Kildaire 2020-12-20 19:36:53 +02:00
parent eee69dcbac
commit bee016f521
2 changed files with 24 additions and 19 deletions

View File

@ -1,6 +1,16 @@
{
"general" : {
"addresses" : ["0.0.0.0"],
"addresses" : ["0.0.0.0"],
"binds" : [
{
"address" : "0.0.0.0",
"port" : "7777"
},
{
"address" : "::",
"port" : "7778"
},
],
"port" : "7777",
"network" : "aBasedIRCNetwork",
"name" : "MyBrandSpankingNewIRCServer",
@ -14,4 +24,4 @@
"port" : ""
}
}
}
}

View File

@ -71,7 +71,7 @@ public final class DGeneralConfig
{
/* Addresses to bind sockets to */
private string[] addresses;
private Address[] addresses;
private ushort port;
/* Server information */
@ -91,14 +91,18 @@ public final class DGeneralConfig
try
{
/* Set the addresses */
foreach(JSONValue address; generalBlock["addresses"].array())
/* Set the addresses to bind to */
foreach(JSONValue bindBlock; generalBlock["binds"].array())
{
config.addresses ~= [address.str()];
/* Get the address */
string address = bindBlock["address"].str();
/* Get the port */
ushort port = to!(ushort)(bindBlock["port"].str());
/* Add the address and port tuple to the list of addresses to bind to */
config.addresses ~= parseAddress(address, port);
}
/* Set the ports */
config.port = to!(ushort)(generalBlock["port"].str());
/* Set the network name */
config.network = generalBlock["network"].str();
@ -127,16 +131,7 @@ public final class DGeneralConfig
public Address[] getAddresses()
{
/* Address(es) to listen on */
Address[] listenAddresses;
/* Create the addresses */
foreach(string address; addresses)
{
listenAddresses ~= parseAddress(address, port);
}
return listenAddresses;
return addresses;
}
}