Replaces tab with 4 spaces

This commit is contained in:
WolverinDEV
2020-01-24 02:57:58 +01:00
parent b2199c8d56
commit a651eb879e
114 changed files with 22120 additions and 22120 deletions
+101 -101
View File
@@ -9,7 +9,7 @@ using namespace ts;
using namespace ts::server;
ViewEntry::ViewEntry(const std::shared_ptr<ts::BasicChannel> &handle, bool editable) : handle(handle), editable(editable) {
memtrack::allocated<ViewEntry>(this);
memtrack::allocated<ViewEntry>(this);
assert(handle);
this->view_timestamp = chrono::system_clock::now();
@@ -19,13 +19,13 @@ ViewEntry::ViewEntry(const std::shared_ptr<ts::BasicChannel> &handle, bool edita
}
ViewEntry::~ViewEntry() {
memtrack::freed<ViewEntry>(this);
memtrack::freed<ViewEntry>(this);
}
ChannelId ts::ViewEntry::channelId() const {
if(this->cached_channel_id != 0) return this->cached_channel_id; //We've already got a channel id
if(this->cached_channel_id != 0) return this->cached_channel_id; //We've already got a channel id
//TODO cached_channel_id should be > 0 every time?
//TODO cached_channel_id should be > 0 every time?
auto channel = this->handle.lock();
if(!channel) {
logCritical(LOG_GENERAL, "ViewEntry::channelId() called without a valid handle and cached_channel_id == 0!");
@@ -35,7 +35,7 @@ ChannelId ts::ViewEntry::channelId() const {
}
ChannelId ViewEntry::parentId() const {
if(this->cached_parent_id != 0) return this->cached_parent_id;
if(this->cached_parent_id != 0) return this->cached_parent_id;
auto channel = this->handle.lock();
return channel && channel->parent() ? channel->parent()->channelId() : 0;
@@ -52,14 +52,14 @@ void ts::ViewEntry::setPreviousChannelId(ts::ChannelId id) {
void ts::ViewEntry::setParentChannelId(ts::ChannelId id) {
assert(this->editable);
this->cached_parent_id = id;
this->cached_parent_id = id;
}
ClientChannelView::ClientChannelView(server::ConnectedClient* handle) : owner(handle) {
memtrack::allocated<ClientChannelView>(this);
memtrack::allocated<ClientChannelView>(this);
}
ClientChannelView::~ClientChannelView() {
memtrack::freed<ClientChannelView>(this);
memtrack::freed<ClientChannelView>(this);
}
ServerId ClientChannelView::getServerId() {
@@ -70,9 +70,9 @@ std::deque<std::shared_ptr<BasicChannel>> ClientChannelView::channels(const std:
int deep) {
std::deque<std::shared_ptr<BasicChannel>> result;
for(const auto& entry : this->entries(head ? make_shared<ViewEntry>(head) : nullptr, deep)) {
auto channel = dynamic_pointer_cast<ViewEntry>(entry)->handle.lock();
if(channel)
result.push_back(channel);
auto channel = dynamic_pointer_cast<ViewEntry>(entry)->handle.lock();
if(channel)
result.push_back(channel);
}
return result;
@@ -90,37 +90,37 @@ std::shared_ptr<ViewEntry> ClientChannelView::find_channel(ts::ChannelId id) {
}
std::shared_ptr<ViewEntry> ClientChannelView::find_channel(const std::shared_ptr<ts::BasicChannel> &channel) {
if(!channel) return nullptr;
if(!channel) return nullptr;
deque<shared_ptr<BasicChannel>> heads{channel};
shared_ptr<LinkedTreeEntry> head = nullptr;
bool deep_search = false;
deque<shared_ptr<BasicChannel>> heads{channel};
shared_ptr<LinkedTreeEntry> head = nullptr;
bool deep_search = false;
while(heads.front()) {
auto parent = heads.front()->parent();
if(!parent && heads.front()->properties()[property::CHANNEL_PID].as<ChannelId>() != 0) {
head = this->find_linked_entry(channel->channelId(), nullptr);//We're searching for a deleted head! So lets iterate over everything
deep_search = true;
break;
}
heads.push_front(parent);
}
while(heads.front()) {
auto parent = heads.front()->parent();
if(!parent && heads.front()->properties()[property::CHANNEL_PID].as<ChannelId>() != 0) {
head = this->find_linked_entry(channel->channelId(), nullptr);//We're searching for a deleted head! So lets iterate over everything
deep_search = true;
break;
}
heads.push_front(parent);
}
if(!deep_search) {
heads.pop_front();
if(!deep_search) {
heads.pop_front();
while(heads.size() > 1) {
auto front = move(heads.front());
heads.pop_front();
while(heads.size() > 1) {
auto front = move(heads.front());
heads.pop_front();
head = this->find_linked_entry(front->channelId(), head, 1);
if(!head) return nullptr; //Channel tree not visible!
}
head = this->find_linked_entry(front->channelId(), head, 1);
if(!head) return nullptr; //Channel tree not visible!
}
head = this->find_linked_entry(channel->channelId(), head, 1);
}
head = this->find_linked_entry(channel->channelId(), head, 1);
}
return head ? static_pointer_cast<ViewEntry>(head->entry) : nullptr;
return head ? static_pointer_cast<ViewEntry>(head->entry) : nullptr;
}
std::deque<std::shared_ptr<ViewEntry>> ClientChannelView::insert_channels(shared_ptr<TreeView::LinkedTreeEntry> head, bool test_permissions, bool first_only, std::shared_ptr<server::CalculateCache> cache) {
@@ -130,26 +130,26 @@ std::deque<std::shared_ptr<ViewEntry>> ClientChannelView::insert_channels(shared
bool has_perm = !test_permissions || owner->permissionGranted(permission::PERMTEST_ORDERED, permission::b_channel_ignore_view_power, 1, nullptr, true, cache);
bool first = true;
while(head) {
if(!first && first_only) break;
first = false;
if(!first && first_only) break;
first = false;
auto channel = dynamic_pointer_cast<BasicChannel>(head->entry);
if(this->channel_visible(channel)) {
if(head->child_head) {
for(const auto& sub : this->insert_channels(head->child_head, test_permissions, false, cache))
result.push_back(sub);
}
if(head->child_head) {
for(const auto& sub : this->insert_channels(head->child_head, test_permissions, false, cache))
result.push_back(sub);
}
head = head->next;
continue;
}
if(!has_perm) {
if(!channel->permission_granted(permission::i_channel_needed_view_power, this->owner->calculate_permission_value(permission::i_channel_view_power, channel->channelId()), false)) {
head = head->next;
debugMessage(this->getServerId(), "{}[CHANNEL] Dropping channel {} ({}) (No permissions)", CLIENT_STR_LOG_PREFIX_(this->owner), channel->channelId(), channel->name());
continue;
}
if(!channel->permission_granted(permission::i_channel_needed_view_power, this->owner->calculate_permission_value(permission::i_channel_view_power, channel->channelId()), false)) {
head = head->next;
debugMessage(this->getServerId(), "{}[CHANNEL] Dropping channel {} ({}) (No permissions)", CLIENT_STR_LOG_PREFIX_(this->owner), channel->channelId(), channel->name());
continue;
}
}
auto entry = make_shared<ViewEntry>(dynamic_pointer_cast<BasicChannel>(head->entry), true);
std::shared_ptr<ViewEntry> parent, previous;
@@ -171,11 +171,11 @@ std::deque<std::shared_ptr<ViewEntry>> ClientChannelView::insert_channels(shared
head = head->next;
continue;
};
debugMessage(this->getServerId(), "{}[CHANNELS] Insert channel {} ({} => order {}) after {} ({})",
CLIENT_STR_LOG_PREFIX_(this->owner),
channel->channelId(), channel->name(), entry->previousChannelId(),
previous ? previous->channelId() : 0, previous_channel ? previous_channel->name() : ""
);
debugMessage(this->getServerId(), "{}[CHANNELS] Insert channel {} ({} => order {}) after {} ({})",
CLIENT_STR_LOG_PREFIX_(this->owner),
channel->channelId(), channel->name(), entry->previousChannelId(),
previous ? previous->channelId() : 0, previous_channel ? previous_channel->name() : ""
);
result.push_back(entry);
@@ -221,7 +221,7 @@ std::deque<std::shared_ptr<ViewEntry>> ClientChannelView::show_channel(std::shar
while(remote_previous && !(previous = dynamic_pointer_cast<ViewEntry>(this->find_entry(remote_previous->entry->channelId())))) {
remote_previous = remote_previous->previous;
}
auto previous_channel = previous ? previous->channel() : nullptr; //weak could be may nullptr
auto previous_channel = previous ? previous->channel() : nullptr; //weak could be may nullptr
debugMessage(this->getServerId(), "{}[CHANNELS] Insert channel {} ({}) after {} ({})",
CLIENT_STR_LOG_PREFIX_(this->owner),
channel->channelId(), channel->name(),
@@ -286,56 +286,56 @@ std::deque<std::pair<bool, std::shared_ptr<ViewEntry>>> ClientChannelView::updat
}
std::deque<std::pair<bool, std::shared_ptr<ViewEntry>>> ClientChannelView::update_channel_path(std::shared_ptr<ts::TreeView::LinkedTreeEntry> l_channel, std::shared_ptr<ts::TreeView::LinkedTreeEntry> l_own, shared_ptr<CalculateCache> cache, ssize_t length) {
if(!cache) cache = make_shared<CalculateCache>();
std::deque<std::pair<bool, std::shared_ptr<ViewEntry>>> result;
bool has_perm = owner->permissionGranted(permission::PERMTEST_ORDERED, permission::b_channel_ignore_view_power, 1, nullptr, true, cache);
if(!cache) cache = make_shared<CalculateCache>();
std::deque<std::pair<bool, std::shared_ptr<ViewEntry>>> result;
bool has_perm = owner->permissionGranted(permission::PERMTEST_ORDERED, permission::b_channel_ignore_view_power, 1, nullptr, true, cache);
while(l_channel && length-- != 0) {
auto b_channel = dynamic_pointer_cast<BasicChannel>(l_channel->entry);
sassert(b_channel);
auto visible = this->channel_visible(b_channel);
if(!visible) {
if(l_channel->parent.lock() && !this->channel_visible(dynamic_pointer_cast<BasicChannel>(l_channel->parent.lock()->entry))) {
l_channel = l_channel->next;
continue; /* all subchannels had been checked, because parent isnt visible */
}
//Test if channel comes visible again!
visible = true;
while(l_channel && length-- != 0) {
auto b_channel = dynamic_pointer_cast<BasicChannel>(l_channel->entry);
sassert(b_channel);
auto visible = this->channel_visible(b_channel);
if(!visible) {
if(l_channel->parent.lock() && !this->channel_visible(dynamic_pointer_cast<BasicChannel>(l_channel->parent.lock()->entry))) {
l_channel = l_channel->next;
continue; /* all subchannels had been checked, because parent isnt visible */
}
//Test if channel comes visible again!
visible = true;
if(!has_perm) {
if(!b_channel->permission_granted(permission::i_channel_needed_view_power, this->owner->calculate_permission_value(permission::i_channel_view_power, b_channel->channelId()), false)) {
visible = false;
}
}
if(visible) {
for(const auto& entry : this->show_channel(l_channel, visible))
result.emplace_back(true, entry);
for(const auto& entry : this->insert_channels(l_channel->child_head, true, false, cache))
result.emplace_back(true, entry);
}
if(!has_perm) {
if(!b_channel->permission_granted(permission::i_channel_needed_view_power, this->owner->calculate_permission_value(permission::i_channel_view_power, b_channel->channelId()), false)) {
visible = false;
}
}
if(visible) {
for(const auto& entry : this->show_channel(l_channel, visible))
result.emplace_back(true, entry);
for(const auto& entry : this->insert_channels(l_channel->child_head, true, false, cache))
result.emplace_back(true, entry);
}
l_channel = l_channel->next;
continue; /* all subchannels had been checked */
} else if(visible && !has_perm) {
for(const auto& entry : this->test_channel(l_channel, l_own, cache))
result.emplace_back(false, entry);
}
l_channel = l_channel->next;
continue; /* all subchannels had been checked */
} else if(visible && !has_perm) {
for(const auto& entry : this->test_channel(l_channel, l_own, cache))
result.emplace_back(false, entry);
}
//Root node is okey, test children
if(l_channel->child_head) {
auto entries = this->update_channel_path(l_channel->child_head, l_own, cache, -1);
result.insert(result.end(), entries.begin(), entries.end());
}
//Root node is okey, test children
if(l_channel->child_head) {
auto entries = this->update_channel_path(l_channel->child_head, l_own, cache, -1);
result.insert(result.end(), entries.begin(), entries.end());
}
l_channel = l_channel->next;
}
l_channel = l_channel->next;
}
return result;
return result;
}
std::deque<std::pair<ClientChannelView::ChannelAction, std::shared_ptr<ViewEntry>>> ClientChannelView::change_order(const shared_ptr<LinkedTreeEntry> &channel, const std::shared_ptr<LinkedTreeEntry> &parent, const shared_ptr<LinkedTreeEntry> &head) {
std::deque<std::pair<ClientChannelView::ChannelAction, std::shared_ptr<ViewEntry>>> result;
std::deque<std::pair<ClientChannelView::ChannelAction, std::shared_ptr<ViewEntry>>> result;
auto l_entry = this->find_linked_entry(channel->entry->channelId());
auto l_parent = parent ? this->find_linked_entry(parent->entry->channelId()) : nullptr;
if(!l_entry) { //Channel not visible yet
@@ -343,7 +343,7 @@ std::deque<std::pair<ClientChannelView::ChannelAction, std::shared_ptr<ViewEntry
bool has_perm = owner->permissionGranted(permission::PERMTEST_ORDERED, permission::b_channel_ignore_view_power, 1, nullptr);
if(!has_perm) {
has_perm = dynamic_pointer_cast<BasicChannel>(channel->entry)->permission_granted(permission::i_channel_needed_view_power, this->owner->calculate_permission_value(permission::i_channel_view_power, dynamic_pointer_cast<BasicChannel>(channel->entry)->channelId()), false);
has_perm = dynamic_pointer_cast<BasicChannel>(channel->entry)->permission_granted(permission::i_channel_needed_view_power, this->owner->calculate_permission_value(permission::i_channel_view_power, dynamic_pointer_cast<BasicChannel>(channel->entry)->channelId()), false);
}
if(!has_perm) return {}; //Channel wasn't visible and he still has no permission for that :)
@@ -354,7 +354,7 @@ std::deque<std::pair<ClientChannelView::ChannelAction, std::shared_ptr<ViewEntry
}
for(const auto& shown : this->insert_channels(channel, true, true))
result.push_back({ClientChannelView::ENTER_VIEW, shown});
result.push_back({ClientChannelView::ENTER_VIEW, shown});
return result; //An invisible channel became visible
}
//Channel visible!
@@ -410,17 +410,17 @@ bool ClientChannelView::remove_channel(ts::ChannelId channelId) {
}
std::deque<ChannelId> ClientChannelView::delete_channel_root(const std::shared_ptr<ts::BasicChannel> &channel){
auto linked = this->find_channel(channel);
if(!linked) return {};
auto linked = this->find_channel(channel);
if(!linked) return {};
std::deque<ChannelId> result;
for(const auto& channel : this->delete_entry(linked))
result.push_back(channel->channelId());
return result;
std::deque<ChannelId> result;
for(const auto& channel : this->delete_entry(linked))
result.push_back(channel->channelId());
return result;
}
void ClientChannelView::reset() {
while(this->head)
while(this->head)
this->delete_entry(this->head->entry);
}