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

View File

@ -4,7 +4,7 @@ import std.stdio;
import std.conv : to; import std.conv : to;
import std.string : split; import std.string : split;
public class DClient public final class DClient
{ {
/** /**
* tristanabale tag manager * tristanabale tag manager
@ -12,6 +12,9 @@ public class DClient
private Manager manager; 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; private long i = 20;
this(Address address) 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) public bool join(string channel)
{ {
/* TODO: DO oneshot as protocol supports csv channels */ /* TODO: DO oneshot as protocol supports csv channels */
@ -68,11 +78,15 @@ public class DClient
return cast(bool)resp[0]; return cast(bool)resp[0];
} }
/**
* Lists all the channels on the server
*
* @returns string[] the list of channels
*/
public string[] list() public string[] list()
{ {
//static ulong i = 50; /* List of channels */
string[] channels; string[] channels;
/* The protocol data to send */ /* The protocol data to send */
@ -84,10 +98,14 @@ public class DClient
/* Receive the server's response */ /* Receive the server's response */
byte[] resp = manager.receiveMessage(i); byte[] resp = manager.receiveMessage(i);
string channelList = cast(string)resp[1..resp.length]; /* Only generate a list if command was successful */
channels = split(channelList, ","); 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++; i++;
return channels; return channels;