11void PlayerManager::IndexBySteamId(Player*
player)
19void PlayerManager::UnindexBySteamId(
const Player*
player)
28 auto it = _playersBySteamId.find(
player->SteamId());
29 if (
it != _playersBySteamId.end() &&
it->second ==
player)
31 _playersBySteamId.erase(
it);
35void PlayerManager::Reindex()
38 _ordered.reserve(_playersBySlot.size());
39 for (
const auto& [
slot,
player] : _playersBySlot)
41 _ordered.push_back(
player.get());
43 std::sort(_ordered.begin(), _ordered.end(), [](
const Player*
a,
const Player*
b) { return a->Slot() < b->Slot(); });
46void PlayerManager::Drop(
int slot)
48 auto it = _playersBySlot.find(
slot);
49 if (
it == _playersBySlot.end())
58 it = _playersBySlot.find(
slot);
59 if (
it == _playersBySlot.end())
64 UnindexBySteamId(
it->second.get());
65 _playersBySlot.erase(
it);
76 auto player = std::make_unique<Player>(
slot,
steamId, std::move(name), std::move(
ip), _entities);
92 if (!_playersBySlot.contains(
slot))
103 std::vector<int>
slots;
104 slots.reserve(_playersBySlot.size());
105 for (
const auto& [
slot,
player] : _playersBySlot)
117 _playersBySlot.clear();
118 _playersBySteamId.clear();
147 auto it = _playersBySlot.find(
slot);
148 return it != _playersBySlot.end() ?
it->second.get() :
nullptr;
159 auto it = _playersBySteamId.find(
steamId);
160 return it != _playersBySteamId.end() ?
it->second :
nullptr;
Event< Player & > FullyConnected
A player finished connecting (post ClientFullyConnect) - the first point their name and replicated co...
void OnClientFullyConnected(int slot)
Player * Add(int slot, int64_t steamId, std::string name, std::string ip)
void OnClientSettingsChanged(int slot)
Event< Player & > Disconnected
A player is leaving. Raised while they are still in the roster, so the handler can read their identit...
PlayerRef RefFor(int slot)
Player * BySteamId(int64_t steamId)
Event< Player & > SettingsChanged
A player changed a replicated setting (name, userinfo cvars). Fires on every change,...
Event< Player & > Connected
A player joined and is now in the roster. Their name is not meaningful yet - FullyConnected is the fi...
One connected player, owned by PlayerManager for the length of the connection.
Event< int > FullyConnected
static std::string ReadFile(const std::filesystem::path &path)
A storable reference to a player: the slot plus the SteamID that occupied it.