8000 zdxsv Settings: Sign Out Everywhere (revoke the tokens of every PC) by inada-s-ai[bot] · Pull Request #700 · inada-s/pcsx2 · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ZDXSV.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ PCSX2 はこの PC 用のサインイントークンを保存し、それでロ
「アカウント」には、zdxsv アカウントと、サーバーが認める数の未作成の枠が並びます。未作成の枠は、選んで最初に接続したときに
アカウントになります。「PS2 から引き継ぐ」で、PS2 で遊んでいるアカウントを追加できます (PS2 でケネディポートのロビーのチャットに dc と入力し、表示された
コードを 3 分以内に入力します。PS2 でもそのまま遊べます)。
「アカウント」でオンラインに使うアカウントを選びます。「サインアウト」でトークンを無効にします。
「アカウント」でオンラインに使うアカウントを選びます。「サインアウト」でトークンを無効にします。「すべての PC でサインアウト」は同じ Discord アカウントでサインインしているすべての PC(この PC も含む)のトークンを無効にします。それぞれサインインし直す必要があります。

トークンがないままネットに接続すると、サインインページが開き、サインインするまでゲームが一時停止します。
ゲームを再開するとサインインを中止し、ネットワークメニューに戻ります。
Expand Down
3 changes: 2 additions & 1 deletion ZDXSV.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ PCSX2 keeps a sign-in token for this PC and logs in with it. Account lists your
the server allows; an empty slot becomes an account when you first connect with it picked. Carry Over
from PS2 adds the account you play on a PS2 (on the PS2, type dc in the chat of the Kennedy Port lobby and enter the code it shows within 3 minutes; the
PS2 keeps playing with it). Account picks the one used online.
Sign Out revokes the token.
Sign Out revokes the token. Sign Out Everywhere revokes the tokens of every PC signed in with your Discord
account (this one too); each has to sign in again.

