diff options
author | Peter Powell <petpow@saberuk.com> | 2019-03-30 13:12:05 +0000 |
---|---|---|
committer | P. Powell <petpow@saberuk.com> | 2019-09-23 13:23:02 +0100 |
commit | 67bd3e44c015b041a9a0ebbc2deb8369d72d9919 (patch) | |
tree | 22d63f0a892faeff18c847a43787c928265115c3 | |
parent | 264981fb1bb68a70039febc0ef77ef8a576e92bb (diff) |
Remove the dependency on the inspircd12 module.
-rw-r--r-- | modules/protocol/inspircd3.cpp | 908 |
1 files changed, 820 insertions, 88 deletions
diff --git a/modules/protocol/inspircd3.cpp b/modules/protocol/inspircd3.cpp index 927f7d2e0..c49ed806f 100644 --- a/modules/protocol/inspircd3.cpp +++ b/modules/protocol/inspircd3.cpp @@ -11,13 +11,50 @@ #include "module.h" #include "modules/cs_mode.h" +#include "modules/sasl.h" -static unsigned int spanningtree_proto_ver = 0; +struct SASLUser +{ + Anope::string uid; + Anope::string acc; + time_t created; +}; -static ServiceReference<IRCDProto> insp12("IRCDProto", "inspircd12"); +static std::list<SASLUser> saslusers; + +static Anope::string rsquit_server, rsquit_id; + +static unsigned int spanningtree_proto_ver = 0; class InspIRCd3Proto : public IRCDProto { + private: + void SendChgIdentInternal(const Anope::string &nick, const Anope::string &vIdent) + { + if (!Servers::Capab.count("CHGIDENT")) + Log() << "CHGIDENT not loaded!"; + else + UplinkSocket::Message(Me) << "CHGIDENT " << nick << " " << vIdent; + } + + void SendChgHostInternal(const Anope::string &nick, const Anope::string &vhost) + { + if (!Servers::Capab.count("CHGHOST")) + Log() << "CHGHOST not loaded!"; + else + UplinkSocket::Message(Me) << "CHGHOST " << nick << " " << vhost; + } + + void SendAddLine(const Anope::string &xtype, const Anope::string &mask, time_t duration, const Anope::string &addedby, const Anope::string &reason) + { + UplinkSocket::Message(Me) << "ADDLINE " << xtype << " " << mask << " " << addedby << " " << Anope::CurTime << " " << duration << " :" << reason; + } + + void SendDelLine(const Anope::string &xtype, const Anope::string &mask) + { + UplinkSocket::Message(Me) << "DELLINE " << xtype << " " << mask; + } + public: InspIRCd3Proto(Module *creator) : IRCDProto(creator, "InspIRCd 3") { @@ -39,7 +76,7 @@ class InspIRCd3Proto : public IRCDProto UplinkSocket::Message() << "CAPAB START 1202"; UplinkSocket::Message() << "CAPAB CAPABILITIES :PROTOCOL=1202 CASEMAPPING=" << Config->GetBlock("options")->Get<const Anope::string>("casemap", "ascii"); UplinkSocket::Message() << "CAPAB END"; - insp12->SendConnect(); + SendServer(Me); } void SendSASLMechanisms(std::vector<Anope::string> &mechanisms) anope_override @@ -51,39 +88,379 @@ class InspIRCd3Proto : public IRCDProto UplinkSocket::Message(Me) << "METADATA * saslmechlist :" << (mechanisms.empty() ? "" : mechlist.substr(1)); } - void SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf) anope_override { insp12->SendSVSKillInternal(source, user, buf); } - void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override { insp12->SendGlobalNotice(bi, dest, msg); } - void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override { insp12->SendGlobalPrivmsg(bi, dest, msg); } - void SendAkillDel(const XLine *x) anope_override { insp12->SendAkillDel(x); } - void SendTopic(const MessageSource &whosets, Channel *c) anope_override { insp12->SendTopic(whosets, c); }; - void SendVhostDel(User *u) anope_override { insp12->SendVhostDel(u); } - void SendAkill(User *u, XLine *x) anope_override { insp12->SendAkill(u, x); } - void SendNumericInternal(int numeric, const Anope::string &dest, const Anope::string &buf) anope_override { insp12->SendNumericInternal(numeric, dest, buf); } - void SendModeInternal(const MessageSource &source, const Channel *dest, const Anope::string &buf) anope_override { insp12->SendModeInternal(source, dest, buf); } - void SendClientIntroduction(User *u) anope_override { insp12->SendClientIntroduction(u); } - void SendServer(const Server *server) anope_override { insp12->SendServer(server); } - void SendSquit(Server *s, const Anope::string &message) anope_override { insp12->SendSquit(s, message); } - void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override { insp12->SendJoin(user, c, status); } - void SendSQLineDel(const XLine *x) anope_override { insp12->SendSQLineDel(x); } - void SendSQLine(User *u, const XLine *x) anope_override { insp12->SendSQLine(u, x); } - void SendVhost(User *u, const Anope::string &vident, const Anope::string &vhost) anope_override { insp12->SendVhost(u, vident, vhost); } - void SendSVSHold(const Anope::string &nick, time_t t) anope_override { insp12->SendSVSHold(nick, t); } - void SendSVSHoldDel(const Anope::string &nick) anope_override { insp12->SendSVSHoldDel(nick); } - void SendSZLineDel(const XLine *x) anope_override { insp12->SendSZLineDel(x); } - void SendSZLine(User *u, const XLine *x) anope_override { insp12->SendSZLine(u, x); } - void SendSVSJoin(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string &other) anope_override { insp12->SendSVSJoin(source, u, chan, other); } - void SendSVSPart(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string ¶m) anope_override { insp12->SendSVSPart(source, u, chan, param); } - void SendSWhois(const MessageSource &bi, const Anope::string &who, const Anope::string &mask) anope_override { insp12->SendSWhois(bi, who, mask); } - void SendBOB() anope_override { insp12->SendBOB(); } - void SendEOB() anope_override { insp12->SendEOB(); } - void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) { insp12->SendGlobopsInternal(source, buf); } - void SendLogin(User *u, NickAlias *na) anope_override { insp12->SendLogin(u, na); } - void SendLogout(User *u) anope_override { insp12->SendLogout(u); } - void SendChannel(Channel *c) anope_override { insp12->SendChannel(c); } - void SendSASLMessage(const SASL::Message &message) anope_override { insp12->SendSASLMessage(message); } - void SendSVSLogin(const Anope::string &uid, const Anope::string &acc, const Anope::string &vident, const Anope::string &vhost) anope_override { insp12->SendSVSLogin(uid, acc, vident, vhost); } - bool IsExtbanValid(const Anope::string &mask) anope_override { return insp12->IsExtbanValid(mask); } - bool IsIdentValid(const Anope::string &ident) anope_override { return insp12->IsIdentValid(ident); } + void SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf) anope_override + { + IRCDProto::SendSVSKillInternal(source, user, buf); + user->KillInternal(source, buf); + } + + void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override + { + UplinkSocket::Message(bi) << "NOTICE $" << dest->GetName() << " :" << msg; + } + + void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override + { + UplinkSocket::Message(bi) << "PRIVMSG $" << dest->GetName() << " :" << msg; + } + + void SendAkillDel(const XLine *x) anope_override + { + { + /* InspIRCd may support regex bans + * Mask is expected in format: 'n!u@h\sr' and spaces as '\s' + * We remove the '//' and replace '#' and any ' ' with '\s' + */ + if (x->IsRegex() && Servers::Capab.count("RLINE")) + { + Anope::string mask = x->mask; + if (mask.length() >= 2 && mask[0] == '/' && mask[mask.length() - 1] == '/') + mask = mask.substr(1, mask.length() - 2); + size_t h = mask.find('#'); + if (h != Anope::string::npos) + { + mask = mask.replace(h, 1, "\\s"); + mask = mask.replace_all_cs(" ", "\\s"); + } + SendDelLine("R", mask); + return; + } + else if (x->IsRegex() || x->HasNickOrReal()) + return; + + /* ZLine if we can instead */ + if (x->GetUser() == "*") + { + cidr addr(x->GetHost()); + if (addr.valid()) + { + IRCD->SendSZLineDel(x); + return; + } + } + + SendDelLine("G", x->GetUser() + "@" + x->GetHost()); + } + } + + void SendTopic(const MessageSource &source, Channel *c) anope_override + { + if (Servers::Capab.count("SVSTOPIC")) + { + UplinkSocket::Message(c->ci->WhoSends()) << "SVSTOPIC " << c->name << " " << c->topic_ts << " " << c->topic_setter << " :" << c->topic; + } + else + { + /* If the last time a topic was set is after the TS we want for this topic we must bump this topic's timestamp to now */ + time_t ts = c->topic_ts; + if (c->topic_time > ts) + ts = Anope::CurTime; + /* But don't modify c->topic_ts, it should remain set to the real TS we want as ci->last_topic_time pulls from it */ + UplinkSocket::Message(source) << "FTOPIC " << c->name << " " << ts << " " << c->topic_setter << " :" << c->topic; + } + } + + void SendVhostDel(User *u) anope_override + { + UserMode *um = ModeManager::FindUserModeByName("CLOAK"); + + if (um && !u->HasMode(um->name)) + // Just set +x if we can + u->SetMode(NULL, um); + else + // Try to restore cloaked host + this->SendChgHostInternal(u->nick, u->chost); + } + + void SendAkill(User *u, XLine *x) anope_override + { + // Calculate the time left before this would expire, capping it at 2 days + time_t timeleft = x->expires - Anope::CurTime; + if (timeleft > 172800 || !x->expires) + timeleft = 172800; + + /* InspIRCd may support regex bans, if they do we can send this and forget about it + * Mask is expected in format: 'n!u@h\sr' and spaces as '\s' + * We remove the '//' and replace '#' and any ' ' with '\s' + */ + if (x->IsRegex() && Servers::Capab.count("RLINE")) + { + Anope::string mask = x->mask; + if (mask.length() >= 2 && mask[0] == '/' && mask[mask.length() - 1] == '/') + mask = mask.substr(1, mask.length() - 2); + size_t h = mask.find('#'); + if (h != Anope::string::npos) + { + mask = mask.replace(h, 1, "\\s"); + mask = mask.replace_all_cs(" ", "\\s"); + } + SendAddLine("R", mask, timeleft, x->by, x->GetReason()); + return; + } + else if (x->IsRegex() || x->HasNickOrReal()) + { + if (!u) + { + /* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */ + for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + if (x->manager->Check(it->second, x)) + this->SendAkill(it->second, x); + return; + } + + const XLine *old = x; + + if (old->manager->HasEntry("*@" + u->host)) + return; + + /* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */ + x = new XLine("*@" + u->host, old->by, old->expires, old->reason, old->id); + old->manager->AddXLine(x); + + Log(Config->GetClient("OperServ"), "akill") << "AKILL: Added an akill for " << x->mask << " because " << u->GetMask() << "#" << u->realname << " matches " << old->mask; + } + + /* ZLine if we can instead */ + if (x->GetUser() == "*") + { + cidr addr(x->GetHost()); + if (addr.valid()) + { + IRCD->SendSZLine(u, x); + return; + } + } + + SendAddLine("G", x->GetUser() + "@" + x->GetHost(), timeleft, x->by, x->GetReason()); + } + + void SendNumericInternal(int numeric, const Anope::string &dest, const Anope::string &buf) anope_override + { + User *u = User::Find(dest); + UplinkSocket::Message() << "PUSH " << dest << " ::" << Me->GetName() << " " << numeric << " " << (u ? u->nick : dest) << " " << buf; + } + + void SendModeInternal(const MessageSource &source, const Channel *dest, const Anope::string &buf) anope_override + { + UplinkSocket::Message(source) << "FMODE " << dest->name << " " << dest->creation_time << " " << buf; + } + + void SendClientIntroduction(User *u) anope_override + { + Anope::string modes = "+" + u->GetModes(); + UplinkSocket::Message(Me) << "UID " << u->GetUID() << " " << u->timestamp << " " << u->nick << " " << u->host << " " << u->host << " " << u->GetIdent() << " 0.0.0.0 " << u->timestamp << " " << modes << " :" << u->realname; + if (modes.find('o') != Anope::string::npos) + UplinkSocket::Message(u) << "OPERTYPE :services"; + } + + void SendServer(const Server *server) anope_override + { + /* if rsquit is set then we are waiting on a squit */ + if (rsquit_id.empty() && rsquit_server.empty()) + UplinkSocket::Message() << "SERVER " << server->GetName() << " " << Config->Uplinks[Anope::CurrentUplink].password << " " << server->GetHops() << " " << server->GetSID() << " :" << server->GetDescription(); + } + + void SendSquit(Server *s, const Anope::string &message) anope_override + { + if (s != Me) + { + rsquit_id = s->GetSID(); + rsquit_server = s->GetName(); + UplinkSocket::Message() << "RSQUIT " << s->GetName() << " :" << message; + } + else + UplinkSocket::Message() << "SQUIT " << s->GetName() << " :" << message; + } + + void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override + { + UplinkSocket::Message(Me) << "FJOIN " << c->name << " " << c->creation_time << " +" << c->GetModes(true, true) << " :," << user->GetUID(); + /* Note that we can send this with the FJOIN but choose not to + * because the mode stacker will handle this and probably will + * merge these modes with +nrt and other mlocked modes + */ + if (status) + { + /* First save the channel status incase uc->Status == status */ + ChannelStatus cs = *status; + /* If the user is internally on the channel with flags, kill them so that + * the stacker will allow this. + */ + ChanUserContainer *uc = c->FindUser(user); + if (uc != NULL) + uc->status.Clear(); + + BotInfo *setter = BotInfo::Find(user->GetUID()); + for (size_t i = 0; i < cs.Modes().length(); ++i) + c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false); + + if (uc != NULL) + uc->status = cs; + } + } + + void SendSQLineDel(const XLine *x) anope_override + { + SendDelLine("Q", x->mask); + } + + void SendSQLine(User *u, const XLine *x) anope_override + { + // Calculate the time left before this would expire, capping it at 2 days + time_t timeleft = x->expires - Anope::CurTime; + if (timeleft > 172800 || !x->expires) + timeleft = 172800; + SendAddLine("Q", x->mask, timeleft, x->by, x->GetReason()); + } + + void SendVhost(User *u, const Anope::string &vIdent, const Anope::string &vhost) anope_override + { + if (!vIdent.empty()) + this->SendChgIdentInternal(u->nick, vIdent); + if (!vhost.empty()) + this->SendChgHostInternal(u->nick, vhost); + } + + void SendSVSHold(const Anope::string &nick, time_t t) anope_override + { + UplinkSocket::Message(Config->GetClient("NickServ")) << "SVSHOLD " << nick << " " << t << " :Being held for registered user"; + } + + void SendSVSHoldDel(const Anope::string &nick) anope_override + { + UplinkSocket::Message(Config->GetClient("NickServ")) << "SVSHOLD " << nick; + } + + void SendSZLineDel(const XLine *x) anope_override + { + SendDelLine("Z", x->GetHost()); + } + + void SendSZLine(User *u, const XLine *x) anope_override + { + // Calculate the time left before this would expire, capping it at 2 days + time_t timeleft = x->expires - Anope::CurTime; + if (timeleft > 172800 || !x->expires) + timeleft = 172800; + SendAddLine("Z", x->GetHost(), timeleft, x->by, x->GetReason()); + } + + void SendSVSJoin(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string &other) anope_override + { + UplinkSocket::Message(source) << "SVSJOIN " << u->GetUID() << " " << chan; + } + + void SendSVSPart(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string ¶m) anope_override + { + if (!param.empty()) + UplinkSocket::Message(source) << "SVSPART " << u->GetUID() << " " << chan << " :" << param; + else + UplinkSocket::Message(source) << "SVSPART " << u->GetUID() << " " << chan; + } + + void SendSWhois(const MessageSource &bi, const Anope::string &who, const Anope::string &mask) anope_override + { + User *u = User::Find(who); + + UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " swhois :" << mask; + } + + void SendBOB() anope_override + { + UplinkSocket::Message(Me) << "BURST " << Anope::CurTime; + Module *enc = ModuleManager::FindFirstOf(ENCRYPTION); + UplinkSocket::Message(Me) << "VERSION :Anope-" << Anope::Version() << " " << Me->GetName() << " :" << IRCD->GetProtocolName() << " - (" << (enc ? enc->name : "none") << ") -- " << Anope::VersionBuildString(); + } + + void SendEOB() anope_override + { + UplinkSocket::Message(Me) << "ENDBURST"; + } + + void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) anope_override + { + if (Servers::Capab.count("GLOBOPS")) + UplinkSocket::Message(source) << "SNONOTICE g :" << buf; + else + UplinkSocket::Message(source) << "SNONOTICE A :" << buf; + } + + void SendLogin(User *u, NickAlias *na) anope_override + { + /* InspIRCd uses an account to bypass chmode +R, not umode +r, so we can't send this here */ + if (na->nc->HasExt("UNCONFIRMED")) + return; + + UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " accountname :" << na->nc->display; + } + + void SendLogout(User *u) anope_override + { + UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " accountname :"; + } + + void SendChannel(Channel *c) anope_override + { + UplinkSocket::Message(Me) << "FJOIN " << c->name << " " << c->creation_time << " +" << c->GetModes(true, true) << " :"; + } + + void SendSASLMessage(const SASL::Message &message) anope_override + { + UplinkSocket::Message(Me) << "ENCAP " << message.target.substr(0, 3) << " SASL " << message.source << " " << message.target << " " << message.type << " " << message.data << (message.ext.empty() ? "" : (" " + message.ext)); + } + + void SendSVSLogin(const Anope::string &uid, const Anope::string &acc, const Anope::string &vident, const Anope::string &vhost) anope_override + { + UplinkSocket::Message(Me) << "METADATA " << uid << " accountname :" << acc; + + if (!vident.empty()) + UplinkSocket::Message(Me) << "ENCAP " << uid.substr(0, 3) << " CHGIDENT " << uid << " " << vident; + if (!vhost.empty()) + UplinkSocket::Message(Me) << "ENCAP " << uid.substr(0, 3) << " CHGHOST " << uid << " " << vhost; + + SASLUser su; + su.uid = uid; + su.acc = acc; + su.created = Anope::CurTime; + + for (std::list<SASLUser>::iterator it = saslusers.begin(); it != saslusers.end();) + { + SASLUser &u = *it; + + if (u.created + 30 < Anope::CurTime || u.uid == uid) + it = saslusers.erase(it); + else + ++it; + } + + saslusers.push_back(su); + } + + bool IsExtbanValid(const Anope::string &mask) anope_override + { + return mask.length() >= 3 && mask[1] == ':'; + } + + bool IsIdentValid(const Anope::string &ident) anope_override + { + if (ident.empty() || ident.length() > Config->GetBlock("networkinfo")->Get<unsigned>("userlen")) + return false; + + for (unsigned i = 0; i < ident.length(); ++i) + { + const char &c = ident[i]; + + if (c >= 'A' && c <= '}') + continue; + + if ((c >= '0' && c <= '9') || c == '-' || c == '.') + continue; + + return false; + } + + return true; + } }; class InspIRCdAutoOpMode : public ChannelModeList @@ -786,9 +1163,7 @@ struct IRCDMessageCapab : Message::Capab struct IRCDMessageEncap : IRCDMessage { - ServiceReference<IRCDMessage> insp12_encap; - - IRCDMessageEncap(Module *creator) : IRCDMessage(creator, "ENCAP", 4), insp12_encap("IRCDMessage", "inspircd12/encap") { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + IRCDMessageEncap(Module *creator) : IRCDMessage(creator, "ENCAP", 4) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { @@ -822,9 +1197,17 @@ struct IRCDMessageEncap : IRCDMessage u->SetRealname(params[3]); UplinkSocket::Message(u) << "FNAME " << params[3]; } - - if (insp12_encap) - insp12_encap->Run(source, params); + else if (SASL::sasl && params[1] == "SASL" && params.size() >= 6) + { + SASL::Message m; + m.source = params[2]; + m.target = params[3]; + m.type = params[4]; + m.data = params[5]; + m.ext = params.size() > 6 ? params[6] : ""; + + SASL::sasl->ProcessMessage(m); + } } }; @@ -895,12 +1278,11 @@ struct IRCDMessageSave : IRCDMessage class IRCDMessageMetadata : IRCDMessage { - ServiceReference<IRCDMessage> insp12_metadata; const bool &do_topiclock; const bool &do_mlock; public: - IRCDMessageMetadata(Module *creator, const bool &handle_topiclock, const bool &handle_mlock) : IRCDMessage(creator, "METADATA", 3), insp12_metadata("IRCDMessage", "inspircd12/metadata"), do_topiclock(handle_topiclock), do_mlock(handle_mlock) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + IRCDMessageMetadata(Module *creator, const bool &handle_topiclock, const bool &handle_mlock) : IRCDMessage(creator, "METADATA", 3), do_topiclock(handle_topiclock), do_mlock(handle_mlock) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { @@ -930,16 +1312,387 @@ class IRCDMessageMetadata : IRCDMessage } } } + else if (isdigit(params[0][0])) + { + if (params[1].equals_cs("accountname")) + { + User *u = User::Find(params[0]); + NickCore *nc = NickCore::Find(params[2]); + if (u && nc) + u->Login(nc); + } + + /* + * possible incoming ssl_cert messages: + * Received: :409 METADATA 409AAAAAA ssl_cert :vTrSe c38070ce96e41cc144ed6590a68d45a6 <...> <...> + * Received: :409 METADATA 409AAAAAC ssl_cert :vTrSE Could not get peer certificate: error:00000000:lib(0):func(0):reason(0) + */ + else if (params[1].equals_cs("ssl_cert")) + { + User *u = User::Find(params[0]); + if (!u) + return; + u->Extend<bool>("ssl"); + Anope::string data = params[2].c_str(); + size_t pos1 = data.find(' ') + 1; + size_t pos2 = data.find(' ', pos1); + if ((pos2 - pos1) >= 32) // inspircd supports md5 and sha1 fingerprint hashes -> size 32 or 40 bytes. + { + u->fingerprint = data.substr(pos1, pos2 - pos1); + } + FOREACH_MOD(OnFingerprint, (u)); + } + } + else if (params[0] == "*") + { + // Wed Oct 3 15:40:27 2012: S[14] O :20D METADATA * modules :-m_svstopic.so - if (insp12_metadata) - insp12_metadata->Run(source, params); + if (params[1].equals_cs("modules") && !params[2].empty()) + { + // only interested when it comes from our uplink + Server* server = source.GetServer(); + if (!server || server->GetUplink() != Me) + return; + + bool plus = (params[2][0] == '+'); + if (!plus && params[2][0] != '-') + return; + + bool required = false; + Anope::string capab, module = params[2].substr(1); + + if (module.equals_cs("m_services_account.so")) + required = true; + else if (module.equals_cs("m_hidechans.so")) + required = true; + else if (module.equals_cs("m_chghost.so")) + capab = "CHGHOST"; + else if (module.equals_cs("m_chgident.so")) + capab = "CHGIDENT"; + else if (module.equals_cs("m_svshold.so")) + capab = "SVSHOLD"; + else if (module.equals_cs("m_rline.so")) + capab = "RLINE"; + else if (module.equals_cs("m_topiclock.so")) + capab = "TOPICLOCK"; + else + return; + + if (required) + { + if (!plus) + Log() << "Warning: InspIRCd unloaded module " << module << ", Anope won't function correctly without it"; + } + else + { + if (plus) + Servers::Capab.insert(capab); + else + Servers::Capab.erase(capab); + + Log() << "InspIRCd " << (plus ? "loaded" : "unloaded") << " module " << module << ", adjusted functionality"; + } + + } + } } }; -class ProtoInspIRCd3 : public Module +struct IRCDMessageEndburst : IRCDMessage +{ + IRCDMessageEndburst(Module *creator) : IRCDMessage(creator, "ENDBURST", 0) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + { + Server *s = source.GetServer(); + + Log(LOG_DEBUG) << "Processed ENDBURST for " << s->GetName(); + + s->Sync(true); + } +}; + +struct IRCDMessageFJoin : IRCDMessage +{ + IRCDMessageFJoin(Module *creator) : IRCDMessage(creator, "FJOIN", 2) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + { + Anope::string modes; + if (params.size() >= 3) + { + for (unsigned i = 2; i < params.size() - 1; ++i) + modes += " " + params[i]; + if (!modes.empty()) + modes.erase(modes.begin()); + } + + std::list<Message::Join::SJoinUser> users; + + spacesepstream sep(params[params.size() - 1]); + Anope::string buf; + while (sep.GetToken(buf)) + { + Message::Join::SJoinUser sju; + + /* Loop through prefixes and find modes for them */ + for (char c; (c = buf[0]) != ',' && c;) + { + buf.erase(buf.begin()); + sju.first.AddMode(c); + } + /* Erase the , */ + if (!buf.empty()) + buf.erase(buf.begin()); + + sju.second = User::Find(buf); + if (!sju.second) + { + Log(LOG_DEBUG) << "FJOIN for nonexistent user " << buf << " on " << params[0]; + continue; + } + + users.push_back(sju); + } + + time_t ts = Anope::string(params[1]).is_pos_number_only() ? convertTo<time_t>(params[1]) : Anope::CurTime; + Message::Join::SJoin(source, params[0], ts, modes, users); + } +}; + +struct IRCDMessageFMode : IRCDMessage { - Module *m_insp12; + IRCDMessageFMode(Module *creator) : IRCDMessage(creator, "FMODE", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + { + /* :source FMODE #test 12345678 +nto foo */ + Anope::string modes = params[2]; + for (unsigned n = 3; n < params.size(); ++n) + modes += " " + params[n]; + + Channel *c = Channel::Find(params[0]); + time_t ts; + + try + { + ts = convertTo<time_t>(params[1]); + } + catch (const ConvertException &) + { + ts = 0; + } + + if (c) + c->SetModesInternal(source, modes, ts); + } +}; + +struct IRCDMessageFTopic : IRCDMessage +{ + IRCDMessageFTopic(Module *creator) : IRCDMessage(creator, "FTOPIC", 4) { } + + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + { + /* :source FTOPIC channel topicts setby :topic */ + + Channel *c = Channel::Find(params[0]); + if (c) + c->ChangeTopicInternal(NULL, params[2], params[3], Anope::string(params[1]).is_pos_number_only() ? convertTo<time_t>(params[1]) : Anope::CurTime); + } +}; + +struct IRCDMessageIdle : IRCDMessage +{ + IRCDMessageIdle(Module *creator) : IRCDMessage(creator, "IDLE", 1) { } + + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + { + BotInfo *bi = BotInfo::Find(params[0]); + if (bi) + UplinkSocket::Message(bi) << "IDLE " << source.GetSource() << " " << Anope::StartTime << " " << (Anope::CurTime - bi->lastmsg); + else + { + User *u = User::Find(params[0]); + if (u && u->server == Me) + UplinkSocket::Message(u) << "IDLE " << source.GetSource() << " " << Anope::StartTime << " 0"; + } + } +}; + +struct IRCDMessageMode : IRCDMessage +{ + IRCDMessageMode(Module *creator) : IRCDMessage(creator, "MODE", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + { + if (IRCD->IsChannelValid(params[0])) + { + Channel *c = Channel::Find(params[0]); + + Anope::string modes = params[1]; + for (unsigned n = 2; n < params.size(); ++n) + modes += " " + params[n]; + + if (c) + c->SetModesInternal(source, modes); + } + else + { + /* InspIRCd lets opers change another + users modes, we have to kludge this + as it slightly breaks RFC1459 + */ + User *u = User::Find(params[0]); + if (u) + u->SetModesInternal(source, "%s", params[1].c_str()); + } + } +}; + +struct IRCDMessageNick : IRCDMessage +{ + IRCDMessageNick(Module *creator) : IRCDMessage(creator, "NICK", 2) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + { + source.GetUser()->ChangeNick(params[0]); + } +}; + +struct IRCDMessageOperType : IRCDMessage +{ + IRCDMessageOperType(Module *creator) : IRCDMessage(creator, "OPERTYPE", 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_USER); } + + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + { + /* opertype is equivalent to mode +o because servers + don't do this directly */ + User *u = source.GetUser(); + if (!u->HasMode("OPER")) + u->SetModesInternal(source, "+o"); + } +}; + + +struct IRCDMessageRSQuit : IRCDMessage +{ + IRCDMessageRSQuit(Module *creator) : IRCDMessage(creator, "RSQUIT", 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + { + Server *s = Server::Find(params[0]); + const Anope::string &reason = params.size() > 1 ? params[1] : ""; + if (!s) + return; + + UplinkSocket::Message(Me) << "SQUIT " << s->GetSID() << " :" << reason; + s->Delete(s->GetName() + " " + s->GetUplink()->GetName()); + } +}; + +struct IRCDMessageServer : IRCDMessage +{ + IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 5) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + + /* + * [Nov 04 00:08:46.308435 2009] debug: Received: SERVER irc.inspircd.com pass 0 964 :Testnet Central! + * 0: name + * 1: pass + * 2: hops + * 3: numeric + * 4: desc + */ + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + { + unsigned int hops = Anope::string(params[2]).is_pos_number_only() ? convertTo<unsigned>(params[2]) : 0; + new Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], hops, params[4], params[3]); + } +}; + +struct IRCDMessageSQuit : Message::SQuit +{ + IRCDMessageSQuit(Module *creator) : Message::SQuit(creator) { } + + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + { + if (params[0] == rsquit_id || params[0] == rsquit_server) + { + /* squit for a recently squit server, introduce the juped server now */ + Server *s = Server::Find(rsquit_server); + + rsquit_id.clear(); + rsquit_server.clear(); + + if (s && s->IsJuped()) + IRCD->SendServer(s); + } + else + Message::SQuit::Run(source, params); + } +}; + +struct IRCDMessageTime : IRCDMessage +{ + IRCDMessageTime(Module *creator) : IRCDMessage(creator, "TIME", 2) { } + + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + { + UplinkSocket::Message(Me) << "TIME " << source.GetSource() << " " << params[1] << " " << Anope::CurTime; + } +}; + +struct IRCDMessageUID : IRCDMessage +{ + IRCDMessageUID(Module *creator) : IRCDMessage(creator, "UID", 8) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + /* + * [Nov 03 22:09:58.176252 2009] debug: Received: :964 UID 964AAAAAC 1225746297 w00t2 localhost testnet.user w00t 127.0.0.1 1225746302 +iosw +ACGJKLNOQcdfgjklnoqtx :Robin Burchell <w00t@inspircd.org> + * 0: uid + * 1: ts + * 2: nick + * 3: host + * 4: dhost + * 5: ident + * 6: ip + * 7: signon + * 8+: modes and params -- IMPORTANT, some modes (e.g. +s) may have parameters. So don't assume a fixed position of realname! + * last: realname + */ + void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + { + time_t ts = convertTo<time_t>(params[1]); + + Anope::string modes = params[8]; + for (unsigned i = 9; i < params.size() - 1; ++i) + modes += " " + params[i]; + + NickAlias *na = NULL; + if (SASL::sasl) + for (std::list<SASLUser>::iterator it = saslusers.begin(); it != saslusers.end();) + { + SASLUser &u = *it; + + if (u.created + 30 < Anope::CurTime) + it = saslusers.erase(it); + else if (u.uid == params[0]) + { + na = NickAlias::Find(u.acc); + it = saslusers.erase(it); + } + else + ++it; + } + + User *u = User::OnIntroduce(params[2], params[5], params[3], params[4], params[6], source.GetServer(), params[params.size() - 1], ts, modes, params[0], na ? *na->nc : NULL); + if (u) + u->signon = convertTo<time_t>(params[7]); + } +}; + +class ProtoInspIRCd3 : public Module +{ InspIRCd3Proto ircd_proto; /* Core message handlers */ @@ -957,12 +1710,6 @@ class ProtoInspIRCd3 : public Module Message::Stats message_stats; Message::Topic message_topic; - /* InspIRCd 1.2 message handlers */ - ServiceAlias message_endburst, message_fjoin, message_fmode, - message_ftopic, message_idle, message_mode, - message_nick, message_opertype, message_rsquit, message_server, - message_squit, message_time, message_uid; - /* Our message handlers */ IRCDMessageAway message_away; IRCDMessageCapab message_capab; @@ -971,6 +1718,19 @@ class ProtoInspIRCd3 : public Module IRCDMessageFIdent message_fident; IRCDMessageMetadata message_metadata; IRCDMessageSave message_save; + IRCDMessageEndburst message_endburst; + IRCDMessageFJoin message_fjoin; + IRCDMessageFMode message_fmode; + IRCDMessageFTopic message_ftopic; + IRCDMessageIdle message_idle; + IRCDMessageMode message_mode; + IRCDMessageNick message_nick; + IRCDMessageOperType message_opertype; + IRCDMessageRSQuit message_rsquit; + IRCDMessageServer message_server; + IRCDMessageSQuit message_squit; + IRCDMessageTime message_time; + IRCDMessageUID message_uid; bool use_server_side_topiclock, use_server_side_mlock; @@ -984,41 +1744,13 @@ class ProtoInspIRCd3 : public Module ircd_proto(this), message_error(this), message_invite(this), message_join(this), message_kick(this), message_kill(this), message_motd(this), message_notice(this), message_part(this), message_ping(this), message_privmsg(this), - message_quit(this), message_stats(this), message_topic(this), - - message_endburst("IRCDMessage", "inspircd3/endburst", "inspircd12/endburst"), - message_fjoin("IRCDMessage", "inspircd3/fjoin", "inspircd12/fjoin"), - message_fmode("IRCDMessage", "inspircd3/fmode", "inspircd12/fmode"), - message_ftopic("IRCDMessage", "inspircd3/ftopic", "inspircd12/ftopic"), - message_idle("IRCDMessage", "inspircd3/idle", "inspircd12/idle"), - message_mode("IRCDMessage", "inspircd3/mode", "inspircd12/mode"), - message_nick("IRCDMessage", "inspircd3/nick", "inspircd12/nick"), - message_opertype("IRCDMessage", "inspircd3/opertype", "inspircd12/opertype"), - message_rsquit("IRCDMessage", "inspircd3/rsquit", "inspircd12/rsquit"), - message_server("IRCDMessage", "inspircd3/server", "inspircd12/server"), - message_squit("IRCDMessage", "inspircd3/squit", "inspircd12/squit"), - message_time("IRCDMessage", "inspircd3/time", "inspircd12/time"), - message_uid("IRCDMessage", "inspircd3/uid", "inspircd12/uid"), - - message_away(this), message_capab(this), message_encap(this), message_fhost(this), message_fident(this), - message_metadata(this, use_server_side_topiclock, use_server_side_mlock), message_save(this) - { - - if (ModuleManager::LoadModule("inspircd12", User::Find(creator)) != MOD_ERR_OK) - throw ModuleException("Unable to load inspircd12"); - m_insp12 = ModuleManager::FindModule("inspircd12"); - if (!m_insp12) - throw ModuleException("Unable to find inspircd12"); - if (!insp12) - throw ModuleException("No protocol interface for insp12"); - ModuleManager::DetachAll(m_insp12); - - } - - ~ProtoInspIRCd3() + message_quit(this), message_stats(this), message_topic(this), message_away(this), message_capab(this), + message_encap(this), message_fhost(this), message_fident(this), + message_metadata(this, use_server_side_topiclock, use_server_side_mlock), message_save(this), + message_endburst(this), message_fjoin(this), message_fmode(this), message_ftopic(this), message_idle(this), + message_mode(this), message_nick(this), message_opertype(this), message_rsquit(this), message_server(this), + message_squit(this), message_time(this), message_uid(this) { - m_insp12 = ModuleManager::FindModule("inspircd12"); - ModuleManager::UnloadModule(m_insp12, NULL); } void OnReload(Configuration::Conf *conf) anope_override |