From 1e3ca829fb872fba1d81ac6d7576ee63440e25e1 Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Sat, 30 Jan 2021 16:27:41 +0200 Subject: [PATCH] Refactored --- source/dnetd/dconnection.d | 24 ++++++++++++++++++++---- source/dnetd/dlink.d | 5 +++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/source/dnetd/dconnection.d b/source/dnetd/dconnection.d index 4fafdf5..7782db2 100644 --- a/source/dnetd/dconnection.d +++ b/source/dnetd/dconnection.d @@ -177,6 +177,25 @@ public class DConnection : Thread { gprintln(to!(string)(this)~" Cleaning up connection..."); + /* Leave all channels this connetion was a member of */ + cleanUp_channels(); + + /* Remove this user from the connection queue */ + server.removeConnection(this); + + gprintln(to!(string)(this)~" Connection cleaned up"); + } + + /** + * Part of the clean up process - `cleanUp()` + * + * Will leave all channels this connection is + * a member of + */ + private void cleanUp_channels() + { + gprintln(to!(string)(this)~" Leaving all channels..."); + /* Remove this user from all channels he is in */ DChannel[] channels = server.getChannels(); @@ -191,11 +210,8 @@ public class DConnection : Thread gprintln(to!(string)(this)~" Leaving '"~currentChannel.getName()~"'..."); } } - - /* Remove this user from the connection queue */ - server.removeConnection(this); - gprintln(to!(string)(this)~" Connection cleaned up"); + gprintln(to!(string)(this)~" Leaving all channels... [done]"); } /* TODO: add mutex for writing with message and funciton for doing so */ diff --git a/source/dnetd/dlink.d b/source/dnetd/dlink.d index 8f64fda..325e77a 100644 --- a/source/dnetd/dlink.d +++ b/source/dnetd/dlink.d @@ -227,6 +227,7 @@ public final class DLink : Thread this(server, name, address); /* Save connection */ + //this.connection = connection; } public string getName() @@ -258,6 +259,9 @@ public final class DMeyer : Thread start(); } + /** + * Every 3 seconds information on what servers are linked will be printed out + */ private void worker() { while(true) @@ -265,6 +269,7 @@ public final class DMeyer : Thread linksMutex.lock(); gprintln("Linked servers: "~to!(string)(links), DebugType.WARNING); linksMutex.unlock(); + Thread.sleep(dur!("seconds")(3)); } }