restrict:添加不能update和down自己的文件限制。

This commit is contained in:
taynpg 2025-01-07 15:08:37 +08:00
parent fbb1ae43e8
commit e825387201
2 changed files with 17 additions and 2 deletions

View File

@ -136,8 +136,14 @@ bool CClient::down_task(const std::string& param)
logger_->error("No matched id[{}] in task list.", id);
return false;
}
down_ = std::make_shared<TransInfomation>();
if (task_list_[id]->id == own_id_) {
logger_->warn("You can't down your own file!!!");
return false;
}
const auto& vec = task_list_[id]->files;
down_ = std::make_shared<TransInfomation>();
if (vec.empty()) {
logger_->warn("No files List, Please Check!");
@ -336,6 +342,13 @@ bool CClient::request_update_list(const std::string& param)
logger_->error("No Index Found {}.", index);
return false;
}
const auto& sr = task_list_[index];
if (sr->id == own_id_) {
logger_->warn("You can't update your own file!!!");
return false;
}
// 读取list文件
std::ifstream in(COfPath::to_full(list_file));
if (!in.is_open()) {
@ -454,6 +467,7 @@ void CClient::handle_frame(CFrameBuffer* buf)
switch (buf->type_) {
case TYPE_GET_ID: {
logger_->debug("Your ID:{}", buf->tid_);
own_id_ = buf->tid_;
break;
}
case TYPE_GET_LIST: {
@ -658,7 +672,7 @@ void CClient::send_file_data_th(const char* keys)
logger_->error("Stop Trans {} To {} failed.", t->cur_file_, str_key);
return;
}
//std::this_thread::sleep_for(std::chrono::milliseconds(10));
// std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
buf->type_ = TYPE_TRANS_DONE;

View File

@ -86,6 +86,7 @@ private:
std::string list_file_;
std::string list_serve_id_;
std::thread update_list_th_;
std::string own_id_{};
};
class CFileOpr