1
0
mirror of https://github.com/deavmi/birchwood synced 2024-09-20 11:43:22 +02:00

ConnectionInfo

- Updated `string getDB(string)` to `T getDB(T)(string)` which will now attempt conversion to type `T`, on failure to do so it will return `T.init`

ConnInfo

- Added `setDefaults(ref ConnectionInfo)` which will set defaults in the `db`, namely so far it sets the `MAXNICKLEN` to `9` as per rfc1459

Package (`birchwood.config`)

- Now publically imports `setDefaults()`
This commit is contained in:
Tristan B. Velloza Kildaire 2023-03-25 13:37:18 +02:00
parent 1015a4ec1c
commit 9ca98ac664
2 changed files with 27 additions and 3 deletions

View File

@ -5,6 +5,7 @@ module birchwood.config.conninfo;
import std.socket : SocketException, Address, getAddress;
import birchwood.client.exceptions;
import std.conv : to, ConvException;
/**
* Represents the connection details for a server
@ -127,11 +128,25 @@ public shared struct ConnectionInfo
db[key] = value;
}
public string getDB(string key)
public T getDB(T)(string key)
{
import std.stdio;
writeln("GETDB: '"~key~"' with len ", key.length);
if(key in db)
{
return db[key];
/* Attempt conversion into T */
try
{
/* Fetch and convert */
T value = to!(T)(db[key]);
return value;
}
/* If conversion to type T fails */
catch(ConvException e)
{
/* Return the initial value for such a paremeter */
return T.init;
}
}
else
{
@ -205,4 +220,13 @@ public shared struct ConnectionInfo
}
}
}
public void setDefaults(ref ConnectionInfo connInfo)
{
/* Set the `MAXNICKLEN` to a default of 9 */
connInfo.updateDB("MAXNICKLEN", "9");
assert(connInfo.getDB!(ulong)("MAXNICKLEN") == 9);
import std.stdio;
writeln("MAXKAK: ", connInfo.getDB!(ulong)("MAXNICKLEN"));
}

View File

@ -6,4 +6,4 @@ module birchwood.config;
/**
* Connection information
*/
public import birchwood.config.conninfo : ConnectionInfo;
public import birchwood.config.conninfo : ConnectionInfo, setDefaults;