Now allow custom connects

This commit is contained in:
Tristan B. Kildaire 2020-09-26 18:40:31 +02:00
parent 1fee8c96b2
commit fa620ba152
2 changed files with 71 additions and 9 deletions

View File

@ -6,9 +6,27 @@ import client;
import std.string : cmp, split, strip;
import std.conv : to;
import notifications;
import std.file;
import std.json;
JSONValue config;
void main()
{
/* Check if the default config exists */
if(exists("/home/deavmi/.config/skippy/config")) /* TODO: Change */
{
/* Load the config */
loadConfig("/home/deavmi/.config/skippy/config");
}
else
{
/* Set default config */
defaultConfig();
}
/* Start the REPL */
commandLine();
}
@ -46,14 +64,38 @@ void commandLine()
/* If the command is `connect` */
else if(cmp(command, "connect") == 0)
{
string address = elements[1];
string port = elements[2];
Address addr = parseAddress(address, to!(ushort)(port));
/* If there is only one argument then it is a server name */
if(elements.length == 2)
{
string serverName = elements[1];
try
{
/* Get the address and port */
JSONValue serverInfo = config["servers"][serverName];
}
catch(JSONException e)
{
writeln("Could not find server: "~to!(string)(e));
}
}
/* Then it must be `<address> <port>` */
else if(elements.length == 3)
{
string address = elements[1];
string port = elements[2];
Address addr = parseAddress(address, to!(ushort)(port));
writeln("Connecting to "~to!(string)(addr)~"...");
client = new DClient(addr);
d = new NotificationWatcher(client.getManager());
writeln("Connected!");
writeln("Connecting to "~to!(string)(addr)~"...");
client = new DClient(addr);
d = new NotificationWatcher(client.getManager());
writeln("Connected!");
}
/* Syntax error */
else
{
writeln("Syntax error");
}
}
/* If the command is `auth` */
else if(cmp(command, "auth") == 0)
@ -74,7 +116,11 @@ void commandLine()
else if(cmp(command, "list") == 0)
{
string[] channels = client.list();
writeln(channels);
writeln("Channels ("~to!(string)(channels.length)~" total)\n");
foreach(string channel; channels)
{
writeln("\t"~channel);
}
}
/* If the command is `join` */
else if(cmp(command, "join") == 0)
@ -108,3 +154,19 @@ void commandLine()
}
}
void defaultConfig()
{
/* Server block */
JSONValue serverBlock;
/* TODO: Remove test servers? */
serverBlock["dserv"] = "";
config["servers"] = serverBlock;
}
void loadConfig(string configPath)
{
/* TODO: Implement me */
}

View File

@ -65,7 +65,7 @@ public class DClient
byte[] resp = manager.receiveMessage(1);
string channelList = cast(string)resp[1..resp.length];
channels = split(channelList);
channels = split(channelList, ",");
/* TODO: Throw error on resp[0] zero */