diff --git a/source/dnetd/dchannel.d b/source/dnetd/dchannel.d index 7581aaf..a78f639 100644 --- a/source/dnetd/dchannel.d +++ b/source/dnetd/dchannel.d @@ -9,6 +9,7 @@ module dnetd.dchannel; import dnetd.dconnection : DConnection; +import core.sync.mutex : Mutex; public class DChannel { @@ -22,10 +23,12 @@ public class DChannel * Users in this channel */ private DConnection[] members; + private Mutex memberLock; this(string name) { - + /* Initialize the lock */ + memberLock = new Mutex(); } public string getName() @@ -34,8 +37,30 @@ public class DChannel } public void join(DConnection client) + { + /* Lock the members list */ + memberLock.lock(); + + /** + * TODO: Error handling if the calling DConnection fails midway + * and doesn't unlock it + */ + + /* Add the client */ + members ~= client; + + /* Unlock the members list */ + memberLock.unlock(); + } + + public void leave(DConnection client) { } + + public override string toString() + { + return "DChannel [Name: "~name~", Members: "~members~"]"; + } } \ No newline at end of file