BF2MC-Matchmaker
server.h
1 #ifndef SERVER_H
2 #define SERVER_H
3 
4 #include <vector>
5 #include <memory>
6 
7 #include <net/socket.h>
8 
9 class Server : public Net::Socket
10 {
11  public:
15  enum Type
16  {
17  QR,
18  GPSP,
19  GPCM,
24  None,
25  };
26 
27  private:
28  std::vector<std::shared_ptr<Net::Socket>> _clients;
30  mutable std::mutex _mutex;
32  public:
38  Server(Server::Type type);
39 
45  std::vector<std::shared_ptr<Net::Socket>> GetClients();
46 
50  void Listen();
51 
55  void UDPListen();
56 
60  void DisconnectAllClients();
61 
65  void Close();
66 
67  // Events
73  void onServerListen() const;
74 
80  void onServerShutdown() const;
81 
87  void onClientConnect(const Net::Socket& client) const;
88 
94  void onClientConnect(const std::shared_ptr<Net::Socket>& client) const;
95 
101  void onClientDisconnect(const Net::Socket& client);
102 };
103 
104 #endif // SERVER_H
A base class representing a network socket.
Definition: socket.h:15
Definition: server.h:10
std::mutex _mutex
Definition: server.h:30
std::vector< std::shared_ptr< Net::Socket > > GetClients()
Get the vector of client sockets connected to this server.
Definition: server.cpp:86
void Close()
Close the server and stop listening for incoming connections.
Definition: server.cpp:293
void onClientConnect(const Net::Socket &client) const
Called when a client connects to the server.
Definition: server.cpp:314
std::vector< std::shared_ptr< Net::Socket > > _clients
Definition: server.h:28
Server(Server::Type type)
Constructor for the Server class.
Definition: server.cpp:24
void UDPListen()
Start listening for incoming UDP packets on the server.
Definition: server.cpp:224
Type
Enum defining the types of servers.
Definition: server.h:16
@ GPSP
Definition: server.h:18
@ GameStats
Definition: server.h:22
@ Browsing
Definition: server.h:21
@ Websocket
Definition: server.h:23
@ None
Definition: server.h:24
@ QR
Definition: server.h:17
@ GPCM
Definition: server.h:19
@ Webserver
Definition: server.h:20
void onClientDisconnect(const Net::Socket &client)
Called when a client disconnects from the server.
Definition: server.cpp:336
Server::Type _type
Definition: server.h:29
void DisconnectAllClients()
Disconnect all connected clients from the server.
Definition: server.cpp:268
void onServerListen() const
Called when the server starts listening for incoming connections.
Definition: server.cpp:304
void onServerShutdown() const
Called when the server is shutting down.
Definition: server.cpp:309
void Listen()
Start listening for incoming connections on the server.
Definition: server.cpp:93