State of refactoring

This commit is contained in:
Kalila L 2021-03-17 19:37:06 -04:00
parent 712b5e5088
commit 0216b34681
9 changed files with 77 additions and 42 deletions

View file

@ -37,6 +37,7 @@
#include <SettingHandle.h> #include <SettingHandle.h>
#include <SettingHelpers.h> #include <SettingHelpers.h>
#include <FingerprintUtils.h> #include <FingerprintUtils.h>
#include <ModerationFlags.h>
#include "DomainServerNodeData.h" #include "DomainServerNodeData.h"
@ -864,15 +865,17 @@ void DomainServerSettingsManager::processNodeKickRequestPacket(QSharedPointer<Re
QUuid nodeUUID = QUuid::fromRfc4122(message->readWithoutCopy(NUM_BYTES_RFC4122_UUID)); QUuid nodeUUID = QUuid::fromRfc4122(message->readWithoutCopy(NUM_BYTES_RFC4122_UUID));
bool hasOptionalBanParameters = false; bool hasOptionalBanParameters = false;
bool banByUsername = false; int banParameters;
bool banByFingerprint = false; bool banByUsername;
bool banByIP = false; bool banByFingerprint;
bool banByIP;
// pull optional ban parameters from the packet // pull optional ban parameters from the packet
if (message.data()->getSize() > NUM_BYTES_RFC4122_UUID) { if (message.data()->getSize() > NUM_BYTES_RFC4122_UUID) {
hasOptionalBanParameters = true; hasOptionalBanParameters = true;
message->readPrimitive(&banByUsername); message->readPrimitive(&banParameters);
message->readPrimitive(&banByFingerprint); banByUsername = banParameters & ModerationFlags::BanFlags::BAN_BY_USERNAME;
message->readPrimitive(&banByIP); banByFingerprint = banParameters & ModerationFlags::BanFlags::BAN_BY_FINGERPRINT;
banByIP = banParameters & ModerationFlags::BanFlags::BAN_BY_IP;
} }
if (!nodeUUID.isNull() && nodeUUID != sendingNode->getUUID()) { if (!nodeUUID.isNull() && nodeUUID != sendingNode->getUUID()) {
@ -894,28 +897,16 @@ void DomainServerSettingsManager::processNodeKickRequestPacket(QSharedPointer<Re
// if we have a verified user name for this user, we first apply the kick to the username // if we have a verified user name for this user, we first apply the kick to the username
// if we have optional ban parameters, we should ban the username based on the parameter // if we have optional ban parameters, we should ban the username based on the parameter
if (hasOptionalBanParameters) { if (!hasOptionalBanParameters || banByUsername) {
if (banByUsername) {
// check if there were already permissions
bool hadPermissions = havePermissionsForName(verifiedUsername);
// grab or create permissions for the given username
auto userPermissions = _agentPermissions[matchingNode->getPermissions().getKey()];
newPermissions = !hadPermissions || userPermissions->can(NodePermissions::Permission::canConnectToDomain);
// ensure that the connect permission is clear
userPermissions->clear(NodePermissions::Permission::canConnectToDomain);
}
} else {
// check if there were already permissions // check if there were already permissions
bool hadPermissions = havePermissionsForName(verifiedUsername); bool hadPermissions = havePermissionsForName(verifiedUsername);
// grab or create permissions for the given username // grab or create permissions for the given username
auto userPermissions = _agentPermissions[matchingNode->getPermissions().getKey()]; auto userPermissions = _agentPermissions[matchingNode->getPermissions().getKey()];
newPermissions = !hadPermissions || userPermissions->can(NodePermissions::Permission::canConnectToDomain); newPermissions =
!hadPermissions || userPermissions->can(NodePermissions::Permission::canConnectToDomain);
// ensure that the connect permission is clear // ensure that the connect permission is clear
userPermissions->clear(NodePermissions::Permission::canConnectToDomain); userPermissions->clear(NodePermissions::Permission::canConnectToDomain);
} }

View file

@ -2493,7 +2493,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
return viewFrustum.getPosition(); return viewFrustum.getPosition();
}); });
DependencyManager::get<UsersScriptingInterface>()->setKickConfirmationOperator([this] (const QUuid& nodeID, bool banByUsername, bool banByFingerprint, bool banByIP) { userKickConfirmation(nodeID, banByUsername, banByFingerprint, banByIP); }); DependencyManager::get<UsersScriptingInterface>()->setKickConfirmationOperator([this] (const QUuid& nodeID, int banFlags) { userKickConfirmation(nodeID, banFlags); });
render::entities::WebEntityRenderer::setAcquireWebSurfaceOperator([=](const QString& url, bool htmlContent, QSharedPointer<OffscreenQmlSurface>& webSurface, bool& cachedWebSurface) { render::entities::WebEntityRenderer::setAcquireWebSurfaceOperator([=](const QString& url, bool htmlContent, QSharedPointer<OffscreenQmlSurface>& webSurface, bool& cachedWebSurface) {
bool isTablet = url == TabletScriptingInterface::QML; bool isTablet = url == TabletScriptingInterface::QML;
@ -3575,7 +3575,7 @@ void Application::onDesktopRootItemCreated(QQuickItem* rootItem) {
_desktopRootItemCreated = true; _desktopRootItemCreated = true;
} }
void Application::userKickConfirmation(const QUuid& nodeID, bool banByUsername, bool banByFingerprint, bool banByIP) { void Application::userKickConfirmation(const QUuid& nodeID, int banFlags) {
auto avatarHashMap = DependencyManager::get<AvatarHashMap>(); auto avatarHashMap = DependencyManager::get<AvatarHashMap>();
auto avatar = avatarHashMap->getAvatarBySessionID(nodeID); auto avatar = avatarHashMap->getAvatarBySessionID(nodeID);
@ -3600,7 +3600,7 @@ void Application::userKickConfirmation(const QUuid& nodeID, bool banByUsername,
// ask the NodeList to kick the user with the given session ID // ask the NodeList to kick the user with the given session ID
if (yes) { if (yes) {
DependencyManager::get<NodeList>()->kickNodeBySessionID(nodeID, banByUsername, banByFingerprint, banByIP); DependencyManager::get<NodeList>()->kickNodeBySessionID(nodeID, banFlags);
} }
DependencyManager::get<UsersScriptingInterface>()->setWaitForKickResponse(false); DependencyManager::get<UsersScriptingInterface>()->setWaitForKickResponse(false);

View file

@ -608,7 +608,7 @@ private:
void toggleTabletUI(bool shouldOpen = false) const; void toggleTabletUI(bool shouldOpen = false) const;
bool shouldCaptureMouse() const; bool shouldCaptureMouse() const;
void userKickConfirmation(const QUuid& nodeID, bool banByUsername, bool banByFingerprint, bool banByIP); void userKickConfirmation(const QUuid& nodeID, int banFlags);
MainWindow* _window; MainWindow* _window;
QElapsedTimer& _sessionRunTimer; QElapsedTimer& _sessionRunTimer;

View file

@ -42,6 +42,7 @@
#include "udt/PacketHeaders.h" #include "udt/PacketHeaders.h"
#include "SharedUtil.h" #include "SharedUtil.h"
#include <Trace.h> #include <Trace.h>
#include <ModerationFlags.h>
using namespace std::chrono; using namespace std::chrono;
@ -1263,21 +1264,30 @@ float NodeList::getInjectorGain() {
return _injectorGain; return _injectorGain;
} }
void NodeList::kickNodeBySessionID(const QUuid& nodeID, bool banByUsername, bool banByFingerprint, bool banByIP) { void NodeList::kickNodeBySessionID(const QUuid& nodeID, int banFlags) {
// send a request to domain-server to kick the node with the given session ID // send a request to domain-server to kick the node with the given session ID
// the domain-server will handle the persistence of the kick (via username or IP) // the domain-server will handle the persistence of the kick (via username or IP)
if (!nodeID.isNull() && getSessionUUID() != nodeID ) { if (!nodeID.isNull() && getSessionUUID() != nodeID ) {
if (getThisNodeCanKick()) { if (getThisNodeCanKick()) {
// setup the packet // setup the packet
auto kickPacket = NLPacket::create(PacketType::NodeKickRequest, NUM_BYTES_RFC4122_UUID + (sizeof(bool) * 3), true); auto kickPacket = NLPacket::create(PacketType::NodeKickRequest, NUM_BYTES_RFC4122_UUID + sizeof(int), true);
//int banParameters {};
//if (banByUsername) {
// banParameters |= ModerationFlags::BanFlags::BAN_BY_USERNAME;
//}
//if (banByFingerprint) {
// banParameters |= ModerationFlags::BanFlags::BAN_BY_FINGERPRINT;
//}
//if (banByIP) {
// banParameters |= ModerationFlags::BanFlags::BAN_BY_IP;
//}
// write the node ID to the packet // write the node ID to the packet
kickPacket->write(nodeID.toRfc4122()); kickPacket->write(nodeID.toRfc4122());
// write the ban parameters to the packet // write the ban parameters to the packet
kickPacket->writePrimitive(banByUsername); kickPacket->writePrimitive(banFlags);
kickPacket->writePrimitive(banByFingerprint);
kickPacket->writePrimitive(banByIP);
qCDebug(networking) << "Sending packet to kick node" << uuidStringWithoutCurlyBraces(nodeID); qCDebug(networking) << "Sending packet to kick node" << uuidStringWithoutCurlyBraces(nodeID);

View file

@ -86,7 +86,7 @@ public:
void setInjectorGain(float gain); void setInjectorGain(float gain);
float getInjectorGain(); float getInjectorGain();
void kickNodeBySessionID(const QUuid& nodeID, bool banByUsername = true, bool banByFingerprint = true, bool banByIP = false); void kickNodeBySessionID(const QUuid& nodeID, int banFlags);
void muteNodeBySessionID(const QUuid& nodeID); void muteNodeBySessionID(const QUuid& nodeID);
void requestUsernameFromSessionID(const QUuid& nodeID); void requestUsernameFromSessionID(const QUuid& nodeID);
bool getRequestsDomainListData() { return _requestsDomainListData; } bool getRequestsDomainListData() { return _requestsDomainListData; }

View file

@ -1,3 +1,4 @@
// //
// UserActivityLoggerScriptingInterface.h // UserActivityLoggerScriptingInterface.h
// libraries/networking/src // libraries/networking/src

View file

@ -52,15 +52,14 @@ float UsersScriptingInterface::getAvatarGain(const QUuid& nodeID) {
return DependencyManager::get<NodeList>()->getAvatarGain(nodeID); return DependencyManager::get<NodeList>()->getAvatarGain(nodeID);
} }
void UsersScriptingInterface::kick(const QUuid& nodeID, bool banByUsername, bool banByFingerprint, bool banByIP) { void UsersScriptingInterface::kick(const QUuid& nodeID, int banFlags) {
if (_kickConfirmationOperator) { if (_kickConfirmationOperator) {
bool waitingForKickResponse = _kickResponseLock.resultWithReadLock<bool>([&] { return _waitingForKickResponse; }); bool waitingForKickResponse = _kickResponseLock.resultWithReadLock<bool>([&] { return _waitingForKickResponse; });
if (getCanKick() && !waitingForKickResponse) { if (getCanKick() && !waitingForKickResponse) {
_kickConfirmationOperator(nodeID, banByUsername, banByFingerprint, banByIP); _kickConfirmationOperator(nodeID, banFlags);
} }
} else { } else {
DependencyManager::get<NodeList>()->kickNodeBySessionID(nodeID, banByUsername, banByFingerprint, banByIP); DependencyManager::get<NodeList>()->kickNodeBySessionID(nodeID, banFlags);
} }
} }

View file

@ -17,6 +17,7 @@
#include <DependencyManager.h> #include <DependencyManager.h>
#include <shared/ReadWriteLockable.h> #include <shared/ReadWriteLockable.h>
#include <ModerationFlags.h>
/**jsdoc /**jsdoc
* The <code>Users</code> API provides features to regulate your interaction with other users. * The <code>Users</code> API provides features to regulate your interaction with other users.
@ -40,9 +41,14 @@ class UsersScriptingInterface : public QObject, public Dependency {
Q_PROPERTY(bool canKick READ getCanKick) Q_PROPERTY(bool canKick READ getCanKick)
Q_PROPERTY(bool requestsDomainListData READ getRequestsDomainListData WRITE setRequestsDomainListData) Q_PROPERTY(bool requestsDomainListData READ getRequestsDomainListData WRITE setRequestsDomainListData)
Q_PROPERTY(unsigned int NO_BAN READ ModerationFlags::BanFlags::NO_BAN CONSTANT)
Q_PROPERTY(unsigned int BAN_BY_USERNAME READ ModerationFlags::BanFlags::BAN_BY_USERNAME CONSTANT)
Q_PROPERTY(unsigned int BAN_BY_FINGERPRINT READ ModerationFlags::BanFlags::BAN_BY_FINGERPRINT CONSTANT)
Q_PROPERTY(unsigned int BAN_BY_IP READ ModerationFlags::BanFlags::BAN_BY_IP CONSTANT)
public: public:
UsersScriptingInterface(); UsersScriptingInterface();
void setKickConfirmationOperator(std::function<void(const QUuid& nodeID, bool banByUsername, bool banByFingerprint, bool banByIP)> kickConfirmationOperator) { void setKickConfirmationOperator(std::function<void(const QUuid& nodeID, int banFlags)> kickConfirmationOperator) {
_kickConfirmationOperator = kickConfirmationOperator; _kickConfirmationOperator = kickConfirmationOperator;
} }
@ -113,7 +119,7 @@ public slots:
/**jsdoc /**jsdoc
* Kicks and bans a user. This removes them from the server and prevents them from returning. The ban is by user name if * Kicks and bans a user. This removes them from the server and prevents them from returning. The ban is by user name if
* available and by machine fingerprint. * available and by machine fingerprint. The ban functionality can be controlled with flags.
* <p>This function only works if you're an administrator of the domain you're in.</p> * <p>This function only works if you're an administrator of the domain you're in.</p>
* @function Users.kick * @function Users.kick
* @param {Uuid} sessionID - The session ID of the user to kick and ban. * @param {Uuid} sessionID - The session ID of the user to kick and ban.
@ -121,7 +127,7 @@ public slots:
* @param {boolean} [banByFingerprint=true] - Should ban the user's machine fingerprint. * @param {boolean} [banByFingerprint=true] - Should ban the user's machine fingerprint.
* @param {boolean} [banByIP=false] - Should ban the user's IP address. * @param {boolean} [banByIP=false] - Should ban the user's IP address.
*/ */
void kick(const QUuid& nodeID, bool banByUsername = true, bool banByFingerprint = true, bool banByIP = false); void kick(const QUuid& nodeID, int banFlags = 0);
/**jsdoc /**jsdoc
* Mutes a user's microphone for everyone. The mute is not permanent: the user can unmute themselves. * Mutes a user's microphone for everyone. The mute is not permanent: the user can unmute themselves.
@ -241,7 +247,7 @@ private:
bool getRequestsDomainListData(); bool getRequestsDomainListData();
void setRequestsDomainListData(bool requests); void setRequestsDomainListData(bool requests);
std::function<void(const QUuid& nodeID, bool banByUsername, bool banByFingerprint, bool banByIP)> _kickConfirmationOperator; std::function<void(const QUuid& nodeID, int banFlags)> _kickConfirmationOperator;
ReadWriteLockable _kickResponseLock; ReadWriteLockable _kickResponseLock;
bool _waitingForKickResponse { false }; bool _waitingForKickResponse { false };

View file

@ -0,0 +1,28 @@
//
// ModerationFlags.h
// libraries/shared/src
//
// Created by Kalila L. on Mar 11 2021.
// Copyright 2021 Vircadia contributors.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef vircadia_ModerationFlags_h
#define vircadia_ModerationFlags_h
class ModerationFlags {
public:
enum BanFlags
{
NO_BAN = 0,
BAN_BY_USERNAME = 1,
BAN_BY_FINGERPRINT = 2,
BAN_BY_IP = 4
};
int test(int lol) { return lol; };
};
#endif // vircadia_ModerationFlags_h