Updates for the new token system
This commit is contained in:
@@ -174,31 +174,74 @@ void VirtualServer::unregisterInternalClient(std::shared_ptr<ConnectedClient> cl
|
||||
}
|
||||
|
||||
bool VirtualServer::assignDefaultChannel(const shared_ptr<ConnectedClient>& client, bool join) {
|
||||
shared_lock server_channel_lock(this->channel_tree_lock);
|
||||
std::shared_ptr<BasicChannel> channel = nullptr;
|
||||
if(client->properties()->hasProperty(property::CLIENT_DEFAULT_CHANNEL) && !client->properties()[property::CLIENT_DEFAULT_CHANNEL].as<string>().empty()) {
|
||||
auto str = client->properties()[property::CLIENT_DEFAULT_CHANNEL].as<std::string>();
|
||||
if(str[0] == '/' && str.find_first_not_of("0123456789", 1) == string::npos)
|
||||
channel = this->channelTree->findChannel(static_cast<ChannelId>(stoll(str.substr(1))));
|
||||
else
|
||||
channel = this->channelTree->findChannelByPath(str);
|
||||
if (channel) {
|
||||
if(!channel->permission_granted(permission::i_channel_needed_join_power, client->calculate_permission(permission::i_channel_join_power, channel->channelId()), false)) {
|
||||
logMessage(this->serverId, "{} Client tried to connect to a channel which he hasn't permission for. Channel: {} ({})", CLIENT_STR_LOG_PREFIX_(client), channel->channelId(), channel->name());
|
||||
channel = nullptr;
|
||||
} else if (!channel->passwordMatch(client->properties()[property::CLIENT_DEFAULT_CHANNEL_PASSWORD], true) && !permission::v2::permission_granted(1, client->calculate_permission(permission::b_channel_join_ignore_password, channel->channelId()))) {
|
||||
logMessage(this->serverId, "{} Client tried to connect to a channel which is password protected and he hasn't the right password. Channel: {} ({})", CLIENT_STR_LOG_PREFIX_(client), channel->channelId(), channel->name());
|
||||
channel = nullptr;
|
||||
}
|
||||
} else
|
||||
logMessage(this->serverId, "{} Client {}/{} tried to join on a not existing channel. Name: {}",
|
||||
CLIENT_STR_LOG_PREFIX_(client),
|
||||
client->getDisplayName(), client->getUid(),
|
||||
client->properties()[property::CLIENT_DEFAULT_CHANNEL].as<std::string>());
|
||||
}
|
||||
if(!channel) channel = this->channelTree->getDefaultChannel();
|
||||
if(!channel) return false;
|
||||
std::shared_lock server_channel_lock{this->channel_tree_lock};
|
||||
std::shared_ptr<BasicChannel> channel{};
|
||||
|
||||
auto requested_channel_path = client->properties()[property::CLIENT_DEFAULT_CHANNEL].value();
|
||||
if(!requested_channel_path.empty()) {
|
||||
if (requested_channel_path[0] == '/' && requested_channel_path.find_first_not_of("0123456789", 1) == std::string::npos) {
|
||||
ChannelId channel_id{0};
|
||||
try {
|
||||
channel_id = std::stoull(requested_channel_path.substr(1));
|
||||
} catch (std::exception&) {
|
||||
logTrace(this->getServerId(), "{} Failed to parse provided channel path as channel id.");
|
||||
}
|
||||
|
||||
if(channel_id > 0) {
|
||||
channel = this->channelTree->findChannel(channel_id);
|
||||
}
|
||||
} else {
|
||||
channel = this->channelTree->findChannelByPath(requested_channel_path);
|
||||
}
|
||||
}
|
||||
|
||||
if(channel) {
|
||||
/* Client proposes a target channel */
|
||||
auto& channel_whitelist = client->join_whitelisted_channel;
|
||||
auto whitelist_entry = std::find_if(channel_whitelist.begin(), channel_whitelist.end(), [&](const auto& entry) { return entry.first == channel->channelId(); });
|
||||
|
||||
auto client_channel_password = client->properties()[property::CLIENT_DEFAULT_CHANNEL_PASSWORD].value();
|
||||
if(whitelist_entry != channel_whitelist.end()) {
|
||||
debugMessage(this->getServerId(), "{} Allowing client to join channel {} because the token he used explicitly allowed it.", client->getLoggingPrefix(), channel->channelId());
|
||||
|
||||
if(whitelist_entry->second != "ignore") {
|
||||
if (!channel->passwordMatch(client_channel_password, true)) {
|
||||
if (!permission::v2::permission_granted(1, client->calculate_permission(permission::b_channel_join_ignore_password, channel->channelId()))) {
|
||||
channel = nullptr;
|
||||
goto skip_permissions;
|
||||
}
|
||||
}
|
||||
}
|
||||
goto skip_permissions;
|
||||
}
|
||||
|
||||
if(!channel->permission_granted(permission::i_channel_needed_join_power, client->calculate_permission(permission::i_channel_join_power, channel->channelId()), false)) {
|
||||
debugMessage(this->getServerId(), "{} Tried to join channel {} but hasn't enough join power.", client->getLoggingPrefix(), channel->channelId());
|
||||
channel = nullptr;
|
||||
goto skip_permissions;
|
||||
}
|
||||
|
||||
if (!channel->passwordMatch(client->properties()[property::CLIENT_DEFAULT_CHANNEL_PASSWORD], true)) {
|
||||
if(!permission::v2::permission_granted(1, client->calculate_permission(permission::b_channel_join_ignore_password, channel->channelId()))) {
|
||||
debugMessage(this->getServerId(), "{} Tried to join channel {} but hasn't given the right channel password.", client->getLoggingPrefix(), channel->channelId());
|
||||
channel = nullptr;
|
||||
goto skip_permissions;
|
||||
}
|
||||
}
|
||||
|
||||
skip_permissions:;
|
||||
}
|
||||
|
||||
if(!channel) {
|
||||
/* Client did not propose a channel or the proposed channel got rejected */
|
||||
channel = this->channelTree->getDefaultChannel();
|
||||
if(!channel) {
|
||||
logCritical(this->getServerId(), "Channel tree is missing the default channel.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
debugMessage(this->getServerId(), "{} Using channel {} as default client channel.", client->getLoggingPrefix(), channel->channelId());
|
||||
if(join) {
|
||||
server_channel_lock.unlock();
|
||||
unique_lock server_channel_w_lock(this->channel_tree_lock);
|
||||
@@ -321,10 +364,13 @@ void VirtualServer::notify_client_kick(
|
||||
* Note: channel cant be a ref because the channel itself gets deleted!
|
||||
*/
|
||||
void VirtualServer::delete_channel(shared_ptr<ts::ServerChannel> channel, const shared_ptr<ConnectedClient> &invoker, const std::string& kick_message, unique_lock<std::shared_mutex> &tree_lock, bool temp_delete) {
|
||||
if(!tree_lock.owns_lock())
|
||||
if(!tree_lock.owns_lock()) {
|
||||
tree_lock.lock();
|
||||
if(channel->deleted)
|
||||
}
|
||||
|
||||
if(channel->deleted) {
|
||||
return;
|
||||
}
|
||||
|
||||
deque<std::shared_ptr<ConnectedClient>> clients;
|
||||
{
|
||||
@@ -365,6 +411,8 @@ void VirtualServer::delete_channel(shared_ptr<ts::ServerChannel> channel, const
|
||||
unique_lock client_channel_lock(client->channel_lock);
|
||||
client->notifyChannelDeleted(client->channels->delete_channel_root(channel), invoker);
|
||||
});
|
||||
|
||||
this->tokenManager->handle_channel_deleted(channel->channelId());
|
||||
}
|
||||
|
||||
void VirtualServer::client_move(
|
||||
|
||||
Reference in New Issue
Block a user