Added 'list' command

This commit is contained in:
Tristan B. Kildaire 2020-09-25 22:16:23 +02:00
parent 6feeb0a332
commit 1fee8c96b2
3 changed files with 37 additions and 0 deletions

View File

@ -70,6 +70,12 @@ void commandLine()
writeln("Auth bad"); writeln("Auth bad");
} }
} }
/* If the command is `list` */
else if(cmp(command, "list") == 0)
{
string[] channels = client.list();
writeln(channels);
}
/* If the command is `join` */ /* If the command is `join` */
else if(cmp(command, "join") == 0) else if(cmp(command, "join") == 0)
{ {

View File

@ -2,6 +2,7 @@ import tristanable.manager : Manager;
import std.socket; import std.socket;
import std.stdio; import std.stdio;
import std.conv : to; import std.conv : to;
import std.string : split;
public class DClient public class DClient
{ {
@ -54,6 +55,23 @@ public class DClient
return cast(bool)resp[0]; return cast(bool)resp[0];
} }
public string[] list()
{
string[] channels;
byte[] data = [6];
manager.sendMessage(1, data);
byte[] resp = manager.receiveMessage(1);
string channelList = cast(string)resp[1..resp.length];
channels = split(channelList);
/* TODO: Throw error on resp[0] zero */
return channels;
}
public Manager getManager() public Manager getManager()
{ {
return manager; return manager;

View File

@ -33,10 +33,23 @@ public class NotificationWatcher : Thread
writeln(notificationReply.getData()); writeln(notificationReply.getData());
string msg = cast(string)notificationReply.getData(); string msg = cast(string)notificationReply.getData();
writeln("!> "~msg); writeln("!> "~msg);
process(notificationReply.getData());
} }
} }
Thread.getThis().sleep(dur!("seconds")(2)); Thread.getThis().sleep(dur!("seconds")(2));
} }
} }
/**
* Processes an incoming notification
* accordingly
*/
private void process(byte[] data)
{
/* TODO: Implement me */
/* TODO: Check notification type */
byte notificationType = data[0];
}
} }