With no token, going online opens the sign-in page and pauses the game until you sign in; resume
the game to cancel it and go back to the network menu.
Expand Down
4 changes: 2 additions & 2 deletions docs/zdxsv/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ page greys it out and its tooltip names the variable.
| `[DEV9/Eth] ZdxsvFastBootLobby` | `false` | test | With `ZdxsvFastBoot`: at the user_id selection, presses Circle (still at unlimited speed) until ID 1 is picked and confirmed, and ends in the lobby (戦場選択, emulog `Zdxsv: fast boot: lobby`); `gave up in the user_id selection` after 60 s. No settings UI. Env `ZDXSV_FAST_BOOT_LOBBY=1/0` overrides. |
| `[DEV9/Eth] ZdxsvFastLogin` | `true` | feature | Z game, on the way to the lobby: when DNAS starts, log in through `ZdxsvLoginApiUrl` with the token in `inis/zdxsv_auth_token.txt` (form `token`); no token: the VM pauses, the sign-in of `ZdxsvAuthUrl` runs in the browser, the VM resumes when it ends (resuming by hand cancels it) and the new token logs in; at every DNAS start, and jump to the lobby connect (no DNAS, no login browser). No token after the sign-in, a refused login, or resuming during the hold: back to the network menu (connection menu), no DNAS. No `ZdxsvLoginApiUrl`: the normal login. `ZDXSV_FAST_LOGIN` overrides. Ini only. |
| `[DEV9/Eth] ZdxsvLoginApiUrl` | server `/lbs/login` | feature | The zdxsv login API (`POST`; the zdxsv lobby API `/lbs/login`) (form `token`; JSON `login_key`, `session_id`, `lobby_addr`, `lbs_info`) used by `ZdxsvFastLogin`. The same with or without DEV9. `ZDXSV_LOGIN_API_URL` overrides it (the rigs: the local stack). Ini only. |
| `[DEV9/Eth] ZdxsvAuthUrl` | server `/auth` | feature | The zdxsv sign-in base URL for Settings → zdxsv → Account: the browser opens `<url>/start` (the reply comes to a listener on `127.0.0.1`, random port, for 10 minutes); `POST <url>/token` (PKCE) saves the token to `inis/zdxsv_auth_token.txt`, the token `ZdxsvFastLogin` sends; Sign Out `POST <url>/revoke` and deletes the file. `ZDXSV_AUTH_URL` overrides it. Ini only. |
| `[DEV9/Eth] ZdxsvAuthUrl` | server `/auth` | feature | The zdxsv sign-in base URL for Settings → zdxsv → Account: the browser opens `<url>/start` (the reply comes to a listener on `127.0.0.1`, random port, for 10 minutes); `POST <url>/token` (PKCE) saves the token to `inis/zdxsv_auth_token.txt`, the token `ZdxsvFastLogin` sends; Sign Out `POST <url>/revoke` and deletes the file; Sign Out Everywhere sends `all=1` (every token of the Discord account) and keeps the file if the server did not revoke. `ZDXSV_AUTH_URL` overrides it. Ini only. |
| `[DEV9/Eth] ZdxsvAccount` | `0` | feature | Which account of the signed-in Discord account the fast login uses (form `account`, from 1); `0`: the server's default (the first; with no account, the login makes one); `-1`: an empty slot, the login sends `account=new`, the server makes the account and the setting becomes its number. Settings → zdxsv → Account sets it from `POST <ZdxsvAuthUrl>/accounts`; Carry Over from PS2 (`POST <ZdxsvAuthUrl>/accounts/carry`, form `code`) picks the carried account; sign-in and sign-out reset it to `0`. |
| `[DEV9/Eth] ZdxsvLobbyApiUrl` | server | feature | The lobby's public API (`http://host:port`, zdxsv `ZDXSV_LOBBY_API_ADDR`) the replay window's Remote (`/lbs/replay`) and Live (`/lbs/live`) tabs and the Favorites tab ask; empty = none. A live battle is watched at `live:<this URL>#<code>`. |
| `[DEV9/Eth] ZdxsvReplayFavorites` | empty | feature | The replay window's Favorites: one value per battle (battle code, start time, players and rounds, tab-separated), at most 1000; added from the Remote tab, removed in the Favorites tab. |
Expand Down Expand Up @@ -157,7 +157,7 @@ turns GGPO off and leaves the other extensions on. Any other value turns it on.
| `ZDXSV_RERUN_SPLIT=1` | off | diagnostic | The battle report measures the VU1 and SPU2 time per rerun frame (`rerun frame split` line) and the times of a delta save and load (`delta` line: its parts and per section). Off: these read 0 or are empty (the timers cost time in every frame). `benchab.py` sets it. |
| `ZDXSV_SINGLE_DRAW_LIST=0` | on | control | Z game: no single draw list (the game draws a frame's draw list in the next frame, as stock). See rollback.md. |
| `ZDXSV_LOW_LATENCY_PRESENT=0` | on | control | Z game: no low-latency present. On: present the finished frame before the frame limiter sleeps, and poll input right before the next frame runs (in a net battle: before the sleep, see [rollback.md](rollback.md)). |
| `ZDXSV_AUTH_SIGNIN_TEST=1\|signout` | unset | test | At app start, `1` signs in once through `ZdxsvAuthUrl` and logs `Zdxsv: auth: open <url>` instead of opening a browser; `signout` signs out. |
| `ZDXSV_AUTH_SIGNIN_TEST=1\|signout\|signoutall` | unset | test | At app start, `1` signs in once through `ZdxsvAuthUrl` and logs `Zdxsv: auth: open <url>` instead of opening a browser; `signout` signs out; `signoutall` signs out on every PC. |
| `ZDXSV_AUTH_URL=<url>` | unset | test | Overrides `ZdxsvAuthUrl`. |
| `ZDXSV_AUTH_AT_DNAS=0` | unset (on) | test | `ZdxsvFastLogin` with no token skips the sign-in at DNAS (back to the network menu); the rigs set it unless set. |
| `ZDXSV_AUTH_NO_BROWSER=1` | unset | test | Sign-in URLs are only logged (`Zdxsv: auth: open <url>`), no browser opens; the rigs set it, with `ZDXSV_AUTH_URL` = the local stack. |
Expand Down
32 changes: 25 additions & 7 deletions pcsx2-qt/Settings/ZdxsvSettingsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <QtWidgets/QDialogButtonBox>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QMessageBox>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QVBoxLayout>

Expand Down Expand Up @@ -146,7 +147,13 @@ ZdxsvSettingsWidget::ZdxsvSettingsWidget(SettingsWindow* settings_dialog, QWidge
connect(m_ui.zdxsvPresetHigh, &QPushButton::clicked, this, [this]() { applyPreset(3.0f, 2); });
connect(m_ui.zdxsvUPnPNow, &QPushButton::clicked, this, &ZdxsvSettingsWidget::mapUpnpNow);
connect(m_ui.zdxsvSignIn, &QPushButton::clicked, this, &ZdxsvSettingsWidget::signIn);
connect(m_ui.zdxsvSignOut, &QPushButton::clicked, this, &ZdxsvSettingsWidget::signOut);
connect(m_ui.zdxsvSignOut, &QPushButton::clicked, this, [this]() { signOut(false); });
connect(m_ui.zdxsvSignOutAll, &QPushButton::clicked, this, [this]() {
if (QMessageBox::question(this, tr("Sign Out Everywhere"),
tr("Sign out on every PC signed in with this Discord account? Each one has to sign in again.")) ==
QMessageBox::Yes)
signOut(true);
});
connect(m_ui.zdxsvAccountRefresh, &QPushButton::clicked, this, [this]() { loadAccounts(AccountRequest::List); });
connect(m_ui.zdxsvCarry, &QPushButton::clicked, this, &ZdxsvSettingsWidget::carryOver);
connect(m_ui.zdxsvAccountPick, &QComboBox::activated, this, &ZdxsvSettingsWidget::pickAccount);
Expand All @@ -161,6 +168,9 @@ ZdxsvSettingsWidget::ZdxsvSettingsWidget(SettingsWindow* settings_dialog, QWidge
tr("Uses your PS2 account on this PC too. Get the code by typing dc in the Kennedy Port lobby chat on the PS2."));
dialog()->registerWidgetHelp(m_ui.zdxsvSignOut, tr("Sign Out"), tr("None"),
tr("Revokes this PC's sign-in token on the server and deletes it."));
dialog()->registerWidgetHelp(m_ui.zdxsvSignOutAll, tr("Sign Out Everywhere"), tr("None"),
tr("Revokes the sign-in tokens of every PC signed in with this Discord account, this one included. "
"If the server does not answer, this PC stays signed in."));
dialog()->registerWidgetHelp(m_ui.zdxsvUPnPNow, tr("UPnP Now"), tr("None"),
tr("Opens the battle port on the router now."));
dialog()->registerWidgetHelp(m_ui.zdxsvPresetLow, tr("Recommended Settings for Low-Spec PC"), tr("None"),
Expand All @@ -185,6 +195,7 @@ void ZdxsvSettingsWidget::updateAccount()
m_ui.zdxsvAccountStatus->setText(signed_in ? tr("Signed in on this PC.") : tr("Not signed in. Online play needs a sign-in."));
m_ui.zdxsvSignIn->setText(busy ? tr("Cancel Sign-in") : tr("Sign in with Discord"));
m_ui.zdxsvSignOut->setEnabled(!busy && signed_in);
m_ui.zdxsvSignOutAll->setEnabled(!busy && signed_in);
m_ui.zdxsvAccountPick->setEnabled(!busy && signed_in && m_ui.zdxsvAccountPick->count() > 0);
m_ui.zdxsvAccountRefresh->setEnabled(!busy && signed_in);
m_ui.zdxsvCarry->setEnabled(!busy && signed_in && m_carry_room);
Expand Down Expand Up @@ -322,18 +333,25 @@ void ZdxsvSettingsWidget::signIn()
}).detach();
}

