diff --git a/source/dnetd/dchannel.d b/source/dnetd/dchannel.d index b02c54b..af66a0c 100644 --- a/source/dnetd/dchannel.d +++ b/source/dnetd/dchannel.d @@ -37,6 +37,9 @@ public class DChannel return name; } + /** + * Joins the given client to this channel + */ public void join(DConnection client) { /* Lock the members list */ @@ -54,6 +57,9 @@ public class DChannel memberLock.unlock(); } + /** + * Removes the given client from this channel + */ public void leave(DConnection client) { /* Lock the members list */ @@ -78,6 +84,25 @@ public class DChannel memberLock.unlock(); } + public void sendMessage(DConnection sender, string message) + { + /* TODO: Generate message */ + /* TODO: Spec out in protocol */ + /* TODO: Reserved tag 0 for notifications */ + byte[] msg; + + /* Send the message to everyone else in the channel */ + foreach(DConnection member; members) + { + /* Skip sending to self */ + if(!(member is sender)) + { + /* Send the message */ + member.writeSocket(0, msg); + } + } + } + public override string toString() { string toStr; diff --git a/source/dnetd/dconnection.d b/source/dnetd/dconnection.d index b228514..51609f2 100644 --- a/source/dnetd/dconnection.d +++ b/source/dnetd/dconnection.d @@ -110,7 +110,7 @@ public class DConnection : Thread * socket to the client/server, and unlocks the * mutex */ - private bool writeSocket(long tag, byte[] data) + public bool writeSocket(long tag, byte[] data) { /* Send status */ bool status; @@ -265,6 +265,63 @@ public class DConnection : Thread /* TODO: Implement me, use return value */ writeSocket(tag, reply); } + /* If `msg` command (requires: authed) */ + else if(commandByte == 7 && hasAuthed) + { + /* Status */ + bool status = true; + + /* Get the type of message */ + byte messageType = message.data[0]; + + /* Get the channel/person name */ + string destination; + ulong i = 0; + while(message.data[1+i] != cast(byte)0) + { + destination ~= message.data[1+i]; + i++; + } + + /* Get the message (offset from null-terminator, hence +1 at the end) */ + string msg = cast(string)message.data[1+i+1..message.data.length]; + + /* If we are sending to a user */ + if(messageType == cast(byte)0) + { + /* TODO Implemet me */ + } + /* If we are sending to a channel */ + else if(messageType == cast(ubyte)1) + { + /* If the channel exists */ + if(server.getChannelByName(destination)) + { + /* TODO Implemet me */ + } + /* If the channel does not exist */ + else + { + status = false; + } + } + /* Unknown destination type */ + else + { + status = false; + } + + + + /* TODO: Handling here, should we make the user wait? */ + + /* Encode the reply */ + // byte[] reply = [status]; + // reply ~= channelList; + + /* TODO: Implement me, use return value */ + // writeSocket(tag, reply); + } /* TODO: Handle this case */ else {