mirror of
https://github.com/AleziaKurdis/overte.git
synced 2025-04-07 04:53:28 +02:00
State of refactoring
This commit is contained in:
parent
712b5e5088
commit
0216b34681
9 changed files with 77 additions and 42 deletions
|
@ -37,6 +37,7 @@
|
|||
#include <SettingHandle.h>
|
||||
#include <SettingHelpers.h>
|
||||
#include <FingerprintUtils.h>
|
||||
#include <ModerationFlags.h>
|
||||
|
||||
#include "DomainServerNodeData.h"
|
||||
|
||||
|
@ -864,15 +865,17 @@ void DomainServerSettingsManager::processNodeKickRequestPacket(QSharedPointer<Re
|
|||
QUuid nodeUUID = QUuid::fromRfc4122(message->readWithoutCopy(NUM_BYTES_RFC4122_UUID));
|
||||
|
||||
bool hasOptionalBanParameters = false;
|
||||
bool banByUsername = false;
|
||||
bool banByFingerprint = false;
|
||||
bool banByIP = false;
|
||||
int banParameters;
|
||||
bool banByUsername;
|
||||
bool banByFingerprint;
|
||||
bool banByIP;
|
||||
// pull optional ban parameters from the packet
|
||||
if (message.data()->getSize() > NUM_BYTES_RFC4122_UUID) {
|
||||
hasOptionalBanParameters = true;
|
||||
message->readPrimitive(&banByUsername);
|
||||
message->readPrimitive(&banByFingerprint);
|
||||
message->readPrimitive(&banByIP);
|
||||
message->readPrimitive(&banParameters);
|
||||
banByUsername = banParameters & ModerationFlags::BanFlags::BAN_BY_USERNAME;
|
||||
banByFingerprint = banParameters & ModerationFlags::BanFlags::BAN_BY_FINGERPRINT;
|
||||
banByIP = banParameters & ModerationFlags::BanFlags::BAN_BY_IP;
|
||||
}
|
||||
|
||||
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 optional ban parameters, we should ban the username based on the parameter
|
||||
if (hasOptionalBanParameters) {
|
||||
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 {
|
||||
if (!hasOptionalBanParameters || 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);
|
||||
|
||||
|
||||
newPermissions =
|
||||
!hadPermissions || userPermissions->can(NodePermissions::Permission::canConnectToDomain);
|
||||
|
||||
// ensure that the connect permission is clear
|
||||
userPermissions->clear(NodePermissions::Permission::canConnectToDomain);
|
||||
}
|
||||
|
|
|
@ -2493,7 +2493,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
|
|||
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) {
|
||||
bool isTablet = url == TabletScriptingInterface::QML;
|
||||
|
@ -3575,7 +3575,7 @@ void Application::onDesktopRootItemCreated(QQuickItem* rootItem) {
|
|||
_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 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
|
||||
|
||||
if (yes) {
|
||||
DependencyManager::get<NodeList>()->kickNodeBySessionID(nodeID, banByUsername, banByFingerprint, banByIP);
|
||||
DependencyManager::get<NodeList>()->kickNodeBySessionID(nodeID, banFlags);
|
||||
}
|
||||
|
||||
DependencyManager::get<UsersScriptingInterface>()->setWaitForKickResponse(false);
|
||||
|
|
|
@ -608,7 +608,7 @@ private:
|
|||
void toggleTabletUI(bool shouldOpen = false) const;
|
||||
bool shouldCaptureMouse() const;
|
||||
|
||||
void userKickConfirmation(const QUuid& nodeID, bool banByUsername, bool banByFingerprint, bool banByIP);
|
||||
void userKickConfirmation(const QUuid& nodeID, int banFlags);
|
||||
|
||||
MainWindow* _window;
|
||||
QElapsedTimer& _sessionRunTimer;
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include "udt/PacketHeaders.h"
|
||||
#include "SharedUtil.h"
|
||||
#include <Trace.h>
|
||||
#include <ModerationFlags.h>
|
||||
|
||||
using namespace std::chrono;
|
||||
|
||||
|
@ -1263,21 +1264,30 @@ float NodeList::getInjectorGain() {
|
|||
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
|
||||
// the domain-server will handle the persistence of the kick (via username or IP)
|
||||
|
||||
if (!nodeID.isNull() && getSessionUUID() != nodeID ) {
|
||||
if (getThisNodeCanKick()) {
|
||||
// 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
|
||||
kickPacket->write(nodeID.toRfc4122());
|
||||
// write the ban parameters to the packet
|
||||
kickPacket->writePrimitive(banByUsername);
|
||||
kickPacket->writePrimitive(banByFingerprint);
|
||||
kickPacket->writePrimitive(banByIP);
|
||||
kickPacket->writePrimitive(banFlags);
|
||||
|
||||
qCDebug(networking) << "Sending packet to kick node" << uuidStringWithoutCurlyBraces(nodeID);
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ public:
|
|||
void setInjectorGain(float gain);
|
||||
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 requestUsernameFromSessionID(const QUuid& nodeID);
|
||||
bool getRequestsDomainListData() { return _requestsDomainListData; }
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
//
|
||||
// UserActivityLoggerScriptingInterface.h
|
||||
// libraries/networking/src
|
||||
|
|
|
@ -52,15 +52,14 @@ float UsersScriptingInterface::getAvatarGain(const QUuid& 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) {
|
||||
bool waitingForKickResponse = _kickResponseLock.resultWithReadLock<bool>([&] { return _waitingForKickResponse; });
|
||||
if (getCanKick() && !waitingForKickResponse) {
|
||||
_kickConfirmationOperator(nodeID, banByUsername, banByFingerprint, banByIP);
|
||||
_kickConfirmationOperator(nodeID, banFlags);
|
||||
}
|
||||
} else {
|
||||
DependencyManager::get<NodeList>()->kickNodeBySessionID(nodeID, banByUsername, banByFingerprint, banByIP);
|
||||
DependencyManager::get<NodeList>()->kickNodeBySessionID(nodeID, banFlags);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
#include <DependencyManager.h>
|
||||
#include <shared/ReadWriteLockable.h>
|
||||
#include <ModerationFlags.h>
|
||||
|
||||
/**jsdoc
|
||||
* 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 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:
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -113,7 +119,7 @@ public slots:
|
|||
|
||||
/**jsdoc
|
||||
* 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>
|
||||
* @function Users.kick
|
||||
* @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} [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
|
||||
* Mutes a user's microphone for everyone. The mute is not permanent: the user can unmute themselves.
|
||||
|
@ -241,7 +247,7 @@ private:
|
|||
bool getRequestsDomainListData();
|
||||
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;
|
||||
bool _waitingForKickResponse { false };
|
||||
|
|
28
libraries/shared/src/ModerationFlags.h
Normal file
28
libraries/shared/src/ModerationFlags.h
Normal 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
|
Loading…
Reference in a new issue