MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / ProcessPlayerList

Method ProcessPlayerList

src/openrct2/network/NetworkBase.cpp:1971–2058  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1969 }
1970
1971 void NetworkBase::ProcessPlayerList()
1972 {
1973 if (GetMode() == Mode::server)
1974 {
1975 // Avoid sending multiple times the player list, we mark the list invalidated on modifications
1976 // and then send at the end of the tick the final player list.
1977 if (_playerListInvalidated)
1978 {
1979 _playerListInvalidated = false;
1980 ServerSendPlayerList();
1981 }
1982 }
1983 else
1984 {
1985 // As client we have to keep things in order so the update is tick bound.
1986 // Commands/Actions reference players and so this list needs to be in sync with those.
1987 auto itPending = _pendingPlayerLists.begin();
1988 while (itPending != _pendingPlayerLists.end())
1989 {
1990 if (itPending->first > getGameState().currentTicks)
1991 break;
1992
1993 // List of active players found in the list.
1994 std::vector<uint8_t> activePlayerIds;
1995 std::vector<uint8_t> newPlayers;
1996 std::vector<uint8_t> removedPlayers;
1997
1998 for (const auto& pendingPlayer : itPending->second.players)
1999 {
2000 activePlayerIds.push_back(pendingPlayer.id);
2001
2002 auto* player = GetPlayerByID(pendingPlayer.id);
2003 if (player == nullptr)
2004 {
2005 // Add new player.
2006 player = AddPlayer("", "");
2007 if (player != nullptr)
2008 {
2009 *player = pendingPlayer;
2010 if (player->flags & PlayerFlags::kIsServer)
2011 {
2012 _serverConnection->player = player;
2013 }
2014 newPlayers.push_back(player->id);
2015 }
2016 }
2017 else
2018 {
2019 // Update.
2020 *player = pendingPlayer;
2021 }
2022 }
2023
2024 // Remove any players that are not in newly received list
2025 for (const auto& player : player_list)
2026 {
2027 if (std::find(activePlayerIds.begin(), activePlayerIds.end(), player->id) == activePlayerIds.end())
2028 {

Callers

nothing calls this directly

Calls 6

GetModeFunction · 0.85
endMethod · 0.65
beginMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected