A lot of updates

This commit is contained in:
WolverinDEV
2020-02-01 14:32:16 +01:00
parent fe05c63882
commit 543e6b1abc
44 changed files with 714 additions and 392 deletions
+28 -28
View File
@@ -50,10 +50,10 @@ using namespace ts::token;
command_result ConnectedClient::handleCommandClientGetVariables(Command &cmd) {
CMD_REQ_SERVER;
auto client = this->server->findClient(cmd["clid"].as<ClientId>());
ConnectedLockedClient client{this->server->find_client_by_id(cmd["clid"].as<ClientId>())};
shared_lock tree_lock(this->channel_lock);
if (!client || (client != this && !this->isClientVisible(client, false)))
if (!client || (client.client != this && !this->isClientVisible(client.client, false)))
return command_result{error::client_invalid_id, ""};
deque<shared_ptr<property::PropertyDescription>> props;
@@ -61,7 +61,7 @@ command_result ConnectedClient::handleCommandClientGetVariables(Command &cmd) {
props.push_back(property::info((property::ClientProperties) prop.type().property_index));
}
this->notifyClientUpdated(client, props, false);
this->notifyClientUpdated(client.client, props, false);
return command_result{error::ok};
}
@@ -69,26 +69,26 @@ command_result ConnectedClient::handleCommandClientKick(Command &cmd) {
CMD_REQ_SERVER;
CMD_CHK_AND_INC_FLOOD_POINTS(25);
auto client = this->server->findClient(cmd["clid"].as<ClientId>());
ConnectedLockedClient client{this->server->find_client_by_id(cmd["clid"].as<ClientId>())};
if (!client) return command_result{error::client_invalid_id};
if (client->getType() == CLIENT_MUSIC) return command_result{error::client_invalid_type, "You cant kick a music bot!"};
std::shared_ptr<BasicChannel> targetChannel = nullptr;
auto type = cmd["reasonid"].as<ViewReasonId>();
if (type == ViewReasonId::VREASON_CHANNEL_KICK) {
auto channel = client->currentChannel;
auto channel = client->getChannel();
ACTION_REQUIRES_PERMISSION(permission::i_client_kick_from_channel_power, client->calculate_permission(permission::i_client_needed_kick_from_channel_power, client->getChannelId()), client->getChannelId());
targetChannel = this->server->channelTree->getDefaultChannel();
} else if (type == ViewReasonId::VREASON_SERVER_KICK) {
auto channel = client->currentChannel;
auto channel = client->getChannel();
ACTION_REQUIRES_GLOBAL_PERMISSION(permission::i_client_kick_from_server_power, client->calculate_permission(permission::i_client_needed_kick_from_server_power, client->getChannelId()));
targetChannel = nullptr;
} else return command_result{error::not_implemented};
if (targetChannel) {
this->server->notify_client_kick(client, this->ref(), cmd["reasonmsg"].as<std::string>(), targetChannel);
this->server->notify_client_kick(client.client, this->ref(), cmd["reasonmsg"].as<std::string>(), targetChannel);
} else {
this->server->notify_client_kick(client, this->ref(), cmd["reasonmsg"].as<std::string>(), nullptr);
client->closeConnection(system_clock::now() + seconds(1));
this->server->notify_client_kick(client.client, this->ref(), cmd["reasonmsg"].as<std::string>(), nullptr);
client->close_connection(system_clock::now() + seconds(1));
}
return command_result{error::ok};
@@ -139,13 +139,13 @@ command_result ConnectedClient::handleCommandClientMove(Command &cmd) {
shared_lock server_channel_r_lock(this->server->channel_tree_lock);
auto target_client_id = cmd["clid"].as<ClientId>();
auto target_client = target_client_id == 0 ? this->ref() : this->server->findClient(target_client_id);
ConnectedLockedClient target_client{target_client_id == 0 ? this->ref() : this->server->find_client_by_id(target_client_id)};
if(!target_client) {
return command_result{error::client_invalid_id, "Invalid target clid"};
}
if(!target_client->currentChannel) {
if(target_client != this)
if(!target_client->getChannel()) {
if(target_client.client != this)
return command_result{error::client_invalid_id, "Invalid target clid"};
}
auto channel = this->server->channelTree->findChannel(cmd["cid"].as<ChannelId>());
@@ -188,18 +188,18 @@ command_result ConnectedClient::handleCommandClientMove(Command &cmd) {
}
}
if (target_client != this)
if (target_client.client != this)
ACTION_REQUIRES_PERMISSION(permission::i_client_move_power, target_client->calculate_permission(permission::i_client_needed_move_power, target_client->getChannelId()), target_client->getChannelId());
server_channel_r_lock.unlock();
unique_lock server_channel_w_lock(this->server->channel_tree_lock);
auto oldChannel = target_client->getChannel();
this->server->client_move(
target_client,
target_client.client,
channel,
target_client == this ? nullptr : _this.lock(),
target_client.client == this ? nullptr : _this.lock(),
"",
target_client == this ? ViewReasonId::VREASON_USER_ACTION : ViewReasonId::VREASON_MOVED,
target_client.client == this ? ViewReasonId::VREASON_USER_ACTION : ViewReasonId::VREASON_MOVED,
true,
server_channel_w_lock
);
@@ -221,7 +221,7 @@ command_result ConnectedClient::handleCommandClientPoke(Command &cmd) {
CMD_RESET_IDLE;
CMD_CHK_AND_INC_FLOOD_POINTS(25);
auto client = this->server->findClient(cmd["clid"].as<ClientId>());
ConnectedLockedClient client{ this->server->find_client_by_id(cmd["clid"].as<ClientId>())};
if (!client) return command_result{error::client_invalid_id};
if (client->getType() == CLIENT_MUSIC) return command_result{error::client_invalid_type};
ACTION_REQUIRES_PERMISSION(permission::i_client_poke_power, client->calculate_permission(permission::i_client_needed_poke_power, client->getChannelId()), client->getChannelId());
@@ -235,7 +235,7 @@ command_result ConnectedClient::handleCommandClientChatComposing(Command &cmd) {
CMD_REQ_SERVER;
CMD_CHK_AND_INC_FLOOD_POINTS(0);
auto client = this->server->findClient(cmd["clid"].as<ClientId>());
ConnectedLockedClient client{this->server->find_client_by_id(cmd["clid"].as<ClientId>())};
if (!client) return command_result{error::client_invalid_id};
client->notifyClientChatComposing(_this.lock());
@@ -246,16 +246,16 @@ command_result ConnectedClient::handleCommandClientChatClosed(Command &cmd) {
CMD_REQ_SERVER;
CMD_CHK_AND_INC_FLOOD_POINTS(5);
auto client = this->server->findClient(cmd["clid"].as<ClientId>());
ConnectedLockedClient<ConnectedClient> client{this->server->find_client_by_id(cmd["clid"].as<ClientId>())};
if (!client) return command_result{error::client_invalid_id};
{
unique_lock channel_lock(this->channel_lock);
this->openChats.erase(remove_if(this->openChats.begin(), this->openChats.end(), [client](const weak_ptr<ConnectedClient>& weak) {
this->openChats.erase(remove_if(this->openChats.begin(), this->openChats.end(), [&](const weak_ptr<ConnectedClient>& weak) {
return weak.lock() == client;
}), this->openChats.end());
}
{
unique_lock channel_lock(client->channel_lock);
unique_lock channel_lock(client->get_channel_lock());
client->openChats.erase(remove_if(client->openChats.begin(), client->openChats.end(), [&](const weak_ptr<ConnectedClient>& weak) {
return weak.lock().get() == this;
}), client->openChats.end());
@@ -421,9 +421,9 @@ command_result ConnectedClient::handleCommandClientDBEdit(Command &cmd) {
command_result ConnectedClient::handleCommandClientEdit(ts::Command &cmd) {
CMD_REQ_SERVER;
auto client = this->server->findClient(cmd["clid"].as<ClientId>());
ConnectedLockedClient client{this->server->find_client_by_id(cmd["clid"].as<ClientId>())};
if (!client) return command_result{error::client_invalid_id};
return this->handleCommandClientEdit(cmd, client);
return this->handleCommandClientEdit(cmd, client.client);
}
command_result ConnectedClient::handleCommandClientEdit(Command &cmd, const std::shared_ptr<ConnectedClient>& client) {
@@ -657,14 +657,14 @@ command_result ConnectedClient::handleCommandClientMute(Command &cmd) {
CMD_REQ_SERVER;
CMD_RESET_IDLE;
auto client = this->server->findClient(cmd["clid"].as<ClientId>());
ConnectedLockedClient client{this->server->find_client_by_id(cmd["clid"].as<ClientId>())};
if (!client || client->getClientId() == this->getClientId()) return command_result{error::client_invalid_id};
{
unique_lock channel_lock(this->channel_lock);
for(const auto& weak : this->mutedClients)
if(weak.lock() == client) return command_result{error::ok};
this->mutedClients.push_back(client);
this->mutedClients.push_back(client.client);
}
if (config::voice::notifyMuted)
@@ -677,12 +677,12 @@ command_result ConnectedClient::handleCommandClientUnmute(Command &cmd) {
CMD_REQ_SERVER;
CMD_RESET_IDLE;
auto client = this->server->findClient(cmd["clid"].as<ClientId>());
ConnectedLockedClient client{this->server->find_client_by_id(cmd["clid"].as<ClientId>())};
if (!client || client->getClientId() == this->getClientId()) return command_result{error::client_invalid_id};
{
unique_lock channel_lock(this->channel_lock);
this->mutedClients.erase(std::remove_if(this->mutedClients.begin(), this->mutedClients.end(), [client](const weak_ptr<ConnectedClient>& weak) {
this->mutedClients.erase(std::remove_if(this->mutedClients.begin(), this->mutedClients.end(), [&](const weak_ptr<ConnectedClient>& weak) {
auto c = weak.lock();
return !c || c == client;
}), this->mutedClients.end());
@@ -1119,7 +1119,7 @@ command_result ConnectedClient::handleCommandClientInfo(Command &cmd) {
auto client_id = cmd[index]["clid"].as<ClientId>();
if(client_id == 0) continue;
auto client = this->server->findClient(client_id);
ConnectedLockedClient client{this->server->find_client_by_id(client_id)};
if(!client) {
trigger_error = true;
continue;
+14 -11
View File
@@ -228,6 +228,9 @@ command_result ConnectedClient::handleCommand(Command &cmd) {
else if (command == "playlistpermlist") return this->handleCommandPlaylistPermList(cmd);
else if (command == "playlistaddperm") return this->handleCommandPlaylistAddPerm(cmd);
else if (command == "playlistdelperm") return this->handleCommandPlaylistDelPerm(cmd);
else if (command == "playlistclientpermlist") return this->handleCommandPlaylistClientPermList(cmd);
else if (command == "playlistclientaddperm") return this->handleCommandPlaylistClientAddPerm(cmd);
else if (command == "playlistclientdelperm") return this->handleCommandPlaylistClientDelPerm(cmd);
else if (command == "playlistinfo") return this->handleCommandPlaylistInfo(cmd);
else if (command == "playlistedit") return this->handleCommandPlaylistEdit(cmd);
@@ -256,13 +259,13 @@ command_result ConnectedClient::handleCommandGetConnectionInfo(Command &cmd) {
CMD_REQ_SERVER;
CMD_CHK_AND_INC_FLOOD_POINTS(5);
auto client = this->server->findClient(cmd["clid"].as<ClientId>());
ConnectedLockedClient client{this->server->find_client_by_id(cmd["clid"].as<ClientId>())};
if (!client) return command_result{error::client_invalid_id};
bool send_temp;
auto info = client->request_connection_info(_this.lock(), send_temp);
if (info) {
this->notifyConnectionInfo(client, info);
this->notifyConnectionInfo(client.client, info);
} else if(send_temp) {
return command_result{error::no_cached_connection_info};
}
@@ -489,7 +492,7 @@ command_result ConnectedClient::handleCommandSendTextMessage(Command &cmd) {
auto timestamp = system_clock::now();
if (cmd["targetmode"].as<ChatMessageMode>() == ChatMessageMode::TEXTMODE_PRIVATE) {
auto target = this->server->findClient(cmd["target"].as<ClientId>());
ConnectedLockedClient target{this->server->find_client_by_id(cmd["target"].as<ClientId>())};
if (!target) return command_result{error::client_invalid_id};
bool chat_open = false;
@@ -506,24 +509,24 @@ command_result ConnectedClient::handleCommandSendTextMessage(Command &cmd) {
}
if(!chat_open) {
if (target == this)
if (target.client == this)
ACTION_REQUIRES_PERMISSION(permission::b_client_even_textmessage_send, 1, this->getChannelId());
if(!permission::v2::permission_granted(target->calculate_permission(permission::i_client_needed_private_textmessage_power, target->getClientId()), this->calculate_permission(permission::i_client_private_textmessage_power, this->getClientId()), false))
return command_result{permission::i_client_private_textmessage_power};
{
unique_lock channel_lock(target->channel_lock);
unique_lock channel_lock(target->get_channel_lock());
target->openChats.push_back(_this);
}
{
unique_lock channel_lock(this->channel_lock);
this->openChats.push_back(target);
this->openChats.push_back(target.client);
}
}
if(this->handleTextMessage(ChatMessageMode::TEXTMODE_PRIVATE, cmd["msg"], target)) return command_result{error::ok};
if(this->handleTextMessage(ChatMessageMode::TEXTMODE_PRIVATE, cmd["msg"], target.client)) return command_result{error::ok};
target->notifyTextMessage(ChatMessageMode::TEXTMODE_PRIVATE, _this.lock(), target->getClientId(), 0, timestamp, cmd["msg"].string());
this->notifyTextMessage(ChatMessageMode::TEXTMODE_PRIVATE, _this.lock(), target->getClientId(), 0, timestamp, cmd["msg"].string());
} else if (cmd["targetmode"] == ChatMessageMode::TEXTMODE_CHANNEL) {
@@ -809,7 +812,7 @@ command_result ConnectedClient::handleCommandBanClient(Command &cmd) {
if(client->getType() == ClientType::CLIENT_MUSIC)
return command_result{error::client_invalid_id, "You cant ban a music bot!"};
} else {
target_clients = {this->server->findClient(cmd["clid"].as<ClientId>())};
target_clients = {this->server->find_client_by_id(cmd["clid"].as<ClientId>())};
if(!target_clients[0]) {
return command_result{error::client_invalid_id, "Could not find target client"};
}
@@ -855,7 +858,7 @@ command_result ConnectedClient::handleCommandBanClient(Command &cmd) {
if (client->getType() != CLIENT_TEAMSPEAK && client->getType() != CLIENT_QUERY) continue; //Remember if you add new type you have to change stuff here
this->server->notify_client_ban(client, this->ref(), reason, time);
client->closeConnection(system_clock::now() + seconds(2));
client->close_connection(system_clock::now() + seconds(2));
string entry_name, entry_ip, entry_hardware_id;
if(b_ban_name && !no_nickname) {
@@ -1108,8 +1111,8 @@ command_result ConnectedClient::handleCommandPluginCmd(Command &cmd) {
} else if (mode == PluginTargetMode::PLUGINCMD_CLIENT) {
for (int index = 0; index < cmd.bulkCount(); index++) {
auto target = cmd[index]["target"].as<ClientId>();
auto cl = this->server->findClient(target);
if (!cl) return command_result{error::client_invalid_id, "invalid target id"};
ConnectedLockedClient cl{this->server->find_client_by_id(target)};
if (!cl) return command_result{error::client_invalid_id};
cl->notifyPluginCmd(cmd["name"], cmd["data"], _this.lock());
}
}
+243 -101
View File
@@ -296,16 +296,11 @@ command_result ConnectedClient::handleCommandPlaylistList(ts::Command &cmd) {
CMD_RESET_IDLE;
CMD_CHK_AND_INC_FLOOD_POINTS(25);
auto self_dbid = this->getClientDatabaseId();
auto playlist_view_power = this->calculate_permission(permission::i_playlist_view_power, 0);
auto self_ref = this->ref();
auto playlists = this->server->musicManager->playlists();
playlists.erase(find_if(playlists.begin(), playlists.end(), [&](const shared_ptr<music::PlayablePlaylist>& playlist) {
if(playlist->properties()[property::PLAYLIST_OWNER_DBID] == self_dbid)
return false;
auto needed_view_power = playlist->permissions()->getPermissionValue(permission::i_playlist_needed_view_power);
return !permission::v2::permission_granted(needed_view_power, playlist_view_power, false);;
return playlist->client_has_permissions(self_ref, permission::i_playlist_needed_view_power, permission::i_playlist_view_power, music::PlaylistPermissions::do_no_require_granted) != permission::ok;
}), playlists.end());
if(playlists.empty())
@@ -322,12 +317,25 @@ command_result ConnectedClient::handleCommandPlaylistList(ts::Command &cmd) {
notify[index]["playlist_type"] = entry->properties()[property::PLAYLIST_TYPE].value();
notify[index]["playlist_owner_dbid"] = entry->properties()[property::PLAYLIST_OWNER_DBID].value();
notify[index]["playlist_owner_name"] = entry->properties()[property::PLAYLIST_OWNER_NAME].value();
notify[index]["needed_power_modify"] = entry->permissions()->getPermissionValue(permission::i_playlist_needed_modify_power);
notify[index]["needed_power_permission_modify"] = entry->permissions()->getPermissionValue(permission::i_playlist_needed_permission_modify_power);
notify[index]["needed_power_delete"] = entry->permissions()->getPermissionValue(permission::i_playlist_needed_delete_power);
notify[index]["needed_power_song_add"] = entry->permissions()->getPermissionValue(permission::i_playlist_song_needed_add_power);
notify[index]["needed_power_song_move"] = entry->permissions()->getPermissionValue(permission::i_playlist_song_needed_move_power);
notify[index]["needed_power_song_remove"] = entry->permissions()->getPermissionValue(permission::i_playlist_song_needed_remove_power);
auto permissions = entry->permission_manager();
auto permission = permissions->permission_value_flagged(permission::i_playlist_needed_modify_power);
notify[index]["needed_power_modify"] = permission.has_value ? permission.value : 0;
permission = permissions->permission_value_flagged(permission::i_playlist_needed_permission_modify_power);
notify[index]["needed_power_permission_modify"] = permission.has_value ? permission.value : 0;
permission = permissions->permission_value_flagged(permission::i_playlist_needed_delete_power);
notify[index]["needed_power_delete"] = permission.has_value ? permission.value : 0;
permission = permissions->permission_value_flagged(permission::i_playlist_song_needed_add_power);
notify[index]["needed_power_song_add"] = permission.has_value ? permission.value : 0;
permission = permissions->permission_value_flagged(permission::i_playlist_song_needed_move_power);
notify[index]["needed_power_song_move"] = permission.has_value ? permission.value : 0;
permission = permissions->permission_value_flagged(permission::i_playlist_song_needed_remove_power);
notify[index]["needed_power_song_remove"] = permission.has_value ? permission.value : 0;
index++;
}
@@ -363,19 +371,19 @@ command_result ConnectedClient::handleCommandPlaylistCreate(ts::Command &cmd) {
auto power = this->calculate_permission(permission::i_playlist_song_remove_power, 0);
if(power.has_value && power.value >= 0)
playlist->permissions()->setPermission(permission::i_playlist_song_needed_remove_power, power.value, nullptr);
playlist->permission_manager()->set_permission(permission::i_playlist_song_needed_remove_power, {power.value, 0}, permission::v2::set_value, permission::v2::do_nothing);
power = this->calculate_permission(permission::i_playlist_delete_power, 0);
if(power.has_value && power.value >= 0)
playlist->permissions()->setPermission(permission::i_playlist_needed_delete_power, power.value, nullptr);
playlist->permission_manager()->set_permission(permission::i_playlist_needed_delete_power, {power.value, 0}, permission::v2::set_value, permission::v2::do_nothing);
power = this->calculate_permission(permission::i_playlist_modify_power, 0);
if(power.has_value && power.value >= 0)
playlist->permissions()->setPermission(permission::i_playlist_needed_modify_power, power.value, nullptr);
playlist->permission_manager()->set_permission(permission::i_playlist_needed_modify_power, {power.value, 0}, permission::v2::set_value, permission::v2::do_nothing);
power = this->calculate_permission(permission::i_playlist_permission_modify_power, 0);
if(power.has_value && power.value >= 0)
playlist->permissions()->setPermission(permission::i_playlist_needed_permission_modify_power, power.value, nullptr);
playlist->permission_manager()->set_permission(permission::i_playlist_needed_permission_modify_power, {power.value, 0}, permission::v2::set_value, permission::v2::do_nothing);
Command notify(this->notify_response_command("notifyplaylistcreated"));
notify["playlist_id"] = playlist->playlist_id();
@@ -392,8 +400,8 @@ command_result ConnectedClient::handleCommandPlaylistDelete(ts::Command &cmd) {
auto playlist = ref_server->musicManager->find_playlist(cmd["playlist_id"]);
if(!playlist) return command_result{error::playlist_invalid_id};
if(playlist->properties()[property::PLAYLIST_OWNER_DBID] != this->getClientDatabaseId())
ACTION_REQUIRES_GLOBAL_PERMISSION(permission::i_playlist_delete_power, playlist->permissions()->getPermissionValue(permission::i_playlist_needed_delete_power));
if(auto perr = playlist->client_has_permissions(this->ref(), permission::i_playlist_needed_delete_power, permission::i_playlist_delete_power); perr)
return command_result{perr};
string error;
if(!ref_server->musicManager->delete_playlist(playlist->playlist_id(), error)) {
@@ -412,8 +420,8 @@ command_result ConnectedClient::handleCommandPlaylistInfo(ts::Command &cmd) {
auto playlist = ref_server->musicManager->find_playlist(cmd["playlist_id"]);
if(!playlist) return command_result{error::playlist_invalid_id};
if(playlist->properties()[property::PLAYLIST_OWNER_DBID] != this->getClientDatabaseId())
ACTION_REQUIRES_GLOBAL_PERMISSION(permission::i_playlist_view_power, playlist->permissions()->getPermissionValue(permission::i_playlist_needed_view_power));
if(auto perr = playlist->client_has_permissions(this->ref(), permission::i_playlist_needed_view_power, permission::i_playlist_view_power, music::PlaylistPermissions::do_no_require_granted); perr)
return command_result{perr};
Command notify(this->notify_response_command("notifyplaylistinfo"));
@@ -433,8 +441,8 @@ command_result ConnectedClient::handleCommandPlaylistEdit(ts::Command &cmd) {
auto playlist = ref_server->musicManager->find_playlist(cmd["playlist_id"]);
if(!playlist) return command_result{error::playlist_invalid_id};
if(playlist->properties()[property::PLAYLIST_OWNER_DBID] != this->getClientDatabaseId())
ACTION_REQUIRES_GLOBAL_PERMISSION(permission::i_playlist_modify_power, playlist->permissions()->getPermissionValue(permission::i_playlist_needed_modify_power));
if(auto perr = playlist->client_has_permissions(this->ref(), permission::i_playlist_needed_modify_power, permission::i_playlist_modify_power); perr)
return command_result{perr};
deque<pair<shared_ptr<property::PropertyDescription>, string>> properties;
@@ -491,28 +499,41 @@ command_result ConnectedClient::handleCommandPlaylistPermList(ts::Command &cmd)
auto playlist = ref_server->musicManager->find_playlist(cmd["playlist_id"]);
if(!playlist) return command_result{error::playlist_invalid_id};
if(playlist->properties()[property::PLAYLIST_OWNER_DBID] != this->getClientDatabaseId())
ACTION_REQUIRES_GLOBAL_PERMISSION(permission::b_virtualserver_playlist_permission_list, 1);
{
auto value = playlist->calculate_client_specific_permissions(permission::b_virtualserver_playlist_permission_list, this->ref());
if(!permission::v2::permission_granted(1, value))
return command_result{permission::b_virtualserver_playlist_permission_list};
}
auto permissions = playlist->permissions()->listPermissions(PERM_FLAG_PUBLIC);
auto permissions = playlist->permission_manager()->permissions();
if(permissions.empty())
return command_result{error::vs_critical};
return command_result{error::database_empty_result};
Command result(this->notify_response_command("notifyplaylistpermlist"));
auto permission_mapper = serverInstance->getPermissionMapper();
auto perm_sid = cmd.hasParm("permsid") || cmd.hasParm("names");
int index = 0;
result["playlist_id"] = playlist->playlist_id();
for (const auto &elm : permissions) {
if(elm->hasValue()) {
result[index]["permid"] = elm->type->type;
for (const auto &[perm, value] : permissions) {
if(value.flags.value_set) {
if (perm_sid)
result[index]["permsid"] = permission_mapper->permission_name(this->getType(), perm);
else
result[index]["permid"] = perm;
result[index]["permvalue"] = elm->value;
result[index]["permnegated"] = elm->flag_negate;
result[index]["permskip"] = elm->flag_skip;
result[index]["permvalue"] = value.values.value;
result[index]["permnegated"] = value.flags.negate;
result[index]["permskip"] = value.flags.skip;
index++;
}
if(elm->hasGrant()) {
result[index]["permid"] = (uint16_t) (elm->type->type | PERM_ID_GRANT);
result[index]["permvalue"] = elm->granted;
if(value.flags.grant_set) {
if (perm_sid)
result[index]["permsid"] = permission_mapper->permission_name_grant(this->getType(), perm);
else
result[index]["permid"] = perm | PERM_ID_GRANT;
result[index]["permvalue"] = value.values.grant;
result[index]["permnegated"] = 0;
result[index]["permskip"] = 0;
index++;
@@ -531,8 +552,8 @@ command_result ConnectedClient::handleCommandPlaylistAddPerm(ts::Command &cmd) {
auto playlist = ref_server->musicManager->find_playlist(cmd["playlist_id"]);
if(!playlist) return command_result{error::playlist_invalid_id};
if(playlist->properties()[property::PLAYLIST_OWNER_DBID] != this->getClientDatabaseId())
ACTION_REQUIRES_GLOBAL_PERMISSION(permission::i_playlist_permission_modify_power, playlist->permissions()->getPermissionValue(permission::i_playlist_needed_permission_modify_power));
if(auto perr = playlist->client_has_permissions(this->ref(), permission::i_playlist_needed_permission_modify_power, permission::i_playlist_permission_modify_power); perr)
return command_result{perr};
auto max_value = this->calculate_permission(permission::i_permission_modify_power, 0, true);
if(!max_value.has_value) return command_result{permission::i_permission_modify_power};
@@ -556,10 +577,9 @@ command_result ConnectedClient::handleCommandPlaylistAddPerm(ts::Command &cmd) {
}
if (grant) {
playlist->permissions()->setPermissionGranted(permType, cmd[index]["permvalue"], nullptr);
playlist->permission_manager()->set_permission(permType, {0, cmd[index]["permvalue"]}, permission::v2::do_nothing, permission::v2::set_value);
} else {
playlist->permissions()->setPermission(permType, cmd[index]["permvalue"], nullptr, cmd[index]["permskip"], cmd[index]["permnegated"]);
playlist->permission_manager()->set_permission(permType, {cmd[index]["permvalue"],0}, permission::v2::set_value, permission::v2::do_nothing, cmd[index]["permskip"].as<bool>(), cmd[index]["permnegated"].as<bool>());
}
}
@@ -574,8 +594,8 @@ command_result ConnectedClient::handleCommandPlaylistDelPerm(ts::Command &cmd) {
auto playlist = ref_server->musicManager->find_playlist(cmd["playlist_id"]);
if(!playlist) return command_result{error::playlist_invalid_id};
if(playlist->properties()[property::PLAYLIST_OWNER_DBID] != this->getClientDatabaseId())
ACTION_REQUIRES_GLOBAL_PERMISSION(permission::i_playlist_permission_modify_power, playlist->permissions()->getPermissionValue(permission::i_playlist_needed_permission_modify_power));
if(auto perr = playlist->client_has_permissions(this->ref(), permission::i_playlist_needed_permission_modify_power, permission::i_playlist_permission_modify_power); perr)
return command_result{perr};
auto ignore_granted_values = permission::v2::permission_granted(1, this->calculate_permission(permission::b_permission_modify_power_ignore, 0));
bool conOnError = cmd[0].has("continueonerror");
@@ -588,10 +608,154 @@ command_result ConnectedClient::handleCommandPlaylistDelPerm(ts::Command &cmd) {
return command_result{permission::i_permission_modify_power};
}
if (grant) {
playlist->permissions()->setPermissionGranted(permType, permNotGranted, nullptr);
playlist->permission_manager()->set_permission(permType, {0, 0}, permission::v2::do_nothing, permission::v2::delete_value);
} else {
playlist->permissions()->deletePermission(permType, nullptr);
playlist->permission_manager()->set_permission(permType, {0, 0}, permission::v2::delete_value, permission::v2::do_nothing);
}
}
return command_result{error::ok};
}
command_result ConnectedClient::handleCommandPlaylistClientPermList(ts::Command &cmd) {
CMD_REF_SERVER(ref_server);
CMD_RESET_IDLE;
CMD_CHK_AND_INC_FLOOD_POINTS(25);
auto playlist = ref_server->musicManager->find_playlist(cmd["playlist_id"]);
if(!playlist) return command_result{error::playlist_invalid_id};
{
auto value = playlist->calculate_client_specific_permissions(permission::b_virtualserver_playlist_permission_list, this->ref());
if(!permission::v2::permission_granted(1, value))
return command_result{permission::b_virtualserver_playlist_permission_list};
}
auto permissions = playlist->permission_manager()->channel_permissions();
if(permissions.empty())
return command_result{error::database_empty_result};
Command result(this->notify_response_command("notifyplaylistclientpermlist"));
auto client_id = cmd.hasParm("cldbid") ? cmd[0]["cldbid"].as<ClientDbId>() : 0;
auto permission_mapper = serverInstance->getPermissionMapper();
auto perm_sid = cmd.hasParm("permsid") || cmd.hasParm("names");
int index = 0;
ClientDbId last_client_id{0};
result["playlist_id"] = playlist->playlist_id();
result["cldbid"] = client_id;
for (const auto &[perm, client, value] : permissions) {
if(client_id > 0 && client != client_id) continue;
if(last_client_id != client)
result[index]["cldbid"] = client;
if(value.flags.value_set) {
if (perm_sid)
result[index]["permsid"] = permission_mapper->permission_name(this->getType(), perm);
else
result[index]["permid"] = perm;
result[index]["permvalue"] = value.values.value;
result[index]["permnegated"] = value.flags.negate;
result[index]["permskip"] = value.flags.skip;
index++;
}
if(value.flags.grant_set) {
if (perm_sid)
result[index]["permsid"] = permission_mapper->permission_name_grant(this->getType(), perm);
else
result[index]["permid"] = perm | PERM_ID_GRANT;
result[index]["permvalue"] = value.values.grant;
result[index]["permnegated"] = 0;
result[index]["permskip"] = 0;
index++;
}
}
if(index == 0)
return command_result{error::database_empty_result};
this->sendCommand(result);
return command_result{error::ok};
}
command_result ConnectedClient::handleCommandPlaylistClientAddPerm(ts::Command &cmd) {
CMD_REF_SERVER(ref_server);
CMD_RESET_IDLE;
CMD_CHK_AND_INC_FLOOD_POINTS(5);
auto playlist = ref_server->musicManager->find_playlist(cmd["playlist_id"]);
if(!playlist) return command_result{error::playlist_invalid_id};
auto client_id = cmd[0]["cldbid"].as<ClientDbId>();
if(client_id == 0) return command_result{error::client_invalid_id};
if(auto perr = playlist->client_has_permissions(this->ref(), permission::i_playlist_needed_permission_modify_power, permission::i_playlist_permission_modify_power); perr)
return command_result{perr};
auto max_value = this->calculate_permission(permission::i_permission_modify_power, 0, true);
if(!max_value.has_value) return command_result{permission::i_permission_modify_power};
auto ignore_granted_values = permission::v2::permission_granted(1, this->calculate_permission(permission::b_permission_modify_power_ignore, 0));
bool conOnError = cmd[0].has("continueonerror");
for (int index = 0; index < cmd.bulkCount(); index++) {
PARSE_PERMISSION(cmd);
auto val = cmd[index]["permvalue"].as<permission::PermissionValue>();
if(permission_require_granted_value(permType) && !permission::v2::permission_granted(val, max_value)) {
if(conOnError) continue;
return command_result{permission::i_permission_modify_power};
}
if(!ignore_granted_values && !permission::v2::permission_granted(val, this->calculate_permission(permType, 0, true))) {
if(conOnError) continue;
return command_result{permission::i_permission_modify_power};
}
if (grant) {
playlist->permission_manager()->set_channel_permission(permType, client_id, {0, cmd[index]["permvalue"]}, permission::v2::do_nothing, permission::v2::set_value);
} else {
playlist->permission_manager()->set_channel_permission(permType, client_id, {cmd[index]["permvalue"], 0}, permission::v2::set_value, permission::v2::do_nothing, cmd[index]["permskip"].as<bool>(), cmd[index]["permnegated"].as<bool>());
}
}
return command_result{error::ok};
}
command_result ConnectedClient::handleCommandPlaylistClientDelPerm(ts::Command &cmd) {
CMD_REF_SERVER(ref_server);
CMD_RESET_IDLE;
CMD_CHK_AND_INC_FLOOD_POINTS(5);
auto playlist = ref_server->musicManager->find_playlist(cmd["playlist_id"]);
if(!playlist) return command_result{error::playlist_invalid_id};
auto client_id = cmd[0]["cldbid"].as<ClientDbId>();
if(client_id == 0) return command_result{error::client_invalid_id};
if(auto perr = playlist->client_has_permissions(this->ref(), permission::i_playlist_needed_permission_modify_power, permission::i_playlist_permission_modify_power); perr)
return command_result{perr};
auto ignore_granted_values = permission::v2::permission_granted(1, this->calculate_permission(permission::b_permission_modify_power_ignore, 0));
bool conOnError = cmd[0].has("continueonerror");
for (int index = 0; index < cmd.bulkCount(); index++) {
PARSE_PERMISSION(cmd);
if(!ignore_granted_values && !permission::v2::permission_granted(0, this->calculate_permission(permType, 0, true))) {
if(conOnError) continue;
return command_result{permission::i_permission_modify_power};
}
if (grant) {
playlist->permission_manager()->set_channel_permission(permType, client_id, {0, 0}, permission::v2::do_nothing, permission::v2::delete_value);
} else {
playlist->permission_manager()->set_channel_permission(permType, client_id, {0, 0}, permission::v2::delete_value, permission::v2::do_nothing);
}
}
@@ -606,8 +770,8 @@ command_result ConnectedClient::handleCommandPlaylistSongList(ts::Command &cmd)
auto playlist = ref_server->musicManager->find_playlist(cmd["playlist_id"]);
if(!playlist) return command_result{error::playlist_invalid_id};
if(playlist->properties()[property::PLAYLIST_OWNER_DBID] != this->getClientDatabaseId())
ACTION_REQUIRES_GLOBAL_PERMISSION(permission::i_playlist_view_power, playlist->permissions()->getPermissionValue(permission::i_playlist_needed_view_power));
if(auto perr = playlist->client_has_permissions(this->ref(), permission::i_playlist_needed_view_power, permission::i_playlist_view_power); perr)
return command_result{perr};
auto songs = playlist->list_songs();
if(songs.empty())
@@ -640,8 +804,8 @@ command_result ConnectedClient::handleCommandPlaylistSongAdd(ts::Command &cmd) {
auto playlist = ref_server->musicManager->find_playlist(cmd["playlist_id"]);
if(!playlist) return command_result{error::playlist_invalid_id};
if(playlist->properties()[property::PLAYLIST_OWNER_DBID] != this->getClientDatabaseId())
ACTION_REQUIRES_GLOBAL_PERMISSION(permission::i_playlist_song_add_power, playlist->permissions()->getPermissionValue(permission::i_playlist_song_needed_add_power));
if(auto perr = playlist->client_has_permissions(this->ref(), permission::i_playlist_song_needed_add_power, permission::i_playlist_song_add_power); perr)
return command_result{perr};
if(!cmd[0].has("invoker"))
cmd["invoker"] = "";
@@ -672,8 +836,8 @@ command_result ConnectedClient::handleCommandPlaylistSongReorder(ts::Command &cm
auto playlist = ref_server->musicManager->find_playlist(cmd["playlist_id"]);
if(!playlist) return command_result{error::playlist_invalid_id};
if(playlist->properties()[property::PLAYLIST_OWNER_DBID] != this->getClientDatabaseId())
ACTION_REQUIRES_GLOBAL_PERMISSION(permission::i_playlist_song_move_power, playlist->permissions()->getPermissionValue(permission::i_playlist_song_needed_move_power));
if(auto perr = playlist->client_has_permissions(this->ref(), permission::i_playlist_song_needed_move_power, permission::i_playlist_song_move_power); perr)
return command_result{perr};
SongId song_id = cmd["song_id"];
SongId previous_id = cmd["song_previous_song_id"];
@@ -695,8 +859,8 @@ command_result ConnectedClient::handleCommandPlaylistSongRemove(ts::Command &cmd
auto playlist = ref_server->musicManager->find_playlist(cmd["playlist_id"]);
if(!playlist) return command_result{error::playlist_invalid_id};
if(playlist->properties()[property::PLAYLIST_OWNER_DBID] != this->getClientDatabaseId())
ACTION_REQUIRES_GLOBAL_PERMISSION(permission::i_playlist_song_remove_power, playlist->permissions()->getPermissionValue(permission::i_playlist_song_needed_remove_power));
if(auto perr = playlist->client_has_permissions(this->ref(), permission::i_playlist_song_needed_remove_power, permission::i_playlist_song_remove_power); perr)
return command_result{perr};
SongId song_id = cmd["song_id"];
@@ -709,85 +873,63 @@ command_result ConnectedClient::handleCommandPlaylistSongRemove(ts::Command &cmd
return command_result{error::ok};
}
command_result ConnectedClient::handleCommandMusicBotQueueList(Command& cmd) {
return command_result{error::not_implemented}; //FIXME
/*
/****** legacy ******/
command_result ConnectedClient::handleCommandMusicBotQueueList(Command& cmd) {
CMD_REQ_SERVER;
CMD_RESET_IDLE;
CMD_CHK_AND_INC_FLOOD_POINTS(25);
auto bot = this->server->musicManager->findBotById(cmd["bot_id"]);
if(!bot) return command_result{error::music_invalid_id};
PERM_CHECK_CHANNELR(permission::i_client_music_info, bot->permissionValue(permission::i_client_music_needed_info, bot->currentChannel), this->currentChannel, true);
auto playlist = dynamic_pointer_cast<music::PlayablePlaylist>(bot->playlist());
if(!playlist) return command_result{error::vs_critical};
if(auto perr = playlist->client_has_permissions(this->ref(), permission::i_playlist_needed_view_power, permission::i_playlist_view_power); perr)
return command_result{perr};
bool bulked = cmd.hasParm("bulk") || cmd.hasParm("balk") || cmd.hasParm("pipe") || cmd.hasParm("bar") || cmd.hasParm("paypal");
int command_index = 0;
Command notify(this->getExternalType() == CLIENT_VOICE ? "notifymusicqueueentry" : "");
{
auto history = bot->queue()->history();
for(int index = history.size(); index > 0; index--) {
if(!bulked)
notify = Command(this->getExternalType() == CLIENT_VOICE ? "notifymusicqueueentry" : "");
Command notify(this->notify_response_command("notifymusicqueueentry"));
auto songs = playlist->list_songs();
int begin_index{0};
for(auto it = songs.begin(); it != songs.end(); it++)
if((*it)->id == playlist->currently_playing())
break;
else
begin_index--;
apply_song(notify, history[index - 1], command_index);
notify[command_index]["queue_index"] = -index;
if(!bulked)
this->sendCommand(notify);
else
command_index++;
}
}
{
for(auto it = songs.begin(); it != songs.end(); it++) {
if(!bulked)
notify = Command(this->getExternalType() == CLIENT_VOICE ? "notifymusicqueueentry" : "");
notify = Command(this->notify_response_command("notifymusicqueueentry"));
auto song = bot->queue()->currentSong();
apply_song(notify, song, command_index);
notify[command_index]["queue_index"] = 0;
//TODO!
//apply_song(notify, *it, command_index);
notify[command_index]["queue_index"] = begin_index++;
if(!bulked)
this->sendCommand(notify);
else if(song)
else
command_index++;
}
{
auto queue = bot->queue()->queueEntries();
for(int index = 0; index < queue.size(); index++) {
if(!bulked)
notify = Command(this->getExternalType() == CLIENT_VOICE ? "notifymusicqueueentry" : "");
apply_song(notify, queue[index], command_index);
notify[command_index]["queue_index"] = index + 1;
if(!bulked)
this->sendCommand(notify);
else
command_index++;
}
}
debugMessage(this->getServerId(),"Send: {}",notify.build());
if(bulked) {
if(command_index > 0) {
this->sendCommand(notify);
} else return { ErrorType::DBEmpty };
} else
return command_result{error::database_empty_result};
}
if(this->getExternalType() == CLIENT_VOICE) {
if(this->getExternalType() == ClientType::CLIENT_TEAMSPEAK) {
Command notify("notifymusicqueuefinish");
notify["bot_id"] = bot->getClientDatabaseId();
this->sendCommand(notify);
}
return command_result{error::ok};
*/
}
command_result ConnectedClient::handleCommandMusicBotQueueAdd(Command& cmd) {
@@ -898,8 +1040,8 @@ command_result ConnectedClient::handleCommandMusicBotPlaylistAssign(ts::Command
if(ref_server->musicManager->find_bot_by_playlist(playlist))
return command_result{error::playlist_already_in_use};
if(playlist && playlist->properties()[property::PLAYLIST_OWNER_DBID] != this->getClientDatabaseId())
ACTION_REQUIRES_GLOBAL_PERMISSION(permission::i_playlist_view_power, playlist->permissions()->getPermissionValue(permission::i_playlist_needed_view_power));
if(auto perr = playlist->client_has_permissions(this->ref(), permission::i_playlist_needed_view_power, permission::i_playlist_view_power); perr)
return command_result{perr};
if(!ref_server->musicManager->assign_playlist(bot, playlist))
return command_result{error::vs_critical};