parsed arguments
This commit is contained in:
22
Makefile
Normal file
22
Makefile
Normal file
@@ -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
|
24
Server.cpp
Normal file
24
Server.cpp
Normal file
@@ -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 <port> <password>");
|
||||
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;
|
||||
}
|
19
Server.hpp
Normal file
19
Server.hpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef SERVER_HPP
|
||||
#define SERVER_HPP
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
|
||||
class Server {
|
||||
private:
|
||||
int _port;
|
||||
std::string _password;
|
||||
public:
|
||||
Server();
|
||||
~Server();
|
||||
|
||||
void parseArgs(int ac, char **av);
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user