void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { const Anope::string &chan = params[0]; User *u = source.u; Channel *c = findchan(chan); if (!c) { source.Reply(CHAN_X_NOT_IN_USE, chan.c_str()); return; } ChannelInfo *ci = c->ci; if (!ci) { source.Reply(CHAN_X_NOT_REGISTERED, chan.c_str()); return; } if (!ci->AccessFor(u).HasPriv("INVITE") && !u->HasCommand("chanserv/invite")) { source.Reply(ACCESS_DENIED); return; } User *u2; if (params.size() == 1) u2 = u; else { if (!(u2 = finduser(params[1]))) { source.Reply(NICK_X_NOT_IN_USE, params[1].c_str()); return; } } if (c->FindUser(u2)) { if (u2 == u) source.Reply(_("You are already in \002%s\002!"), c->name.c_str()); else source.Reply(_("\002%s\002 is already in \002%s\002!"), u2->nick.c_str(), c->name.c_str()); } else { bool override = !ci->AccessFor(u).HasPriv("INVITE"); ircdproto->SendInvite(ci->WhoSends(), chan, u2->nick); if (u2 != u) { source.Reply(_("\002%s\002 has been invited to \002%s\002."), u2->nick.c_str(), c->name.c_str()); Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "for " << u2->nick; } else {
void BuildChanList(NickAlias *na, TemplateFileServer::Replacements &replacements) { std::deque<ChannelInfo *> queue; na->nc->GetChannelReferences(queue); std::sort(queue.begin(), queue.end(), ChannelSort); for (unsigned i = 0; i < queue.size(); ++i) { ChannelInfo *ci = queue[i]; if (na->nc != ci->GetFounder() && ci->AccessFor(na->nc).empty()) continue; replacements["CHANNEL_NAMES"] = ci->name; replacements["ESCAPED_CHANNEL_NAMES"] = HTTPUtils::URLEncode(ci->name); } }
bool WebCPanel::NickServ::Alist::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements) { std::deque<ChannelInfo *> queue; na->nc->GetChannelReferences(queue); std::sort(queue.begin(), queue.end(), ChannelSort); int chan_count = 0; for (unsigned q = 0; q < queue.size(); ++q) { ChannelInfo *ci = queue[q]; if (ci->GetFounder() == na->nc) { ++chan_count; replacements["NUMBERS"] = stringify(chan_count); replacements["CHANNELS"] = (ci->HasExt("CS_NO_EXPIRE") ? "!" : "") + ci->name; replacements["ACCESSES"] = "Founder"; continue; } AccessGroup access = ci->AccessFor(na->nc); if (access.empty()) continue; ++chan_count; replacements["NUMBERS"] = stringify(chan_count); replacements["CHANNELS"] = (ci->HasExt("CS_NO_EXPIRE") ? "!" : "") + ci->name; Anope::string access_str; for (unsigned i = 0; i < access.size(); ++i) access_str += ", " + access[i]->AccessSerialize(); replacements["ACCESSES"] = access_str.substr(2); } TemplateFileServer page("nickserv/alist.html"); page.Serve(server, page_name, client, message, reply, replacements); return true; }
MemoResult Send(const Anope::string &source, const Anope::string &target, const Anope::string &message, bool force) { bool ischan; MemoInfo *mi = this->GetMemoInfo(target, ischan); if (mi == NULL) return MEMO_INVALID_TARGET; User *sender = finduser(source); if (sender != NULL && !sender->HasPriv("memoserv/no-limit") && !force) { if (Config->MSSendDelay > 0 && sender->lastmemosend + Config->MSSendDelay > Anope::CurTime) return MEMO_TOO_FAST; else if (!mi->memomax) return MEMO_TARGET_FULL; else if (mi->memomax > 0 && mi->memos.size() >= mi->memomax) return MEMO_TARGET_FULL; else if (mi->HasIgnore(sender)) return MEMO_SUCCESS; } if (sender != NULL) sender->lastmemosend = Anope::CurTime; Memo *m = new Memo(); mi->memos.push_back(m); m->owner = target; m->sender = source; m->time = Anope::CurTime; m->text = message; m->SetFlag(MF_UNREAD); FOREACH_MOD(I_OnMemoSend, OnMemoSend(source, target, mi, m)); if (ischan) { ChannelInfo *ci = cs_findchan(target); if (ci->c) { for (CUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) { UserContainer *cu = *it; if (ci->AccessFor(cu->user).HasPriv("MEMO")) { if (cu->user->Account() && cu->user->Account()->HasFlag(NI_MEMO_RECEIVE)) cu->user->SendMessage(MemoServ, MEMO_NEW_X_MEMO_ARRIVED, ci->name.c_str(), Config->UseStrictPrivMsgString.c_str(), Config->MemoServ.c_str(), ci->name.c_str(), mi->memos.size()); } } } } else { NickCore *nc = findnick(target)->nc; if (nc->HasFlag(NI_MEMO_RECEIVE)) { for (std::list<NickAlias *>::iterator it = nc->aliases.begin(), it_end = nc->aliases.end(); it != it_end; ++it) { NickAlias *na = *it; User *user = finduser(na->nick); if (user && user->IsIdentified()) user->SendMessage(MemoServ, MEMO_NEW_MEMO_ARRIVED, source.c_str(), Config->UseStrictPrivMsgString.c_str(), Config->MemoServ.c_str(), mi->memos.size()); } } /* let's get out the mail if set in the nickcore - certus */ if (nc->HasFlag(NI_MEMO_MAIL)) SendMemoMail(nc, mi, m); } return MEMO_SUCCESS; }
void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) { const Anope::string &channel = params[0]; const Anope::string &target = params[1]; Anope::string what = params.size() > 2 ? params[2] : ""; User *u = source.u; ChannelInfo *ci = cs_findchan(params[0]); if (ci == NULL) { source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); return; } if (!ci->AccessFor(u).HasPriv("SET")) { source.Reply(ACCESS_DENIED); return; } ChannelInfo *target_ci = cs_findchan(target); if (!target_ci) { source.Reply(CHAN_X_NOT_REGISTERED, target.c_str()); return; } if (!IsFounder(u, ci) || !IsFounder(u, target_ci)) { source.Reply(ACCESS_DENIED); return; } if (what.equals_ci("ALL")) what.clear(); if (what.empty()) { delete target_ci; target_ci = new ChannelInfo(*ci); target_ci->name = target; RegisteredChannelList[target_ci->name] = target_ci; target_ci->c = findchan(target_ci->name); if (target_ci->c) { target_ci->c->ci = target_ci; check_modes(target_ci->c); ChannelMode *cm; if (u->FindChannel(target_ci->c) != NULL) { /* On most ircds you do not receive the admin/owner mode till its registered */ if ((cm = ModeManager::FindChannelModeByName(CMODE_OWNER))) target_ci->c->SetMode(NULL, cm, u->nick); else if ((cm = ModeManager::FindChannelModeByName(CMODE_PROTECT))) target_ci->c->RemoveMode(NULL, cm, u->nick); } /* Mark the channel as persistent */ if (target_ci->c->HasMode(CMODE_PERM)) target_ci->SetFlag(CI_PERSIST); /* Persist may be in def cflags, set it here */ else if (target_ci->HasFlag(CI_PERSIST) && (cm = ModeManager::FindChannelModeByName(CMODE_PERM))) target_ci->c->SetMode(NULL, CMODE_PERM); if (target_ci->bi && target_ci->c->FindUser(target_ci->bi) == NULL) target_ci->bi->Join(target_ci->c, &Config->BotModeList); } if (target_ci->c && !target_ci->c->topic.empty()) { target_ci->last_topic = target_ci->c->topic; target_ci->last_topic_setter = target_ci->c->topic_setter; target_ci->last_topic_time = target_ci->c->topic_time; } else target_ci->last_topic_setter = source.owner->nick; FOREACH_MOD(I_OnChanRegistered, OnChanRegistered(target_ci)); source.Reply(_("All settings from \002%s\002 have been cloned to \002%s\002"), channel.c_str(), target.c_str()); } else if (what.equals_ci("ACCESS")) { for (unsigned i = 0; i < ci->GetAccessCount(); ++i) { ChanAccess *taccess = ci->GetAccess(i); AccessProvider *provider = taccess->provider; ChanAccess *newaccess = provider->Create(); newaccess->ci = target_ci; newaccess->mask = taccess->mask; newaccess->creator = taccess->creator; newaccess->last_seen = taccess->last_seen; newaccess->created = taccess->created; newaccess->Unserialize(taccess->Serialize()); target_ci->AddAccess(newaccess); } source.Reply(_("All access entries from \002%s\002 have been cloned to \002%s\002"), channel.c_str(), target.c_str()); } else if (what.equals_ci("AKICK")) { target_ci->ClearAkick(); for (unsigned i = 0; i < ci->GetAkickCount(); ++i) { AutoKick *akick = ci->GetAkick(i); if (akick->HasFlag(AK_ISNICK)) target_ci->AddAkick(akick->creator, akick->nc, akick->reason, akick->addtime, akick->last_used); else target_ci->AddAkick(akick->creator, akick->mask, akick->reason, akick->addtime, akick->last_used); } source.Reply(_("All akick entries from \002%s\002 have been cloned to \002%s\002"), channel.c_str(), target.c_str()); } else if (what.equals_ci("BADWORDS")) { target_ci->ClearBadWords(); for (unsigned i = 0; i < ci->GetBadWordCount(); ++i) { BadWord *bw = ci->GetBadWord(i); target_ci->AddBadWord(bw->word, bw->type); } source.Reply(_("All badword entries from \002%s\002 have been cloned to \002%s\002"), channel.c_str(), target.c_str()); } else { this->OnSyntaxError(source, ""); return; } Log(LOG_COMMAND, u, this, ci) << "to clone " << (what.empty() ? "everything from it" : what) << " to " << target_ci->name; return; }
bool WebCPanel::MemoServ::Memos::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply, NickAlias *na, TemplateFileServer::Replacements &replacements) { const Anope::string &chname = message.get_data["channel"]; ChannelInfo *ci; const MemoInfo *mi; Memo *m; for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it) { ci = it->second; if (ci->AccessFor(na->nc).HasPriv("MEMO")) { replacements["CHANNEL_NAMES"] = ci->name; replacements["ESCAPED_CHANNEL_NAMES"] = HTTPUtils::URLEncode(ci->name); } } if (chname.empty()) { replacements["MESSAGES"] = "No Channel specified, displaying the memos for your Nick"; mi = &na->nc->memos; } else { ci = ChannelInfo::Find(chname); if (ci) { replacements["MESSAGES"] = "Displaying the memos for " + chname + "."; mi = &ci->memos; } else { replacements["MESSAGES"] = "Channel " + chname + " not found, displaying the memos for your nick"; mi = &na->nc->memos; } replacements["CHANNEL_NAME"] = ci->name; replacements["ESCAPED_CHANNEL_NAME"] = HTTPUtils::URLEncode(ci->name); } if (message.post_data.count("receiver") > 0 && message.post_data.count("message") > 0) { std::vector<Anope::string> params; params.push_back(HTTPUtils::URLDecode(message.post_data["receiver"])); params.push_back(HTTPUtils::URLDecode(message.post_data["message"])); WebPanel::RunCommand(na->nc->display, na->nc, "MemoServ", "memoserv/send", params, replacements, "CMDR"); } if (message.get_data.count("del") > 0 && message.get_data.count("number") > 0) { std::vector<Anope::string> params; if (!chname.empty()) params.push_back(chname); params.push_back(message.get_data["number"]); WebPanel::RunCommand(na->nc->display, na->nc, "MemoServ", "memoserv/del", params, replacements, "CMDR"); } if (message.get_data.count("read") > 0 && message.get_data.count("number") > 0) { std::vector<Anope::string> params; int number = -1; try { number = convertTo<int>(message.get_data["number"]); } catch (const ConvertException &ex) { replacements["MESSAGES"] = "ERROR - invalid parameter for NUMBER"; } if (number > 0) { m = mi->GetMemo(number-1); if (!m) replacements["MESSAGES"] = "ERROR - invalid memo number."; else if (message.get_data["read"] == "1") m->unread = false; else if (message.get_data["read"] == "2") m->unread = true; } } for (unsigned i = 0; i < mi->memos->size(); ++i) { m = mi->GetMemo(i); replacements["NUMBER"] = stringify(i+1); replacements["SENDER"] = m->sender; replacements["TIME"] = Anope::strftime(m->time); replacements["TEXT"] = HTTPUtils::Escape(m->text); if (m->unread) replacements["UNREAD"] = "YES"; else replacements["UNREAD"] = "NO"; } TemplateFileServer page("memoserv/memos.html"); page.Serve(server, page_name, client, message, reply, replacements); return true; }