void ZdxsvSettingsWidget::signOut()
void ZdxsvSettingsWidget::signOut(bool every_pc)
{
m_ui.zdxsvSignOut->setEnabled(false);
std::thread([widget = QPointer<ZdxsvSettingsWidget>(this)]() {
const std::string error = Zdxsv::AuthSignOut();
QtHost::RunOnUIThread([widget, error]() {
m_ui.zdxsvSignOutAll->setEnabled(false);
std::thread([widget = QPointer<ZdxsvSettingsWidget>(this), every_pc]() {
const std::string error = Zdxsv::AuthSignOut(every_pc);
QtHost::RunOnUIThread([widget, error, every_pc]() {
if (!widget)
return;
SetPickedAccount(0);
const bool signed_in = Zdxsv::AuthTokenRead().has_value();
if (!signed_in)
SetPickedAccount(0);
widget->updateAccount();
if (!error.empty())
if (signed_in)
widget->m_ui.zdxsvAccountStatus->setText(tr("Not signed out; %1").arg(QString::fromStdString(error)));
else if (!error.empty())
widget->m_ui.zdxsvAccountStatus->setText(tr("Signed out on this PC; %1").arg(QString::fromStdString(error)));
else if (every_pc)
widget->m_ui.zdxsvAccountStatus->setText(tr("Signed out on every PC."));
});
}).detach();
}
Expand Down
2 changes: 1 addition & 1 deletion pcsx2-qt/Settings/ZdxsvSettingsWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ZdxsvSettingsWidget : public SettingsWidget
void mapUpnpNow();
void updateAccount();
void signIn();
void signOut();
void signOut(bool every_pc);
enum class AccountRequest
{
List,
Expand Down
7 changes: 7 additions & 0 deletions pcsx2-qt/Settings/ZdxsvSettingsWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="zdxsvSignOutAll">
<property name="text">
<string>Sign Out Everywhere</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
Expand Down
20 changes: 20 additions & 0 deletions pcsx2-qt/Translations/pcsx2-qt_ja-JP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28706,6 +28706,26 @@ for High-Spec PC</source>
<source>Signed out on this PC; %1</source>
<translation>この PC でサインアウトしました。%1</translation>
</message>
<message>
<source>Sign Out Everywhere</source>
<translation>すべての PC でサインアウト</translation>
</message>
<message>
<source>Sign out on every PC signed in with this Discord account? Each one has to sign in again.</source>
<translation>この Discord アカウントでサインインしているすべての PC でサインアウトしますか? それぞれサインインし直す必要があります。</translation>
</message>
<message>
<source>Revokes the sign-in tokens of every PC signed in with this Discord account, this one included. If the server does not answer, this PC stays signed in.</source>
<translation>この Discord アカウントでサインインしているすべての PC (この PC も含む) のサインイントークンを無効にします。サーバーが応答しない場合、この PC はサインインしたままです。</translation>
</message>
<message>
<source>Not signed out; %1</source>
<translation>サインアウトしていません。%1</translation>
</message>
<message>
<source>Signed out on every PC.</source>
<translation>すべての PC でサインアウトしました。</translation>
</message>
<message>
<source>Set to the default during online battles, replays and live spectating (the same on every player&apos;s emulator).</source>
<translation>オンライン対戦、リプレイ、ライブ観戦の間は既定値になります (全プレイヤーのエミュレーターで同じ値)。</translation>
Expand Down
17 changes: 14 additions & 3 deletions pcsx2/Zdxsv/AuthSignIn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,19 +317,30 @@ namespace Zdxsv
return {};
}

std::string AuthSignOut()
std::string AuthSignOut(bool every_pc)
{
std::string error;
if (const std::optional<std::string> token = AuthTokenRead())
{
s32 status;
Post(AuthUrl("/revoke"), "token=" + *token, &status);
Post(AuthUrl("/revoke"), "token=" + *token + (every_pc ? "&all=1" : ""), &status);
if (status < 200 || status > 299)
error = "the server did not revoke the token (" + std::to_string(status) + ")";
}
else if (every_pc)
{
return "not signed in";
}
// Kept on a failed revoke of every PC: it is the only way to retry.
if (every_pc && !error.empty())
{
Console 10BC8 .Error("Zdxsv: auth: sign-out on every PC failed: %s", error.c_str());
return error;
}
if (FileSystem::FileExists(TokenPath().c_str()) && !FileSystem::DeleteFilePath(TokenPath().c_str()))
return "cannot delete the token file";
Console.WriteLn("Zdxsv: auth: signed out%s%s", error.empty() ? "" : ", ", error.c_str());
Console.WriteLn("Zdxsv: auth: signed out%s%s%s", every_pc ? " on every PC" : "", error.empty() ? "" : ", ",
error.c_str());
return error;
}

Expand Down
3 changes: 2 additions & 1 deletion pcsx2/Zdxsv/AuthSignIn.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ namespace Zdxsv
std::string AuthSignIn(const std::function<void(const std::string&)>& open_url, const std::atomic<bool>& cancel);

// Blocking: revokes the token on the server and deletes the file (the file goes even if the server is unreachable).
std::string AuthSignOut();
// every_pc: revokes every token of the Discord account (all PCs); the file stays if the server did not revoke.
std::string AuthSignOut(bool every_pc);

struct AuthAccountList
{
Expand Down
5 changes: 3 additions & 2 deletions pcsx2/Zdxsv/AuthTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ namespace Zdxsv
const char* env = TestEnv("ZDXSV_AUTH_SIGNIN_TEST");
if (!env || !env[0])
return;
if (std::strcmp(env, "signout") == 0)
if (std::strcmp(env, "signout") == 0 || std::strcmp(env, "signoutall") == 0)
{
std::thread([]() { AuthSignOut(); }).detach();
const bool every_pc = std::strcmp(env, "signoutall") == 0;
std::thread([every_pc]() { AuthSignOut(every_pc); }).detach();
return;
}
std::thread([]() {
Expand Down
2 changes: 1 addition & 1 deletion tests/zdxsv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Scripts are in `tests/zdxsv/` except `run.py` (repository root) and
| Online without DEV9: ネット終了 | `ZDXSV_FAST_LOGIN=1 netend.py` (fast boot state): ID 1 → 戦場選択, ネット終了 → はい; `PASS`: the lobby log has `eventPeerLeave` within `LIMIT_END` s (default 5) of the `0x6006` answer; the game is back at the main menu | the build without the net end replies: `FAIL`, the connection stays open (the game hangs on 回線切断の準備); answering only `0x2f`: 12.5 s |
| Online without DEV9: reset, then the lobby again | `lobbyreset.py` (fast boot state, fast login to `boot_lobby.py`): online, the lobby stops, offline after about 2 min, F11 resets, fast boot runs again; `PASS`: online again and the new lobby's `user_id list sent` | a build that turns NoDev9 off at a reset: `FAIL online again`, fast boot gives up at the network menu |
| Fast login: by token | `ZDXSV_FAST_LOGIN=1 tokenlogin.py` (server with token logins): stores a token for a db account, writes `inis/zdxsv_auth_token.txt`; `PASS`: emulog `fast login: by token`, its session is the token account's, the account got a temporary key; every rig with fast login on and no token file gets one for its card's account (`boottime.py`; `freshboot.py`: the stand-in lobby's token, the card's login key) | build without token login: `FAIL: emulog has no fast login: by token` |
| Sign-in: sign-in and sign-out | `signin.py` (server with `/auth/`): fake OAuth provider on 127.0.0.1, p1 with `ZDXSV_AUTH_SIGNIN_TEST=1`, the script plays the browser; then p1 with `signout`; `PASS`: the token file holds a token the db stores for the fake user (no account made); after sign-out the file is gone, the db has no token for it, emulog `auth: signed out` with no error | build without sign-in: `FAIL: emulog has no auth: open` |
| Sign-in: sign-in, sign-out, sign-out on every PC | `signin.py` (server with `/auth/` and `/auth/revoke` `all=1`): fake OAuth provider on 127.0.0.1, p1 with `ZDXSV_AUTH_SIGNIN_TEST=1`, the script plays the browser; the db gets a second token of the fake user (another PC), p1 with `signout`; then p1 with a new token and `signoutall`; `PASS`: the token file holds a token the db stores for the fake user (no account made); after sign-out the file is gone, only the other PC's token is left, emulog `auth: signed out` with no error; after `signoutall` the file is gone, the db has no token for the user, emulog `auth: signed out on every PC` | build without sign-in: `FAIL: emulog has no auth: open`; server without `all=1`: `FAIL`, 1 token left after `signoutall` |
| Sign-in: callback page | `authcallback.py` (no game, no server): PCSX2 without a game, `ZDXSV_AUTH_SIGNIN_TEST=1`, a stand-in token endpoint; the script sends the 127.0.0.1 callback with about 3 KB of headers, as a browser does; `PASS`: the answer is the whole `Signed in` page (no reset) and emulog has `auth: signed in` | a build that closes the callback socket with the request unread: `FAIL`, reset True |
| Sign-in: at DNAS (no token) | `dnassignin.py` (server with `/auth/`, fast login, `ZDXSV_AUTH_AT_DNAS=1`): the fake provider's user is linked to a db account; the script browses `DELAY` s (default 90) after `auth: open`; `PASS`: emulog has the paused sign-in and `by token`, the session is the linked account's, the token file maps to it. `LIMIT` defaults to 600 (the pause counts). | build without it: `FAIL: paused sign-in False` (NET file key login) |
| Sign-in: account pick (`ZdxsvAccount`) | `accountpick.py` (server taking `/lbs/login` `account`, fast login; `PICK` default 2): the two oldest accounts with users linked to one identity, token on the first, `ZdxsvAccount = PICK` in p1's ini; `PASS`: tokenlogin.py checks for the picked account. Settings page (local server with auth on, `ZDXSV_DISCORD_CLIENT_ID` set, a token in the data dir): `settingsui.ps1 -DataPath <dir> -Click zdxsvAccountAdd -Match zdxsvAccount`: a new last item picked, `ZdxsvAccount = N+1` in the ini, the server lists N+1; at 5 Add Account disabled; `-Select 'zdxsvAccountPick=^Account 2'`: `ZdxsvAccount = 2`, still picked at the next start | build without it: `FAIL: emulog session` (the first account's) |
Expand Down
Loading
Loading
0