From e1848d9b89d3c61b11585ec7e99b18f68e676ce1 Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Mon, 26 Oct 2020 13:32:33 +0200 Subject: [PATCH] Why the fuck would I do it like that --- source/dnetd/dconnection.d | 10 +++++++--- source/dnetd/dserver.d | 30 +++++++++++------------------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/source/dnetd/dconnection.d b/source/dnetd/dconnection.d index 71d170f..7dc622a 100644 --- a/source/dnetd/dconnection.d +++ b/source/dnetd/dconnection.d @@ -689,10 +689,14 @@ public class DConnection : Thread /* If `get_user_props` (requires: authed, client) */ else if(command == Command.GET_USER_PROPS && hasAuthed && connType == ConnectionType.CLIENT) { - /* Get all properties */ - string[] propertyKeys = getProperties(); + /* Get the username */ + string username = cast(string)message.data[1..message.data.length]; - /* TODO: This should take in a username */ + /* Get the user */ + DConnection connection = server.findUser(username); + + /* Get all properties of the user */ + string[] propertyKeys = connection.getProperties(); /* Encode the status */ reply ~= [true]; diff --git a/source/dnetd/dserver.d b/source/dnetd/dserver.d index fb3945b..98c5390 100644 --- a/source/dnetd/dserver.d +++ b/source/dnetd/dserver.d @@ -265,11 +265,14 @@ public class DServer : Thread */ public DConnection findUser(string username) { - /* Get all the current connections */ - DConnection[] connections = getConnections(); + /* The found Connection */ + DConnection foundConnection; + + /* Lock the connections list */ + connectionLock.lock(); /* Find the user with the matching user name */ - foreach(DConnection connection; connections) + foreach(DConnection connection; connectionQueue) { /* The connection must be a user (not unspec or server) */ if(connection.getConnectionType() == DConnection.ConnectionType.CLIENT) @@ -277,28 +280,15 @@ public class DServer : Thread /* Match the username */ if(cmp(connection.getUsername(), username) == 0) { - return connection; + foundConnection = connection; } } } - return null; - } - - public DConnection[] getConnections() - { - /* The current connections list */ - DConnection[] currentConnections; - - /* Lock the connections list */ - connectionLock.lock(); - - currentConnections = connectionQueue; - /* Unlock the connections list */ connectionLock.unlock(); - - return currentConnections; + + return foundConnection; } public bool channelExists(string channelName) @@ -396,6 +386,8 @@ public class DServer : Thread return status; } + /* TODO: All these functions can really be re-duced, why am I not using getConnection() */ + /** * Checks whether the given user has the given * property