diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e54b9b6 --- /dev/null +++ b/Makefile @@ -0,0 +1,22 @@ +NAME = ircserv + +SRC = main.cpp Server.cpp + +OBJ = ${SRC:.cpp=.o} + +CXX = c++ + +CXXFLAGS = -std=c++98 -fsanitize=address -g3#-Wall -Wextra -Werror + +all : $(NAME) + +$(NAME) : $(OBJ) + $(CXX) $(CXXFLAGS) $(OBJ) -o $(NAME) + +clean : + rm -rf *.o + +fclean : clean + rm -rf $(NAME) + +re : fclean all \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index 7cc68fb..0000000 --- a/README.md +++ /dev/null @@ -1 +0,0 @@ -# IRC-Server \ No newline at end of file diff --git a/Server.cpp b/Server.cpp new file mode 100644 index 0000000..3669fd5 --- /dev/null +++ b/Server.cpp @@ -0,0 +1,24 @@ +#include "Server.hpp" + +Server::Server() {} + +Server::~Server() {} + +void Server::parseArgs(int ac, char **av) { + if (ac != 3) + throw std::runtime_error("Usage: ./ircserv "); + std::string port(av[1]); + std::string pwd(av[2]); + if (port.empty() || port.find_first_not_of("0123456789") != std::string::npos) + throw std::runtime_error("Error: Invalid arguments"); + + long _port = atol(av[1]); + if (!(_port >= 1 && _port <= 65535)) + throw std::runtime_error("Error: Invalid arguments"); + + if (pwd.empty()) + throw std::runtime_error("Error: Invalid arguments"); + + this->_port = _port; + this->_password = pwd; +} diff --git a/Server.hpp b/Server.hpp new file mode 100644 index 0000000..f26087b --- /dev/null +++ b/Server.hpp @@ -0,0 +1,19 @@ +#ifndef SERVER_HPP +#define SERVER_HPP + + +#include +#include + +class Server { + private: + int _port; + std::string _password; + public: + Server(); + ~Server(); + + void parseArgs(int ac, char **av); +}; + +#endif \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..83d8881 --- /dev/null +++ b/main.cpp @@ -0,0 +1,14 @@ +#include "Server.hpp" + +int main(int ac, char **av) +{ + Server server; + + try { + server.parseArgs(ac, av); + } catch (std::exception& e) { + std::cerr << e.what() << std::endl; + return 1; + } + return 0; +}