-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
59 lines (48 loc) · 1.38 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "includes/Server.hpp"
#include "includes/User.hpp"
#include "includes/Commands.hpp"
// int checkInput(int argc, char *argv[])
// {
// if (argc != 3)
// {
// std::cerr << "Usage: " << argv[0] << " <port number> <password>" << std::endl;
// return -1;
// }
// return 0;
// }
// int main(int argc, char *argv[])
// {
// if (checkInput(argc, argv) < 0)
// return -1;
// Server server(std::atoi(argv[1]), argv[2]);
// server.startServer(atoi(argv[1]), std::string(argv[2]));
// return 0;
// }
#include "./includes/Server.hpp"
int main(int argc, char *argv[])
{
if (argc != 3) {
std::cerr << "Usage: ./ircserv [port] [PASS]" << std::endl;
return (1);
}
int port_num = std::atoi(argv[1]);
std::string port(argv[1]), password(argv[2]);
if (port.empty() || password.empty() || port_num > MAX_PORT \
|| port.length() > 5 || port.find_first_not_of("0123456789") != std::string::npos)
{
std::cerr << "Error: invalid arguments !" << std::endl;
return 1;
}
signal( SIGINT, Utils::signalHandler );
signal( SIGQUIT, Utils::signalHandler );
try
{
Server::_port = port_num;
Server::_password = password;
Server::openSocket();
Server::run();
} catch(const std::exception& e) {
std::cerr << RED << "Exception: " << e.what() << RESET << '\n';
}
return 0;
}