1.Enable random password; 2.Request user to input password when password is incorrect

This commit is contained in:
dijunkun
2024-07-03 15:07:40 +08:00
parent b822221d7f
commit 872152f1be
7 changed files with 1592 additions and 1512 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -18,7 +18,7 @@ int Render::ConnectionStatusWindow() {
connection_status_window_height_));
ImGui::SetWindowFontScale(0.5f);
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0, 1.0, 1.0, 1.0));
// ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0, 1.0, 1.0, 1.0));
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 5.0f);
ImGui::Begin("ConnectionStatusWindow", nullptr,
@@ -32,43 +32,93 @@ int Render::ConnectionStatusWindow() {
if (ConnectionStatus::Connecting == connection_status_) {
text = "Connecting...";
ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7);
ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3);
// Cancel
if (ImGui::Button(
localization::cancel[localization_language_index_].c_str())) {
connect_button_pressed_ = false;
}
} else if (ConnectionStatus::Connected == connection_status_) {
text = "Connected";
} else if (ConnectionStatus::Disconnected == connection_status_) {
text = "Disonnected";
ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7);
ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3);
// Cancel
if (ImGui::Button(
localization::cancel[localization_language_index_].c_str())) {
connect_button_pressed_ = false;
}
} else if (ConnectionStatus::Failed == connection_status_) {
text = "Failed";
ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7);
ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3);
// Cancel
if (ImGui::Button(
localization::cancel[localization_language_index_].c_str())) {
connect_button_pressed_ = false;
}
} else if (ConnectionStatus::Closed == connection_status_) {
text = "Closed";
ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7);
ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3);
// Cancel
if (ImGui::Button(
localization::cancel[localization_language_index_].c_str())) {
connect_button_pressed_ = false;
}
} else if (ConnectionStatus::IncorrectPassword == connection_status_) {
text = "Incorrect password";
text = "Please input password";
auto window_width = ImGui::GetWindowSize().x;
auto window_height = ImGui::GetWindowSize().y;
ImGui::SetCursorPosX((window_width - IPUT_WINDOW_WIDTH / 2) * 0.5f);
ImGui::SetCursorPosY(window_height * 0.4f);
ImGui::SetNextItemWidth(IPUT_WINDOW_WIDTH / 2);
ImGui::InputText("##password", (char *)remote_password_.c_str(), 7,
ImGuiInputTextFlags_CharsNoBlank);
ImGui::SetCursorPosX(window_width * 0.28f);
ImGui::SetCursorPosY(window_height * 0.75f);
// OK
if (ImGui::Button(
localization::ok[localization_language_index_].c_str())) {
connect_button_pressed_ = true;
JoinConnection(peer_reserved_ ? peer_reserved_ : peer_, remote_id_,
remote_password_.c_str());
}
ImGui::SameLine();
if (ImGui::Button(
localization::cancel[localization_language_index_].c_str())) {
remote_password_ = "";
connect_button_pressed_ = false;
}
} else if (ConnectionStatus::NoSuchTransmissionId == connection_status_) {
text = "No such transmissionId";
ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7);
ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3);
// Cancel
if (ImGui::Button(
localization::cancel[localization_language_index_].c_str())) {
connect_button_pressed_ = false;
}
}
auto window_width = ImGui::GetWindowSize().x;
auto window_height = ImGui::GetWindowSize().y;
auto text_width = ImGui::CalcTextSize(text.c_str()).x;
ImGui::SetCursorPosX((window_width - text_width) * 0.5f);
ImGui::SetCursorPosY(window_height * 0.3f);
ImGui::SetCursorPosY(window_height * 0.2f);
ImGui::Text("%s", text.c_str());
ImGui::SetWindowFontScale(1.0f);
ImGui::SetCursorPosX(connection_status_window_width_ * 3 / 7);
ImGui::SetCursorPosY(connection_status_window_height_ * 2 / 3);
ImGui::SetWindowFontScale(0.5f);
// Cancel
if (ImGui::Button(
localization::cancel[localization_language_index_].c_str())) {
connect_button_pressed_ = false;
}
ImGui::SetWindowFontScale(1.0f);
ImGui::SetWindowFontScale(0.5f);
ImGui::End();
ImGui::PopStyleVar(2);
ImGui::PopStyleColor();
// ImGui::PopStyleColor();
ImGui::SetWindowFontScale(1.0f);
}
return 0;

View File

@@ -29,7 +29,7 @@
#define VIDEO_ENCODE_FORMAT_SELECT_WINDOW_PADDING_CN 100
#define VIDEO_ENCODE_FORMAT_SELECT_WINDOW_PADDING_EN 147
#define ENABLE_HARDWARE_VIDEO_CODEC_CHECKBOX_PADDING_CN 151
#define ENABLE_HARDWARE_VIDEO_CODEC_CHECKBOX_PADDING_EN 201
#define ENABLE_HARDWARE_VIDEO_CODEC_CHECKBOX_PADDING_EN 198
#define SETTINGS_SELECT_WINDOW_WIDTH 73
#define SETTINGS_OK_BUTTON_PADDING_CN 55
#define SETTINGS_OK_BUTTON_PADDING_EN 78

View File

