-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMode_command.cpp
More file actions
76 lines (72 loc) · 2.51 KB
/
Mode_command.cpp
File metadata and controls
76 lines (72 loc) · 2.51 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
#include "msg_parse.hpp"
#include "Server.hpp"
int Server::user_mode_setter(msg_parse &command, User &user)
{
if (command.get_cmd_params().size() >= 2)
{
if (command.get_cmd_params()[0] == user.get_nickname())
{
if (command.get_cmd_params()[1][0] == '+')
{
for (size_t i = 1; i < strlen(command.get_cmd_params()[1]); i++)
{
if (command.get_cmd_params()[1][i] == 'i' || command.get_cmd_params()[1][i] == 'w' || command.get_cmd_params()[1][i] == 'r' || command.get_cmd_params()[1][i] == 's')
user.set_modes(command.get_cmd_params()[1][i]);
else if (command.get_cmd_params()[1][i] != 'a' && command.get_cmd_params()[1][i] != 'o' && command.get_cmd_params()[1][i] != 'O')
{
write_reply(user, ERR_UMODEUNKNOWNFLAG, command);
return (0);
}
}
}
else if (command.get_cmd_params()[1][0] == '-')
{
for (size_t i = 1; i < strlen(command.get_cmd_params()[1]); i++)
{
if (command.get_cmd_params()[1][i] == 'i' || command.get_cmd_params()[1][i] == 'w' || command.get_cmd_params()[1][i] == 'o' || command.get_cmd_params()[1][i] == 'O' || command.get_cmd_params()[1][i] == 's')
user.unset_modes(command.get_cmd_params()[1][i]);
else if (command.get_cmd_params()[1][i] != 'a' && command.get_cmd_params()[1][i] != 'r')
{
write_reply(user, ERR_UMODEUNKNOWNFLAG, command);
return (0);
}
}
}
else
write_reply(user, ERR_UMODEUNKNOWNFLAG, command);
}
else
write_reply(user, ERR_USERSDONTMATCH, command);
}
else if (command.get_cmd_params().size() == 1)
write_socket(user.get_fd(), "The available modes are as follows:\na - user is flagged as away;\ni - marks a users as invisible;\nw - user receives wallops;\nr - restricted user connection;\no - operator flag;\nO - local operator flag;\ns - marks a user for receipt of server notices.\n");
else
write_reply(user, ERR_NEEDMOREPARAMS, command);
return (1);
}
int Server::MODE_handler(msg_parse &command, User &user)
{
std::string ch_name;
if (command.get_cmd_params().size())
{
ch_name = command.get_cmd_params().front();
if (__list_nicks.find(ch_name) != __list_nicks.end())
{
user_mode_setter(command, user);
}
else if (ch_name[0] == '!' || ch_name[0] == '#' || ch_name[0] == '&' || ch_name[0] == '+')
{
if (ch_name[0] == '+')
write_reply(user, ERR_NOCHANMODES, command);
else
CHANNEL_MODE_handler(command, user);
}
else
{
write_reply(user, ERR_USERSDONTMATCH, command);
}
}
else
write_reply(user, ERR_NEEDMOREPARAMS, command);
return (1);
}