A class that represents the server.
More...
#include <Server.hpp>
|
| class | Client |
| | A class that represents a client connected to the server. More...
|
| |
|
| static void | sendResponse (int client_fd, CmdID cmd_id, int cmd_code, const std::string &message) |
| | Sends a response to the client.
|
| |
|
| void | executeId (int client_fd, std::vector< std::string > &command) |
| | Executes the ID command.
|
| |
| void | executeMap (int client_fd, std::vector< std::string > &command) |
| | Executes the MAP command.
|
| |
| void | executePseudo (int client_fd, std::vector< std::string > &command) |
| | Executes the PSEUDO command.
|
| |
| void | executeMove (int client_fd, std::vector< std::string > &command) |
| | Executes the MOVE command.
|
| |
| void | executeClientsNb (int client_fd, std::vector< std::string > &command) |
| | Executes the CLIENTS_NB command.
|
| |
| void | executeClientsStats (int client_fd, std::vector< std::string > &command) |
| | Executes the CLIENTS_STATS command.
|
| |
| void | executeClientsPositions (int client_fd, std::vector< std::string > &command) |
| | Executes the CLIENTS_POSITIONS command.
|
| |
|
|
std::unordered_map< std::string, std::function< void(int client_fd, std::vector< std::string > &command)> > | _commands |
| |
|
| void | _checkArgs (int ac, char **av) |
| | Checks the command line arguments.
|
| |
| void | _initMap () |
| | Initializes the map of the game.
|
| |
| void | _initCommands () |
| | Initializes the commands of the server.
|
| |
| void | _initServer () |
| | Initializes the server.
|
| |
| bool | _isPlayerOn (const double &x, const double &y, const char c) const |
| | Checks if the player is on the map.
|
| |
| void | _analyseClientOnCoin (Client &client) |
| | Analyse if the client is on a coin and add it to the client coin list.
|
| |
| void | _updatePlayer (Client &client, double &delta_time, bool &reset_coins) |
| | Updates a client (player)
|
| |
| void | _updateGame () |
| | Updates the game.
|
| |
| void | _addNewClient () |
| | Adds a new client to the server.
|
| |
| void | _disconnectClient (std::size_t poll_index) |
| | Disconnects a client from the server.
|
| |
| void | _executeCommand (std::size_t poll_index, const std::string &command) |
| | Executes a command.
|
| |
| void | _writeClientAction (std::size_t poll_index) |
| | Writes a response to the client.
|
| |
| void | _readClientAction (std::size_t poll_index) |
| | Reads a command from the client.
|
| |
| void | _analysePoll (std::size_t poll_index) |
| | Analyzes the poll events.
|
| |
|
|
std::string | _port |
| |
|
std::string | _map_path |
| |
|
bool | _infinite_mode = false |
| |
|
std::vector< std::string > | _map |
| |
|
struct sockaddr_in | _server |
| |
|
std::unique_ptr< Socket > | _server_socket |
| |
|
std::vector< pollfd > | _poll_list |
| |
|
std::map< std::size_t, std::unique_ptr< Client > > | _clients |
| |
|
std::chrono::time_point< std::chrono::high_resolution_clock > | _last_update |
| |
|
double | _map_x_pos = 0 |
| |
A class that represents the server.
◆ Server() [1/2]
Constructor for Server class.
- Parameters
-
| ac | Number of command line arguments |
| av | Array of command line arguments |
- Exceptions
-
◆ Server() [2/2]
Deleted copy constructor.
- Parameters
-
| other | The other Server object to copy from |
◆ _addNewClient()
Adds a new client to the server.
- Exceptions
-
◆ _analyseClientOnCoin()
| void _analyseClientOnCoin |
( |
Client & | client | ) |
|
|
private |
Analyse if the client is on a coin and add it to the client coin list.
- Parameters
-
| client | The client to analyse |
◆ _analysePoll()
| void _analysePoll |
( |
std::size_t | poll_index | ) |
|
|
private |
Analyzes the poll events.
- Parameters
-
| poll_index | The index of the client in the poll list |
◆ _checkArgs()
| void _checkArgs |
( |
int | ac, |
|
|
char ** | av ) |
|
private |
Checks the command line arguments.
Check the arguments passed to the server.
- Parameters
-
| ac | Number of command line arguments |
| av | Array of command line arguments |
- Exceptions
-
- Parameters
-
| ac | The number of arguments |
| av | The arguments |
- Exceptions
-
◆ _disconnectClient()
| void _disconnectClient |
( |
std::size_t | poll_index | ) |
|
|
private |
Disconnects a client from the server.
- Parameters
-
| poll_index | The index of the client in the poll list |
◆ _executeCommand()
| void _executeCommand |
( |
std::size_t | poll_index, |
|
|
const std::string & | command ) |
|
private |
Executes a command.
- Parameters
-
| poll_index | The index of the client in the poll list |
| command | The command to execute |
◆ _initCommands()
Initializes the commands of the server.
Initialize the commands of the server.
◆ _initMap()
Initializes the map of the game.
Initialize the map from the file.
- Exceptions
-
◆ _initServer()
Initializes the server.
Initialize the server.
- Exceptions
-
◆ _isPlayerOn()
| bool _isPlayerOn |
( |
const double & | x, |
|
|
const double & | y, |
|
|
const char | c ) const |
|
private |
Checks if the player is on the map.
- Parameters
-
| x | The x position of the player |
| y | The y position of the player |
| c | The character to check |
- Returns
- True if the player is on the map, false otherwise
◆ _readClientAction()
| void _readClientAction |
( |
std::size_t | poll_index | ) |
|
|
private |
Reads a command from the client.
- Parameters
-
| poll_index | The index of the client in the poll list |
- Exceptions
-
◆ _updateGame()
Updates the game.
- Note
- This function is called every frame/poll
◆ _updatePlayer()
| void _updatePlayer |
( |
Client & | client, |
|
|
double & | delta_time, |
|
|
bool & | reset_coins ) |
|
private |
Updates a client (player)
- Parameters
-
| client | The client to update |
| delta_time | The time since the last frame |
| reset_coins | True if the coins should be reset and false if not |
◆ _writeClientAction()
| void _writeClientAction |
( |
std::size_t | poll_index | ) |
|
|
private |
Writes a response to the client.
- Parameters
-
| poll_index | The index of the client in the poll list |
◆ executeClientsNb()
| void executeClientsNb |
( |
int | client_fd, |
|
|
std::vector< std::string > & | command ) |
|
protected |
Executes the CLIENTS_NB command.
Execute the clients nb command.
- Parameters
-
| client_fd | The file descriptor of the client |
| command | The command to execute |
◆ executeClientsPositions()
| void executeClientsPositions |
( |
int | client_fd, |
|
|
std::vector< std::string > & | command ) |
|
protected |
Executes the CLIENTS_POSITIONS command.
Execute the clients positions command.
- Parameters
-
| client_fd | The file descriptor of the client |
| command | The command to execute |
◆ executeClientsStats()
| void executeClientsStats |
( |
int | client_fd, |
|
|
std::vector< std::string > & | command ) |
|
protected |
Executes the CLIENTS_STATS command.
Execute the clients stats command.
- Parameters
-
| client_fd | The file descriptor of the client |
| command | The command to execute |
◆ executeId()
| void executeId |
( |
int | client_fd, |
|
|
std::vector< std::string > & | command ) |
|
protected |
Executes the ID command.
Execute the id command.
- Parameters
-
| client_fd | The file descriptor of the client |
| command | The command to execute |
◆ executeMap()
| void executeMap |
( |
int | client_fd, |
|
|
std::vector< std::string > & | command ) |
|
protected |
Executes the MAP command.
Execute the map command.
- Parameters
-
| client_fd | The file descriptor of the client |
| command | The command to execute |
◆ executeMove()
| void executeMove |
( |
int | client_fd, |
|
|
std::vector< std::string > & | command ) |
|
protected |
Executes the MOVE command.
Execute the move command.
- Parameters
-
| client_fd | The file descriptor of the client |
| command | The command to execute |
◆ executePseudo()
| void executePseudo |
( |
int | client_fd, |
|
|
std::vector< std::string > & | command ) |
|
protected |
Executes the PSEUDO command.
Execute the pseudo command.
- Parameters
-
| client_fd | The file descriptor of the client |
| command | The command to execute |
◆ operator=()
Deleted assignment operator.
- Parameters
-
| other | The other Server object to assign from |
- Returns
- Reference to the current object
◆ run()
Runs the server.
- Note
- This function is the main loop of the server
- Exceptions
-
◆ sendResponse()
| void sendResponse |
( |
int | client_fd, |
|
|
CmdID | cmd_id, |
|
|
int | cmd_code, |
|
|
const std::string & | message ) |
|
static |
Sends a response to the client.
- Parameters
-
| client_fd | The file descriptor of the client |
| cmd_id | The command ID |
| cmd_code | The command code |
| message | The message to send |
The documentation for this class was generated from the following files: