forked from nyj001012/ft_irc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
80 lines (75 loc) · 2.34 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
74
75
76
77
78
79
80
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yena <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/30 20:39:21 by yena #+# #+# */
/* Updated: 2023/11/25 21:52:38 by yena ### ########.fr */
/* */
/* ************************************************************************** */
#include "task/Task.hpp"
#include "channel/Channel.hpp"
#include "data/ChannelData.hpp"
#include "include/utils.hpp"
#include "data/UserData.hpp"
#include "include/debug.hpp"
#include "debug/Reflector.hpp"
#include "server/Server.hpp"
#include "user/User.hpp"
#include "handler/RequestHandler.hpp"
#include <cstdlib>
#include <cstring>
#include <exception>
#include <iterator>
#include <iostream>
#include <sstream>
using std::cout;
using std::vector;
using std::string;
void add_user(const string& nick, const string& password, const string& ip_addr, RequestHandler& handler);
int main(int argc, char* argv[])
{
RequestHandler handler;
Reflector::shared().add(UserData::get_storage());
Reflector::shared().add(ChannelData::get_storage());
char* port;
Server server;
if (argc == 3 || (argc == 2 && !std::strcmp(argv[1], "DEBUG")))
{
port = argv[1];
if (!std::strcmp(argv[1], "DEBUG"))
{
std::strcpy(port, getPortInDebugMode().c_str());
server.setIsDebug(true);
Reflector::shared().set_debug(true);
}
else {
server.setIsDebug(false);
Reflector::shared().set_debug(false);
}
if (!isValidPort(port))
{
printError("Error: Invalid port number: " + static_cast<std::string>(port));
return 1;
}
server.initializeServer(port);
while (true)
{
try
{
server.runServer();
}
catch (std::exception& e)
{
printError(e.what());
}
}
}
else
{
printError("Invalid arguments: Usage: ./ircserv <port> <password>");
return 1;
}
}