From e8253872013208b7d3e7d008155fef0c57eacb99 Mon Sep 17 00:00:00 2001 From: taynpg Date: Tue, 7 Jan 2025 15:08:37 +0800 Subject: [PATCH] =?UTF-8?q?restrict=EF=BC=9A=E6=B7=BB=E5=8A=A0=E4=B8=8D?= =?UTF-8?q?=E8=83=BDupdate=E5=92=8Cdown=E8=87=AA=E5=B7=B1=E7=9A=84?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E9=99=90=E5=88=B6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/client.cpp | 18 ++++++++++++++++-- client/client.h | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/client/client.cpp b/client/client.cpp index 94a2233..3cc8783 100644 --- a/client/client.cpp +++ b/client/client.cpp @@ -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(); + + 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(); 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; diff --git a/client/client.h b/client/client.h index 0984921..0020872 100644 --- a/client/client.h +++ b/client/client.h @@ -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