Skip to content

Commit

Permalink
Merge pull request #7976 from spycrab/netplay_index_feedback
Browse files Browse the repository at this point in the history
Qt/NetPlay: Show feedback for index adding
  • Loading branch information
spycrab committed Apr 12, 2019
2 parents f2e3f69 + 8b6bb39 commit 2a1dee4
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Source/Core/Core/NetPlayClient.h
Expand Up @@ -64,6 +64,9 @@ class NetPlayUI
virtual void SetMD5Result(int pid, const std::string& result) = 0; virtual void SetMD5Result(int pid, const std::string& result) = 0;
virtual void AbortMD5() = 0; virtual void AbortMD5() = 0;


virtual void OnIndexAdded(bool success, std::string error) = 0;
virtual void OnIndexRefreshFailed(std::string error) = 0;

virtual void ShowChunkedProgressDialog(const std::string& title, u64 data_size, virtual void ShowChunkedProgressDialog(const std::string& title, u64 data_size,
const std::vector<int>& players) = 0; const std::vector<int>& players) = 0;
virtual void HideChunkedProgressDialog() = 0; virtual void HideChunkedProgressDialog() = 0;
Expand Down
11 changes: 10 additions & 1 deletion Source/Core/Core/NetPlayServer.cpp
Expand Up @@ -183,6 +183,9 @@ void NetPlayServer::SetupIndex()


if (m_traversal_client) if (m_traversal_client)
{ {
if (m_traversal_client->GetState() != TraversalClient::Connected)
return;

session.server_id = std::string(g_TraversalClient->GetHostID().data(), 8); session.server_id = std::string(g_TraversalClient->GetHostID().data(), 8);
} }
else else
Expand All @@ -201,7 +204,13 @@ void NetPlayServer::SetupIndex()


session.EncryptID(Config::Get(Config::NETPLAY_INDEX_PASSWORD)); session.EncryptID(Config::Get(Config::NETPLAY_INDEX_PASSWORD));


m_index.Add(session); if (m_dialog != nullptr)
m_dialog->OnIndexAdded(m_index.Add(session), m_index.GetLastError());

m_index.SetErrorCallback([this] {
if (m_dialog != nullptr)
m_dialog->OnIndexRefreshFailed(m_index.GetLastError());
});
} }


// called from ---NETPLAY--- thread // called from ---NETPLAY--- thread
Expand Down
13 changes: 13 additions & 0 deletions Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp
Expand Up @@ -393,6 +393,19 @@ void NetPlayDialog::OnChat()
}); });
} }


void NetPlayDialog::OnIndexAdded(bool success, const std::string error)
{
DisplayMessage(success ? tr("Successfully added to the NetPlay index") :
tr("Failed to add this session to the NetPlay index: %1")
.arg(QString::fromStdString(error)),
success ? "green" : "red");
}

void NetPlayDialog::OnIndexRefreshFailed(const std::string error)
{
DisplayMessage(QString::fromStdString(error), "red");
}

void NetPlayDialog::OnStart() void NetPlayDialog::OnStart()
{ {
if (!Settings::Instance().GetNetPlayClient()->DoAllPlayersHaveGame()) if (!Settings::Instance().GetNetPlayClient()->DoAllPlayersHaveGame())
Expand Down
3 changes: 3 additions & 0 deletions Source/Core/DolphinQt/NetPlay/NetPlayDialog.h
Expand Up @@ -60,6 +60,9 @@ class NetPlayDialog : public QDialog, public NetPlay::NetPlayUI
void OnGameStartAborted() override; void OnGameStartAborted() override;
void OnGolferChanged(bool is_golfer, const std::string& golfer_name) override; void OnGolferChanged(bool is_golfer, const std::string& golfer_name) override;


void OnIndexAdded(bool success, const std::string error) override;
void OnIndexRefreshFailed(const std::string error) override;

bool IsRecording() override; bool IsRecording() override;
std::string FindGame(const std::string& game) override; std::string FindGame(const std::string& game) override;
std::shared_ptr<const UICommon::GameFile> FindGameFile(const std::string& game) override; std::shared_ptr<const UICommon::GameFile> FindGameFile(const std::string& game) override;
Expand Down
14 changes: 14 additions & 0 deletions Source/Core/UICommon/NetPlayIndex.cpp
Expand Up @@ -142,6 +142,8 @@ void NetPlayIndex::NotificationLoop()
if (!json) if (!json)
{ {
m_last_error = "BAD_JSON"; m_last_error = "BAD_JSON";
m_secret.clear();
m_error_callback();
return; return;
} }


Expand All @@ -150,6 +152,8 @@ void NetPlayIndex::NotificationLoop()
if (status != "OK") if (status != "OK")
{ {
m_last_error = std::move(status); m_last_error = std::move(status);
m_secret.clear();
m_error_callback();
return; return;
} }
} }
Expand Down Expand Up @@ -323,3 +327,13 @@ const std::string& NetPlayIndex::GetLastError() const
{ {
return m_last_error; return m_last_error;
} }

bool NetPlayIndex::HasActiveSession() const
{
return !m_secret.empty();
}

void NetPlayIndex::SetErrorCallback(std::function<void()> function)
{
m_error_callback = function;
}
7 changes: 7 additions & 0 deletions Source/Core/UICommon/NetPlayIndex.h
Expand Up @@ -4,6 +4,7 @@


#pragma once #pragma once


#include <functional>
#include <map> #include <map>
#include <optional> #include <optional>
#include <string> #include <string>
Expand Down Expand Up @@ -46,12 +47,16 @@ class NetPlayIndex
bool Add(NetPlaySession session); bool Add(NetPlaySession session);
void Remove(); void Remove();


bool HasActiveSession() const;

void SetPlayerCount(int player_count); void SetPlayerCount(int player_count);
void SetInGame(bool in_game); void SetInGame(bool in_game);
void SetGame(std::string game); void SetGame(std::string game);


const std::string& GetLastError() const; const std::string& GetLastError() const;


void SetErrorCallback(std::function<void()> callback);

private: private:
void NotificationLoop(); void NotificationLoop();


Expand All @@ -64,4 +69,6 @@ class NetPlayIndex
std::thread m_session_thread; std::thread m_session_thread;


Common::Event m_session_thread_exit_event; Common::Event m_session_thread_exit_event;

std::function<void()> m_error_callback = nullptr;
}; };

0 comments on commit 2a1dee4

Please sign in to comment.