@@ -691,18 +691,36 @@ void GameServer::Send(ConnectionId_t aConnectionId, const ServerAdminMessage& ac
691691
692692void GameServer::SendToLoaded (const ServerMessage& acServerMessage) const
693693{
694+ TiltedPhoques::Vector<ConnectionId_t> players;
695+ players.reserve (m_pWorld->GetPlayerManager ().Count ());
696+
694697 for (Player* pPlayer : m_pWorld->GetPlayerManager ())
695698 {
696- if (pPlayer->GetCellComponent ())
699+ players.push_back (pPlayer->GetConnectionId ());
700+ }
701+
702+ for (auto connectionId : players)
703+ {
704+ Player* pPlayer = m_pWorld->GetPlayerManager ().GetByConnectionId (connectionId);
705+ if (pPlayer && pPlayer->GetCellComponent ())
697706 pPlayer->Send (acServerMessage);
698707 }
699708}
700709
701710void GameServer::SendToPlayers (const ServerMessage& acServerMessage, const Player* apExcludedPlayer) const
702711{
712+ TiltedPhoques::Vector<ConnectionId_t> players;
713+ players.reserve (m_pWorld->GetPlayerManager ().Count ());
714+
703715 for (Player* pPlayer : m_pWorld->GetPlayerManager ())
704716 {
705- if (pPlayer != apExcludedPlayer)
717+ players.push_back (pPlayer->GetConnectionId ());
718+ }
719+
720+ for (auto connectionId : players)
721+ {
722+ Player* pPlayer = m_pWorld->GetPlayerManager ().GetByConnectionId (connectionId);
723+ if (pPlayer && pPlayer != apExcludedPlayer)
706724 pPlayer->Send (acServerMessage);
707725 }
708726}
@@ -731,9 +749,19 @@ bool GameServer::SendToPlayersInRange(const ServerMessage& acServerMessage, cons
731749 if (const auto * characterComponent = m_pWorld->try_get <CharacterComponent>(acOrigin))
732750 isDragon = characterComponent->IsDragon ();
733751
752+ TiltedPhoques::Vector<ConnectionId_t> players;
753+ players.reserve (m_pWorld->GetPlayerManager ().Count ());
754+
734755 for (Player* pPlayer : m_pWorld->GetPlayerManager ())
735756 {
736- if (cellComponent.IsInRange (pPlayer->GetCellComponent (), isDragon) && pPlayer != apExcludedPlayer)
757+ players.push_back (pPlayer->GetConnectionId ());
758+ }
759+
760+ for (auto connectionId : players)
761+ {
762+ Player* pPlayer = m_pWorld->GetPlayerManager ().GetByConnectionId (connectionId);
763+
764+ if (pPlayer && cellComponent.IsInRange (pPlayer->GetCellComponent (), isDragon) && pPlayer != apExcludedPlayer)
737765 pPlayer->Send (acServerMessage);
738766 }
739767
@@ -748,9 +776,19 @@ void GameServer::SendToParty(const ServerMessage& acServerMessage, const PartyCo
748776 return ;
749777 }
750778
779+ TiltedPhoques::Vector<ConnectionId_t> players;
780+ players.reserve (m_pWorld->GetPlayerManager ().Count ());
781+
751782 for (Player* pPlayer : m_pWorld->GetPlayerManager ())
752783 {
753- if (pPlayer == apExcludeSender)
784+ players.push_back (pPlayer->GetConnectionId ());
785+ }
786+
787+ for (auto connectionId : players)
788+ {
789+ Player* pPlayer = m_pWorld->GetPlayerManager ().GetByConnectionId (connectionId);
790+
791+ if (!pPlayer || pPlayer == apExcludeSender)
754792 continue ;
755793
756794 const auto & partyComponent = pPlayer->GetParty ();
@@ -780,9 +818,19 @@ void GameServer::SendToPartyInRange(const ServerMessage& acServerMessage, const
780818
781819 const auto & cellComponent = view.get <CellIdComponent>(*it);
782820
821+ TiltedPhoques::Vector<ConnectionId_t> players;
822+ players.reserve (m_pWorld->GetPlayerManager ().Count ());
823+
783824 for (Player* pPlayer : m_pWorld->GetPlayerManager ())
784825 {
785- if (pPlayer == apExcludeSender)
826+ players.push_back (pPlayer->GetConnectionId ());
827+ }
828+
829+ for (auto connectionId : players)
830+ {
831+ Player* pPlayer = m_pWorld->GetPlayerManager ().GetByConnectionId (connectionId);
832+
833+ if (!pPlayer || pPlayer == apExcludeSender)
786834 continue ;
787835
788836 if (!cellComponent.IsInRange (pPlayer->GetCellComponent (), false ))
0 commit comments