-
Notifications
You must be signed in to change notification settings - Fork 1
/
entry.cpp
70 lines (62 loc) · 2.08 KB
/
entry.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* entry.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sfournie <sfournie@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/02 11:52:15 by sfournie #+# #+# */
/* Updated: 2022/08/24 16:46:09 by sfournie ### ########.fr */
/* */
/* ************************************************************************** */
#include "Server.hpp"
#include "typedef.hpp"
#include <string>
#include <unistd.h>
#include "../includes/color.hpp"
using std::cout;
using std::cerr;
using std::endl;
using std::string;
using irc::t_pollfd;
using irc::Server;
bool is_number(const std::string& s)
{
std::string::const_iterator it = s.begin();
while (it != s.end() && std::isdigit(*it))
++it;
return !s.empty() && it == s.end();
}
int main( int argc, char** argv )
{
int port;
if (argc != 3)
{
cerr << RED << "\v [Error: Usage:] " << RESET << "./ircserv <port> <pass>" << endl << "Valid port range: [6665-6669]\v" << endl;
return FAIL;
}
try
{
if (is_number(string(argv[1])) == false)
{
cerr << "[Error: port:] not a number\v" << endl;
return FAIL;
}
port = std::stoi(string(argv[1]));
if (port < 6665 || port > 6669)
{
cerr << "[Error: port:] Valid port range: [6665-6669]\v" << endl;
return FAIL;
}
Server& server = Server::get_server(static_cast<u_int>(std::stoi(string(argv[1]))), argv[2]);
server.set_signal_ctrl_c();
// check if server did get created
server.run_server();
}
catch (std::exception& e)
{
cerr << "Error running the server: " << e.what() << endl;
return FAIL;
}
return SUCCESS;
}