-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
73 lines (68 loc) · 2.69 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "Server.hpp"
#include "Client.hpp"
void welcome_message()
{
std::cout << R"(
╦╦═╗╔═╗ ╔═╗┌─┐┬─┐┬ ┬┌─┐┬─┐
║╠╦╝║ ╚═╗├┤ ├┬┘└┐┌┘├┤ ├┬┘
ooo╩╩╚═╚═╝ ╚═╝└─┘┴└─ └┘ └─┘┴└─ooo
oooooooooooooooooooooooooooooooooooooooooooooooooo
╔╦╗┬┌─┐┬ ┬┌─┐┬┬ ┬┌─┐ ╦╔═┌─┐┬─┐┌─┐┌┬┐┌─┐┬┌┬┐┬┌─┐
║║║││ ├─┤├─┤││ │└─┐ ╠╩╗├─┤├┬┘├─┤ │ ┌─┘│ │││└─┐
╩ ╩┴└─┘┴ ┴┴ ┴┴┴─┘┴└─┘ ╩ ╩┴ ┴┴└─┴ ┴ ┴ └─┘┴─┴┘┴└─┘
╔╦╗┌─┐┌─┐┌┬┐┬ ┬ ╔═╗┌─┐┌─┐┌─┐┌─┐
║ ├┤ ├┤ ││││ │ ╚═╗├─┘│ ││ │├┤
╩ └─┘└─┘┴ ┴└─┘ ╚═╝┴ └─┘└─┘└
╔╦╗┌─┐┌─┐┌┐┌ ╦═╗┬ ┬┬┌┐┌┌─┐
║║├┤ ├─┤│││ ╠╦╝│ │││││├─┤
═╩╝└─┘┴ ┴┘└┘ ╩╚═└─┘┴┘└┘┴ ┴
ooooooooooooooooooooooooooooooooooooooooooooooooo)"
<< std::endl;
}
int arg_check(const std::string &port, const std::string &pass)
{
if (pass.size() > 10)
{
std::cerr << RED << "Invalid password, password can't be longer than 10 characters" << WHITE << std::endl;
return (1);
}
try
{
int portnum = std::stoi(port);
if (portnum < 1024 || portnum > 65535)
{
std::cerr << RED << "invalid port - range (1024 - 65535)" << WHITE << std::endl;
return (1);
}
}
catch(std::exception &e)
{
std::cerr << RED << "invalid port" << WHITE << std::endl;
}
return (0);
}
int main(int argc, char **argv)
{
if (argc != 3)
{
std::cerr << "Wrong args - ./ircserv port password" << std::endl;
return (1);
}
welcome_message();
if (arg_check(argv[1], argv[2]))
return (1);
Server serv(std::stoi(argv[1]), argv[2]);
try
{
std::signal(SIGINT, Server::handle_signal);
std::signal(SIGQUIT, Server::handle_signal);
serv.server_init();
}
catch (std::exception &e)
{
serv.close_fds();
std::cerr << e.what() << std::endl;
}
std::cout << YELLOW << "Server Closed!" << WHITE << std::endl;
return (0);
}