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"
24#include "FastEngine/network/C_netCommand.hpp"
28#include <unordered_map>
35using ClientSharedPtr = std::shared_ptr<Client>;
59class FGE_API ClientList
64 inline explicit Data(ClientSharedPtr client) :
65 _client(std::move(client))
68 ClientSharedPtr _client;
70 CommandQueue _commands;
72 std::future<uint16_t> _mtuFuture;
75 using DataList = std::unordered_map<Identity, Data, IdentityHash>;
76 using EventList = std::deque<ClientListEvent>;
78 ClientList() =
default;
79 ~ClientList() =
default;
217 mutable std::recursive_mutex g_mutex;
218 bool g_enableClientEventsFlag =
false;
Class that lock a mutex and unlock it only when the object is destroyed.
Definition C_accessLock.hpp:38
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.
void pushClientEvent(ClientListEvent const &evt)
Manually push a client event.
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.
ClientListEvent const & getClientEvent(std::size_t index) const
Get the client event with its index.
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.
std::size_t getClientEventSize() const
Get the number of client events.
Definition C_protocol.hpp:287
Definition C_packet.hpp:52
A wrapper for UDP sockets inheriting from Socket.
Definition C_socket.hpp:348
Represents an event on the client list (client added, client removed, ...)
Definition C_clientList.hpp:43
Definition C_clientList.hpp:63
A class to represent a client or server identity with an IP address and a port.
Definition C_identity.hpp:31