@@ -1,3 +1,5 @@
#include <random>
#include "IconsFontAwesome6.h"
#include "layout_style.h"
#include "localization.h"
@@ -107,14 +109,32 @@ int Render::LocalWindow() {
ImGui::Text("%s",
localization::password[localization_language_index_].c_str());
strncpy(input_password_tmp_, input_password_, sizeof(input_password_));
ImGui::SetNextItemWidth(IPUT_WINDOW_WIDTH);
ImGui::Spacing();
if (!password_inited_) {
char a[] = {
"1234567890QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm"};
std::mt19937 generator(
std::chrono::system_clock::now().time_since_epoch().count());
std::uniform_int_distribution<int> distribution(0, strlen(a) - 1);
random_password_.clear();
for (int i = 0, len = strlen(a); i < 6; i++) {
random_password_ += a[distribution(generator)];
}
password_inited_ = true;
if (random_password_ != password_saved_) {
password_saved_ = random_password_;
SaveSettingsIntoCacheFile();
}
}
ImGui::SetWindowFontScale(1.0f);
ImGui::InputTextWithHint(
"##server_pwd",
localization::max_password_len[localization_language_index_].c_str(),
input_password_, IM_ARRAYSIZE(input_password_),
(char *)random_password_.c_str(), random_password_.length() + 1,
show_password_ ? ImGuiInputTextFlags_CharsNoBlank
: ImGuiInputTextFlags_CharsNoBlank |
ImGuiInputTextFlags_Password);
@@ -135,25 +155,22 @@ int Render::LocalWindow() {
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0, 0, 0, 0));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0, 0, 0, 0));
if (!regenerate_password_) {
if (ImGui::Button(ICON_FA_ARROWS_ROTATE, ImVec2(35, 38))) {
regenerate_password_ = true;
}
} else {
regenerate_password_frame_count_++;
if (ImGui::Button(ICON_FA_SPINNER, ImVec2(35, 38))) {
}
if (regenerate_password_frame_count_ == 15) {
regenerate_password_frame_count_ = 0;
regenerate_password_ = false;
}
if (ImGui::Button(
regenerate_password_ ? ICON_FA_SPINNER : ICON_FA_ARROWS_ROTATE,
ImVec2(35, 38))) {
regenerate_password_ = true;
password_inited_ = false;
regenerate_password_start_time_ = ImGui::GetTime();
LeaveConnection(peer_);
is_create_connection_ = false;
}
if (ImGui::GetTime() - regenerate_password_start_time_ > 0.3f) {
regenerate_password_ = false;
}
ImGui::SetWindowFontScale(1.0f);
ImGui::PopStyleColor(3);
if (strcmp(input_password_tmp_, input_password_)) {
SaveSettingsIntoCacheFile();
}
}
ImGui::PopStyleColor();
ImGui::EndChild();

View File

@@ -29,7 +29,8 @@ int Render::SaveSettingsIntoCacheFile() {
}
fseek(cd_cache_file_, 0, SEEK_SET);
strncpy(cd_cache_.password, input_password_, sizeof(input_password_));
strncpy(cd_cache_.password, password_saved_.c_str(),
password_saved_.length());
memcpy(&cd_cache_.language, &language_button_value_,
sizeof(language_button_value_));
memcpy(&cd_cache_.video_quality, &video_quality_button_value_,
@@ -53,7 +54,7 @@ int Render::LoadSettingsIntoCacheFile() {
fseek(cd_cache_file_, 0, SEEK_SET);
fread(&cd_cache_, sizeof(cd_cache_), 1, cd_cache_file_);
fclose(cd_cache_file_);
strncpy(input_password_, cd_cache_.password, sizeof(cd_cache_.password));
password_saved_ = cd_cache_.password;
language_button_value_ = cd_cache_.language;
video_quality_button_value_ = cd_cache_.video_quality;
video_encode_format_button_value_ = cd_cache_.video_encode_format;
@@ -274,10 +275,10 @@ int Render::Run() {
while (!exit_) {
if (SignalStatus::SignalConnected == signal_status_ &&
!is_create_connection_) {
is_create_connection_ =
CreateConnection(peer_, mac_addr_str_.c_str(), input_password_)
? false
: true;
is_create_connection_ = CreateConnection(peer_, mac_addr_str_.c_str(),
password_saved_.c_str())
? false
: true;
LOG_INFO("Connected with signal server, create p2p connection");
}

View File

@@ -105,6 +105,9 @@ class Render {
std::string settings_button_label_ = "Setting";
char input_password_tmp_[7] = "";
char input_password_[7] = "";
std::string random_password_ = "";
std::string password_saved_ = "";
std::string remote_password_ = "";
std::string local_id_ = "";
char remote_id_[20] = "";
char client_password_[20] = "";
@@ -163,11 +166,12 @@ class Render {
bool control_mouse_ = false;
bool local_id_copied_ = false;
bool show_password_ = true;
bool password_inited_ = false;
bool regenerate_password_ = false;
bool streaming_ = false;
double copy_start_time_ = 0;
int regenerate_password_frame_count_ = 0;
double regenerate_password_start_time_ = 0;
int fps_ = 0;
uint32_t start_time_;

View File

@@ -194,6 +194,7 @@ void Render::OnConnectionStatusCb(ConnectionStatus status, void *user_data) {
render->connection_established_ = false;
render->control_mouse_ = false;
render->exit_video_window_ = false;
render->remote_password_.clear();
if (render->dst_buffer_) {
memset(render->dst_buffer_, 0, 1280 * 720 * 3);
SDL_UpdateTexture(render->stream_texture_, NULL, render->dst_buffer_,