1
0
mirror of https://github.com/deavminet/dnetd synced 2024-09-21 17:53:39 +02:00

WIP: Server linking

Seg fault on link attempt it seems
This commit is contained in:
Tristan B. Kildaire 2021-01-30 12:49:39 +02:00
parent 9f0d66b7bc
commit 9f7330a3df

View File

@ -12,7 +12,7 @@ import std.socket;
import gogga; import gogga;
import core.thread; import core.thread;
import tristanable.encoding : DataMessage; import tristanable.encoding : DataMessage;
import bmessage : bSendMessage = sendMessage; import bmessage : bSendMessage = sendMessage, bReceiveMessage = receiveMessage;
/** /**
* Link manager * Link manager
@ -132,6 +132,24 @@ public final class DLink : Thread
/* Initialize a new outbound connection */ /* Initialize a new outbound connection */
initializeOutboundConnection(); 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 */ /* TODO: Send LINK (1) command */
byte[] data; byte[] data;
data ~= [1]; data ~= [1];
@ -145,13 +163,35 @@ public final class DLink : Thread
DataMessage message = new DataMessage(0, data); DataMessage message = new DataMessage(0, data);
bSendMessage(outboundSocket, message.encode()); 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 */ /* TODO: 0 is good, 1 is bad */
while(true) 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;
} }