BF2MC-Matchmaker
Public Types | Public Member Functions | Private Attributes | List of all members
Server Class Reference
Inheritance diagram for Server:
Inheritance graph
[legend]
Collaboration diagram for Server:
Collaboration graph
[legend]

Public Types

enum  Type {
  QR , GPSP , GPCM , Webserver ,
  Browsing , GameStats , Websocket , None
}
 Enum defining the types of servers. More...
 

Public Member Functions

 Server (Server::Type type)
 Constructor for the Server class. More...
 
std::vector< std::shared_ptr< Net::Socket > > GetClients ()
 Get the vector of client sockets connected to this server. More...
 
void Listen ()
 Start listening for incoming connections on the server.
 
void UDPListen ()
 Start listening for incoming UDP packets on the server.
 
void DisconnectAllClients ()
 Disconnect all connected clients from the server.
 
void Close ()
 Close the server and stop listening for incoming connections.
 
void onServerListen () const
 Called when the server starts listening for incoming connections. More...
 
void onServerShutdown () const
 Called when the server is shutting down. More...
 
void onClientConnect (const Net::Socket &client) const
 Called when a client connects to the server. More...
 
void onClientConnect (const std::shared_ptr< Net::Socket > &client) const
 Called when a client connects to the server. More...
 
void onClientDisconnect (const Net::Socket &client)
 Called when a client disconnects from the server. More...
 
- Public Member Functions inherited from Net::Socket
void Close ()
 Closes the socket.
 
std::string GetIP () const
 Gets the IP address associated with the socket. More...
 
void GetIpArray (uint8_t *ip) const
 Gets the IP address associated with the socket as an array of bytes. More...
 
uint16_t GetPort () const
 Gets the port number associated with the socket. More...
 
std::string GetAddress () const
 Gets the full address (IP:Port) associated with the socket. More...
 
std::string GetSocketType () const
 Gets the socket type. More...
 
std::chrono::system_clock::time_point GetLastRecievedTime () const
 Gets the time when the socket last received data. More...
 
void Send (const std::string &msg) const
 Sends a message over the socket. More...
 
void Send (const std::vector< unsigned char > &msg) const
 Sends a message over the socket. More...
 
void UDPSend (const std::string &msg) const
 Sends a UDP message over the socket. More...
 
void UDPSend (const std::vector< unsigned char > &msg) const
 Sends a UDP message over the socket. More...
 
void UpdateLastRecievedTime ()
 Updates the last received time to the current system time.
 
virtual void WTF_WHY_AM_I_HERE_1337 ()
 Empty virtual function required for static_cast in C++. More...
 

Private Attributes

std::vector< std::shared_ptr< Net::Socket > > _clients
 
Server::Type _type
 
std::mutex _mutex
 

Additional Inherited Members

- Protected Attributes inherited from Net::Socket
int _socket
 
struct sockaddr_in _address
 
std::chrono::system_clock::time_point _recieved_time
 
std::mutex _mutex
 

Detailed Description

Definition at line 9 of file server.h.

Member Enumeration Documentation

◆ Type

Enum defining the types of servers.

Enumerator
QR 

Query and Report (QR) server. UDP:27900, Domain: bfield1942ps2.master.bfmcspy.net

GPSP 

GameSpy Protocol (GPSP) server. TCP:29901, Domain: gpsp.gamespy.com

GPCM 

GameSpy Connection Manager (GPCM) server. TCP:29900, Domain: gpcm.gamespy.com

Webserver 

Web server. TCP:80, Domain: www.easports.com and bfmc.gamespy.com

Browsing 

Browsing server. TCP:28910, Domain: bfield1942ps2.available.gamespy.com and bfield1942ps2.ms7.gamespy.com

GameStats 

Game statistics server. TCP:29920, Domain: bfield1942ps2.gamestats.bfmcspy.net

Websocket 

Websocket server. TCP:55001

None 

No specific server type.

Definition at line 15 of file server.h.

Constructor & Destructor Documentation

◆ Server()

Server::Server ( Server::Type  type)

Constructor for the Server class.

Parameters
typeThe type of the server.

Definition at line 24 of file server.cpp.

Member Function Documentation

◆ GetClients()

std::vector< std::shared_ptr< Net::Socket > > Server::GetClients ( )

Get the vector of client sockets connected to this server.

Returns
Vector of client sockets.

Definition at line 86 of file server.cpp.

◆ onClientConnect() [1/2]

void Server::onClientConnect ( const Net::Socket client) const

Called when a client connects to the server.

Parameters
clientThe client socket that connected.

Definition at line 314 of file server.cpp.

◆ onClientConnect() [2/2]

void Server::onClientConnect ( const std::shared_ptr< Net::Socket > &  client) const

Called when a client connects to the server.

Parameters
clientThe shared pointer to the client socket that connected.

Definition at line 325 of file server.cpp.

◆ onClientDisconnect()

void Server::onClientDisconnect ( const Net::Socket client)

Called when a client disconnects from the server.

Parameters
clientThe client socket that disconnected.

Definition at line 336 of file server.cpp.

◆ onServerListen()

void Server::onServerListen ( ) const

Called when the server starts listening for incoming connections.

This function is called when the server starts listening for incoming connections.

Definition at line 304 of file server.cpp.

◆ onServerShutdown()

void Server::onServerShutdown ( ) const

Called when the server is shutting down.

This function is called when the server is shutting down.

Definition at line 309 of file server.cpp.

Member Data Documentation

◆ _clients

std::vector<std::shared_ptr<Net::Socket> > Server::_clients
private

Vector of client sockets connected to this server.

Definition at line 28 of file server.h.

◆ _mutex

std::mutex Server::_mutex
mutableprivate

Mutex for thread-safe operations on the server.

Definition at line 30 of file server.h.

◆ _type

Server::Type Server::_type
private

Type of the server.

Definition at line 29 of file server.h.


The documentation for this class was generated from the following files: