-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser_authentication.cpp
More file actions
72 lines (70 loc) · 2.26 KB
/
User_authentication.cpp
File metadata and controls
72 lines (70 loc) · 2.26 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
#include "Server.hpp"
#include "msg_parse.hpp"
void Server::user_authentication( msg_parse &command, User &user)
{
if (command.get_cmd() == "NICK")
{
if (command.get_cmd_params().size() > 0)
{
if (strlen(command.get_cmd_params().front()) <= 9 && check_for_bad_char(command.get_cmd_params().front()))
{
if (__list_nicks.insert(command.get_cmd_params().front()).second)
{
if (user.get_nickname().size())
{
std::string full_msg = ":" + this->__name + " " + user.get_nickname() + " " + command.get_cmd_params().front() + "\n";
for (std::vector<Channel* >::iterator it = user.get_channels().begin(); it != user.get_channels().end(); it++)
{
if (!(*it)->get_modes().get_q())
send_msg_to_channel_users(*(*it), full_msg);
}
__list_nicks.erase(user.get_nickname());
}
user.set_nickname(command.get_cmd_params().front());
}
else
write_reply(user, ERR_NICKNAMEINUSE, command);
}
else
write_reply(user, ERR_ERRONEUSNICKNAME, command);
}
else
write_reply(user, ERR_NONICKNAMEGIVEN, command);
}
else if (command.get_cmd() == "USER")
{
if (!user.get_username().size())
{
if (command.get_cmd_params().size() >= 3)
{
user.set_modes(command.get_cmd_params()[1][0]);
user.set_username(command.get_cmd_params().front());
if (command.get_cmd_params().size() == 4)
user.set_realname(command.get_cmd_params()[3]);
else
user.set_realname(command.get_additional_param());
}
else
write_reply(user, ERR_NEEDMOREPARAMS, command);
}
else
write_reply(user, ERR_ALREADYREGISTRED, command);
}
else if (command.get_cmd() == "PASS")
{
if (user.get_pass_check() && command.get_cmd_params().size())
write_reply(user, ERR_ALREADYREGISTRED, command);
else if (command.get_cmd_params().size() == 1 && __password == *command.get_cmd_params().begin())
user.set_pass_check(TRUE);
else if (command.get_cmd_params().size() == 0)
write_reply(user, ERR_NEEDMOREPARAMS, command);
}
if (!user.get_nickname().empty() && !user.get_username().empty() && user.get_pass_check() == 1)
{
user.set_is_real_user(TRUE);
write_reply(user, RPL_WELCOME, command);
write_reply(user, RPL_MYINFO, command);
user.set_pass_check(2);
this->dec_nbr_of_unknown_conns();
}
}