mirror of
https://github.com/deavminet/dnetd
synced 2024-09-21 09:43:37 +02:00
Added server functions for isProperty
and getProperty
for users
This commit is contained in:
parent
3970a35cd0
commit
4af556a8c6
@ -293,8 +293,21 @@ public class DConnection : Thread
|
||||
}
|
||||
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;
|
||||
@ -690,11 +703,17 @@ public class DConnection : Thread
|
||||
/* If `get_user_prop` (requires: authed, 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 */
|
||||
string propertyName = cast(string)message.data[1..message.data.length];
|
||||
string propertyName = dataLine[1];
|
||||
|
||||
/* Determine if it is a valid property */
|
||||
bool status = isProperty(propertyName);
|
||||
bool status = server.isProperty(username, propertyName);
|
||||
|
||||
/* Encode the status */
|
||||
reply ~= [status];
|
||||
@ -703,7 +722,7 @@ public class DConnection : Thread
|
||||
if(status)
|
||||
{
|
||||
/* Get the property value */
|
||||
string propertyValue = getProperty(propertyName);
|
||||
string propertyValue = server.getProperty(username, propertyName);
|
||||
|
||||
/* Encode the property value */
|
||||
reply ~= propertyValue;
|
||||
|
@ -362,6 +362,76 @@ public class DServer : Thread
|
||||
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()
|
||||
{
|
||||
/* The server information */
|
||||
|
Loading…
Reference in New Issue
Block a user