mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-27 04:35:34 +08:00
Add feature password
This commit is contained in:
@@ -496,7 +496,7 @@ int main() {
|
||||
std::string user_id = "S-" + std::string(GetMac(mac_addr));
|
||||
|
||||
if (strcmp(online_label, "Online") == 0) {
|
||||
CreateConnection(peer_server, mac_addr);
|
||||
CreateConnection(peer_server, mac_addr, server_password);
|
||||
|
||||
nv12_buffer_ = new char[NV12_BUFFER_SIZE];
|
||||
#ifdef _WIN32
|
||||
@@ -572,7 +572,7 @@ int main() {
|
||||
if (ImGui::Button(connect_label)) {
|
||||
if (strcmp(connect_label, "Connect") == 0 && !joined) {
|
||||
std::string user_id = "C-" + std::string(GetMac(mac_addr));
|
||||
JoinConnection(peer_client, remote_id);
|
||||
JoinConnection(peer_client, remote_id, client_password);
|
||||
joined = true;
|
||||
} else if (strcmp(connect_label, "Disconnect") == 0 && joined) {
|
||||
LeaveConnection(peer_client);
|
||||
|
||||
@@ -130,6 +130,7 @@ void SignalServer::on_message(websocketpp::connection_hdl hdl,
|
||||
switch (HASH_STRING_PIECE(type.c_str())) {
|
||||
case "create_transmission"_H: {
|
||||
std::string transmission_id = j["transmission_id"].get<std::string>();
|
||||
std::string password = j["password"].get<std::string>();
|
||||
std::string user_id = j["user_id"].get<std::string>();
|
||||
LOG_INFO("Receive user id [{}] create transmission request with id [{}]",
|
||||
user_id, transmission_id);
|
||||
@@ -151,6 +152,8 @@ void SignalServer::on_message(websocketpp::connection_hdl hdl,
|
||||
transmission_manager_.BindUserIdToTransmission(user_id,
|
||||
transmission_id);
|
||||
transmission_manager_.BindUserIdToWsHandle(user_id, hdl);
|
||||
transmission_manager_.BindPasswordToTransmission(password,
|
||||
transmission_id);
|
||||
|
||||
LOG_INFO("Create transmission id [{}]", transmission_id);
|
||||
json message = {{"type", "transmission_id"},
|
||||
@@ -190,16 +193,36 @@ void SignalServer::on_message(websocketpp::connection_hdl hdl,
|
||||
}
|
||||
case "query_user_id_list"_H: {
|
||||
std::string transmission_id = j["transmission_id"].get<std::string>();
|
||||
std::vector<std::string> user_id_list =
|
||||
transmission_manager_.GetAllUserIdOfTransmission(transmission_id);
|
||||
std::string password = j["password"].get<std::string>();
|
||||
|
||||
json message = {{"type", "user_id_list"},
|
||||
{"transmission_id", transmission_id},
|
||||
{"user_id_list", user_id_list},
|
||||
{"status", "success"}};
|
||||
if (transmission_manager_.CheckPassword(password, transmission_id)) {
|
||||
std::vector<std::string> user_id_list =
|
||||
transmission_manager_.GetAllUserIdOfTransmission(transmission_id);
|
||||
|
||||
json message = {{"type", "user_id_list"},
|
||||
{"transmission_id", transmission_id},
|
||||
{"user_id_list", user_id_list},
|
||||
{"status", "success"}};
|
||||
|
||||
send_msg(hdl, message);
|
||||
} else {
|
||||
std::vector<std::string> user_id_list;
|
||||
json message = {{"type", "user_id_list"},
|
||||
{"transmission_id", transmission_id},
|
||||
{"user_id_list", user_id_list},
|
||||
{"status", "failed"},
|
||||
{"reason", "Incorrect password"}};
|
||||
// LOG_INFO(
|
||||
// "Incorrect password [{}] for transmission [{}] with password is "
|
||||
// "[{}]",
|
||||
// password, transmission_id,
|
||||
// transmission_manager_.GetPassword(transmission_id));
|
||||
|
||||
send_msg(hdl, message);
|
||||
}
|
||||
|
||||
// LOG_INFO("Send member_list: [{}]", message.dump());
|
||||
send_msg(hdl, message);
|
||||
|
||||
break;
|
||||
}
|
||||
case "offer"_H: {
|
||||
|
||||
@@ -40,6 +40,25 @@ bool TransmissionManager::BindUserIdToTransmission(
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TransmissionManager::BindPasswordToTransmission(
|
||||
const std::string& password, const std::string& transmission_id) {
|
||||
if (transmission_password_list_.find(transmission_id) ==
|
||||
transmission_password_list_.end()) {
|
||||
transmission_password_list_[transmission_id] = password;
|
||||
// LOG_INFO("Bind password [{}] to transmission [{}]", password,
|
||||
// transmission_id);
|
||||
return true;
|
||||
} else {
|
||||
auto old_password = transmission_password_list_[transmission_id];
|
||||
transmission_password_list_[transmission_id] = password;
|
||||
// LOG_WARN("Update password [{}] to [{}] for transmission [{}]",
|
||||
// old_password, password, transmission_id);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TransmissionManager::BindUserIdToWsHandle(
|
||||
const std::string& user_id, websocketpp::connection_hdl hdl) {
|
||||
if (user_id_ws_hdl_list_.find(user_id) != user_id_ws_hdl_list_.end()) {
|
||||
@@ -94,6 +113,19 @@ bool TransmissionManager::ReleaseAllUserIdFromTransmission(
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TransmissionManager::ReleasePasswordFromTransmission(
|
||||
const std::string& transmission_id) {
|
||||
if (transmission_password_list_.end() ==
|
||||
transmission_password_list_.find(transmission_id)) {
|
||||
LOG_ERROR("No transmission with id [{}]", transmission_id);
|
||||
return false;
|
||||
}
|
||||
|
||||
transmission_password_list_.erase(transmission_id);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
websocketpp::connection_hdl TransmissionManager::GetWsHandle(
|
||||
const std::string& user_id) {
|
||||
if (user_id_ws_hdl_list_.find(user_id) != user_id_ws_hdl_list_.end()) {
|
||||
@@ -111,4 +143,26 @@ std::string TransmissionManager::GetUserId(websocketpp::connection_hdl hdl) {
|
||||
if (it->second.lock().get() == hdl.lock().get()) return it->first;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
bool TransmissionManager::CheckPassword(const std::string& password,
|
||||
const std::string& transmission_id) {
|
||||
if (transmission_password_list_.find(transmission_id) ==
|
||||
transmission_password_list_.end()) {
|
||||
LOG_ERROR("No transmission with id [{}]", transmission_id);
|
||||
return false;
|
||||
}
|
||||
|
||||
return transmission_password_list_[transmission_id] == password;
|
||||
}
|
||||
|
||||
std::string TransmissionManager::GetPassword(
|
||||
const std::string& transmission_id) {
|
||||
if (transmission_password_list_.find(transmission_id) ==
|
||||
transmission_password_list_.end()) {
|
||||
LOG_ERROR("No transmission with id [{}]", transmission_id);
|
||||
return "";
|
||||
}
|
||||
|
||||
return transmission_password_list_[transmission_id];
|
||||
}
|
||||
@@ -17,17 +17,24 @@ class TransmissionManager {
|
||||
public:
|
||||
bool BindUserIdToTransmission(const std::string& user_id,
|
||||
const std::string& transmission_id);
|
||||
bool BindPasswordToTransmission(const std::string& password,
|
||||
const std::string& transmission_id);
|
||||
bool BindUserIdToWsHandle(const std::string& user_id,
|
||||
websocketpp::connection_hdl hdl);
|
||||
|
||||
std::string ReleaseUserIdFromTransmission(websocketpp::connection_hdl hdl);
|
||||
bool ReleaseAllUserIdFromTransmission(const std::string& transmission_id);
|
||||
bool ReleasePasswordFromTransmission(const std::string& transmission_id);
|
||||
|
||||
websocketpp::connection_hdl GetWsHandle(const std::string& user_id);
|
||||
std::string GetUserId(websocketpp::connection_hdl hdl);
|
||||
bool CheckPassword(const std::string& password,
|
||||
const std::string& transmission_id);
|
||||
std::string GetPassword(const std::string& transmission_id);
|
||||
|
||||
private:
|
||||
std::map<std::string, std::vector<std::string>> transmission_user_id_list_;
|
||||
std::map<std::string, std::string> transmission_password_list_;
|
||||
std::map<std::string, websocketpp::connection_hdl> user_id_ws_hdl_list_;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user