void Execute(IRCServer *server, User *u, const std::vector<std::string> ¶ms) { const std::string &target = params[0]; Channel *c = server->FindChannel(target); if (c == NULL) u->WriteNumeric(403, target + " :No such channel"); else if (params.size() == 1) { u->WriteNumeric(332, c->GetName() + " :" + c->GetTopic()); u->WriteNumeric(333, c->GetName() + " " + u->GetNick() + " " + Sinkhole::stringify(c->topic_time)); } else { user_status *status = c->FindUserStatus(u); if (c->HasMode(CMODE_PROTECTEDTOPIC) && (status == NULL || !status->HasMode(CMODE_OP))) u->WriteNumeric(482, c->GetName() + " :You're not a channel operator"); else { std::string topic = params[1]; if (topic.length() > IRCServer::topiclen) topic = topic.substr(0, IRCServer::topiclen); c->SetTopic(topic); c->Send(u->GetMask(), "TOPIC " + c->GetName() + " :" + topic); } } }
void Execute(IRCServer *server, User *u, const std::vector<std::string> ¶ms) { const std::string &channel = params[0]; const std::string &targnick = params[1]; std::string reason = params.size() > 2 ? params[2] : ""; Channel *c = server->FindChannel(channel); User *target = server->FindUser(targnick); if (c == NULL) u->WriteNumeric(403, channel + " :No such channel"); else if (target == NULL) u->WriteNumeric(401, targnick + " :No such nick/channel"); else if (!target->IsOnChannel(c)) u->WriteNumeric(441, target->GetNick() + " " + c->GetName() + " :They aren't on that channel"); else { user_status *status = c->FindUserStatus(u); if (status == NULL || !status->HasMode(CMODE_OP)) u->WriteNumeric(482, c->GetName() + " :You're not a channel operator"); else { if (reason.length() > IRCServer::kicklen) reason = reason.substr(0, IRCServer::kicklen); c->Send(u->GetMask(), "KICK " + c->GetName() + " " + target->GetNick() + " :" + reason); u->Part(c); c->Part(u); } } }