WIP: Direct messages

This commit is contained in:
Tristan B. Kildaire 2021-01-28 15:21:08 +02:00
parent 5bac2157f8
commit 75ac2e16d4
1 changed files with 30 additions and 12 deletions

View File

@ -173,21 +173,39 @@ public final class Connection : Thread
/* Decode is a test for assuming channel message received */
data = data[1..data.length];
gprintln("Channe/User Notification: "~to!(string)(data));
/* Decode the [usernameLength, username] */
ubyte usernameLength = data[1];
gprintln("NormalMessage: (Username length): "~to!(string)(usernameLength));
string username = cast(string)data[2..2+usernameLength];
gprintln("NormalMessage: (Username): "~username);
/* Decode the [channelLength, channel] */
ubyte channelLength = data[2+usernameLength];
gprintln("NormalMessage: (Channel length): "~to!(string)(channelLength));
string channel = cast(string)data[2+usernameLength+1..2+usernameLength+1+channelLength];
gprintln("NormalMessage: (Channel): "~channel);
/* If this is a new message channel notification */
if(data[0] == 0)
{
gprintln("New channel message received", DebugType.WARNING);
findChannel(channel).receiveMessage(username, cast(string)data[2+usernameLength+1+channelLength..data.length]);
/* Decode the [usernameLength, username] */
ubyte usernameLength = data[1];
gprintln("NormalMessage: (Username length): "~to!(string)(usernameLength));
string username = cast(string)data[2..2+usernameLength];
gprintln("NormalMessage: (Username): "~username);
/* Decode the [channelLength, channel] */
ubyte channelLength = data[2+usernameLength];
gprintln("NormalMessage: (Channel length): "~to!(string)(channelLength));
string channel = cast(string)data[2+usernameLength+1..2+usernameLength+1+channelLength];
gprintln("NormalMessage: (Channel): "~channel);
findChannel(channel).receiveMessage(username, cast(string)data[2+usernameLength+1+channelLength..data.length]);
}
/* If this is a new direct message notification */
else if(data[1] == 1)
{
gprintln("New direct message received", DebugType.WARNING);
}
else
{
/* TODO: Handle this */
}
}
/* Channel notification (ntype=1) */
else if(notificationType == 1)