void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { const Anope::string &chan = params[0]; User *u = source.GetUser(); Channel *c = Channel::Find(chan); if (!c) { source.Reply(_("Channel \002{0}\002 doesn't exist."), chan); return; } ChanServ::Channel *ci = c->ci; if (!ci) { source.Reply(_("Channel \002{0}\002 isn't registered."), c->name); return; } if (!source.AccessFor(ci).HasPriv("INVITE") && !source.HasCommand("chanserv/invite")) { source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "INVITE", ci->GetName()); return; } User *u2; if (params.size() == 1) u2 = u; else u2 = User::Find(params[1], true); if (!u2) { source.Reply(_("\002{0}\002 isn't currently online."), params.size() > 1 ? params[1] : source.GetNick()); return; } if (c->FindUser(u2)) { if (u2 == u) source.Reply(_("You are already in \002{0}\002!"), c->name); else source.Reply(_("\002{0}\002 is already in \002{1}\002!"), u2->nick, c->name); return; } bool override = !source.AccessFor(ci).HasPriv("INVITE"); IRCD->SendInvite(ci->WhoSends(), c, u2); if (u2 != u) { source.Reply(_("\002{0}\002 has been invited to \002{1}\002."), u2->nick, c->name); u2->SendMessage(ci->WhoSends(), _("You have been invited to \002{0}\002 by \002{1}\002."), c->name, source.GetNick()); Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "for " << u2->nick; }
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 Invite::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { User *targ = User::Find(params[0]); Channel *c = Channel::Find(params[1]); if (!targ || targ->server != Me || !c || c->FindUser(targ)) return; EventManager::Get()->Dispatch(&Event::Invite::OnInvite, source.GetUser(), c, targ); }
void Join::SJoin(MessageSource &source, const Anope::string &chan, time_t ts, const Anope::string &modes, const std::list<SJoinUser> &users) { bool created; Channel *c = Channel::FindOrCreate(chan, created, ts ? ts : Anope::CurTime); bool keep_their_modes = true; if (created) c->syncing = true; /* Some IRCds do not include a TS */ else if (!ts) ; /* Our creation time is newer than what the server gave us, so reset the channel to the older time */ else if (c->creation_time > ts) { c->creation_time = ts; c->Reset(); } /* Their TS is newer, don't accept any modes from them */ else if (ts > c->creation_time) keep_their_modes = false; /* Update the modes for the channel */ if (keep_their_modes && !modes.empty()) /* If we are syncing, mlock is checked later in Channel::Sync. It is important to not check it here * so that Channel::SetCorrectModes can correctly detect the presence of channel mode +r. */ c->SetModesInternal(source, modes, ts, !c->syncing); for (std::list<SJoinUser>::const_iterator it = users.begin(), it_end = users.end(); it != it_end; ++it) { const ChannelStatus &status = it->first; User *u = it->second; keep_their_modes = ts <= c->creation_time; // OnJoinChannel can call modules which can modify this channel's ts if (c->FindUser(u)) continue; /* Add the user to the channel */ c->JoinUser(u, keep_their_modes ? &status : NULL); /* Check if the user is allowed to join */ if (c->CheckKick(u)) continue; /* Set whatever modes the user should have, and remove any that * they aren't allowed to have (secureops etc). */ c->SetCorrectModes(u, true); EventManager::Get()->Dispatch(&Event::JoinChannel::OnJoinChannel, u, c); } /* Channel is done syncing */ if (c->syncing) { /* Sync the channel (mode lock, topic, etc) */ /* the channel is synced when the netmerge is complete */ Server *src = source.GetServer() ? source.GetServer() : Me; if (src && src->IsSynced()) { c->Sync(); if (c->CheckDelete()) delete c; } } }
void OnUserLogin(User *u) override { ServiceBot *NickServ = Config->GetClient("NickServ"); if (!NickServ) return; std::vector<AutoJoin *> channels = u->Account()->GetRefs<AutoJoin *>(); if (channels.empty()) return; /* Set +r now, so we can ajoin users into +R channels */ ModeManager::ProcessModes(); for (AutoJoin *entry : channels) { Channel *c = Channel::Find(entry->GetChannel()); ChanServ::Channel *ci; if (c) ci = c->ci; else ci = ChanServ::Find(entry->GetChannel()); bool need_invite = false; Anope::string key = entry->GetKey(); ChanServ::AccessGroup u_access; if (ci != NULL) { if (ci->HasFieldS("CS_SUSPENDED")) continue; u_access = ci->AccessFor(u); } if (c != NULL) { if (c->FindUser(u) != NULL) continue; else if (c->HasMode("OPERONLY") && !u->HasMode("OPER")) continue; else if (c->HasMode("ADMINONLY") && !u->HasMode("ADMIN")) continue; else if (c->HasMode("SSL") && !(u->HasMode("SSL") || u->HasExtOK("ssl"))) continue; else if (c->MatchesList(u, "BAN") == true && c->MatchesList(u, "EXCEPT") == false) need_invite = true; else if (c->HasMode("INVITE") && c->MatchesList(u, "INVITEOVERRIDE") == false) need_invite = true; if (c->HasMode("KEY")) { Anope::string k; if (c->GetParam("KEY", k)) { if (u_access.HasPriv("GETKEY")) key = k; else if (key != k) need_invite = true; } } if (c->HasMode("LIMIT")) { Anope::string l; if (c->GetParam("LIMIT", l)) { try { unsigned limit = convertTo<unsigned>(l); if (c->users.size() >= limit) need_invite = true; } catch (const ConvertException &) { } } } } if (need_invite && c != NULL) { if (!u_access.HasPriv("INVITE")) continue; IRCD->SendInvite(NickServ, c, u); } IRCD->SendSVSJoin(NickServ, u, entry->GetChannel(), key); } }
void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { const Anope::string &chan = params[0]; User *u = source.GetUser(); Channel *c = Channel::Find(chan); if (!c) { source.Reply(_("Channel \002{0}\002 doesn't exist."), chan); return; } ChanServ::Channel *ci = c->GetChannel(); if (!ci) { source.Reply(_("Channel \002{0}\002 isn't registered."), c->name); return; } if (!source.AccessFor(ci).HasPriv("INVITE") && !source.HasOverrideCommand("chanserv/invite")) { source.Reply(_("Access denied. You do not have privilege \002{0}\002 on \002{1}\002."), "INVITE", ci->GetName()); return; } User *u2; if (params.size() == 1) u2 = u; else u2 = User::Find(params[1], true); if (!u2) { source.Reply(_("\002{0}\002 isn't currently online."), params.size() > 1 ? params[1] : source.GetNick()); return; } if (c->FindUser(u2)) { if (u2 == u) source.Reply(_("You are already in \002{0}\002!"), c->name); else source.Reply(_("\002{0}\002 is already in \002{1}\002!"), u2->nick, c->name); return; } IRCD->Send<messages::Invite>(ci->WhoSends(), c, u2); if (u2 != u) { source.Reply(_("\002{0}\002 has been invited to \002{1}\002."), u2->nick, c->name); u2->SendMessage(ci->WhoSends(), _("You have been invited to \002{0}\002 by \002{1}\002."), c->name, source.GetNick()); logger.Command(source, ci, _("{source} used {command} on {channel} to invite {0}"), u2->nick); } else { u2->SendMessage(ci->WhoSends(), _("You have been invited to \002{0}\002."), c->name); logger.Command(source, ci, _("{source} used {command} on {channel}")); } }
Server::Server(Server *up, const Anope::string &sname, unsigned shops, const Anope::string &desc, const Anope::string &ssid, bool jupe) : name(sname), hops(shops), description(desc), sid(ssid), uplink(up), users(0) { syncing = true; juped = jupe; quitting = false; Servers::ByName[sname] = this; if (!ssid.empty()) Servers::ByID[ssid] = this; Log(this, "connect") << "has connected to the network (uplinked to " << (this->uplink ? this->uplink->GetName() : "no uplink") << ")"; /* Add this server to our uplinks leaf list */ if (this->uplink) { this->uplink->AddLink(this); /* Check to be sure this isn't a juped server */ if (Me == this->uplink && !juped) { /* Now do mode related stuff as we know what modes exist .. */ for (botinfo_map::iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) { BotInfo *bi = it->second; Anope::string modes = !bi->botmodes.empty() ? ("+" + bi->botmodes) : IRCD->DefaultPseudoclientModes; bi->SetModesInternal(bi, modes.c_str()); for (unsigned i = 0; i < bi->botchannels.size(); ++i) { size_t h = bi->botchannels[i].find('#'); if (h == Anope::string::npos) continue; Anope::string chname = bi->botchannels[i].substr(h); Channel *c = Channel::Find(chname); if (c && c->FindUser(bi)) { Anope::string want_modes = bi->botchannels[i].substr(0, h); for (unsigned j = 0; j < want_modes.length(); ++j) { ChannelMode *cm = ModeManager::FindChannelModeByChar(want_modes[j]); if (cm == NULL) cm = ModeManager::FindChannelModeByChar(ModeManager::GetStatusChar(want_modes[j])); if (cm && cm->type == MODE_STATUS) { MessageSource ms = bi; c->SetModeInternal(ms, cm, bi->nick); } } } } } IRCD->SendBOB(); for (unsigned i = 0; i < Me->GetLinks().size(); ++i) { Server *s = Me->GetLinks()[i]; if (s->juped) IRCD->SendServer(s); } /* We make the bots go online */ for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) { User *u = it->second; BotInfo *bi = BotInfo::Find(u->GetUID()); if (bi) { XLine x(bi->nick, "Reserved for services"); IRCD->SendSQLine(NULL, &x); } IRCD->SendClientIntroduction(u); if (bi) bi->introduced = true; } for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it) { Channel *c = it->second; if (c->users.empty()) IRCD->SendChannel(c); else for (Channel::ChanUserList::const_iterator cit = c->users.begin(), cit_end = c->users.end(); cit != cit_end; ++cit) IRCD->SendJoin(cit->second->user, c, &cit->second->status); for (Channel::ModeList::const_iterator it2 = c->GetModes().begin(); it2 != c->GetModes().end(); ++it2) { ChannelMode *cm = ModeManager::FindChannelModeByName(it2->first); if (!cm || cm->type != MODE_LIST) continue; ModeManager::StackerAdd(c->ci->WhoSends(), c, cm, true, it2->second); } if (!c->topic.empty() && !c->topic_setter.empty()) IRCD->SendTopic(c->ci->WhoSends(), c); c->syncing = true; } } } FOREACH_MOD(OnNewServer, (this)); }