From 947b01250bbbb4c4208afba9c476ab5f5ebb9930 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Fri, 23 Aug 2019 14:20:51 +0200 Subject: [PATCH] Add More RP-Application-Reason --- gui/src/registdialog.cpp | 2 +- lib/include/chiaki/session.h | 7 +++++++ lib/src/regist.c | 11 +++++++++++ lib/src/session.c | 29 ++++++++++++++++++++++------- 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/gui/src/registdialog.cpp b/gui/src/registdialog.cpp index d1fddff..0e7dbb1 100644 --- a/gui/src/registdialog.cpp +++ b/gui/src/registdialog.cpp @@ -58,7 +58,7 @@ RegistDialog::RegistDialog(Settings *settings, const QString &host, QWidget *par broadcast_check_box->setChecked(host.isEmpty()); psn_id_edit = new QLineEdit(this); - form_layout->addRow(tr("PSN ID (username):"), psn_id_edit); + form_layout->addRow(tr("PSN ID (username, case-sensitive):"), psn_id_edit); pin_edit = new QLineEdit(this); pin_edit->setValidator(new QRegularExpressionValidator(pin_re, pin_edit)); diff --git a/lib/include/chiaki/session.h b/lib/include/chiaki/session.h index 8d8e712..165242a 100644 --- a/lib/include/chiaki/session.h +++ b/lib/include/chiaki/session.h @@ -38,6 +38,13 @@ extern "C" { #endif +#define CHIAKI_RP_APPLICATION_REASON_REGIST_FAILED 0x80108b09 +#define CHIAKI_RP_APPLICATION_REASON_INVALID_PSN_ID 0x80108b02 +#define CHIAKI_RP_APPLICATION_REASON_IN_USE 0x80108b10 +#define CHIAKI_RP_APPLICATION_REASON_CRASH 0x80108b15 + +const char *chiaki_rp_application_reason_string(uint32_t reason); + #define CHIAKI_RP_DID_SIZE 32 #define CHIAKI_SESSION_ID_SIZE_MAX 80 diff --git a/lib/src/regist.c b/lib/src/regist.c index fd4c6e0..3fa6114 100644 --- a/lib/src/regist.c +++ b/lib/src/regist.c @@ -453,6 +453,17 @@ static ChiakiErrorCode regist_recv_response(ChiakiRegist *regist, ChiakiRegister if(http_response.code != 200) { CHIAKI_LOGE(regist->log, "Regist received HTTP code %d", http_response.code); + + for(ChiakiHttpHeader *header=http_response.headers; header; header=header->next) + { + if(strcmp(header->key, "RP-Application-Reason") == 0) + { + uint32_t reason = strtoul(header->value, NULL, 0x10); + CHIAKI_LOGE(regist->log, "Reported Application Reason: %#x (%s)", (unsigned int)reason, chiaki_rp_application_reason_string(reason)); + break; + } + } + chiaki_http_response_fini(&http_response); return CHIAKI_ERR_UNKNOWN; } diff --git a/lib/src/session.c b/lib/src/session.c index a2f3311..c0052df 100644 --- a/lib/src/session.c +++ b/lib/src/session.c @@ -42,11 +42,27 @@ #define SESSION_PORT 9295 -#define RP_APPLICATION_REASON_IN_USE 0x80108b10 -#define RP_APPLICATION_REASON_CRASH 0x80108b15 - #define SESSION_EXPECT_TIMEOUT_MS 5000 + +const char *chiaki_rp_application_reason_string(uint32_t reason) +{ + switch(reason) + { + case CHIAKI_RP_APPLICATION_REASON_REGIST_FAILED: + return "Regist failed, probably invalid PIN"; + case CHIAKI_RP_APPLICATION_REASON_INVALID_PSN_ID: + return "Invalid PSN ID"; + case CHIAKI_RP_APPLICATION_REASON_IN_USE: + return "Remote is already in use"; + case CHIAKI_RP_APPLICATION_REASON_CRASH: + return "Remote Play on Console crashed"; + default: + return "unknown"; + } +} + + CHIAKI_EXPORT void chiaki_connect_video_profile_preset(ChiakiConnectVideoProfile *profile, ChiakiVideoResolutionPreset resolution, ChiakiVideoFPSPreset fps) { switch(resolution) @@ -626,14 +642,13 @@ static bool session_thread_request_session(ChiakiSession *session) } else { + CHIAKI_LOGE(session->log, "Reported Application Reason: %#x (%s)", (unsigned int)response.error_code, chiaki_rp_application_reason_string(response.error_code)); switch(response.error_code) { - case RP_APPLICATION_REASON_IN_USE: - CHIAKI_LOGE(session->log, "Remote is already in use"); + case CHIAKI_RP_APPLICATION_REASON_IN_USE: session->quit_reason = CHIAKI_QUIT_REASON_SESSION_REQUEST_RP_IN_USE; break; - case RP_APPLICATION_REASON_CRASH: - CHIAKI_LOGE(session->log, "Remote seems to have crashed"); + case CHIAKI_RP_APPLICATION_REASON_CRASH: session->quit_reason = CHIAKI_QUIT_REASON_SESSION_REQUEST_RP_CRASH; break; default: