From 44cce182ae0cab25232a9d4aed1221ae535d36ca Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Wed, 15 Mar 2023 16:32:49 +0200 Subject: [PATCH] ConnectionInfo - Set default `fakeLag` to `1` - Added `getFakeLag()` and `setFakeLag()` Client - Added `getConnInfo()` to return the client's associated `ConnectionInfo` Sender - Use the fakelag configured by user --- source/birchwood/client/client.d | 9 +++++++++ source/birchwood/client/sender.d | 5 +---- source/birchwood/config/conninfo.d | 15 ++++++++++++++- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/source/birchwood/client/client.d b/source/birchwood/client/client.d index 71cdbb7..445d225 100644 --- a/source/birchwood/client/client.d +++ b/source/birchwood/client/client.d @@ -71,6 +71,10 @@ public class Client : Thread //TODO: Do something here, tare downs } + public ConnectionInfo getConnInfo() + { + return connInfo; + } /** @@ -875,6 +879,11 @@ public class Client : Thread //snootnet: 178.62.125.123 //bonobonet: fd08:8441:e254::5 ConnectionInfo connInfo = ConnectionInfo.newConnection("worcester.community.networks.deavmi.assigned.network", 6667, "testBirchwood"); + + // // Set the fakelag to 1 second + // connInfo.setFakeLag(1); + + // Create a new Client Client client = new Client(connInfo); client.connect(); diff --git a/source/birchwood/client/sender.d b/source/birchwood/client/sender.d index 2db0b65..8f22468 100644 --- a/source/birchwood/client/sender.d +++ b/source/birchwood/client/sender.d @@ -79,9 +79,6 @@ public final class SenderThread : Thread */ private void sendHandlerFunc() { - /* TODO: Hoist up into ConnInfo */ - ulong fakeLagInBetween = 1; - while(client.running) { // // Do a once-off call to `ensure()` here which then only runs once and @@ -115,7 +112,7 @@ public final class SenderThread : Thread foreach(ubyte[] message; sendQueue[]) { client.socket.send(message); - Thread.sleep(dur!("seconds")(fakeLagInBetween)); + Thread.sleep(dur!("seconds")(client.getConnInfo().getFakeLag())); } /* Empty the send queue */ diff --git a/source/birchwood/config/conninfo.d b/source/birchwood/config/conninfo.d index d1fee31..ce2b9be 100644 --- a/source/birchwood/config/conninfo.d +++ b/source/birchwood/config/conninfo.d @@ -14,7 +14,7 @@ public struct ConnectionInfo private ulong bulkReadSize; /* Client behaviour (TODO: what is sleep(0), like nothing) */ - private ulong fakeLag = 0; + private ulong fakeLag; /* The quit message */ public const string quitMessage; @@ -26,6 +26,9 @@ public struct ConnectionInfo this.nickname = nickname; this.bulkReadSize = bulkReadSize; this.quitMessage = quitMessage; + + // Set the default fakelag to 1 + this.fakeLag = 1; } public ulong getBulkReadSize() @@ -38,6 +41,16 @@ public struct ConnectionInfo return addrInfo; } + public ulong getFakeLag() + { + return fakeLag; + } + + public void setFakeLag(ulong fakeLag) + { + this.fakeLag = fakeLag; + } + /** * Creates a ConnectionInfo struct representing a client configuration which * can be provided to the Client class to create a new connection based on its