Updated to working version of tristnabel

This commit is contained in:
Tristan B. Kildaire 2020-10-16 17:15:39 +02:00
parent 6729642e25
commit 11862d0d72
4 changed files with 84 additions and 84 deletions

View File

@ -4,7 +4,7 @@
],
"copyright": "Copyright © 2020, Tristan B. Kildaire",
"dependencies": {
"libdnet": "~>0.1.0",
"libdnet": "~>0.1.2",
},
"description": "dnet client",
"license": "GPLv3",

View File

@ -2,7 +2,7 @@
"fileVersion": 1,
"versions": {
"bformat": "1.0.8",
"libdnet": "0.1.0",
"tristanable": "0.1.0"
"libdnet": "0.1.2",
"tristanable": "0.1.1"
}
}

View File

@ -4,7 +4,7 @@ import std.socket;
import libdnet.dclient : DClient;
import std.string : cmp, split, strip;
import std.conv : to;
import notifications;
// import notifications;
import std.file;
import std.json;
@ -13,7 +13,7 @@ JSONValue config;
/* Current conneciton */
DClient dclient;
NotificationWatcher dnotifications;
//NotificationWatcher dnotifications;
Mode currentMode;
@ -128,7 +128,7 @@ void commandLine()
addr = getAddress(address, to!(ushort)(port))[0];
writeln("Connecting to "~to!(string)(addr)~"...");
dclient = new DClient(addr);
dnotifications= new NotificationWatcher(dclient.getManager());
//dnotifications= new NotificationWatcher(dclient.getManager());
writeln("Connected!");
/* Get the message of the day */

View File

@ -1,91 +1,91 @@
import core.thread : Thread;
import tristanable.manager;
import tristanable.notifications;
import std.stdio;
import core.time : dur;
import tristanable.encoding;
// import core.thread : Thread;
// import tristanable.manager;
// import tristanable.notifications;
// import std.stdio;
// import core.time : dur;
// import tristanable.encoding;
public class NotificationWatcher : Thread
{
private Manager manager;
// public class NotificationWatcher : Thread
// {
// private Manager manager;
this(Manager manager)
{
super(&worker);
// this(Manager manager)
// {
// super(&worker);
this.manager = manager;
manager.reserveTag(0);
// this.manager = manager;
// manager.reserveTag(0);
start();
}
// start();
// }
private void worker()
{
while(true)
{
/* Check for notifications every 2 seconds */
NotificationReply[] notifications =manager.popNotifications();
// private void worker()
// {
// while(true)
// {
// /* Check for notifications every 2 seconds */
// NotificationReply[] notifications =manager.popNotifications();
if(notifications.length)
{
//writeln(notifications);
foreach(NotificationReply notificationReply; notifications)
{
//writeln(notificationReply.getData());
string msg = cast(string)notificationReply.getData();
writeln("!> "~msg);
process(notificationReply.getData());
}
}
// if(notifications.length)
// {
// //writeln(notifications);
// foreach(NotificationReply notificationReply; notifications)
// {
// //writeln(notificationReply.getData());
// string msg = cast(string)notificationReply.getData();
// writeln("!> "~msg);
// process(notificationReply.getData());
// }
// }
Thread.getThis().sleep(dur!("seconds")(2));
}
}
// Thread.getThis().sleep(dur!("seconds")(2));
// }
// }
/**
* Processes an incoming notification
* accordingly
*/
private void process(byte[] data)
{
/* TODO: Implement me */
// /**
// * Processes an incoming notification
// * accordingly
// */
// private void process(byte[] data)
// {
// /* TODO: Implement me */
/* TODO: Check notification type */
byte notificationType = data[0];
// /* TODO: Check notification type */
// byte notificationType = data[0];
/* For normal message (to channel or user) */
if(notificationType == cast(byte)0)
{
/* TODO: Decode using tristanable */
writeln("new message");
}
/* Channel notification (ntype=1) */
else if(notificationType == cast(byte)1)
{
/* TODO: Decode using tristanable */
/* TODO: Get the username of the user that left */
//writeln("user left/join message");
// /* For normal message (to channel or user) */
// if(notificationType == cast(byte)0)
// {
// /* TODO: Decode using tristanable */
// writeln("new message");
// }
// /* Channel notification (ntype=1) */
// else if(notificationType == cast(byte)1)
// {
// /* TODO: Decode using tristanable */
// /* TODO: Get the username of the user that left */
// //writeln("user left/join message");
/* Get the sub-type */
byte subType = data[1];
// /* Get the sub-type */
// byte subType = data[1];
/* If the notification was leave (stype=0) */
if(subType == cast(byte)0)
{
string username = cast(string)data[2..data.length];
writeln("<-- "~username~" left the channel");
}
/* If the notification was join (stype=1) */
else if(subType == cast(byte)1)
{
string username = cast(string)data[2..data.length];
writeln("--> "~username~" joined the channel");
}
/* TODO: Unknown */
else
{
// /* If the notification was leave (stype=0) */
// if(subType == cast(byte)0)
// {
// string username = cast(string)data[2..data.length];
// writeln("<-- "~username~" left the channel");
// }
// /* If the notification was join (stype=1) */
// else if(subType == cast(byte)1)
// {
// string username = cast(string)data[2..data.length];
// writeln("--> "~username~" joined the channel");
// }
// /* TODO: Unknown */
// else
// {
}
}
}
}
// }
// }
// }
// }