safe:安全性更新,服务端改为从不主动给客户端发送信息,并添加客户端上线时间查看功能。

This commit is contained in:
taynpg 2024-12-24 09:46:24 +08:00
parent 21d4570028
commit 698d51a548
3 changed files with 22 additions and 13 deletions

View File

@ -56,6 +56,12 @@ void CClient::run(const std::string& ip, const std::string& port)
client_->async_recv();
hearts_ = std::thread([&]() { hearts(); });
std::thread thread([&]() { io_context_.run(); });
CFrameBuffer* bf = new CFrameBuffer();
bf->type_ = TYPE_GET_ID;
send_frame(bf);
delete bf;
logger_->warn("SupportCmd:Get|Up|Down|Cancel|Update");
char line[512]{};
while (std::cin.getline(line, 512)) {
@ -443,7 +449,7 @@ void CClient::handle_frame(CFrameBuffer* buf)
task_list_[index]->id = id;
}
logger_->debug("***********************************************");
logger_->debug("**********************************************************");
logger_->info("{}", real);
}
}

View File

@ -54,7 +54,8 @@ std::vector<TaskList> CTcpServer::get_clients()
TaskList t;
t.id_ = item.first;
t.task_ = item.second->task_;
t.time_ = item.second->time_;
t.task_time_ = item.second->task_time_;
t.online_time_ = item.second->online_time_;
result.push_back(t);
}
return result;
@ -67,7 +68,7 @@ void CTcpServer::get_client_list(CFrameBuffer** buf)
std::string msg;
int index = 1;
for (const auto& item : vec) {
msg.append(fmt::format("[{}][{}][{}]", index, item.id_, item.time_));
msg.append(fmt::format("[{}][{}][{}][{}]", index, item.id_, item.online_time_, item.task_time_));
auto files = COfStr::split(item.task_, "|");
for (const auto& file : files) {
msg.append("\n" + file);
@ -114,7 +115,7 @@ void CTcpServer::trans_data(CFrameBuffer* buf)
logger_->info("[{}] UpList. {}", buf->fid_, turn_files_path);
if (fcli) {
fcli->task_ = files_path;
fcli->time_ = OfUtil::now_time();
fcli->task_time_ = OfUtil::now_time();
}
break;
}
@ -122,10 +123,15 @@ void CTcpServer::trans_data(CFrameBuffer* buf)
logger_->info("[{}] Cancle Task.", buf->fid_);
if (fcli) {
fcli->task_.clear();
fcli->time_.clear();
fcli->task_time_.clear();
}
break;
}
case TYPE_GET_ID: {
buf->tid_ = buf->fid_;
send_frame(fcli->socket_, buf);
break;
}
case TYPE_JUDGE_ACTIVE: {
if (fcli && tcli) {
break;
@ -194,6 +200,7 @@ void CTcpServer::accept_client()
logger_->info("New connection from {}", client_key);
auto cache = std::make_shared<ClientCache>();
cache->socket_ = socket;
cache->online_time_ = OfUtil::now_time();
client_map_[client_key] = cache;
can = true;
}
@ -233,12 +240,6 @@ void CTcpServer::th_client(std::shared_ptr<asio::ip::tcp::socket> socket, const
cache = client_map_[client_key];
}
auto* f = new CFrameBuffer();
f->type_ = TYPE_GET_ID;
f->tid_ = client_key;
send_frame(socket, f);
delete f;
while (true) {
asio::error_code error;
size_t length = socket->read_some(asio::buffer(cache->tmp_buf_), error);

View File

@ -12,13 +12,15 @@ struct ClientCache {
CMutBuffer buffer_{};
std::array<char, g_BuffSize> tmp_buf_{};
std::string task_{};
std::string time_{};
std::string task_time_{};
std::string online_time_{};
FrameType cur_type_{TYPE_DEFAULT};
};
struct TaskList {
std::string id_{};
std::string task_{};
std::string time_{};
std::string task_time_{};
std::string online_time_{};
};
class CTcpServer