BF2MC-Matchmaker
Public Member Functions | Static Public Member Functions | Private Member Functions | List of all members
GameStats::Client Class Reference

Represents a client for game statistics. More...

#include <client.h>

Inheritance diagram for GameStats::Client:
Inheritance graph
[legend]
Collaboration diagram for GameStats::Client:
Collaboration graph
[legend]

Public Member Functions

 Client (int socket, struct sockaddr_in address)
 Constructor for Game Statistics Client. More...
 
 ~Client ()
 Destructor for Game Statistics Client.
 
void Listen ()
 Start listening for client requests. More...
 
void Disconnect ()
 Disconnect the client. More...
 
void onRequest (const std::string &request)
 Handle incoming requests from the client. More...
 
void requestChallenge ()
 Request a challenge from the client. More...
 
void requestAuth (const GameSpy::Parameter &parameter)
 Request authentication with provided parameters. More...
 
void requestNewGame (const GameSpy::Parameter &parameter)
 Request to create a new game with provided parameters. More...
 
void requestUpdateGame (const GameSpy::Parameter &parameter)
 Request to update an existing game with provided parameters. 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...
 

Static Public Member Functions

static void Heartbeat ()
 Heartbeat function to manage client connections. More...
 
static std::vector< unsigned char > Encrypt (const std::string &response)
 Encrypts a response message. More...
 
static std::string Decrypt (const std::vector< unsigned char > &request)
 Decrypts a request message. More...
 
static void Test ()
 

Private Member Functions

void _LogTransaction (const std::string &direction, const std::string &response) const
 Log a transaction with direction and response. More...
 
bool _GetKeyAndPlayerIndex (const std::string &input, std::string &key, int &player_index)
 Get the key and the player index from string input. More...
 

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

Represents a client for game statistics.

This class extends the Net::Socket class to handle client connections and requests for game statistics.

Definition at line 15 of file gamestats/client.h.

Constructor & Destructor Documentation

◆ Client()

GameStats::Client::Client ( int  socket,
struct sockaddr_in  address 
)

Constructor for Game Statistics Client.

Parameters
socketThe socket ID.
addressThe client's address.

Definition at line 27 of file gamestats/client.cpp.

Member Function Documentation

◆ _GetKeyAndPlayerIndex()

bool GameStats::Client::_GetKeyAndPlayerIndex ( const std::string &  input,
std::string &  key,
int &  player_index 
)
private

Get the key and the player index from string input.

Parameters
inputThe input to extract the key and player index.
keyThe key to return
player_indexThe player_index to return
Returns
True/False if extraction went well.

Definition at line 336 of file gamestats/client.cpp.

◆ _LogTransaction()

void GameStats::Client::_LogTransaction ( const std::string &  direction,
const std::string &  response 
) const
private

Log a transaction with direction and response.

This function logs a transaction with the specified direction (e.g., "<--" or "-->") and the response received.

Parameters
directionThe direction of the transaction ("<--" or "-->").
responseThe response data to be logged.

Definition at line 320 of file gamestats/client.cpp.

◆ Decrypt()

std::string GameStats::Client::Decrypt ( const std::vector< unsigned char > &  request)
static

Decrypts a request message.

This static function decrypts a received request message. It takes a vector of unsigned chars (encrypted message) and returns the decrypted message as a string.

Parameters
requestThe encrypted request message to decrypt.
Returns
The decrypted message as a string.

Definition at line 386 of file gamestats/client.cpp.

◆ Disconnect()

void GameStats::Client::Disconnect ( )

Disconnect the client.

This function disconnects the client from the server. It closes the socket connection and cleans up resources.

Definition at line 98 of file gamestats/client.cpp.

◆ Encrypt()

std::vector< unsigned char > GameStats::Client::Encrypt ( const std::string &  response)
static

Encrypts a response message.

This static function encrypts a response message before sending it over the network. It takes a string message and returns the encrypted message as a vector of unsigned chars.

Parameters
responseThe response message to encrypt.
Returns
The encrypted message as a vector of unsigned chars.

Definition at line 406 of file gamestats/client.cpp.

◆ Heartbeat()

void GameStats::Client::Heartbeat ( )
static

Heartbeat function to manage client connections.

This function periodically checks for client connections and closes connections that have not sent any data in the last minute.

Definition at line 362 of file gamestats/client.cpp.

◆ Listen()

void GameStats::Client::Listen ( )

Start listening for client requests.

This function starts listening for incoming requests from the client. It is typically called after the client has been initialized.

Definition at line 39 of file gamestats/client.cpp.

◆ onRequest()

void GameStats::Client::onRequest ( const std::string &  request)

Handle incoming requests from the client.

This function is called to process incoming requests from the client.

Parameters
requestThe incoming request data.

Definition at line 107 of file gamestats/client.cpp.

◆ requestAuth()

void GameStats::Client::requestAuth ( const GameSpy::Parameter &  parameter)

Request authentication with provided parameters.

This function sends a response to the client for authentication with the provided parameters.

Parameters
parameterThe authentication parameters.

Definition at line 161 of file gamestats/client.cpp.

◆ requestChallenge()

void GameStats::Client::requestChallenge ( )

Request a challenge from the client.

This function sends a response to the client to provide a challenge for authentication purposes.

Definition at line 136 of file gamestats/client.cpp.

◆ requestNewGame()

void GameStats::Client::requestNewGame ( const GameSpy::Parameter &  parameter)

Request to create a new game with provided parameters.

This function sends a request to the client to create a new game with the provided parameters.

Parameters
parameterThe parameters for creating a new game.

Definition at line 183 of file gamestats/client.cpp.

◆ requestUpdateGame()

void GameStats::Client::requestUpdateGame ( const GameSpy::Parameter &  parameter)

Request to update an existing game with provided parameters.

This function sends a response to the client to update an existing game with the provided parameters.

Parameters
parameterThe parameters for updating an existing game.

Definition at line 205 of file gamestats/client.cpp.


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