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) { 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()) { if (sendingNode->getCanKick()) {
// From the packet, pull the UUID we're identifying // From the packet, pull the UUID we're identifying
QUuid nodeUUID = QUuid::fromRfc4122(message->readWithoutCopy(NUM_BYTES_RFC4122_UUID)); QUuid nodeUUID = QUuid::fromRfc4122(message->readWithoutCopy(NUM_BYTES_RFC4122_UUID));
// If the UUID isn't NULL...
if (!nodeUUID.isNull()) { 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 limitedNodeList = DependencyManager::get<LimitedNodeList>();
auto matchingNode = limitedNodeList->nodeWithUUID(nodeUUID); auto matchingNode = limitedNodeList->nodeWithUUID(nodeUUID);
// If we do have a matching node...
if (matchingNode) { 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(); QString verifiedUsername = matchingNode->getPermissions().getVerifiedUserName();
// If the verified username is Empty...
if (verifiedUsername.isEmpty()) { if (verifiedUsername.isEmpty()) {
// Make sure we're using an empty string as the Verified Username
verifiedUsername = ""; verifiedUsername = "";
} }
// setup the packet // Setup the packet
auto usernameFromIDReplyPacket = NLPacket::create(PacketType::UsernameFromIDReply, NUM_BYTES_RFC4122_UUID + sizeof(verifiedUsername), true); auto usernameFromIDReplyPacket = NLPacket::create(PacketType::UsernameFromIDReply, NUM_BYTES_RFC4122_UUID + sizeof(verifiedUsername), true);
// write the node ID to the packet // write the node ID to the packet
@ -775,6 +779,7 @@ void DomainServerSettingsManager::processUsernameFromIDRequestPacket(QSharedPoin
// write the username to the packet // write the username to the packet
usernameFromIDReplyPacket->writeString(verifiedUsername); usernameFromIDReplyPacket->writeString(verifiedUsername);
// Ship it!
limitedNodeList->sendPacket(std::move(usernameFromIDReplyPacket), *sendingNode); limitedNodeList->sendPacket(std::move(usernameFromIDReplyPacket), *sendingNode);
} }
else { else {
@ -782,7 +787,7 @@ void DomainServerSettingsManager::processUsernameFromIDRequestPacket(QSharedPoin
} }
} }
else { 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."; qWarning() << "Node username request received for invalid node ID. Refusing to process.";
} }

View file

@ -72,17 +72,20 @@ Rectangle {
table.selection.deselect(userIndex); table.selection.deselect(userIndex);
} }
break; break;
// Received an "updateUsername()" request from the JS
case 'updateUsername': case 'updateUsername':
// The User ID (UUID) is the first parameter in the message.
var userId = message.params[0]; var userId = message.params[0];
// The Username String (name + UUID) is the second parameter in the message.
var userName = message.params[1]; var userName = message.params[1];
console.log('passed userId:', userId); // If the userId is empty, we're updating "myData".
console.log('passed userName:', userName);
if (!userId) { if (!userId) {
myData.userName = userName; myData.userName = userName;
myCard.userName = userName; myCard.userName = userName;
} else { } else {
// Get the index in userModel and userData associated with the passed UUID
var userIndex = findSessionIndex(userId); var userIndex = findSessionIndex(userId);
console.log('computed userIndex:', userIndex); // Set the userName appropriately
userModel.get(userIndex).userName = userName; userModel.get(userIndex).userName = userName;
userData[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) { void NodeList::requestUsernameFromSessionID(const QUuid& nodeID) {
// send a request to domain-server to get the username associated with the given session ID // 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 // setup the packet
auto usernameFromIDRequestPacket = NLPacket::create(PacketType::UsernameFromIDRequest, NUM_BYTES_RFC4122_UUID, true); 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()); usernameFromIDRequestPacket->write(nodeID.toRfc4122());
} }
qDebug() << "Sending packet to get username of node" << uuidStringWithoutCurlyBraces(nodeID); qDebug() << "Sending packet to get username of node" << uuidStringWithoutCurlyBraces(nodeID);
sendPacket(std::move(usernameFromIDRequestPacket), _domainHandler.getSockAddr()); sendPacket(std::move(usernameFromIDRequestPacket), _domainHandler.getSockAddr());
@ -923,5 +922,5 @@ void NodeList::processUsernameFromIDReply(QSharedPointer<ReceivedMessage> messag
qDebug() << "Got username" << username << "for node" << nodeUUIDString; 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 receivedDomainServerList();
void ignoredNode(const QUuid& nodeID); void ignoredNode(const QUuid& nodeID);
void ignoreRadiusEnabledChanged(bool isIgnored); void ignoreRadiusEnabledChanged(bool isIgnored);
void usernameFromID(const QString& nodeID, const QString& username); void usernameFromIDReply(const QString& nodeID, const QString& username);
private slots: private slots:
void stopKeepalivePingTimer(); void stopKeepalivePingTimer();

View file

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

View file

@ -104,7 +104,7 @@ signals:
* Notifies scripts of the username associated with a UUID. * Notifies scripts of the username associated with a UUID.
* @function Users.enteredIgnoreRadius * @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: '', userName: '',
sessionId: id || '' 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); Users.requestUsernameFromID(id);
} }
data.push(avatarPalDatum); data.push(avatarPalDatum);
@ -133,14 +136,19 @@ function populateUserList() {
pal.sendToQml({method: 'users', params: data}); 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; var data;
// If the ID we've received is our ID...
if (AvatarList.getAvatar('').sessionUUID === id) { if (AvatarList.getAvatar('').sessionUUID === id) {
// Set the data to contain specific strings.
data = ['', username + ' (hidden)'] data = ['', username + ' (hidden)']
} else { } else {
// Set the data to contain the ID and the username+ID concat string.
data = [id, username + '/' + id]; data = [id, username + '/' + id];
} }
print('Username Data:', JSON.stringify(data)); print('Username Data:', JSON.stringify(data));
// Ship the data off to QML
pal.sendToQml({ method: 'updateUsername', params: data }); pal.sendToQml({ method: 'updateUsername', params: data });
} }
@ -264,7 +272,7 @@ function onVisibileChanged() {
button.clicked.connect(onClicked); button.clicked.connect(onClicked);
pal.visibleChanged.connect(onVisibileChanged); pal.visibleChanged.connect(onVisibileChanged);
pal.closed.connect(off); pal.closed.connect(off);
Users.usernameFromID.connect(usernameFromID); Users.usernameFromIDReply.connect(usernameFromIDReply);
// //
// Cleanup. // Cleanup.
@ -274,7 +282,7 @@ Script.scriptEnding.connect(function () {
toolBar.removeButton(buttonName); toolBar.removeButton(buttonName);
pal.visibleChanged.disconnect(onVisibileChanged); pal.visibleChanged.disconnect(onVisibileChanged);
pal.closed.disconnect(off); pal.closed.disconnect(off);
Users.usernameFromID.disconnect(usernameFromID); Users.usernameFromIDReply.disconnect(usernameFromIDReply);
off(); off();
}); });