diff --git a/Flakkari/ParseArgument.cpp b/Flakkari/ParseArgument.cpp index 9bf67f5..7359bc3 100644 --- a/Flakkari/ParseArgument.cpp +++ b/Flakkari/ParseArgument.cpp @@ -35,6 +35,8 @@ ParseArgument::ParseArgument(int ac, const char *av[]) else if (std::string(av[i]) == "-port") { _port = static_cast(std::stoi(av[i + 1])); + if (_port < 1024 || _port > 65535) + throw std::runtime_error("Invalid port number, must be between 1024 and 65535"); ++i; } else if (std::string(av[i]) == "-h" || std::string(av[i]) == "--help") diff --git a/Flakkari/ParseArgument.hpp b/Flakkari/ParseArgument.hpp index 1289d2a..cc52364 100644 --- a/Flakkari/ParseArgument.hpp +++ b/Flakkari/ParseArgument.hpp @@ -46,6 +46,24 @@ class ParseArgument { */ ~ParseArgument() = default; + /** + * @brief Gets the game directory. + * @return A constant reference to the game directory string. + */ + const std::string &getGameDir() const; + + /** + * @brief Gets the IP address. + * @return A constant reference to the IP address string. + */ + const std::string &getIp() const; + + /** + * @brief Gets the port number. + * @return The port number as an unsigned short. + */ + unsigned short getPort() const; + private: std::string _gameDir; ///< The game directory. std::string _ip; ///< The IP address, default is "localhost". diff --git a/Flakkari/core.cpp b/Flakkari/core.cpp index f1a9641..24a85d7 100644 --- a/Flakkari/core.cpp +++ b/Flakkari/core.cpp @@ -9,11 +9,11 @@ int main(int ac, const char *av[]) { - if (ac != 4) - return FLAKKARI_LOG_ERROR("Usage: ./r-type_server "), 84; try { - Flakkari::UDPServer server(av[1], av[2], static_cast(std::stoi(av[3]))); + Flakkari::ParseArgument parseArg(ac, av); + + Flakkari::UDPServer server(parseArg.getGameDir(), parseArg.getIp(), parseArg.getPort()); server.run(); } catch (const std::exception &e)