Comments and clarity

This commit is contained in:
Zach Fox 2016-12-16 14:38:39 -08:00
parent aa837d8858
commit e940daf5b4
7 changed files with 34 additions and 19 deletions

View file

@ -748,26 +748,30 @@ void DomainServerSettingsManager::processNodeKickRequestPacket(QSharedPointer<Re
}
}
// This function processes the "Get Username from ID" request.
void DomainServerSettingsManager::processUsernameFromIDRequestPacket(QSharedPointer<ReceivedMessage> message, SharedNodePointer sendingNode) {
// before we do any processing on this packet make sure it comes from a node that is allowed to kick
// Before we do any processing on this packet, make sure it comes from a node that is allowed to kick (is an admin)
if (sendingNode->getCanKick()) {
// From the packet, pull the UUID we're identifying
QUuid nodeUUID = QUuid::fromRfc4122(message->readWithoutCopy(NUM_BYTES_RFC4122_UUID));
// If the UUID isn't NULL...
if (!nodeUUID.isNull()) {
// make sure we actually have a node with this UUID
// First, make sure we actually have a node with this UUID
auto limitedNodeList = DependencyManager::get<LimitedNodeList>();
auto matchingNode = limitedNodeList->nodeWithUUID(nodeUUID);
// If we do have a matching node...
if (matchingNode) {
// we have a matching node, time to figure out the username
// It's time to figure out the username
QString verifiedUsername = matchingNode->getPermissions().getVerifiedUserName();
// If the verified username is Empty...
if (verifiedUsername.isEmpty()) {
// Make sure we're using an empty string as the Verified Username
verifiedUsername = "";
}
// setup the packet
// Setup the packet
auto usernameFromIDReplyPacket = NLPacket::create(PacketType::UsernameFromIDReply, NUM_BYTES_RFC4122_UUID + sizeof(verifiedUsername), true);
// write the node ID to the packet
@ -775,6 +779,7 @@ void DomainServerSettingsManager::processUsernameFromIDRequestPacket(QSharedPoin
// write the username to the packet
usernameFromIDReplyPacket->writeString(verifiedUsername);
// Ship it!
limitedNodeList->sendPacket(std::move(usernameFromIDReplyPacket), *sendingNode);
}
else {
@ -782,7 +787,7 @@ void DomainServerSettingsManager::processUsernameFromIDRequestPacket(QSharedPoin
}
}
else {
// this isn't a UUID we can use
// This isn't a UUID we can use
qWarning() << "Node username request received for invalid node ID. Refusing to process.";
}

View file

@ -72,17 +72,20 @@ Rectangle {
table.selection.deselect(userIndex);
}
break;
// Received an "updateUsername()" request from the JS
case 'updateUsername':
// The User ID (UUID) is the first parameter in the message.
var userId = message.params[0];
// The Username String (name + UUID) is the second parameter in the message.
var userName = message.params[1];
console.log('passed userId:', userId);
console.log('passed userName:', userName);
// If the userId is empty, we're updating "myData".
if (!userId) {
myData.userName = userName;
myCard.userName = userName;
} else {
// Get the index in userModel and userData associated with the passed UUID
var userIndex = findSessionIndex(userId);
console.log('computed userIndex:', userIndex);
// Set the userName appropriately
userModel.get(userIndex).userName = userName;
userData[userIndex].userName = userName;
}

View file

@ -893,7 +893,7 @@ void NodeList::muteNodeBySessionID(const QUuid& nodeID) {
void NodeList::requestUsernameFromSessionID(const QUuid& nodeID) {
// send a request to domain-server to get the username associated with the given session ID
if (getThisNodeCanKick()) {
if (getThisNodeCanKick() || nodeID.isNull()) {
// setup the packet
auto usernameFromIDRequestPacket = NLPacket::create(PacketType::UsernameFromIDRequest, NUM_BYTES_RFC4122_UUID, true);
@ -904,7 +904,6 @@ void NodeList::requestUsernameFromSessionID(const QUuid& nodeID) {
usernameFromIDRequestPacket->write(nodeID.toRfc4122());
}
qDebug() << "Sending packet to get username of node" << uuidStringWithoutCurlyBraces(nodeID);
sendPacket(std::move(usernameFromIDRequestPacket), _domainHandler.getSockAddr());
@ -923,5 +922,5 @@ void NodeList::processUsernameFromIDReply(QSharedPointer<ReceivedMessage> messag
qDebug() << "Got username" << username << "for node" << nodeUUIDString;
emit usernameFromID(nodeUUIDString, username);
emit usernameFromIDReply(nodeUUIDString, username);
}

View file

@ -111,7 +111,7 @@ signals:
void receivedDomainServerList();
void ignoredNode(const QUuid& nodeID);
void ignoreRadiusEnabledChanged(bool isIgnored);
void usernameFromID(const QString& nodeID, const QString& username);
void usernameFromIDReply(const QString& nodeID, const QString& username);
private slots:
void stopKeepalivePingTimer();

View file

@ -18,7 +18,7 @@ UsersScriptingInterface::UsersScriptingInterface() {
auto nodeList = DependencyManager::get<NodeList>();
connect(nodeList.data(), &LimitedNodeList::canKickChanged, this, &UsersScriptingInterface::canKickChanged);
connect(nodeList.data(), &NodeList::ignoreRadiusEnabledChanged, this, &UsersScriptingInterface::ignoreRadiusEnabledChanged);
connect(nodeList.data(), &NodeList::usernameFromID, this, &UsersScriptingInterface::usernameFromID);
connect(nodeList.data(), &NodeList::usernameFromIDReply, this, &UsersScriptingInterface::usernameFromIDReply);
}
void UsersScriptingInterface::ignore(const QUuid& nodeID) {

View file

@ -104,7 +104,7 @@ signals:
* Notifies scripts of the username associated with a UUID.
* @function Users.enteredIgnoreRadius
*/
void usernameFromID(const QString& nodeID, const QString& username);
void usernameFromIDReply(const QString& nodeID, const QString& username);
};

View file

@ -121,7 +121,10 @@ function populateUserList() {
userName: '',
sessionId: id || ''
};
if (Users.canKick) {
// If the current user is an admin OR
// they're requesting their own username ("id" is blank)...
if (Users.canKick || !id) {
// Request the username from the given UUID
Users.requestUsernameFromID(id);
}
data.push(avatarPalDatum);
@ -133,14 +136,19 @@ function populateUserList() {
pal.sendToQml({method: 'users', params: data});
}
function usernameFromID(id, username) {
// The function that handles the reply from the server
function usernameFromIDReply(id, username) {
var data;
// If the ID we've received is our ID...
if (AvatarList.getAvatar('').sessionUUID === id) {
// Set the data to contain specific strings.
data = ['', username + ' (hidden)']
} else {
// Set the data to contain the ID and the username+ID concat string.
data = [id, username + '/' + id];
}
print('Username Data:', JSON.stringify(data));
// Ship the data off to QML
pal.sendToQml({ method: 'updateUsername', params: data });
}
@ -264,7 +272,7 @@ function onVisibileChanged() {
button.clicked.connect(onClicked);
pal.visibleChanged.connect(onVisibileChanged);
pal.closed.connect(off);
Users.usernameFromID.connect(usernameFromID);
Users.usernameFromIDReply.connect(usernameFromIDReply);
//
// Cleanup.
@ -274,7 +282,7 @@ Script.scriptEnding.connect(function () {
toolBar.removeButton(buttonName);
pal.visibleChanged.disconnect(onVisibileChanged);
pal.closed.disconnect(off);
Users.usernameFromID.disconnect(usernameFromID);
Users.usernameFromIDReply.disconnect(usernameFromIDReply);
off();
});