Fixed some bugs

This commit is contained in:
WolverinDEV
2019-10-20 12:09:28 +02:00
parent 0c6fd1f864
commit 0bedf6c42a
21 changed files with 147 additions and 86 deletions
@@ -3451,9 +3451,12 @@ CommandResult ConnectedClient::handleCommandSendTextMessage(Command &cmd) {
CMD_REQ_CHANNEL;
channel = this->currentChannel;
channel_id = this->currentChannel->channelId();
}
if(channel == this->currentChannel) {
channel_tree_read_lock.unlock(); //Method may creates a music bot which modifies the channel tree
if(this->handleTextMessage(ChatMessageMode::TEXTMODE_CHANNEL, cmd["msg"], nullptr))
return CommandResult::Success;
channel_tree_read_lock.lock();
}
if(!this->permissionGranted(permission::PERMTEST_ORDERED, permission::b_client_channel_textmessage_send, 1, channel, false))
@@ -3565,17 +3568,20 @@ CommandResult ConnectedClient::handleCommandClientChatClosed(Command &cmd) {
//1 .. n
// notifyfilelist cid=1 path=\/ return_code=1:x name=testFile size=35256 datetime=1509459767 type=1|name=testDir size=0 datetime=1509459741 type=0|name=testDir_2 size=0 datetime=1509459763 type=0
//notifyfilelistfinished cid=1 path=\/
inline void appendFileList(Command &fileList, vector<std::shared_ptr<file::FileEntry>> files) {
inline void cmd_filelist_append_files(ServerId sid, Command &command, vector<std::shared_ptr<file::FileEntry>> files) {
int index = 0;
logTrace(sid, "Sending file list for path {}", command["path"].string());
for (const auto& fileEntry : files) {
debugMessage(lstream << "Having file " << fileEntry->path << "/" << fileEntry->name << " (Name: " << fileEntry->name << ")" << endl);
fileList[index]["name"] = fileEntry->name;
fileList[index]["datetime"] = std::chrono::duration_cast<std::chrono::seconds>(fileEntry->lastChanged.time_since_epoch()).count();
fileList[index]["type"] = fileEntry->type;
logTrace(sid, " - {} ({})", fileEntry->name, fileEntry->type == file::FileType::FILE ? "file" : "directory");
command[index]["name"] = fileEntry->name;
command[index]["datetime"] = std::chrono::duration_cast<std::chrono::seconds>(fileEntry->lastChanged.time_since_epoch()).count();
command[index]["type"] = fileEntry->type;
if (fileEntry->type == file::FileType::FILE)
fileList[index]["size"] = static_pointer_cast<file::File>(fileEntry)->fileSize;
command[index]["size"] = static_pointer_cast<file::File>(fileEntry)->fileSize;
else
fileList[index]["size"] = 0;
command[index]["size"] = 0;
index++;
}
}
@@ -3592,10 +3598,10 @@ CommandResult ConnectedClient::handleCommandFTGetFileList(Command &cmd) {
Command fileListFinished("notifyfilelistfinished");
fileList["path"] = cmd["path"].as<std::string>();
fileList["return_code"] = code;
if(!code.empty()) fileList["return_code"] = code;
fileListFinished["path"] = cmd["path"].as<std::string>();
fileList["cid"] = cmd["cid"].as<size_t>();
fileListFinished["cid"] = cmd["cid"].as<size_t>();
fileListFinished["cid"] = cmd["cid"].as<ChannelId>();
if (cmd[0].has("cid") && cmd["cid"] != 0) { //Channel
auto channel = this->server->channelTree->findChannel(cmd["cid"].as<ChannelId>());
@@ -3603,27 +3609,32 @@ CommandResult ConnectedClient::handleCommandFTGetFileList(Command &cmd) {
if (!channel->passwordMatch(cmd["cpw"]) && !this->permissionGranted(permission::PERMTEST_ORDERED, permission::b_ft_ignore_password, 1, channel, true))
return cmd["cpw"].string().empty() ? CommandResultPermissionError{permission::b_ft_ignore_password} : CommandResult{findError("channel_invalid_password")};
CHANNEL_PERMISSION_TEST(permission::i_ft_file_browse_power, permission::i_ft_needed_file_browse_power, channel, true);
appendFileList(fileList, serverInstance->getFileServer()->listFiles(serverInstance->getFileServer()->resolveDirectory(this->server, channel, cmd["path"].as<std::string>())));
cmd_filelist_append_files(
this->getServerId(),
fileList,
serverInstance->getFileServer()->listFiles(serverInstance->getFileServer()->resolveDirectory(this->server, channel, cmd["path"].as<std::string>()))
);
} else {
if (cmd["path"].as<string>() == "/icons" || cmd["path"].as<string>() == "/icons/") {
appendFileList(fileList, serverInstance->getFileServer()->listFiles(serverInstance->getFileServer()->iconDirectory(this->server)));
cmd_filelist_append_files(this->getServerId(), fileList, serverInstance->getFileServer()->listFiles(serverInstance->getFileServer()->iconDirectory(this->server)));
PERM_CHECKR(permission::b_icon_manage, 1, true);
} else if (cmd["path"].as<string>() == "/") {
appendFileList(fileList, serverInstance->getFileServer()->listFiles(serverInstance->getFileServer()->avatarDirectory(this->server)));
cmd_filelist_append_files(this->getServerId(), fileList, serverInstance->getFileServer()->listFiles(serverInstance->getFileServer()->avatarDirectory(this->server)));
PERM_CHECKR(permission::b_icon_manage, 1, true);
} else {
cerr << "Unknown requested directory: '" << cmd["path"].as<std::string>() << "'" << endl;
logMessage(this->getServerId(), "{} Requested file list for unknown path/name: path: {} name: {}", cmd["path"].string(), cmd["name"].string());
return CommandResult::NotImplemented;
}
}
if (fileList[0].has("name")) {
if(dynamic_cast<VoiceClient*>(this)) {
dynamic_cast<VoiceClient*>(this)->sendCommand0(fileList, false, true); /* We need to process this directly else the order could get shuffeled up! */
dynamic_cast<VoiceClient*>(this)->sendCommand0(fileList, false, true); /* We need to process this directly else the order could get shuffled up! */
this->sendCommand(fileListFinished);
} else {
this->sendCommand(fileList);
this->sendCommand(fileListFinished);
if(this->getType() != CLIENT_QUERY)
this->sendCommand(fileListFinished);
}
return CommandResult::Success;
} else {
@@ -3690,7 +3701,7 @@ CommandResult ConnectedClient::handleCommandFTDeleteFile(Command &cmd) {
}
files.push_back(serverInstance->getFileServer()->findFile(cmd["name"].string(), serverInstance->getFileServer()->avatarDirectory(this->server)));
} else {
cerr << "Unknown requested file to delete: " << cmd["path"].as<std::string>() << endl;
logError(this->getServerId(), "Unknown requested file to delete: {}", cmd["path"].as<std::string>());
return CommandResult::NotImplemented;
}
}