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

Implemented setProperty on the server

This commit is contained in:
Tristan B. Kildaire 2020-10-20 10:45:17 +02:00
parent 3be0a028c6
commit 70549b8fdb
2 changed files with 75 additions and 0 deletions

View File

@ -55,6 +55,7 @@ public class DConnection : Thread
GET_USER_PROP,
SET_USER_PROP,
DELETE_USER_PROP,
IS_USER_PROP,
UNKNOWN
@ -318,6 +319,11 @@ public class DConnection : Thread
{
command = Command.DELETE_USER_PROP;
}
else if(commandByte == 19)
{
command = Command.IS_USER_PROP;
}
@ -742,13 +748,55 @@ public class DConnection : Thread
/* If `set_user_prop` (requires: authed, client) */
else if(command == Command.SET_USER_PROP && hasAuthed && connType == ConnectionType.CLIENT)
{
/* Get the <user>,<propertyName>,<propertyValue> */
string[] dataLine = split(cast(string)message.data[1..message.data.length],",");
/* Get the username */
string username = dataLine[0];
/* Get the property */
string propertyName = dataLine[1];
/* Get the property value */
string propertyValue = dataLine[2];
/* Determine if it is a valid property */
bool status = server.isProperty(username, propertyName);
/* Encode the status */
reply ~= [status];
/* Encode the property value if one exists */
if(status)
{
/* Set the property value */
server.setProperty(username, propertyName, propertyValue);
}
}
/* If `delete_user_prop` (requires: authed, client) */
else if(command == Command.DELETE_USER_PROP && hasAuthed && connType == ConnectionType.CLIENT)
{
}
/* If `is_user_prop` (requires: authed, client) */
else if(command == Command.IS_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 = dataLine[1];
/* Determine if it is a valid property */
bool status = server.isProperty(username, propertyName);
/* Encode the status */
reply ~= [true];
reply ~= [status];
}

View File

@ -430,6 +430,33 @@ public class DServer : Thread
return propertyValue;
}
/**
* Set the property of the given user to the given value
*/
public void setProperty(string username, string propertyName, 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();
/* Set the property's value of the user */
matchedConnection.setProperty(propertyName, propertyValue);
}
public string getServerInfo()