From 90aeab834483b4acf98d2959103f29b97813e538 Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Thu, 28 Jan 2021 23:43:22 +0200 Subject: [PATCH] Pass DLinkCOnfig to DMeyer --- source/dnetd/dconfig.d | 13 ++++++++++--- source/dnetd/dconnection.d | 4 +++- source/dnetd/dlink.d | 6 ++++-- source/dnetd/dserver.d | 2 +- testing/1.json | 25 +++++++++++++++++++++++++ testing/2.json | 25 +++++++++++++++++++++++++ 6 files changed, 68 insertions(+), 7 deletions(-) create mode 100644 testing/1.json create mode 100644 testing/2.json diff --git a/source/dnetd/dconfig.d b/source/dnetd/dconfig.d index 377f139..c096779 100644 --- a/source/dnetd/dconfig.d +++ b/source/dnetd/dconfig.d @@ -47,8 +47,8 @@ public final class DConfig config.generalConfig = DGeneralConfig.getConfig(generalBlock); /* Get the `links` block */ - //JSONValue linksBlock = json["links"]; - //config.linksConfig = DLinkConfig.getConfig(linksBlock); + JSONValue linksBlock = json["links"]; + config.linksConfig = DLinkConfig.getConfig(linksBlock); } catch(JSONException e) { @@ -108,7 +108,6 @@ public final class DGeneralConfig /* Set the message of the day */ config.motd = generalBlock["motd"].str(); - } catch(JSONException e) { @@ -132,5 +131,13 @@ public final class DGeneralConfig public final class DLinkConfig { + public static DLinkConfig getConfig(JSONValue linksBlocks) + { + DLinkConfig dlinkConfig; + + + + return dlinkConfig; + } } \ No newline at end of file diff --git a/source/dnetd/dconnection.d b/source/dnetd/dconnection.d index 999ebbe..adcf032 100644 --- a/source/dnetd/dconnection.d +++ b/source/dnetd/dconnection.d @@ -377,9 +377,11 @@ public class DConnection : Thread else if(command == Command.LINK && !hasAuthed) { /* TODO: Implement me later */ + gprintln("Server is requesting a link..."); /* Check if this connection is a DLink'd one */ //server.getMeyer().get + gprintln("OurMeyer: "~to!(string)(server.getMeyer())); /* Set the type of this connection to `server` */ @@ -389,7 +391,7 @@ public class DConnection : Thread /* If `register` command (requires: unauthed, client) */ else if(command == Command.REGISTER && !hasAuthed && connType == ConnectionType.CLIENT) { - + /* TODO: Implement me */ } /* If `join` command (requires: authed, client) */ else if(command == Command.JOIN && hasAuthed && connType == ConnectionType.CLIENT) diff --git a/source/dnetd/dlink.d b/source/dnetd/dlink.d index e3404bb..db9f7ce 100644 --- a/source/dnetd/dlink.d +++ b/source/dnetd/dlink.d @@ -5,6 +5,7 @@ import core.sync.mutex : Mutex; import std.stdio; import std.conv; import dnetd.dserver; +import dnetd.dconfig; /** * DLink @@ -35,13 +36,14 @@ public final class DLink public final class DMeyer { - /* List of links (direct peers + additional information) */ + /* Direct peers */ private DLink[] links; private Mutex linksMutex; + /* Associated server */ private DServer server; - this(DServer server) + this(DServer server, DLinkConfig linkConfig) { this.server = server; linksMutex = new Mutex(); diff --git a/source/dnetd/dserver.d b/source/dnetd/dserver.d index 26e0f7b..b99daca 100644 --- a/source/dnetd/dserver.d +++ b/source/dnetd/dserver.d @@ -154,7 +154,7 @@ public class DServer : Thread private void startServer() { /* Initialize the Meyer linking sub-system */ - meyerSS = new DMeyer(this); + meyerSS = new DMeyer(this, config.getLinks()); /* Start the listener starter */ start(); diff --git a/testing/1.json b/testing/1.json new file mode 100644 index 0000000..e26e12f --- /dev/null +++ b/testing/1.json @@ -0,0 +1,25 @@ +{ + "general" : { + "binds" : [ + { + "address" : "0.0.0.0", + "port" : "5555" + }, + { + "address" : "::", + "port" : "5556" + }, + ], + "network" : "aBasedIRCNetwork", + "name" : "MyBrandSpankingNewIRCServer", + "motd" : "Welcome to my generic dnet chat server!" + }, + + "links" : { + "server1" : { + "name" : "server2", + "address" : "127.0.0.1", + "port" : "6666" + } + } +} diff --git a/testing/2.json b/testing/2.json new file mode 100644 index 0000000..ee8f22e --- /dev/null +++ b/testing/2.json @@ -0,0 +1,25 @@ +{ + "general" : { + "binds" : [ + { + "address" : "0.0.0.0", + "port" : "6666" + }, + { + "address" : "::", + "port" : "6667" + } + ], + "network" : "aBasedIRCNetwork", + "name" : "MyBrandSpankingNewIRCServer", + "motd" : "Welcome to my generic dnet chat server!" + }, + + "links" : { + "server1" : { + "name" : "server1", + "address" : "127.0.0.1", + "port" : "5555" + } + } +}