Merge pull request #8275 from bdr99/netplay-player-log

NetPlay: Show a message in chat when a player joins or leaves
This commit is contained in:
Connor McLaughlin 2019-08-14 11:23:18 +10:00 committed by GitHub
commit 181d79228a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 2 deletions

View File

@ -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<std::recursive_mutex> 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));
}

View File

@ -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;

View File

@ -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] {

View File

@ -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;