Skip to content

Commit

Permalink
Expired session fix
Browse files Browse the repository at this point in the history
  • Loading branch information
FlavioFS committed Aug 24, 2021
1 parent 348ce04 commit d7689fa
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 20 deletions.
9 changes: 6 additions & 3 deletions ParsecSoda/DX11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ D3D11_MAPPED_SUBRESOURCE _resource;

void DX11::clear()
{
//if (_lDevice != NULL) _lDevice->Release();
if (_lDeskDupl != NULL) _lDeskDupl->Release();
if (_lAcquiredDesktopImage != NULL) _lAcquiredDesktopImage->Release();
}
Expand Down Expand Up @@ -232,6 +231,8 @@ bool DX11::init()

bool DX11::captureScreen(ParsecDSO *ps)
{
static ID3D11Texture2D* lastFramePointer;

if (!_lDeskDupl)
{
if (!clearAndRecover())
Expand All @@ -247,13 +248,15 @@ bool DX11::captureScreen(ParsecDSO *ps)
DXGI_OUTDUPL_FRAME_INFO lFrameInfo;
ID3D11Texture2D* currTexture = NULL;

hr = _lDeskDupl->AcquireNextFrame(1, &lFrameInfo, &lDesktopResource);
hr = _lDeskDupl->AcquireNextFrame(4, &lFrameInfo, &lDesktopResource);
if (FAILED(hr)) {
_lDeskDupl->ReleaseFrame();

_mutex.unlock();
if (hr != DXGI_ERROR_WAIT_TIMEOUT)
{
if (lDesktopResource != nullptr) lDesktopResource->Release();
if (lastFramePointer != nullptr) lastFramePointer->Release();
clearAndRecover();
}

Expand All @@ -267,7 +270,7 @@ bool DX11::captureScreen(ParsecDSO *ps)
// LEL
////////////////////////////////////////
ParsecHostD3D11SubmitFrame(ps, 0, _lDevice, _lImmediateContext, _lAcquiredDesktopImage);

lastFramePointer = _lAcquiredDesktopImage;

_lDeskDupl->ReleaseFrame();

Expand Down
3 changes: 2 additions & 1 deletion ParsecSoda/Guest.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class Guest
enum class Status
{
OK = 0,
INVALID = 1
INVALID = 1,
EXPIRED = 2
};

/**
Expand Down
17 changes: 11 additions & 6 deletions ParsecSoda/Hosting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,7 @@ void Hosting::init()
MetadataCache::savePreferences(preferences);
_parsecSession.loadSessionCache();

_host.name = "Host";
_host.status = Guest::Status::INVALID;
if (isReady())
{
_parsecSession.fetchAccountData(&_host);
}
fetchAccountData();

_chatBot = new ChatBot(
audioIn, audioOut, _banList, _dice, _dx11,
Expand Down Expand Up @@ -149,6 +144,16 @@ ParsecSession& Hosting::getSession()
return _parsecSession;
}

void Hosting::fetchAccountData()
{
_host.name = "Host";
_host.status = Guest::Status::INVALID;
if (isReady())
{
_parsecSession.fetchAccountData(&_host);
}
}

ParsecHostConfig& Hosting::getHostConfig()
{
return _hostConfig;
Expand Down
1 change: 1 addition & 0 deletions ParsecSoda/Hosting.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Hosting
bool& isGamepadLock();
Guest& getHost();
ParsecSession& getSession();
void fetchAccountData();
ParsecHostConfig& getHostConfig();
DX11& getDX11();
vector<string>& getMessageLog();
Expand Down
14 changes: 8 additions & 6 deletions ParsecSoda/ParsecSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ bool ParsecSession::loadSessionCache()
{
sessionId = cache.sessionID;
hostPeerId = cache.peerID;
_isValid = true;
_isValid = false;
return true;
}

Expand Down Expand Up @@ -279,10 +279,10 @@ const bool ParsecSession::fetchArcadeRoomList()
return false;
}

const bool ParsecSession::fetchAccountData(Guest *user)
void ParsecSession::fetchAccountData(Guest *user)
{
if (!_isValid || sessionId.empty()) {
return false;
if (sessionId.empty()) {
return;
}

_accountDataThread = thread ([user, this]() {
Expand Down Expand Up @@ -341,16 +341,18 @@ const bool ParsecSession::fetchAccountData(Guest *user)

user->status = Guest::Status::OK;
result = true;
_isValid = true;
}
catch (const std::exception&) {}

MTY_JSONDestroy(&json);
}
else
{
user->name = "Host";
user->name = "Session Expired";
user->userID = 0;
user->status = Guest::Status::INVALID;
user->status = Guest::Status::EXPIRED;
_isValid = false;
}

_accountDataThread.detach();
Expand Down
2 changes: 1 addition & 1 deletion ParsecSoda/ParsecSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ParsecSession
const ParsecSession::SessionStatus pollSession(ParsecSession::AuthResult auth);
const AuthResult authenticate();
const bool fetchArcadeRoomList();
const bool fetchAccountData(Guest* user);
void fetchAccountData(Guest* user);
bool& isValid();
const string getSessionError();
const int getSessionStatus();
Expand Down
7 changes: 4 additions & 3 deletions ParsecSoda/Widgets/LoginWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ void LoginWidget::render(bool& isValidSession)
ImVec2(w, 50)
))
{
//attemptLoginPersonal();
attemptLogin3rd();
}
ImGui::PopStyleColor();
Expand Down Expand Up @@ -178,7 +177,7 @@ void LoginWidget::render3rd(float width)
AppColors::pop();
TitleTooltipWidget::render(
"Authentication Code",
"Copy and Paste this code to the link in your browser window"
"Copy and Paste this code to the link in your browser window\n\nIf a browser window does not show automatically, go to:\nhttps://parsec.app/activate/"
);
}

Expand All @@ -189,7 +188,7 @@ void LoginWidget::renderCreateAccount(float width)
ImGui::SetCursorPosX(width - 166.0f);
if (ImGui::Button("Create new account"))
{
ShellExecute(0, 0, L"https://parsec.app/login", 0, 0, SW_SHOW);
ShellExecute(0, 0, L"https://parsec.app/activate/", 0, 0, SW_SHOW);
}
if (ImGui::IsItemHovered()) ImGui::SetMouseCursor(ImGuiMouseCursor_Hand);
AppColors::pop();
Expand Down Expand Up @@ -224,6 +223,7 @@ void LoginWidget::attemptLoginPersonal()
_showError = true;
}

_hosting.fetchAccountData();
_isLoginLocked = false;
_loginThread.detach();
});
Expand Down Expand Up @@ -273,6 +273,7 @@ void LoginWidget::attemptLogin3rd()
}
}

_hosting.fetchAccountData();
_isLoginLocked = false;
_loginThread.detach();
});
Expand Down

0 comments on commit d7689fa

Please sign in to comment.