Added check for response value before generating list, added Javadoc

This commit is contained in:
Tristan B. Kildaire 2020-09-29 09:41:44 +02:00
parent 8a55a7c026
commit a0c9cc9986
2 changed files with 29 additions and 8 deletions

View File

@ -182,12 +182,14 @@ void commandLine()
/* If the command is `query` */
else if(cmp(command, "query") == 0)
{
/* Get the username to query */
string user = elements[1];
/* Set current "channel" to username */
currentChannel = user;
/* Set mode to USER */
currentMode = Mode.USER;
}
else
{
@ -208,6 +210,7 @@ void commandLine()
if(dclient)
{
/* TODO: Fix in tristanable */
dclient.disconnect();
}

View File

@ -4,7 +4,7 @@ import std.stdio;
import std.conv : to;
import std.string : split;
public class DClient
public final class DClient
{
/**
* tristanabale tag manager
@ -12,6 +12,9 @@ public class DClient
private Manager manager;
/* TODO: Tristsnable doesn't, unlike my java version, let youn really reuse tags */
/* TODO: Reason is after use they do not get deleted, only later by garbage collector */
/* TODO: To prevent weird stuff from possibly going down, we use unique ones each time */
private long i = 20;
this(Address address)
{
@ -50,6 +53,13 @@ public class DClient
}
/**
* Joins the given channel
*
* @param channel the channel to join
* @returns bool true if the join was
* successful, false otherwise
*/
public bool join(string channel)
{
/* TODO: DO oneshot as protocol supports csv channels */
@ -68,11 +78,15 @@ public class DClient
return cast(bool)resp[0];
}
/**
* Lists all the channels on the server
*
* @returns string[] the list of channels
*/
public string[] list()
{
//static ulong i = 50;
/* List of channels */
string[] channels;
/* The protocol data to send */
@ -84,10 +98,14 @@ public class DClient
/* Receive the server's response */
byte[] resp = manager.receiveMessage(i);
string channelList = cast(string)resp[1..resp.length];
channels = split(channelList, ",");
/* Only generate a list if command was successful */
if(resp[0])
{
/* Generate the channel list */
string channelList = cast(string)resp[1..resp.length];
channels = split(channelList, ",");
}
/* TODO: Throw error on resp[0] zero */
i++;
return channels;