-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTOPIC_command.cpp
More file actions
62 lines (59 loc) · 2.24 KB
/
TOPIC_command.cpp
File metadata and controls
62 lines (59 loc) · 2.24 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
#include "msg_parse.hpp"
#include "Server.hpp"
void Server::TOPIC_handler(User &user, msg_parse &command)
{
if (command.get_cmd_params().size() >= 1)
{
std::list<Channel>::iterator chan;
std::string chan_name = command.get_cmd_params().front();
int unset = 0;
if (chan_name[chan_name.length() - 1] == '.')
{
unset = 1;
chan_name = chan_name.substr(0, chan_name.length() - 1);
}
if ((chan = find_channel(command.get_cmd_params()[0][0], chan_name.substr(1, chan_name.length() - 1))) != __channels.end())
{
if (find_user_in_channel(user, *chan) == *(*chan).get_users().end() && !user.get_modes().get_o())
{
write_reply(user, ERR_NOTONCHANNEL, command);
return ;
}
if (command.get_cmd_params().size() == 1 && !command.get_additional_param().size())
{
if (unset || command.get_has_additional_param())
(*chan).set_topic("");
else if ((*chan).get_topic().empty())
{
std::string full_msg = ":" + this->__name + " 331 " + command.get_cmd() + " " + command.get_cmd_params().front() + " :No topic is set\n";
send(user.get_fd(), full_msg.c_str(), full_msg.size(), 0);
return ;
}
else
{
std::string full_msg = ":" + this->__name + " 332 " + command.get_cmd() + " " + command.get_cmd_params().front() + " :" + (*chan).get_topic() +"\n" ;
send(user.get_fd(), full_msg.c_str(), full_msg.size(), 0);
return ;
}
}
if (!((*chan).get_modes().get_t() && !is_operator_on_channel(user, *chan)) || user.get_modes().get_o())
{
if (command.get_cmd_params().size() == 2)
(*chan).set_topic(command.get_cmd_params()[1]);
else if (!command.get_additional_param().empty())
(*chan).set_topic(command.get_additional_param());
std::string full_msg = ":" + this->__name + " 332 " + command.get_cmd() + " " + command.get_cmd_params().front() + " :" + (*chan).get_topic() +"\n";
send(user.get_fd(), full_msg.c_str(), full_msg.size(), 0);
}
else
{
std::string full_msg = ":" + this->__name + " 482 " + command.get_cmd_params().front() + " :You're not channel operator\n";
send(user.get_fd(), full_msg.c_str(), full_msg.size(), 0);
}
}
else
write_reply(user, ERR_NOSUCHCHANNEL, command);
}
else
write_reply(user, ERR_NEEDMOREPARAMS, command);
}