mirror of
https://github.com/deavminet/skippy.git
synced 2025-01-20 21:11:13 +00:00
Now allow custom connects
This commit is contained in:
parent
1fee8c96b2
commit
fa620ba152
78
source/app.d
78
source/app.d
@ -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 */
|
||||
}
|
@ -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 */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user