From 9f7330a3dfb7ab36214025c9c9854e6f87c53fde Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Sat, 30 Jan 2021 12:49:39 +0200 Subject: [PATCH] WIP: Server linking Seg fault on link attempt it seems --- source/dnetd/dlink.d | 46 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/source/dnetd/dlink.d b/source/dnetd/dlink.d index 29f7565..74a7789 100644 --- a/source/dnetd/dlink.d +++ b/source/dnetd/dlink.d @@ -12,7 +12,7 @@ import std.socket; import gogga; import core.thread; import tristanable.encoding : DataMessage; -import bmessage : bSendMessage = sendMessage; +import bmessage : bSendMessage = sendMessage, bReceiveMessage = receiveMessage; /** * Link manager @@ -132,6 +132,24 @@ public final class DLink : Thread /* Initialize a new outbound connection */ initializeOutboundConnection(); + bool status = linkHandshake(); + + /* TODO: Implement me */ + while(true) + { + + } + } + + /** + * Performs the server LINK command and makes sure + * the server accepts the linking and also that the + * links name on our local server match up + */ + private bool linkHandshake() + { + bool status = true; + /* TODO: Send LINK (1) command */ byte[] data; data ~= [1]; @@ -145,13 +163,35 @@ public final class DLink : Thread DataMessage message = new DataMessage(0, data); bSendMessage(outboundSocket, message.encode()); + /* TODO: Await an acknowledgement [status] */ + byte[] receivedResponseBytes; + bReceiveMessage(outboundSocket, receivedResponseBytes); + DataMessage receivedResponse = DataMessage.decode(receivedResponseBytes); + ubyte[] dataReply = cast(ubyte[])receivedResponse.getData(); - /* TODO: Implement me */ - while(true) + /* TODO: 0 is good, 1 is bad */ + if(dataReply[0] == 0) { + /* TODO: Get server name, makes sure it matches on in config file */ + } + else if(dataReply[0] == 1) + { + /* TODO: Handle this case */ + gprintln("Server linking rejected", DebugType.ERROR); + status = false; + } + else + { + /* TODO: Handle this case */ + status = false; + } + /* TODO: If 0, then expect following [nameLen, name] */ + + + return status; }