diff --git a/source/birchwood/client/receiver.d b/source/birchwood/client/receiver.d index fcc9fb0..95b54ff 100644 --- a/source/birchwood/client/receiver.d +++ b/source/birchwood/client/receiver.d @@ -5,11 +5,15 @@ import core.thread : Thread, dur; import std.container.slist : SList; import core.sync.mutex : Mutex; +import eventy : EventyEvent = Event; + // TODO: Examine the below import which seemingly fixes stuff for libsnooze import libsnooze.clib; import libsnooze; import birchwood.client; +import birchwood.protocol.messages : Message, decodeMessage; +import std.string : indexOf; public final class ReceiverThread : Thread { @@ -40,7 +44,10 @@ public final class ReceiverThread : Thread */ this(Client client) { + super(&recvHandlerFunc); this.client = client; + this.receiveEvent = new Event(); // TODO: Catch any libsnooze error here + this.recvQueueLock = new Mutex(); } /** @@ -59,7 +66,7 @@ public final class ReceiverThread : Thread */ private void recvHandlerFunc() { - while(running) + while(client.running) { // TODO: Insert libsnooze wait here @@ -137,8 +144,8 @@ public final class ReceiverThread : Thread /* TODO: Implement */ // TODO: Remove the Eventy push and replace with a handler call (on second thought no) - Event pongEvent = new PongEvent(pingID); - engine.push(pongEvent); + EventyEvent pongEvent = new PongEvent(pingID); + client.engine.push(pongEvent); } /* Now let's go message by message */ @@ -159,8 +166,8 @@ public final class ReceiverThread : Thread curMsg = Message.parseReceivedMessage(messageNormal); // TODO: Remove the Eventy push and replace with a handler call (on second thought no) - Event ircEvent = new IRCEvent(curMsg); - engine.push(ircEvent); + EventyEvent ircEvent = new IRCEvent(curMsg); + client.engine.push(ircEvent); } diff --git a/source/birchwood/client/sender.d b/source/birchwood/client/sender.d index 4bbe45c..773be68 100644 --- a/source/birchwood/client/sender.d +++ b/source/birchwood/client/sender.d @@ -40,7 +40,10 @@ public final class SenderThread : Thread */ this(Client client) { + super(&sendHandlerFunc); this.client = client; + this.sendEvent = new Event(); // TODO: Catch any libsnooze error here + this.sendQueueLock = new Mutex(); } /** @@ -54,7 +57,7 @@ public final class SenderThread : Thread /* TODO: Hoist up into ConnInfo */ ulong fakeLagInBetween = 1; - while(running) + while(client.running) { // TODO: Insert libsnooze wait here @@ -70,7 +73,7 @@ public final class SenderThread : Thread foreach(ubyte[] message; sendQueue[]) { - this.socket.send(message); + client.socket.send(message); Thread.sleep(dur!("seconds")(fakeLagInBetween)); } diff --git a/source/birchwood/constants.d b/source/birchwood/protocol/constants.d similarity index 99% rename from source/birchwood/constants.d rename to source/birchwood/protocol/constants.d index 0965fa2..e3ab7d6 100644 --- a/source/birchwood/constants.d +++ b/source/birchwood/protocol/constants.d @@ -1,4 +1,4 @@ -module birchwood.constants; +module birchwood.protocol.constants; /* Reply object */ public enum ReplyType : ulong diff --git a/source/birchwood/messages.d b/source/birchwood/protocol/messages.d similarity index 98% rename from source/birchwood/messages.d rename to source/birchwood/protocol/messages.d index a7d4cab..101033d 100644 --- a/source/birchwood/messages.d +++ b/source/birchwood/protocol/messages.d @@ -1,10 +1,10 @@ -module birchwood.messages; +module birchwood.protocol.messages; import dlog; import std.string; import std.conv : to, ConvException; -import birchwood.constants : ReplyType; +import birchwood.protocol.constants : ReplyType; // TODO: Before release we should remove this import import std.stdio : writeln; diff --git a/source/birchwood/protocol/package.d b/source/birchwood/protocol/package.d new file mode 100644 index 0000000..073ce31 --- /dev/null +++ b/source/birchwood/protocol/package.d @@ -0,0 +1,3 @@ +module birchwood.protocol; + +public import birchwood.protocol.messages : Message; \ No newline at end of file