Add function to find STKPeer by player name
This commit is contained in:
parent
a3c6c63be8
commit
ddbdf2d244
@ -1547,6 +1547,28 @@ std::shared_ptr<STKPeer> STKHost::findPeerByHostId(uint32_t id) const
|
||||
return ret != m_peers.end() ? ret->second : nullptr;
|
||||
} // findPeerByHostId
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
std::shared_ptr<STKPeer>
|
||||
STKHost::findPeerByName(const core::stringw& name) const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_peers_mutex);
|
||||
auto ret = std::find_if(m_peers.begin(), m_peers.end(),
|
||||
[name](const std::pair<ENetPeer*, std::shared_ptr<STKPeer> >& p)
|
||||
{
|
||||
bool found = false;
|
||||
for (auto& profile : p.second->getPlayerProfiles())
|
||||
{
|
||||
if (profile->getName() == name)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return found;
|
||||
});
|
||||
return ret != m_peers.end() ? ret->second : nullptr;
|
||||
} // findPeerByName
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void STKHost::initClientNetwork(ENetEvent& event, Network* new_network)
|
||||
{
|
||||
|
@ -256,6 +256,8 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
std::shared_ptr<STKPeer> findPeerByHostId(uint32_t id) const;
|
||||
// ------------------------------------------------------------------------
|
||||
std::shared_ptr<STKPeer> findPeerByName(const core::stringw& name) const;
|
||||
// ------------------------------------------------------------------------
|
||||
void sendPacketExcept(STKPeer* peer, NetworkString *data,
|
||||
bool reliable = true);
|
||||
// ------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user