parsed arguments

This commit is contained in:
bettercallous
2024-04-08 07:20:11 +00:00
parent 8aece78bb2
commit 2fdb0eb6c4
5 changed files with 79 additions and 1 deletions

24
Server.cpp Normal file
View 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;
}