Replaces tab with 4 spaces
This commit is contained in:
+127
-127
@@ -19,7 +19,7 @@ DataClient::DataClient(sql::SqlManager* database, const std::shared_ptr<TSServer
|
||||
}
|
||||
|
||||
DataClient::~DataClient() {
|
||||
this->clientPermissions = nullptr;
|
||||
this->clientPermissions = nullptr;
|
||||
this->_properties = nullptr;
|
||||
}
|
||||
|
||||
@@ -35,45 +35,45 @@ bool DataClient::loadDataForCurrentServer() { //TODO for query
|
||||
|
||||
ClientDbId client_db_id = 0;
|
||||
sql::command(this->sql, "SELECT `cldbid`,`firstConnect`,`connections` FROM `clients` WHERE `serverId` = :sid AND `clientUid` = :uid LIMIT 1",
|
||||
variable{":sid", server_id},
|
||||
variable{":uid", this->getUid()}
|
||||
variable{":sid", server_id},
|
||||
variable{":uid", this->getUid()}
|
||||
).query([&](DataClient* cl, int length, string* values, string* names){
|
||||
for (int index = 0; index < length; index++) {
|
||||
try {
|
||||
if (names[index] == "cldbid") {
|
||||
client_db_id = stoull(values[index]);
|
||||
} else if (names[index] == "firstConnect") {
|
||||
cl->properties()[property::CLIENT_CREATED] = values[index];
|
||||
} else if (names[index] == "connections") {
|
||||
cl->properties()[property::CLIENT_TOTALCONNECTIONS] = values[index];
|
||||
} else {
|
||||
logWarning(LOG_INSTANCE, "Received unknown column with name {} within client list", names[index]);
|
||||
}
|
||||
} catch(const std::exception& ex) {
|
||||
logError(server_id, "Failed to load client {} base properties from database. Colum parsing for column {} failed. Value: {}. Message: {}",
|
||||
for (int index = 0; index < length; index++) {
|
||||
try {
|
||||
if (names[index] == "cldbid") {
|
||||
client_db_id = stoull(values[index]);
|
||||
} else if (names[index] == "firstConnect") {
|
||||
cl->properties()[property::CLIENT_CREATED] = values[index];
|
||||
} else if (names[index] == "connections") {
|
||||
cl->properties()[property::CLIENT_TOTALCONNECTIONS] = values[index];
|
||||
} else {
|
||||
logWarning(LOG_INSTANCE, "Received unknown column with name {} within client list", names[index]);
|
||||
}
|
||||
} catch(const std::exception& ex) {
|
||||
logError(server_id, "Failed to load client {} base properties from database. Colum parsing for column {} failed. Value: {}. Message: {}",
|
||||
this->getUid(),
|
||||
names[index],
|
||||
values[index],
|
||||
ex.what()
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}, this);
|
||||
|
||||
if(client_db_id == 0)
|
||||
return false;
|
||||
return false;
|
||||
|
||||
this->properties()[property::CLIENT_DATABASE_ID] = client_db_id; /* do this before the property saving (it saved the cldbid as well!)*/
|
||||
this->properties()[property::CLIENT_DATABASE_ID] = client_db_id; /* do this before the property saving (it saved the cldbid as well!)*/
|
||||
|
||||
//Load general properties
|
||||
deque<ts::PropertyWrapper> copied;
|
||||
for(const auto& prop : this->_properties->list_properties()){
|
||||
if((prop.type().flags & property::FLAG_GLOBAL) == 0) continue;
|
||||
if(prop.type().default_value == prop.value()) continue;
|
||||
copied.push_back(prop);
|
||||
}
|
||||
//Load general properties
|
||||
deque<ts::PropertyWrapper> copied;
|
||||
for(const auto& prop : this->_properties->list_properties()){
|
||||
if((prop.type().flags & property::FLAG_GLOBAL) == 0) continue;
|
||||
if(prop.type().default_value == prop.value()) continue;
|
||||
copied.push_back(prop);
|
||||
}
|
||||
|
||||
if(!ref_server) {
|
||||
if(this->getType() == ClientType::CLIENT_WEB || this->getType() == ClientType::CLIENT_TEAMSPEAK)
|
||||
@@ -96,7 +96,7 @@ bool DataClient::loadDataForCurrentServer() { //TODO for query
|
||||
else if(prop.type() == property::CLIENT_LASTCONNECTED)
|
||||
query = "UPDATE `clients` SET `lastConnect` = :value WHERE `serverId` = :sid AND `cldbid` = :cldbid";
|
||||
else
|
||||
return;
|
||||
return;
|
||||
|
||||
debugMessage(server_id, "[Property] Updating general client table property for client {}. Key: {} Value: {}", client_db_id, prop.type().name, prop.value());
|
||||
sql::command(this->sql, query, variable{":sid", 0}, variable{":cldbid", client_db_id}, variable{":value", prop.value()}).executeLater()
|
||||
@@ -106,150 +106,150 @@ bool DataClient::loadDataForCurrentServer() { //TODO for query
|
||||
|
||||
this->_properties->toggleSave(false);
|
||||
for(const auto& e : copied) {
|
||||
auto p = this->properties()->find(e.type().type_property, e.type().property_index);
|
||||
auto p = this->properties()->find(e.type().type_property, e.type().property_index);
|
||||
p = e.value();
|
||||
p.setModified(false);
|
||||
}
|
||||
this->_properties->toggleSave(true);
|
||||
|
||||
this->clientPermissions = serverInstance->databaseHelper()->loadClientPermissionManager(ref_server, this->getClientDatabaseId());
|
||||
this->clientPermissions = serverInstance->databaseHelper()->loadClientPermissionManager(ref_server, this->getClientDatabaseId());
|
||||
|
||||
//Setup / fix stuff
|
||||
if(!this->properties()[property::CLIENT_FLAG_AVATAR].as<string>().empty()){
|
||||
if(
|
||||
!ref_server ||
|
||||
!serverInstance->getFileServer()->findFile("/avatar_" + this->getAvatarId(),serverInstance->getFileServer()->avatarDirectory(ref_server))) {
|
||||
if(config::server::delete_missing_icon_permissions)
|
||||
if(config::server::delete_missing_icon_permissions)
|
||||
this->properties()[property::CLIENT_FLAG_AVATAR] = "";
|
||||
}
|
||||
}
|
||||
|
||||
if(ref_server)
|
||||
this->properties()[property::CLIENT_UNREAD_MESSAGES] = ref_server->letters->unread_letter_count(this->getUid());
|
||||
this->properties()[property::CLIENT_UNREAD_MESSAGES] = ref_server->letters->unread_letter_count(this->getUid());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
permission::v2::PermissionFlaggedValue DataClient::permissionValueFlagged(permission::PermissionType type, const std::shared_ptr<BasicChannel>& target, std::shared_ptr<CalculateCache> cache, std::shared_ptr<TSServer> server, bool server_defined) {
|
||||
if(!server_defined && !server)
|
||||
server = this->server;
|
||||
if(!server_defined && !server)
|
||||
server = this->server;
|
||||
|
||||
if(server) {
|
||||
auto result = server->calculatePermissions2(this->getClientDatabaseId(), {type}, this->getType(), target ? target->channelId() : 0, false, cache);
|
||||
if(result.empty() || result[0].first != type)
|
||||
return permission::v2::empty_permission_flagged_value;
|
||||
return result[0].second;
|
||||
} else {
|
||||
/* if you're not bound to a channel then you cant be bound to a server as well. */
|
||||
bool permission_set = false;
|
||||
permission::PermissionValue result = permNotGranted;
|
||||
for(const auto &gr : serverInstance->getGroupManager()->getServerGroups(this->getClientDatabaseId(), this->getType())){
|
||||
auto group_permissions = gr->group->permissions();
|
||||
auto flagged_permissions = group_permissions->permission_value_flagged(type);
|
||||
if(flagged_permissions.has_value) {
|
||||
if(flagged_permissions.value > result || flagged_permissions.value == -1) {
|
||||
result = flagged_permissions.value;
|
||||
permission_set = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return {result, permission_set};
|
||||
}
|
||||
if(server) {
|
||||
auto result = server->calculatePermissions2(this->getClientDatabaseId(), {type}, this->getType(), target ? target->channelId() : 0, false, cache);
|
||||
if(result.empty() || result[0].first != type)
|
||||
return permission::v2::empty_permission_flagged_value;
|
||||
return result[0].second;
|
||||
} else {
|
||||
/* if you're not bound to a channel then you cant be bound to a server as well. */
|
||||
bool permission_set = false;
|
||||
permission::PermissionValue result = permNotGranted;
|
||||
for(const auto &gr : serverInstance->getGroupManager()->getServerGroups(this->getClientDatabaseId(), this->getType())){
|
||||
auto group_permissions = gr->group->permissions();
|
||||
auto flagged_permissions = group_permissions->permission_value_flagged(type);
|
||||
if(flagged_permissions.has_value) {
|
||||
if(flagged_permissions.value > result || flagged_permissions.value == -1) {
|
||||
result = flagged_permissions.value;
|
||||
permission_set = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return {result, permission_set};
|
||||
}
|
||||
}
|
||||
|
||||
permission::PermissionValue DataClient::permissionValue(permission::PermissionTestType test, permission::PermissionType type, const std::shared_ptr<BasicChannel>& target, std::shared_ptr<CalculateCache> cache, std::shared_ptr<TSServer> server, bool server_defined) {
|
||||
auto result = this->permissionValueFlagged(type, target, cache, server, server_defined);
|
||||
if(result.has_value)
|
||||
return result.value;
|
||||
return permNotGranted;
|
||||
auto result = this->permissionValueFlagged(type, target, cache, server, server_defined);
|
||||
if(result.has_value)
|
||||
return result.value;
|
||||
return permNotGranted;
|
||||
}
|
||||
|
||||
std::deque<std::pair<permission::PermissionType, permission::PermissionValue>> DataClient::permissionValues(permission::PermissionTestType test, const std::deque<permission::PermissionType>& permissions, const std::shared_ptr<BasicChannel> &channel, std::shared_ptr<CalculateCache> cache, std::shared_ptr<TSServer> server, bool server_defined) {
|
||||
if(!server_defined && !server) server = this->server;
|
||||
if(!server_defined && !server) server = this->server;
|
||||
|
||||
if(server) return server->calculatePermissions(test, this->getClientDatabaseId(), permissions, this->getType(), channel, cache);
|
||||
deque<pair<permission::PermissionType, permission::PermissionValue>> result;
|
||||
if(server) return server->calculatePermissions(test, this->getClientDatabaseId(), permissions, this->getType(), channel, cache);
|
||||
deque<pair<permission::PermissionType, permission::PermissionValue>> result;
|
||||
|
||||
/* when you're not bound to any channel cou could only have server group permissions */
|
||||
/* we're loading here all server groups */
|
||||
{
|
||||
auto server_groups = serverInstance->getGroupManager()->getServerGroups(this->getClientDatabaseId(), this->getType());
|
||||
for(const auto& permission : permissions) {
|
||||
permission::PermissionValue value = permNotGranted;
|
||||
/* when you're not bound to any channel cou could only have server group permissions */
|
||||
/* we're loading here all server groups */
|
||||
{
|
||||
auto server_groups = serverInstance->getGroupManager()->getServerGroups(this->getClientDatabaseId(), this->getType());
|
||||
for(const auto& permission : permissions) {
|
||||
permission::PermissionValue value = permNotGranted;
|
||||
|
||||
for(const auto &gr : serverInstance->getGroupManager()->getServerGroups(this->getClientDatabaseId(), this->getType())){
|
||||
auto group_permissions = gr->group->permissions();
|
||||
auto flagged_permissions = group_permissions->permission_value_flagged(permission);
|
||||
if(flagged_permissions.has_value)
|
||||
if(flagged_permissions.value > value || flagged_permissions.value == -1) value = flagged_permissions.value;
|
||||
}
|
||||
for(const auto &gr : serverInstance->getGroupManager()->getServerGroups(this->getClientDatabaseId(), this->getType())){
|
||||
auto group_permissions = gr->group->permissions();
|
||||
auto flagged_permissions = group_permissions->permission_value_flagged(permission);
|
||||
if(flagged_permissions.has_value)
|
||||
if(flagged_permissions.value > value || flagged_permissions.value == -1) value = flagged_permissions.value;
|
||||
}
|
||||
|
||||
result.emplace_back(permission, value);
|
||||
}
|
||||
}
|
||||
result.emplace_back(permission, value);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
permission::PermissionValue DataClient::getPermissionGrantValue(permission::PermissionTestType test, permission::PermissionType type, const std::shared_ptr<BasicChannel>& target) {
|
||||
permission::PermissionValue result = permNotGranted;
|
||||
permission::PermissionValue result = permNotGranted;
|
||||
|
||||
if(this->server) {
|
||||
return this->server->calculatePermissionGrant(test, this->getClientDatabaseId(), type, this->getType(), target);
|
||||
} else {
|
||||
/* if you're not bound to a channel then you cant be bound to a server as well. */
|
||||
//TODO: Implement negate flag!
|
||||
for(const auto &gr : serverInstance->getGroupManager()->getServerGroups(this->getClientDatabaseId(), this->getType())){
|
||||
auto group_permissions = gr->group->permissions();
|
||||
auto flagged_permissions = group_permissions->permission_granted_flagged(type);
|
||||
if(flagged_permissions.has_value)
|
||||
if(flagged_permissions.value > result || flagged_permissions.value == -1) result = flagged_permissions.value;
|
||||
}
|
||||
}
|
||||
if(this->server) {
|
||||
return this->server->calculatePermissionGrant(test, this->getClientDatabaseId(), type, this->getType(), target);
|
||||
} else {
|
||||
/* if you're not bound to a channel then you cant be bound to a server as well. */
|
||||
//TODO: Implement negate flag!
|
||||
for(const auto &gr : serverInstance->getGroupManager()->getServerGroups(this->getClientDatabaseId(), this->getType())){
|
||||
auto group_permissions = gr->group->permissions();
|
||||
auto flagged_permissions = group_permissions->permission_granted_flagged(type);
|
||||
if(flagged_permissions.has_value)
|
||||
if(flagged_permissions.value > result || flagged_permissions.value == -1) result = flagged_permissions.value;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool DataClient::permissionGranted(PermissionTestType test, permission::PermissionType type, permission::PermissionValue required, const shared_ptr<BasicChannel>& target, bool force_granted, std::shared_ptr<CalculateCache> cache, std::shared_ptr<TSServer> server, bool server_defined) {
|
||||
auto value = this->permissionValue(test, type, target, cache, server, server_defined);
|
||||
bool result = this->permission_granted(value, required, force_granted);
|
||||
bool result = this->permission_granted(value, required, force_granted);
|
||||
|
||||
#ifdef DEBUG_PERMISSION
|
||||
{
|
||||
auto serverId = 0;
|
||||
auto client = dynamic_cast<ConnectedClient*>(this);
|
||||
if(client)
|
||||
serverId = client->getServerId();
|
||||
debugMessage(serverId, "[Permission] Value test result for test type {}.", test);
|
||||
debugMessage(serverId,
|
||||
"[Permission] Permission: {} Required value: {} Gained value: {} Force required: {} Channel: {} Result: {}",
|
||||
permission::resolvePermissionData(type)->name,
|
||||
required, value, force_granted, (target ? target->name() : "none"), result
|
||||
);
|
||||
};
|
||||
{
|
||||
auto serverId = 0;
|
||||
auto client = dynamic_cast<ConnectedClient*>(this);
|
||||
if(client)
|
||||
serverId = client->getServerId();
|
||||
debugMessage(serverId, "[Permission] Value test result for test type {}.", test);
|
||||
debugMessage(serverId,
|
||||
"[Permission] Permission: {} Required value: {} Gained value: {} Force required: {} Channel: {} Result: {}",
|
||||
permission::resolvePermissionData(type)->name,
|
||||
required, value, force_granted, (target ? target->name() : "none"), result
|
||||
);
|
||||
};
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
bool DataClient::permissionGrantGranted(PermissionTestType test, permission::PermissionType type, permission::PermissionValue required, const shared_ptr<BasicChannel>& target, bool force_granted) {
|
||||
auto value = this->getPermissionGrantValue(test, type, target);
|
||||
bool result = this->permission_granted(value, required, force_granted);
|
||||
auto value = this->getPermissionGrantValue(test, type, target);
|
||||
bool result = this->permission_granted(value, required, force_granted);
|
||||
|
||||
#ifdef DEBUG_PERMISSION
|
||||
{
|
||||
auto serverId = 0;
|
||||
auto client = dynamic_cast<ConnectedClient*>(this);
|
||||
if(client)
|
||||
serverId = client->getServerId();
|
||||
debugMessage(serverId, "[Permission] Grant test result for test type {}.", test);
|
||||
debugMessage(serverId,
|
||||
"[Permission] Permission: {} Required value: {} Gained value: {} Force required: {} Channel: {} Result: {}",
|
||||
permission::resolvePermissionData(type)->name,
|
||||
required, value, force_granted, (target ? target->name() : "none"), result
|
||||
);
|
||||
};
|
||||
{
|
||||
auto serverId = 0;
|
||||
auto client = dynamic_cast<ConnectedClient*>(this);
|
||||
if(client)
|
||||
serverId = client->getServerId();
|
||||
debugMessage(serverId, "[Permission] Grant test result for test type {}.", test);
|
||||
debugMessage(serverId,
|
||||
"[Permission] Permission: {} Required value: {} Gained value: {} Force required: {} Channel: {} Result: {}",
|
||||
permission::resolvePermissionData(type)->name,
|
||||
required, value, force_granted, (target ? target->name() : "none"), result
|
||||
);
|
||||
};
|
||||
#endif
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<GroupAssignment>> DataClient::assignedServerGroups() {
|
||||
@@ -269,11 +269,11 @@ bool DataClient::serverGroupAssigned(const shared_ptr<Group> &group) {
|
||||
}
|
||||
|
||||
bool DataClient::channelGroupAssigned(const shared_ptr<Group> &group, const shared_ptr<BasicChannel> &channel) {
|
||||
if(!channel) return false;
|
||||
auto gr = this->assignedChannelGroup(channel);
|
||||
sassert(gr);
|
||||
if(!gr) return false;
|
||||
return gr->group == group;
|
||||
if(!channel) return false;
|
||||
auto gr = this->assignedChannelGroup(channel);
|
||||
sassert(gr);
|
||||
if(!gr) return false;
|
||||
return gr->group == group;
|
||||
}
|
||||
|
||||
std::string DataClient::getAvatarId() {
|
||||
|
||||
Reference in New Issue
Block a user