diff --git a/Source/Core/Core/NetPlayClient.cpp b/Source/Core/Core/NetPlayClient.cpp index d157d892a3..40b4f1703a 100644 --- a/Source/Core/Core/NetPlayClient.cpp +++ b/Source/Core/Core/NetPlayClient.cpp @@ -305,6 +305,8 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet) m_players[player.pid] = player; } + m_dialog->OnPlayerConnect(player.name); + m_dialog->Update(); } break; @@ -314,10 +316,15 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet) PlayerId pid; packet >> pid; - INFO_LOG(NETPLAY, "Player %s (%d) left", m_players.find(pid)->second.name.c_str(), pid); - { std::lock_guard lkp(m_crit.players); + const auto it = m_players.find(pid); + if (it == m_players.end()) + break; + + const auto& player = it->second; + INFO_LOG(NETPLAY, "Player %s (%d) left", player.name.c_str(), pid); + m_dialog->OnPlayerDisconnect(player.name); m_players.erase(m_players.find(pid)); } diff --git a/Source/Core/Core/NetPlayClient.h b/Source/Core/Core/NetPlayClient.h index 7ece1a5a68..2e6acf4518 100644 --- a/Source/Core/Core/NetPlayClient.h +++ b/Source/Core/Core/NetPlayClient.h @@ -46,6 +46,8 @@ public: virtual void OnMsgStartGame() = 0; virtual void OnMsgStopGame() = 0; virtual void OnMsgPowerButton() = 0; + virtual void OnPlayerConnect(const std::string& player) = 0; + virtual void OnPlayerDisconnect(const std::string& player) = 0; virtual void OnPadBufferChanged(u32 buffer) = 0; virtual void OnHostInputAuthorityChanged(bool enabled) = 0; virtual void OnDesync(u32 frame, const std::string& player) = 0; diff --git a/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp b/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp index d8e2a5f4d2..69d01a94a4 100644 --- a/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp +++ b/Source/Core/DolphinQt/NetPlay/NetPlayDialog.cpp @@ -887,6 +887,16 @@ void NetPlayDialog::OnMsgPowerButton() QueueOnObject(this, [] { UICommon::TriggerSTMPowerEvent(); }); } +void NetPlayDialog::OnPlayerConnect(const std::string& player) +{ + DisplayMessage(tr("%1 has joined").arg(QString::fromStdString(player)), "darkcyan"); +} + +void NetPlayDialog::OnPlayerDisconnect(const std::string& player) +{ + DisplayMessage(tr("%1 has left").arg(QString::fromStdString(player)), "darkcyan"); +} + void NetPlayDialog::OnPadBufferChanged(u32 buffer) { QueueOnObject(this, [this, buffer] { diff --git a/Source/Core/DolphinQt/NetPlay/NetPlayDialog.h b/Source/Core/DolphinQt/NetPlay/NetPlayDialog.h index 64824d2847..84fc24e5e1 100644 --- a/Source/Core/DolphinQt/NetPlay/NetPlayDialog.h +++ b/Source/Core/DolphinQt/NetPlay/NetPlayDialog.h @@ -49,6 +49,8 @@ public: void OnMsgStartGame() override; void OnMsgStopGame() override; void OnMsgPowerButton() override; + void OnPlayerConnect(const std::string& player) override; + void OnPlayerDisconnect(const std::string& player) override; void OnPadBufferChanged(u32 buffer) override; void OnHostInputAuthorityChanged(bool enabled) override; void OnDesync(u32 frame, const std::string& player) override;