diff --git a/source/dnetd/dconnection.d b/source/dnetd/dconnection.d index 47e0eac..04a6078 100644 --- a/source/dnetd/dconnection.d +++ b/source/dnetd/dconnection.d @@ -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 ,, */ + 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 , */ + 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]; + } diff --git a/source/dnetd/dserver.d b/source/dnetd/dserver.d index c695d15..fb3945b 100644 --- a/source/dnetd/dserver.d +++ b/source/dnetd/dserver.d @@ -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()