Why the fuck would I do it like that

This commit is contained in:
Tristan B. Kildaire 2020-10-26 13:32:33 +02:00
parent c560d9d4d9
commit e1848d9b89
2 changed files with 18 additions and 22 deletions

View File

@ -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];

View File

@ -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