Skip to content
Permalink
Browse files

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

NetPlay: Show a message in chat when a player joins or leaves
  • Loading branch information...
stenzek committed Aug 14, 2019
2 parents dd8bc7b + 8857db9 commit 181d79228ab811b711c0cc87c62988d222c389d7
@@ -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));
}

@@ -46,6 +46,8 @@ class NetPlayUI
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;
@@ -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] {
@@ -49,6 +49,8 @@ class NetPlayDialog : public QDialog, public NetPlay::NetPlayUI
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;

0 comments on commit 181d792

Please sign in to comment.
You can’t perform that action at this time.