mirror of
https://github.com/deavminet/skippy.git
synced 2025-01-18 11:50:51 +00:00
Upgraded to new libdnet, working on restoring notifications support to skippy
This commit is contained in:
parent
72f44d6ead
commit
219b1b8211
2
dub.json
2
dub.json
@ -4,7 +4,7 @@
|
||||
],
|
||||
"copyright": "Copyright © 2020, Tristan B. Kildaire",
|
||||
"dependencies": {
|
||||
"libdnet": "~>0.1.13"
|
||||
"libdnet": "~>0.1.15"
|
||||
},
|
||||
"description": "dnet client",
|
||||
"license": "GPLv3",
|
||||
|
@ -2,7 +2,7 @@
|
||||
"fileVersion": 1,
|
||||
"versions": {
|
||||
"bformat": "1.0.8",
|
||||
"libdnet": "0.1.13",
|
||||
"libdnet": "0.1.15",
|
||||
"tristanable": "0.1.1"
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
writeln("Connected!");
|
||||
|
||||
/* Get the message of the day */
|
||||
|
@ -1,91 +1,94 @@
|
||||
// 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 DClient client;
|
||||
|
||||
// this(Manager manager)
|
||||
// {
|
||||
// super(&worker);
|
||||
this(DClient 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());
|
||||
|
||||
// Thread.getThis().sleep(dur!("seconds")(2));
|
||||
// }
|
||||
// }
|
||||
/* Await a notification */
|
||||
manager.awaitNotification();
|
||||
string msg = cast(string)notificationReply.getData();
|
||||
writeln("!> "~msg);
|
||||
process(notificationReply.getData());
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Processes an incoming notification
|
||||
// * accordingly
|
||||
// */
|
||||
// private void process(byte[] data)
|
||||
// {
|
||||
// /* TODO: Implement me */
|
||||
Thread.getThis().sleep(dur!("seconds")(2));
|
||||
}
|
||||
}
|
||||
|
||||
// /* TODO: Check notification type */
|
||||
// byte notificationType = data[0];
|
||||
/**
|
||||
* Processes an incoming notification
|
||||
* accordingly
|
||||
*/
|
||||
private void process(byte[] data)
|
||||
{
|
||||
/* TODO: Implement me */
|
||||
|
||||
// /* 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");
|
||||
/* TODO: Check notification type */
|
||||
byte notificationType = data[0];
|
||||
|
||||
// /* Get the sub-type */
|
||||
// byte subType = data[1];
|
||||
/* 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");
|
||||
|
||||
// /* 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
|
||||
// {
|
||||
/* 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
|
||||
{
|
||||
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user