Repository navigation
Expand file tree
/
Copy pathtopic.cpp
More file actions
47 lines (46 loc) · 1.58 KB
/
Copy pathtopic.cpp
File metadata and controls
47 lines (46 loc) · 1.58 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
#include "channel.hpp"
#include "user.hpp"
#include "replies.hpp"
#include "pendingClient.hpp"
#include "server.hpp"
void Server::topicCmd(std::vector<std::string> tokens, User* user){
std::string command = parsse(tokens[0]);
if (tokens.size() == 2 && tokens[1][0] == ':'){
sendReply(user->get_fd(), ERR_NEEDMOREPARAMS(command));
return ;
}
std::string channelname = parsse(tokens[1]);
Channel* channel = getChannelName(channelname);
if (!channel){
sendReply(user->get_fd(), ERR_NOSUCHCHANNEL(command));
return ;
}
if (!(channel->isUserInChannel(user->get_fd()))){
sendReply(user->get_fd(), ERR_NOTONCHANNEL(user->getNickname(), channel->getName()));
return ;
}
if (tokens.size() == 2){
if (channel->getTopic() == ""){
sendReply(user->get_fd(), RPL_NOTOPIC(user->getNickname(), channel->getName()));
return ;
}
for (std::vector<int>::const_iterator it = (channel->getUsers_fd()).begin(); it != (channel->getUsers_fd()).end(); ++it){
sendReply(*it, RPL_TOPIC(user->getNickname(), channel->getName(), channel->getTopic()));
}
return ;
}
std::string topic;
for (size_t i = 2; i < tokens.size(); ++i) {
topic += tokens[i];
if (i + 1 < tokens.size())
topic += " ";
}
if (!(channel->isOperator(user->get_fd())) && channel->getTopicRest()){
sendReply(user->get_fd(), ERR_CHANOPRIVSNEEDED(channel->getName()));
return ;
}
channel->setTopic(topic);
for (std::vector<int>::const_iterator it = (channel->getUsers_fd()).begin(); it != (channel->getUsers_fd()).end(); ++it){
sendReply(*it, RPL_TOPIC(user->getNickname(), channel->getName(), channel->getTopic()));
}
}