mirror of
https://github.com/deavminet/dnetd
synced 2024-09-21 17:53:39 +02:00
Implemented setProperty
on the server
This commit is contained in:
parent
3be0a028c6
commit
70549b8fdb
@ -55,6 +55,7 @@ public class DConnection : Thread
|
|||||||
GET_USER_PROP,
|
GET_USER_PROP,
|
||||||
SET_USER_PROP,
|
SET_USER_PROP,
|
||||||
DELETE_USER_PROP,
|
DELETE_USER_PROP,
|
||||||
|
IS_USER_PROP,
|
||||||
|
|
||||||
|
|
||||||
UNKNOWN
|
UNKNOWN
|
||||||
@ -318,6 +319,11 @@ public class DConnection : Thread
|
|||||||
{
|
{
|
||||||
command = Command.DELETE_USER_PROP;
|
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) */
|
/* If `set_user_prop` (requires: authed, client) */
|
||||||
else if(command == Command.SET_USER_PROP && hasAuthed && connType == ConnectionType.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) */
|
/* If `delete_user_prop` (requires: authed, client) */
|
||||||
else if(command == Command.DELETE_USER_PROP && hasAuthed && connType == ConnectionType.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];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -430,6 +430,33 @@ public class DServer : Thread
|
|||||||
return propertyValue;
|
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()
|
public string getServerInfo()
|
||||||
|
Loading…
Reference in New Issue
Block a user