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

Added server functions for isProperty and getProperty for users

This commit is contained in:
Tristan B. Kildaire 2020-10-20 09:54:42 +02:00
parent 3970a35cd0
commit 4af556a8c6
2 changed files with 93 additions and 4 deletions

View File

@ -293,8 +293,21 @@ public class DConnection : Thread
} }
else if(commandByte == 15) else if(commandByte == 15)
{ {
command = Command.SET_PROP; command = Command.GET_USER_PROPS;
} }
else if(commandByte == 16)
{
command = Command.GET_USER_PROP;
}
else if(commandByte == 17)
{
command = Command.SET_USER_PROP;
}
else if(commandByte == 18)
{
command = Command.DELETE_USER_PROP;
}
return command; return command;
@ -690,11 +703,17 @@ public class DConnection : Thread
/* If `get_user_prop` (requires: authed, client) */ /* If `get_user_prop` (requires: authed, client) */
else if(command == Command.GET_USER_PROP && hasAuthed && connType == ConnectionType.CLIENT) else if(command == Command.GET_USER_PROP && hasAuthed && connType == ConnectionType.CLIENT)
{ {
/* Get the <user>,<propertyName> */
string[] dataLine = split(cast(string)message.data[1..message.data.length],",");
/* Get the username */
string username = dataLine[0];
/* Get the proerty */ /* Get the proerty */
string propertyName = cast(string)message.data[1..message.data.length]; string propertyName = dataLine[1];
/* Determine if it is a valid property */ /* Determine if it is a valid property */
bool status = isProperty(propertyName); bool status = server.isProperty(username, propertyName);
/* Encode the status */ /* Encode the status */
reply ~= [status]; reply ~= [status];
@ -703,7 +722,7 @@ public class DConnection : Thread
if(status) if(status)
{ {
/* Get the property value */ /* Get the property value */
string propertyValue = getProperty(propertyName); string propertyValue = server.getProperty(username, propertyName);
/* Encode the property value */ /* Encode the property value */
reply ~= propertyValue; reply ~= propertyValue;

View File

@ -362,6 +362,76 @@ public class DServer : Thread
return matchedConnection.getStatusMessage(username); return matchedConnection.getStatusMessage(username);
} }
/**
* Checks whether the given user has the given
* property
*/
public bool isProperty(string username, string propertyName)
{
/* Whether or not the user has the given property */
bool status;
/* Lock the connections list */
connectionLock.lock();
/* The matching connection */
DConnection matchedConnection;
/* Find the connection */
foreach(DConnection connection; connectionQueue)
{
if(cmp(connection.getUsername(), username) == 0)
{
matchedConnection = connection;
break;
}
}
/* Unlock the connections list */
connectionLock.unlock();
/* Check for the user's property */
status = matchedConnection.isProperty(propertyName);
return status;
}
/**
* Checks whether the given user has the given
* property
*/
public string getProperty(string username, string propertyName)
{
/* The retrieved property value */
string propertyValue;
/* Lock the connections list */
connectionLock.lock();
/* The matching connection */
DConnection matchedConnection;
/* Find the connection */
foreach(DConnection connection; connectionQueue)
{
if(cmp(connection.getUsername(), username) == 0)
{
matchedConnection = connection;
break;
}
}
/* Unlock the connections list */
connectionLock.unlock();
/* Check for the user's property */
propertyValue = matchedConnection.getProperty(propertyName);
return propertyValue;
}
public string getServerInfo() public string getServerInfo()
{ {
/* The server information */ /* The server information */