|
Eile Mit Weile
|
Manages all connected Players. More...
#include <PlayerManager.hpp>
Static Public Member Functions | |
| static bool | TryGetPlayer (const std::string &player_id, Player *&player_ptr) |
| static bool | AddOrGetPlayer (std::string name, const std::string &player_id, Player *&player_ptr) |
| static bool | RemovePlayer (const std::string &player_id, Player *&player) |
Static Private Attributes | |
| static std::shared_mutex | rw_lock |
| static std::unordered_map< std::string, Player * > | players_lut = {} |
Manages all connected Players.
The PlayerManager only exists on the server side. It stores all connected users since starting the server. It offers functionality to retrieve players by id or adding players when they first connect to the server.
Note: This class design is taken from https://gitlab.ethz.ch/hraymond/cse-lama-example-project. They made the choice to have all members be static, which is why this class is a singleton and should not be instantiated. Its members are referenced by other classes without them having to instatiate a PlayerManager as a member var. We consider this bad practice but changing would require a lot of refactoring so we decided to keep it as is.
|
static |
Returns true if the desired Player player_id was found or false otherwise. The found Player is written into player_ptr. If the player was not found, a new Player is created (constructor) and added to the unordered_map of Players.
Returns true if the desired Player player_id was found and removed or false otherwise.
|
staticprivate |
Unordered_map of all connected players. The Player::id (in UniqueSerializable) serves as a key.
|
inlinestaticprivate |
Mutex to lock the unordered_map of players for reading and writing.