20 constexpr int START_FD = 4;
21 constexpr double GRAVITY = 9.81;
22 constexpr double JETPACK_SPEED = 10.0;
23 constexpr double PLAYER_SPEED = 5.0;
24 constexpr char INVALID_PSEUDO_CHARACTERS[] =
":| \t\n\r";
68 static void sendResponse(
int client_fd, CmdID cmd_id,
int cmd_code,
const std::string &message);
124 bool _isPlayerOn(
const double &x,
const double &y,
const char c)
const;
164 void _executeCommand(std::size_t poll_index,
const std::string &command);
187 std::unordered_map<std::string, std::function<void(
int client_fd, std::vector<std::string> &command)>> _commands;
194 void executeId(
int client_fd, std::vector<std::string> &command);
200 void executeMap(
int client_fd, std::vector<std::string> &command);
206 void executePseudo(
int client_fd, std::vector<std::string> &command);
212 void executeMove(
int client_fd, std::vector<std::string> &command);
235 #define MAX_HEIGHT (_map.size() - 1)
239 std::string _map_path;
240 bool _infinite_mode =
false;
241 std::vector<std::string> _map;
242 struct sockaddr_in _server;
243 std::unique_ptr<Socket> _server_socket;
244 std::vector<pollfd> _poll_list;
245 std::map<std::size_t, std::unique_ptr<Client>> _clients;
246 std::chrono::time_point<std::chrono::high_resolution_clock> _last_update;
247 double _map_x_pos = 0;
A class that represents a client connected to the server.
Definition ServerClient.hpp:23
A class that represents the server.
Definition Server.hpp:30
void _readClientAction(std::size_t poll_index)
Reads a command from the client.
Definition Server.cpp:213
void _analyseClientOnCoin(Client &client)
Analyse if the client is on a coin and add it to the client coin list.
Definition Game.cpp:37
void run()
Runs the server.
Definition Server.cpp:258
void executePseudo(int client_fd, std::vector< std::string > &command)
Executes the PSEUDO command.
Definition Pseudo.cpp:21
Server & operator=(const Server &)=delete
Deleted assignment operator.
void executeId(int client_fd, std::vector< std::string > &command)
Executes the ID command.
Definition Id.cpp:21
bool _isPlayerOn(const double &x, const double &y, const char c) const
Checks if the player is on the map.
Definition Game.cpp:23
void executeMap(int client_fd, std::vector< std::string > &command)
Executes the MAP command.
Definition Map.cpp:21
void executeClientsPositions(int client_fd, std::vector< std::string > &command)
Executes the CLIENTS_POSITIONS command.
Definition ClientsPositions.cpp:21
void executeClientsNb(int client_fd, std::vector< std::string > &command)
Executes the CLIENTS_NB command.
Definition ClientsNb.cpp:21
void _initServer()
Initializes the server.
Definition Server.cpp:99
void _initCommands()
Initializes the commands of the server.
Definition Server.cpp:83
Server(int ac, char **av)
Constructor for Server class.
Definition Server.cpp:121
void _addNewClient()
Adds a new client to the server.
Definition Server.cpp:143
void _updateGame()
Updates the game.
Definition Game.cpp:98
void executeMove(int client_fd, std::vector< std::string > &command)
Executes the MOVE command.
Definition Move.cpp:21
void _executeCommand(std::size_t poll_index, const std::string &command)
Executes a command.
Definition Server.cpp:173
~Server()
Destructor for Server class.
Definition Server.cpp:134
void _initMap()
Initializes the map of the game.
Definition Server.cpp:62
Server(const Server &)=delete
Deleted copy constructor.
void executeClientsStats(int client_fd, std::vector< std::string > &command)
Executes the CLIENTS_STATS command.
Definition ClientsStats.cpp:21
static void sendResponse(int client_fd, CmdID cmd_id, int cmd_code, const std::string &message)
Sends a response to the client.
Definition Server.cpp:279
void _writeClientAction(std::size_t poll_index)
Writes a response to the client.
Definition Server.cpp:193
void _disconnectClient(std::size_t poll_index)
Disconnects a client from the server.
Definition Server.cpp:161
void _checkArgs(int ac, char **av)
Checks the command line arguments.
Definition Server.cpp:23
void _analysePoll(std::size_t poll_index)
Analyzes the poll events.
Definition Server.cpp:239
void _updatePlayer(Client &client, double &delta_time, bool &reset_coins)
Updates a client (player)
Definition Game.cpp:62