mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-20 05:23:12 -07:00
Support multiple PIN Entries
This commit is contained in:
parent
31fb11fd43
commit
d668423775
10 changed files with 81 additions and 13 deletions
|
@ -36,7 +36,7 @@ class LoginPINDialog : public QDialog
|
||||||
void UpdateButtons();
|
void UpdateButtons();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit LoginPINDialog(QWidget *parent = nullptr);
|
explicit LoginPINDialog(bool incorrect, QWidget *parent = nullptr);
|
||||||
|
|
||||||
QString GetPIN() { return pin; }
|
QString GetPIN() { return pin; }
|
||||||
};
|
};
|
||||||
|
|
|
@ -105,7 +105,7 @@ class StreamSession : public QObject
|
||||||
signals:
|
signals:
|
||||||
void CurrentImageUpdated();
|
void CurrentImageUpdated();
|
||||||
void SessionQuit(ChiakiQuitReason reason, const QString &reason_str);
|
void SessionQuit(ChiakiQuitReason reason, const QString &reason_str);
|
||||||
void LoginPINRequested();
|
void LoginPINRequested(bool incorrect);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void UpdateGamepads();
|
void UpdateGamepads();
|
||||||
|
|
|
@ -47,7 +47,7 @@ class StreamWindow: public QMainWindow
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void SessionQuit(ChiakiQuitReason reason, const QString &reason_str);
|
void SessionQuit(ChiakiQuitReason reason, const QString &reason_str);
|
||||||
void LoginPINRequested();
|
void LoginPINRequested(bool incorrect);
|
||||||
void ToggleFullscreen();
|
void ToggleFullscreen();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -23,16 +23,22 @@
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QRegularExpressionValidator>
|
#include <QRegularExpressionValidator>
|
||||||
|
#include <QLabel>
|
||||||
|
|
||||||
#define PIN_LENGTH 4
|
#define PIN_LENGTH 4
|
||||||
|
|
||||||
static const QRegularExpression pin_re(QString("[0-9]").repeated(PIN_LENGTH));
|
static const QRegularExpression pin_re(QString("[0-9]").repeated(PIN_LENGTH));
|
||||||
|
|
||||||
LoginPINDialog::LoginPINDialog(QWidget *parent) : QDialog(parent)
|
LoginPINDialog::LoginPINDialog(bool incorrect, QWidget *parent) : QDialog(parent)
|
||||||
{
|
{
|
||||||
|
setWindowTitle(tr("Console Login PIN"));
|
||||||
|
|
||||||
auto layout = new QVBoxLayout(this);
|
auto layout = new QVBoxLayout(this);
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|
||||||
|
if(incorrect)
|
||||||
|
layout->addWidget(new QLabel(tr("Entered PIN was incorrect!"), this));
|
||||||
|
|
||||||
pin_edit = new QLineEdit(this);
|
pin_edit = new QLineEdit(this);
|
||||||
pin_edit->setPlaceholderText(tr("Login PIN"));
|
pin_edit->setPlaceholderText(tr("Login PIN"));
|
||||||
pin_edit->setValidator(new QRegularExpressionValidator(pin_re, pin_edit));
|
pin_edit->setValidator(new QRegularExpressionValidator(pin_re, pin_edit));
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include <QAudioOutput>
|
#include <QAudioOutput>
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <chiaki/session.h>
|
||||||
|
|
||||||
StreamSessionConnectInfo::StreamSessionConnectInfo()
|
StreamSessionConnectInfo::StreamSessionConnectInfo()
|
||||||
{
|
{
|
||||||
|
@ -332,7 +333,7 @@ void StreamSession::Event(ChiakiEvent *event)
|
||||||
emit SessionQuit(event->quit.reason, event->quit.reason_str ? QString::fromUtf8(event->quit.reason_str) : QString());
|
emit SessionQuit(event->quit.reason, event->quit.reason_str ? QString::fromUtf8(event->quit.reason_str) : QString());
|
||||||
break;
|
break;
|
||||||
case CHIAKI_EVENT_LOGIN_PIN_REQUEST:
|
case CHIAKI_EVENT_LOGIN_PIN_REQUEST:
|
||||||
emit LoginPINRequested();
|
emit LoginPINRequested(event->login_pin_request.pin_incorrect);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,9 +104,9 @@ void StreamWindow::SessionQuit(ChiakiQuitReason reason, const QString &reason_st
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void StreamWindow::LoginPINRequested()
|
void StreamWindow::LoginPINRequested(bool incorrect)
|
||||||
{
|
{
|
||||||
auto dialog = new LoginPINDialog(this);
|
auto dialog = new LoginPINDialog(incorrect, this);
|
||||||
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
dialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
connect(dialog, &QDialog::finished, this, [this, dialog](int result) {
|
connect(dialog, &QDialog::finished, this, [this, dialog](int result) {
|
||||||
grabKeyboard();
|
grabKeyboard();
|
||||||
|
|
|
@ -45,6 +45,8 @@ typedef struct chiaki_ctrl_t
|
||||||
ChiakiStopPipe notif_pipe;
|
ChiakiStopPipe notif_pipe;
|
||||||
ChiakiMutex notif_mutex;
|
ChiakiMutex notif_mutex;
|
||||||
|
|
||||||
|
bool login_pin_requested;
|
||||||
|
|
||||||
chiaki_socket_t sock;
|
chiaki_socket_t sock;
|
||||||
uint8_t recv_buf[512];
|
uint8_t recv_buf[512];
|
||||||
size_t recv_buf_size;
|
size_t recv_buf_size;
|
||||||
|
|
|
@ -121,6 +121,10 @@ typedef struct chiaki_event_t
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
ChiakiQuitEvent quit;
|
ChiakiQuitEvent quit;
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
bool pin_incorrect; // false on first request, true if the pin entered before was incorrect
|
||||||
|
} login_pin_request;
|
||||||
};
|
};
|
||||||
} ChiakiEvent;
|
} ChiakiEvent;
|
||||||
|
|
||||||
|
|
|
@ -49,15 +49,22 @@ typedef enum ctrl_message_type_t {
|
||||||
CTRL_MESSAGE_TYPE_HEARTBEAT_REQ = 0xfe,
|
CTRL_MESSAGE_TYPE_HEARTBEAT_REQ = 0xfe,
|
||||||
CTRL_MESSAGE_TYPE_HEARTBEAT_REP = 0x1fe,
|
CTRL_MESSAGE_TYPE_HEARTBEAT_REP = 0x1fe,
|
||||||
CTRL_MESSAGE_TYPE_LOGIN_PIN_REQ = 0x4,
|
CTRL_MESSAGE_TYPE_LOGIN_PIN_REQ = 0x4,
|
||||||
CTRL_MESSAGE_TYPE_LOGIN_PIN_REP = 0x8004
|
CTRL_MESSAGE_TYPE_LOGIN_PIN_REP = 0x8004,
|
||||||
|
CTRL_MESSAGE_TYPE_LOGIN = 0x5
|
||||||
} CtrlMessageType;
|
} CtrlMessageType;
|
||||||
|
|
||||||
|
typedef enum ctrl_login_state_t {
|
||||||
|
CTRL_LOGIN_STATE_SUCCESS = 0x0,
|
||||||
|
CTRL_LOGIN_STATE_PIN_INCORRECT = 0x1
|
||||||
|
} CtrlLoginState;
|
||||||
|
|
||||||
|
|
||||||
static void *ctrl_thread_func(void *user);
|
static void *ctrl_thread_func(void *user);
|
||||||
static ChiakiErrorCode ctrl_message_send(ChiakiCtrl *ctrl, CtrlMessageType type, const uint8_t *payload, size_t payload_size);
|
static ChiakiErrorCode ctrl_message_send(ChiakiCtrl *ctrl, CtrlMessageType type, const uint8_t *payload, size_t payload_size);
|
||||||
static void ctrl_message_received_session_id(ChiakiCtrl *ctrl, uint8_t *payload, size_t payload_size);
|
static void ctrl_message_received_session_id(ChiakiCtrl *ctrl, uint8_t *payload, size_t payload_size);
|
||||||
static void ctrl_message_received_heartbeat_req(ChiakiCtrl *ctrl, uint8_t *payload, size_t payload_size);
|
static void ctrl_message_received_heartbeat_req(ChiakiCtrl *ctrl, uint8_t *payload, size_t payload_size);
|
||||||
static void ctrl_message_received_login_pin_req(ChiakiCtrl *ctrl, uint8_t *payload, size_t payload_size);
|
static void ctrl_message_received_login_pin_req(ChiakiCtrl *ctrl, uint8_t *payload, size_t payload_size);
|
||||||
|
static void ctrl_message_received_login(ChiakiCtrl *ctrl, uint8_t *payload, size_t payload_size);
|
||||||
|
|
||||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_ctrl_start(ChiakiCtrl *ctrl, ChiakiSession *session)
|
CHIAKI_EXPORT ChiakiErrorCode chiaki_ctrl_start(ChiakiCtrl *ctrl, ChiakiSession *session)
|
||||||
{
|
{
|
||||||
|
@ -65,6 +72,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_ctrl_start(ChiakiCtrl *ctrl, ChiakiSession
|
||||||
|
|
||||||
ctrl->should_stop = false;
|
ctrl->should_stop = false;
|
||||||
ctrl->login_pin_entered = false;
|
ctrl->login_pin_entered = false;
|
||||||
|
ctrl->login_pin_requested = false;
|
||||||
ctrl->login_pin = NULL;
|
ctrl->login_pin = NULL;
|
||||||
ctrl->login_pin_size = 0;
|
ctrl->login_pin_size = 0;
|
||||||
|
|
||||||
|
@ -307,9 +315,12 @@ static void ctrl_message_received(ChiakiCtrl *ctrl, uint16_t msg_type, uint8_t *
|
||||||
case CTRL_MESSAGE_TYPE_LOGIN_PIN_REQ:
|
case CTRL_MESSAGE_TYPE_LOGIN_PIN_REQ:
|
||||||
ctrl_message_received_login_pin_req(ctrl, payload, payload_size);
|
ctrl_message_received_login_pin_req(ctrl, payload, payload_size);
|
||||||
break;
|
break;
|
||||||
|
case CTRL_MESSAGE_TYPE_LOGIN:
|
||||||
|
ctrl_message_received_login(ctrl, payload, payload_size);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
CHIAKI_LOGW(ctrl->session->log, "Received Ctrl Message with unknown type %#x", msg_type);
|
CHIAKI_LOGW(ctrl->session->log, "Received Ctrl Message with unknown type %#x", msg_type);
|
||||||
chiaki_log_hexdump(ctrl->session->log, CHIAKI_LOG_VERBOSE, payload, payload_size);
|
chiaki_log_hexdump(ctrl->session->log, CHIAKI_LOG_WARNING, payload, payload_size);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -385,12 +396,50 @@ static void ctrl_message_received_login_pin_req(ChiakiCtrl *ctrl, uint8_t *paylo
|
||||||
|
|
||||||
CHIAKI_LOGI(ctrl->session->log, "Ctrl received Login PIN request");
|
CHIAKI_LOGI(ctrl->session->log, "Ctrl received Login PIN request");
|
||||||
|
|
||||||
chiaki_mutex_lock(&ctrl->session->state_mutex);
|
ctrl->login_pin_requested = true;
|
||||||
|
|
||||||
|
ChiakiErrorCode err = chiaki_mutex_lock(&ctrl->session->state_mutex);
|
||||||
|
assert(err == CHIAKI_ERR_SUCCESS);
|
||||||
ctrl->session->ctrl_login_pin_requested = true;
|
ctrl->session->ctrl_login_pin_requested = true;
|
||||||
chiaki_mutex_unlock(&ctrl->session->state_mutex);
|
chiaki_mutex_unlock(&ctrl->session->state_mutex);
|
||||||
chiaki_cond_signal(&ctrl->session->state_cond);
|
chiaki_cond_signal(&ctrl->session->state_cond);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ctrl_message_received_login(ChiakiCtrl *ctrl, uint8_t *payload, size_t payload_size)
|
||||||
|
{
|
||||||
|
if(payload_size != 1)
|
||||||
|
{
|
||||||
|
CHIAKI_LOGW(ctrl->session->log, "Ctrl received Login message with payload of size %llx", (unsigned long long)payload_size);
|
||||||
|
if(payload_size < 1)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CtrlLoginState state = payload[0];
|
||||||
|
switch(state)
|
||||||
|
{
|
||||||
|
case CTRL_LOGIN_STATE_SUCCESS:
|
||||||
|
CHIAKI_LOGI(ctrl->session->log, "Ctrl received Login message: success");
|
||||||
|
ctrl->login_pin_requested = false;
|
||||||
|
break;
|
||||||
|
case CTRL_LOGIN_STATE_PIN_INCORRECT:
|
||||||
|
CHIAKI_LOGI(ctrl->session->log, "Ctrl received Login message: PIN incorrect");
|
||||||
|
if(ctrl->login_pin_requested)
|
||||||
|
{
|
||||||
|
CHIAKI_LOGI(ctrl->session->log, "Ctrl requesting PIN from Session again");
|
||||||
|
ChiakiErrorCode err = chiaki_mutex_lock(&ctrl->session->state_mutex);
|
||||||
|
assert(err == CHIAKI_ERR_SUCCESS);
|
||||||
|
ctrl->session->ctrl_login_pin_requested = true;
|
||||||
|
chiaki_mutex_unlock(&ctrl->session->state_mutex);
|
||||||
|
chiaki_cond_signal(&ctrl->session->state_cond);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
CHIAKI_LOGW(ctrl->session->log, "Ctrl Login PIN incorrect message, but PIN was not requested");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
CHIAKI_LOGI(ctrl->session->log, "Ctrl received Login message with state: %x", state);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
typedef struct ctrl_response_t {
|
typedef struct ctrl_response_t {
|
||||||
|
|
|
@ -365,13 +365,19 @@ static void *session_thread_func(void *arg)
|
||||||
if(session->ctrl_failed)
|
if(session->ctrl_failed)
|
||||||
goto ctrl_failed;
|
goto ctrl_failed;
|
||||||
|
|
||||||
if(session->ctrl_login_pin_requested)
|
bool pin_incorrect = false;
|
||||||
|
while(session->ctrl_login_pin_requested)
|
||||||
{
|
{
|
||||||
session->ctrl_login_pin_requested = false;
|
session->ctrl_login_pin_requested = false;
|
||||||
|
if(pin_incorrect)
|
||||||
|
CHIAKI_LOGI(session->log, "Login PIN was incorrect, requested again by Ctrl");
|
||||||
|
else
|
||||||
CHIAKI_LOGI(session->log, "Ctrl requested Login PIN");
|
CHIAKI_LOGI(session->log, "Ctrl requested Login PIN");
|
||||||
ChiakiEvent event = { 0 };
|
ChiakiEvent event = { 0 };
|
||||||
event.type = CHIAKI_EVENT_LOGIN_PIN_REQUEST;
|
event.type = CHIAKI_EVENT_LOGIN_PIN_REQUEST;
|
||||||
|
event.login_pin_request.pin_incorrect = pin_incorrect;
|
||||||
session_send_event(session, &event);
|
session_send_event(session, &event);
|
||||||
|
pin_incorrect = true;
|
||||||
|
|
||||||
chiaki_cond_timedwait_pred(&session->state_cond, &session->state_mutex, UINT64_MAX, session_check_state_pred_pin, session);
|
chiaki_cond_timedwait_pred(&session->state_cond, &session->state_mutex, UINT64_MAX, session_check_state_pred_pin, session);
|
||||||
CHECK_STOP(quit_ctrl);
|
CHECK_STOP(quit_ctrl);
|
||||||
|
@ -387,7 +393,7 @@ static void *session_thread_func(void *arg)
|
||||||
session->login_pin_size = 0;
|
session->login_pin_size = 0;
|
||||||
|
|
||||||
// wait for session id again
|
// wait for session id again
|
||||||
chiaki_cond_timedwait_pred(&session->state_cond, &session->state_mutex, SESSION_EXPECT_TIMEOUT_MS, session_check_state_pred_session_id, session);
|
chiaki_cond_timedwait_pred(&session->state_cond, &session->state_mutex, SESSION_EXPECT_TIMEOUT_MS, session_check_state_pred_ctrl_start, session);
|
||||||
CHECK_STOP(quit_ctrl);
|
CHECK_STOP(quit_ctrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue