-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
78 lines (60 loc) · 1.77 KB
/
main.cpp
File metadata and controls
78 lines (60 loc) · 1.77 KB
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
#include "Irc.hpp"
MESSAGE convert_to_protocol_message(Message msg)
{
MESSAGE message;
message.message = msg.message;
message.id = msg.client_socket;
message.status = msg.status_out;
return (message);
}
Message convert_to_server_message(MESSAGE msg)
{
Message message;
message.message = msg.message;
message.client_socket = msg.id;
message.status_out = msg.status;
return (message);
}
std::list<MESSAGE> convert_to_protocol_meesage_list(std::list<Message> messages)
{
std::list<MESSAGE> new_messages;
std::list<Message>::iterator it;
for (it = messages.begin(); it != messages.end(); it++)
{
new_messages.push_back(convert_to_protocol_message(*it));
}
return (new_messages);
}
std::list<Message> convert_to_server_message_list(std::list<MESSAGE> messages)
{
std::list<Message> new_messages;
std::list<MESSAGE>::iterator it;
for (it = messages.begin(); it != messages.end(); it++)
{
new_messages.push_back(convert_to_server_message(*it));
}
return (new_messages);
}
int main(int argc, char **argv)
{
Protocol protocol;
protocol.set_hostname("localhost");
int port = 6667;
if (argc > 1)
port = atoi(argv[1]);
if (argc > 2)
protocol.set_password(argv[2]);
Server server(port, 5);
while (1)
{
if (!server.update())
continue;
if (server.check_read(server.get_socket()))
server.accept_connection();
server.update_messages();
std::list<Message> messages = server.get_messages();
std::list<MESSAGE> to_be_msg = protocol.update(convert_to_protocol_meesage_list(messages));
server.send_messages(convert_to_server_message_list(to_be_msg));
}
return 0;
}