17#ifndef _FGE_C_CLIENTLIST_HPP_INCLUDED
18#define _FGE_C_CLIENTLIST_HPP_INCLUDED
20#include "FastEngine/fge_extern.hpp"
21#include "C_client.hpp"
22#include "C_protocol.hpp"
23#include "FastEngine/C_accessLock.hpp"
27#include <unordered_map>
34using ClientSharedPtr = std::shared_ptr<Client>;
41class FGE_API ClientList
51 enum class Types : uint8_t
56 using Types_t = std::underlying_type_t<Types>;
58 inline Event(Types eventType,
Identity const& clientId) :
67 using DataList = std::unordered_map<Identity, ClientSharedPtr, IdentityHash>;
68 using EventList = std::deque<Event>;
70 ClientList() =
default;
71 ClientList(ClientList
const& r);
72 ClientList(ClientList&& r)
noexcept;
73 ~ClientList() =
default;
75 ClientList& operator=(ClientList
const& r);
76 ClientList& operator=(ClientList&& r)
noexcept;
100 bool moveTo(ClientList& targetList,
Identity const&
id);
213 mutable std::recursive_mutex g_mutex;
214 bool g_enableClientEventsFlag =
false;
Class that lock a mutex and unlock it only when the object is destroyed.
Definition C_accessLock.hpp:38
void pushClientEvent(Event const &evt)
Manually push a client event.
void clear()
Clear the client list and the event list.
bool isWatchingEvent() const
Check if the gathering of client events is enabled.
void remove(Identity const &id)
Remove a client from the list.
AccessLock< std::recursive_mutex > acquireLock() const
Acquire a unique lock, with the ClientList mutex.
void clearClientEvent()
Clear the client event list.
void sendToAll(SocketUdp &socket, Packet &pck) const
Directly send a packet to every client in the list.
void watchEvent(bool on)
Enable or disable the gathering of client events.
DataList::iterator remove(DataList::const_iterator itPos, AccessLock< std::recursive_mutex > const &lock)
Remove a client from the list.
DataList::iterator begin(AccessLock< std::recursive_mutex > const &lock)
Get the begin iterator of the ClientList.
ClientSharedPtr get(Identity const &id) const
Get a client from the list.
void sendToAll(TransmitPacketPtr const &pck) const
Push a packet to every client in the list.
void add(Identity const &id, ClientSharedPtr const &newClient)
Add a client to the list.
std::size_t getSize() const
Get the number of clients in the list.
Event const & getClientEvent(std::size_t index) const
Get the client event with its index.
std::size_t getClientEventSize() const
Get the number of client events.
Definition C_packet.hpp:52
A wrapper for UDP sockets inheriting from Socket.
Definition C_socket.hpp:355
Represents an event on the client list (client added, client removed, ...).
Definition C_clientList.hpp:50
A class to represent a client or server identity with an IP address and a port.
Definition C_identity.hpp:31