2020-09-24 17:20:11 +00:00
|
|
|
import std.stdio;
|
|
|
|
|
|
|
|
import tristanable.manager;
|
|
|
|
import std.socket;
|
2020-09-24 23:08:51 +00:00
|
|
|
import client;
|
|
|
|
import std.string : cmp, split, strip;
|
|
|
|
import std.conv : to;
|
2020-09-25 17:51:24 +00:00
|
|
|
import notifications;
|
2020-09-24 17:20:11 +00:00
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2020-09-24 23:08:51 +00:00
|
|
|
commandLine();
|
|
|
|
}
|
|
|
|
|
|
|
|
void commandLine()
|
|
|
|
{
|
|
|
|
/* Current conneciton */
|
|
|
|
DClient client;
|
|
|
|
|
2020-09-25 17:51:24 +00:00
|
|
|
NotificationWatcher d;
|
|
|
|
|
2020-09-24 23:08:51 +00:00
|
|
|
/* The current command */
|
|
|
|
string commandLine;
|
2020-09-25 17:51:24 +00:00
|
|
|
|
|
|
|
string currentChannel;
|
2020-09-24 23:08:51 +00:00
|
|
|
|
|
|
|
while(true)
|
|
|
|
{
|
|
|
|
/* Read in a command line */
|
|
|
|
write("> ");
|
|
|
|
commandLine = readln();
|
2020-09-24 17:20:11 +00:00
|
|
|
|
2020-09-24 23:08:51 +00:00
|
|
|
if(cmp(strip(commandLine), "") == 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2020-09-24 17:20:11 +00:00
|
|
|
|
2020-09-24 23:08:51 +00:00
|
|
|
string[] elements = split(commandLine);
|
|
|
|
string command = elements[0];
|
|
|
|
|
|
|
|
/* If the command is `exit` */
|
|
|
|
if(cmp(command, "exit") == 0)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* 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));
|
2020-09-24 17:20:11 +00:00
|
|
|
|
2020-09-24 23:08:51 +00:00
|
|
|
writeln("Connecting to "~to!(string)(addr)~"...");
|
|
|
|
client = new DClient(addr);
|
2020-09-25 17:51:24 +00:00
|
|
|
d = new NotificationWatcher(client.getManager());
|
2020-09-24 23:08:51 +00:00
|
|
|
writeln("Connected!");
|
|
|
|
}
|
|
|
|
/* If the command is `auth` */
|
|
|
|
else if(cmp(command, "auth") == 0)
|
|
|
|
{
|
|
|
|
string username = elements[1];
|
|
|
|
string password = elements[2];
|
2020-09-24 17:20:11 +00:00
|
|
|
|
2020-09-25 17:51:24 +00:00
|
|
|
if(client.auth(username, password))
|
|
|
|
{
|
|
|
|
writeln("Auth good");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
writeln("Auth bad");
|
|
|
|
}
|
|
|
|
}
|
2020-09-25 20:16:23 +00:00
|
|
|
/* If the command is `list` */
|
|
|
|
else if(cmp(command, "list") == 0)
|
|
|
|
{
|
|
|
|
string[] channels = client.list();
|
|
|
|
writeln(channels);
|
|
|
|
}
|
2020-09-25 17:51:24 +00:00
|
|
|
/* If the command is `join` */
|
|
|
|
else if(cmp(command, "join") == 0)
|
|
|
|
{
|
|
|
|
string[] channels = elements[1..elements.length];
|
|
|
|
|
|
|
|
foreach(string channel; channels)
|
|
|
|
{
|
|
|
|
if(client.join(channel))
|
|
|
|
{
|
|
|
|
writeln("Already present in channel "~channel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
currentChannel = elements[elements.length-1];
|
|
|
|
}
|
|
|
|
/* If the command is `msg` */
|
|
|
|
else if(cmp(command, "open") == 0)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//client.sendMessage()
|
2020-09-24 23:08:51 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-24 17:20:11 +00:00
|
|
|
|
2020-09-24 23:08:51 +00:00
|
|
|
if(client)
|
|
|
|
{
|
2020-09-25 17:51:24 +00:00
|
|
|
client.disconnect();
|
2020-09-24 23:08:51 +00:00
|
|
|
}
|
|
|
|
|
2020-09-24 17:20:11 +00:00
|
|
|
}
|