diff options
Diffstat (limited to 'modules/protocol')
-rw-r--r-- | modules/protocol/bahamut.cpp | 225 | ||||
-rw-r--r-- | modules/protocol/hybrid.cpp | 341 | ||||
-rw-r--r-- | modules/protocol/inspircd-ts6.h | 817 | ||||
-rw-r--r-- | modules/protocol/inspircd11.cpp | 249 | ||||
-rw-r--r-- | modules/protocol/inspircd12.cpp | 854 | ||||
-rw-r--r-- | modules/protocol/inspircd20.cpp | 243 | ||||
-rw-r--r-- | modules/protocol/ngircd.cpp | 193 | ||||
-rw-r--r-- | modules/protocol/plexus.cpp | 573 | ||||
-rw-r--r-- | modules/protocol/ratbox.cpp | 555 | ||||
-rw-r--r-- | modules/protocol/unreal.cpp | 318 |
10 files changed, 1704 insertions, 2664 deletions
diff --git a/modules/protocol/bahamut.cpp b/modules/protocol/bahamut.cpp index e39226dd8..839876d90 100644 --- a/modules/protocol/bahamut.cpp +++ b/modules/protocol/bahamut.cpp @@ -49,7 +49,7 @@ class BahamutIRCdProto : public IRCDProto void SendModeInternal(const BotInfo *source, const Channel *dest, const Anope::string &buf) anope_override { - if (Capab.count("TSMODE") > 0) + if (Servers::Capab.count("TSMODE") > 0) { if (source) UplinkSocket::Message(source) << "MODE " << dest->name << " " << dest->creation_time << " " << buf; @@ -93,13 +93,13 @@ class BahamutIRCdProto : public IRCDProto /* SQLINE */ void SendSQLine(User *, const XLine *x) anope_override { - UplinkSocket::Message() << "SQLINE " << x->Mask << " :" << x->GetReason(); + UplinkSocket::Message() << "SQLINE " << x->mask << " :" << x->GetReason(); } /* UNSLINE */ void SendSGLineDel(const XLine *x) anope_override { - UplinkSocket::Message() << "UNSGLINE 0 :" << x->Mask; + UplinkSocket::Message() << "UNSGLINE 0 :" << x->mask; } /* UNSZLINE */ @@ -115,13 +115,13 @@ class BahamutIRCdProto : public IRCDProto void SendSZLine(User *, 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) + time_t timeleft = x->expires - Anope::CurTime; + if (timeleft > 172800 || !x->expires) timeleft = 172800; /* this will likely fail so its only here for legacy */ UplinkSocket::Message() << "SZLINE " << x->GetHost() << " :" << x->GetReason(); /* this is how we are supposed to deal with it */ - UplinkSocket::Message() << "AKILL " << x->GetHost() << " * " << timeleft << " " << x->By << " " << Anope::CurTime << " :" << x->GetReason(); + UplinkSocket::Message() << "AKILL " << x->GetHost() << " * " << timeleft << " " << x->by << " " << Anope::CurTime << " :" << x->GetReason(); } /* SVSNOOP */ @@ -133,7 +133,7 @@ class BahamutIRCdProto : public IRCDProto /* SGLINE */ void SendSGLine(User *, const XLine *x) anope_override { - UplinkSocket::Message() << "SGLINE " << x->Mask.length() << " :" << x->Mask << ":" << x->GetReason(); + UplinkSocket::Message() << "SGLINE " << x->mask.length() << " :" << x->mask << ":" << x->GetReason(); } /* RAKILL */ @@ -148,7 +148,7 @@ class BahamutIRCdProto : public IRCDProto if (x->GetUser() == "*") { sockaddrs(x->GetHost()); - ircdproto->SendSZLineDel(x); + IRCD->SendSZLineDel(x); return; } } @@ -166,7 +166,7 @@ class BahamutIRCdProto : public IRCDProto /* UNSQLINE */ void SendSQLineDel(const XLine *x) anope_override { - UplinkSocket::Message() << "UNSQLINE " << x->Mask; + UplinkSocket::Message() << "UNSQLINE " << x->mask; } /* JOIN - SJOIN */ @@ -182,11 +182,11 @@ class BahamutIRCdProto : public IRCDProto */ UserContainer *uc = c->FindUser(user); if (uc != NULL) - uc->Status->ClearFlags(); + uc->status->ClearFlags(); - BotInfo *setter = findbot(user->nick); + BotInfo *setter = BotInfo::Find(user->nick); for (unsigned i = 0; i < ModeManager::ChannelModes.size(); ++i) - if (cs.HasFlag(ModeManager::ChannelModes[i]->Name)) + if (cs.HasFlag(ModeManager::ChannelModes[i]->name)) c->SetMode(setter, ModeManager::ChannelModes[i], user->GetUID(), false); } } @@ -210,10 +210,10 @@ class BahamutIRCdProto : public IRCDProto 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->UID); + x = new XLine("*@" + u->host, old->by, old->expires, old->reason, old->id); old->manager->AddXLine(x); - Log(findbot(Config->OperServ), "akill") << "AKILL: Added an akill for " << x->Mask << " because " << u->GetMask() << "#" << u->realname << " matches " << old->Mask; + Log(OperServ, "akill") << "AKILL: Added an akill for " << x->mask << " because " << u->GetMask() << "#" << u->realname << " matches " << old->mask; } /* ZLine if we can instead */ @@ -222,17 +222,17 @@ class BahamutIRCdProto : public IRCDProto if (x->GetUser() == "*") { sockaddrs(x->GetHost()); - ircdproto->SendSZLine(u, x); + IRCD->SendSZLine(u, x); return; } } catch (const SocketException &) { } // Calculate the time left before this would expire, capping it at 2 days - time_t timeleft = x->Expires - Anope::CurTime; + time_t timeleft = x->expires - Anope::CurTime; if (timeleft > 172800) timeleft = 172800; - UplinkSocket::Message() << "AKILL " << x->GetHost() << " " << x->GetUser() << " " << timeleft << " " << x->By << " " << Anope::CurTime << " :" << x->GetReason(); + UplinkSocket::Message() << "AKILL " << x->GetHost() << " " << x->GetUser() << " " << timeleft << " " << x->by << " " << Anope::CurTime << " :" << x->GetReason(); } /* @@ -270,7 +270,7 @@ class BahamutIRCdProto : public IRCDProto void SendConnect() anope_override { - UplinkSocket::Message() << "PASS " << Config->Uplinks[CurrentUplink]->password << " :TS"; + UplinkSocket::Message() << "PASS " << Config->Uplinks[Anope::CurrentUplink]->password << " :TS"; UplinkSocket::Message() << "CAPAB SSJOIN NOQUIT BURST UNCONNECT NICKIP TSMODE TS3"; SendServer(Me); /* @@ -295,20 +295,18 @@ class BahamutIRCdProto : public IRCDProto void SendLogin(User *u) anope_override { - const BotInfo *ns = findbot(Config->NickServ); - ircdproto->SendMode(ns, u, "+d %d", u->timestamp); + IRCD->SendMode(NickServ, u, "+d %d", u->timestamp); } void SendLogout(User *u) anope_override { - const BotInfo *ns = findbot(Config->NickServ); - ircdproto->SendMode(ns, u, "+d 1"); + IRCD->SendMode(NickServ, u, "+d 1"); } }; struct IRCDMessageBurst : IRCDMessage { - IRCDMessageBurst() : IRCDMessage("BURST", 0) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + IRCDMessageBurst(Module *creator) : IRCDMessage(creator, "BURST", 0) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { @@ -327,14 +325,15 @@ struct IRCDMessageBurst : IRCDMessage struct IRCDMessageMode : IRCDMessage { - IRCDMessageMode(const Anope::string &n) : IRCDMessage(n, 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + IRCDMessageMode(Module *creator, const Anope::string &sname) : IRCDMessage(creator, sname, 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { - if (params.size() > 2 && ircdproto->IsChannelValid(params[0])) + if (params.size() > 2 && IRCD->IsChannelValid(params[0])) { - Channel *c = findchan(params[0]); + Channel *c = Channel::Find(params[0]); time_t ts = 0; + try { ts = convertTo<time_t>(params[1]); @@ -346,7 +345,7 @@ struct IRCDMessageMode : IRCDMessage } else { - User *u = finduser(params[0]); + User *u = User::Find(params[0]); if (u) u->SetModesInternal("%s", params[1].c_str()); } @@ -375,7 +374,7 @@ struct IRCDMessageMode : IRCDMessage */ struct IRCDMessageNick : IRCDMessage { - IRCDMessageNick() : IRCDMessage("NICK", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + IRCDMessageNick(Module *creator) : IRCDMessage(creator, "NICK", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { @@ -389,18 +388,18 @@ struct IRCDMessageNick : IRCDMessage } User *user = new User(params[0], params[4], params[5], "", params[8], s, params[9], params[2].is_pos_number_only() ? convertTo<time_t>(params[2]) : 0, params[3]); - if (user && nickserv) + if (user && NickServService) { const NickAlias *na; - if (user->timestamp == convertTo<time_t>(params[7]) && (na = findnick(user->nick))) + if (user->timestamp == convertTo<time_t>(params[7]) && (na = NickAlias::Find(user->nick))) { NickCore *nc = na->nc; user->Login(nc); if (!Config->NoNicknameOwnership && na->nc->HasFlag(NI_UNCONFIRMED) == false) - user->SetMode(findbot(Config->NickServ), UMODE_REGISTERED); + user->SetMode(NickServ, UMODE_REGISTERED); } else - nickserv->Validate(user); + NickServService->Validate(user); } } else @@ -412,7 +411,7 @@ struct IRCDMessageNick : IRCDMessage struct IRCDMessageServer : IRCDMessage { - IRCDMessageServer() : IRCDMessage("SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { @@ -424,77 +423,39 @@ struct IRCDMessageServer : IRCDMessage struct IRCDMessageSJoin : IRCDMessage { - IRCDMessageSJoin() : IRCDMessage("SJOIN", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + IRCDMessageSJoin(Module *creator) : IRCDMessage(creator, "SJOIN", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { - Channel *c = findchan(params[1]); - time_t ts = Anope::string(params[0]).is_pos_number_only() ? convertTo<time_t>(params[0]) : 0; - bool keep_their_modes = true; - - if (!c) - { - c = new Channel(params[1], ts); - c->SetFlag(CH_SYNCING); - } - /* Our creation time is newer than what the server gave us */ - else if (c->creation_time > ts) - { - c->creation_time = ts; - c->Reset(); - } - /* Their TS is newer than ours, our modes > theirs, unset their modes if need be */ - else if (ts > c->creation_time) - keep_their_modes = false; - - /* If we need to keep their modes, and this SJOIN string contains modes */ - if (keep_their_modes && params.size() >= 4) - { - /* Set the modes internally */ - Anope::string modes; + Anope::string modes; + if (params.size() >= 4) for (unsigned i = 2; i < params.size(); ++i) modes += " " + params[i]; - if (!modes.empty()) - modes.erase(modes.begin()); - c->SetModesInternal(source, modes); - } + if (!modes.empty()) + modes.erase(modes.begin()); + + std::list<Message::Join::SJoinUser> users; /* For some reason, bahamut will send a SJOIN from the user joining a channel * if the channel already existed */ - if (!c->HasFlag(CH_SYNCING) && params.size() == 2) + if (source.GetUser()) { - User *u = source.GetUser(); - - EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnPreJoinChannel, OnPreJoinChannel(u, c)); - - /* Add the user to the channel */ - c->JoinUser(u); - - /* Now set whatever modes this user is allowed to have on the channel */ - chan_set_correct_modes(u, c, 1, true); - - /* Check to see if modules want the user to join, if they do - * check to see if they are allowed to join (CheckKick will kick/ban them) - * Don't trigger OnJoinChannel event then as the user will be destroyed - */ - if (MOD_RESULT == EVENT_STOP && (!c->ci || !c->ci->CheckKick(u))) - { - FOREACH_MOD(I_OnJoinChannel, OnJoinChannel(u, c)); - } + Message::Join::SJoinUser sju; + sju.second = source.GetUser(); + users.push_back(sju); } else { spacesepstream sep(params[params.size() - 1]); Anope::string buf; + while (sep.GetToken(buf)) { - std::list<ChannelMode *> Status; - char ch; + Message::Join::SJoinUser sju; /* Get prefixes from the nick */ - while ((ch = ModeManager::GetStatusChar(buf[0]))) + for (char ch; (ch = ModeManager::GetStatusChar(buf[0]));) { buf.erase(buf.begin()); ChannelMode *cm = ModeManager::FindChannelModeByChar(ch); @@ -504,50 +465,22 @@ struct IRCDMessageSJoin : IRCDMessage continue; } - if (keep_their_modes) - Status.push_back(cm); + sju.first.SetFlag(cm->name); } - User *u = finduser(buf); - if (!u) + sju.second = User::Find(buf); + if (!sju.second) { - Log(LOG_DEBUG) << "SJOIN for nonexistant user " << buf << " on " << c->name; + Log(LOG_DEBUG) << "SJOIN for nonexistant user " << buf << " on " << params[1]; continue; } - EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnPreJoinChannel, OnPreJoinChannel(u, c)); - - /* Add the user to the channel */ - c->JoinUser(u); - - /* Update their status internally on the channel - * This will enforce secureops etc on the user - */ - for (std::list<ChannelMode *>::iterator it = Status.begin(), it_end = Status.end(); it != it_end; ++it) - c->SetModeInternal(source, *it, buf); - - /* Now set whatever modes this user is allowed to have on the channel */ - chan_set_correct_modes(u, c, 1, true); - - /* Check to see if modules want the user to join, if they do - * check to see if they are allowed to join (CheckKick will kick/ban them) - * Don't trigger OnJoinChannel event then as the user will be destroyed - */ - if (MOD_RESULT != EVENT_STOP && c->ci && c->ci->CheckKick(u)) - continue; - - FOREACH_MOD(I_OnJoinChannel, OnJoinChannel(u, c)); + users.push_back(sju); } } - /* Channel is done syncing */ - if (c->HasFlag(CH_SYNCING)) - { - /* Unset the syncing flag */ - c->UnsetFlag(CH_SYNCING); - c->Sync(); - } + time_t ts = Anope::string(params[0]).is_pos_number_only() ? convertTo<time_t>(params[0]) : Anope::CurTime; + Message::Join::SJoin(source, params[1], ts, modes, users); return true; } @@ -555,11 +488,11 @@ struct IRCDMessageSJoin : IRCDMessage struct IRCDMessageTopic : IRCDMessage { - IRCDMessageTopic() : IRCDMessage("TOPIC", 4) { } + IRCDMessageTopic(Module *creator) : IRCDMessage(creator, "TOPIC", 4) { } bool Run(MessageSource &, const std::vector<Anope::string> ¶ms) anope_override { - Channel *c = findchan(params[0]); + Channel *c = Channel::Find(params[0]); if (c) c->ChangeTopicInternal(params[1], params[3], Anope::string(params[2]).is_pos_number_only() ? convertTo<time_t>(params[2]) : Anope::CurTime); return true; @@ -571,23 +504,22 @@ class ProtoBahamut : public Module BahamutIRCdProto ircd_proto; /* Core message handlers */ - CoreIRCDMessageAway core_message_away; - CoreIRCDMessageCapab core_message_capab; - CoreIRCDMessageError core_message_error; - CoreIRCDMessageJoin core_message_join; - CoreIRCDMessageKick core_message_kick; - CoreIRCDMessageKill core_message_kill; - CoreIRCDMessageMOTD core_message_motd; - CoreIRCDMessagePart core_message_part; - CoreIRCDMessagePing core_message_ping; - CoreIRCDMessagePrivmsg core_message_privmsg; - CoreIRCDMessageQuit core_message_quit; - CoreIRCDMessageSQuit core_message_squit; - CoreIRCDMessageStats core_message_stats; - CoreIRCDMessageTime core_message_time; - CoreIRCDMessageTopic core_message_topic; - CoreIRCDMessageVersion core_message_version; - CoreIRCDMessageWhois core_message_whois; + Message::Away message_away; + Message::Capab message_capab; + Message::Error message_error; + Message::Join message_join; + Message::Kick message_kick; + Message::Kill message_kill; + Message::MOTD message_motd; + Message::Part message_part; + Message::Ping message_ping; + Message::Privmsg message_privmsg; + Message::Quit message_quit; + Message::SQuit message_squit; + Message::Stats message_stats; + Message::Time message_time; + Message::Version message_version; + Message::Whois message_whois; /* Our message handlers */ IRCDMessageBurst message_burst; @@ -636,7 +568,13 @@ class ProtoBahamut : public Module public: ProtoBahamut(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL), - message_mode("MODE"), message_svsmode("SVSMODE") + message_away(this), message_capab(this), message_error(this), message_join(this), + message_kick(this), message_kill(this), message_motd(this), message_part(this), + message_ping(this), message_privmsg(this), message_quit(this), message_squit(this), + message_stats(this), message_time(this), message_version(this), message_whois(this), + + message_burst(this), message_mode(this, "MODE"), message_svsmode(this, "SVSMODE"), + message_nick(this), message_server(this), message_sjoin(this), message_topic(this) { this->SetAuthor("Anope"); @@ -645,10 +583,15 @@ class ProtoBahamut : public Module ModuleManager::Attach(I_OnUserNickChange, this); } + IRCDProto *GetIRCDProto() anope_override + { + return &ircd_proto; + } + void OnUserNickChange(User *u, const Anope::string &) anope_override { u->RemoveModeInternal(ModeManager::FindUserModeByName(UMODE_REGISTERED)); - ircdproto->SendLogout(u); + IRCD->SendLogout(u); } }; diff --git a/modules/protocol/hybrid.cpp b/modules/protocol/hybrid.cpp index d3d67d84e..1161db3fa 100644 --- a/modules/protocol/hybrid.cpp +++ b/modules/protocol/hybrid.cpp @@ -37,44 +37,40 @@ class HybridProto : public IRCDProto UplinkSocket::Message(bi) << "PRIVMSG $$" << dest->GetName() << " :" << msg; } - void SendSQLine(User *, const XLine *x) anope_override + void SendGlobopsInternal(const BotInfo *source, const Anope::string &buf) anope_override { - const BotInfo *bi = findbot(Config->OperServ); + UplinkSocket::Message(source) << "OPERWALL :" << buf; + } - UplinkSocket::Message(bi) << "RESV * " << x->Mask << " :" << x->GetReason(); + void SendSQLine(User *, const XLine *x) anope_override + { + UplinkSocket::Message(OperServ) << "RESV * " << x->mask << " :" << x->GetReason(); } void SendSGLineDel(const XLine *x) anope_override { - const BotInfo *bi = findbot(Config->OperServ); - - UplinkSocket::Message(bi) << "UNXLINE * " << x->Mask; + UplinkSocket::Message(OperServ) << "UNXLINE * " << x->mask; } void SendSGLine(User *, const XLine *x) anope_override { - const BotInfo *bi = findbot(Config->OperServ); - - UplinkSocket::Message(bi) << "XLINE * " << x->Mask << " 0 :" << x->GetReason(); + UplinkSocket::Message(OperServ) << "XLINE * " << x->mask << " 0 :" << x->GetReason(); } void SendSZLineDel(const XLine *x) anope_override { - const BotInfo *bi = findbot(Config->OperServ); - - UplinkSocket::Message(bi) << "UNDLINE * " << x->GetHost(); + UplinkSocket::Message(OperServ) << "UNDLINE * " << x->GetHost(); } void SendSZLine(User *, const XLine *x) anope_override { - const BotInfo *bi = findbot(Config->OperServ); /* Calculate the time left before this would expire, capping it at 2 days */ - time_t timeleft = x->Expires - Anope::CurTime; + time_t timeleft = x->expires - Anope::CurTime; - if (timeleft > 172800 || !x->Expires) + if (timeleft > 172800 || !x->expires) timeleft = 172800; - UplinkSocket::Message(bi) << "DLINE * " << timeleft << " " << x->GetHost() << " :" << x->GetReason(); + UplinkSocket::Message(OperServ) << "DLINE * " << timeleft << " " << x->GetHost() << " :" << x->GetReason(); } void SendAkillDel(const XLine *x) anope_override @@ -82,16 +78,12 @@ class HybridProto : public IRCDProto if (x->IsRegex() || x->HasNickOrReal()) return; - const BotInfo *bi = findbot(Config->OperServ); - - UplinkSocket::Message(bi) << "UNKLINE * " << x->GetUser() << " " << x->GetHost(); + UplinkSocket::Message(OperServ) << "UNKLINE * " << x->GetUser() << " " << x->GetHost(); } void SendSQLineDel(const XLine *x) anope_override { - const BotInfo *bi = findbot(Config->OperServ); - - UplinkSocket::Message(bi) << "UNRESV * " << x->Mask; + UplinkSocket::Message(OperServ) << "UNRESV * " << x->mask; } void SendJoin(const User *user, Channel *c, const ChannelStatus *status) anope_override @@ -111,14 +103,12 @@ class HybridProto : public IRCDProto UserContainer *uc = c->FindUser(user); if (uc != NULL) - *uc->Status = *status; + *uc->status = *status; } } void SendAkill(User *u, XLine *x) anope_override { - const BotInfo *bi = findbot(Config->OperServ); - if (x->IsRegex() || x->HasNickOrReal()) { if (!u) @@ -140,32 +130,35 @@ class HybridProto : public IRCDProto return; /* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */ - XLine *xline = new XLine("*@" + u->host, old->By, old->Expires, old->Reason, old->UID); + XLine *xline = new XLine("*@" + u->host, old->by, old->expires, old->reason, old->id); old->manager->AddXLine(xline); x = xline; - Log(bi, "akill") << "AKILL: Added an akill for " << x->Mask << " because " << u->GetMask() << "#" - << u->realname << " matches " << old->Mask; + Log(OperServ, "akill") << "AKILL: Added an akill for " << x->mask << " because " << u->GetMask() << "#" + << u->realname << " matches " << old->mask; } /* Calculate the time left before this would expire, capping it at 2 days */ - time_t timeleft = x->Expires - Anope::CurTime; + time_t timeleft = x->expires - Anope::CurTime; - if (timeleft > 172800 || !x->Expires) + if (timeleft > 172800 || !x->expires) timeleft = 172800; - UplinkSocket::Message(bi) << "KLINE * " << timeleft << " " << x->GetUser() << " " << x->GetHost() << " :" << x->GetReason(); + UplinkSocket::Message(OperServ) << "KLINE * " << timeleft << " " << x->GetUser() << " " << x->GetHost() << " :" << x->GetReason(); } void SendServer(const Server *server) anope_override { - UplinkSocket::Message() << "SERVER " << server->GetName() << " " << server->GetHops() << " :" << server->GetDescription(); + if (server == Me) + UplinkSocket::Message() << "SERVER " << server->GetName() << " " << server->GetHops() << " :" << server->GetDescription(); + else + UplinkSocket::Message(Me) << "SID " << server->GetName() << " " << server->GetHops() << " " << server->GetSID() << " :" << server->GetDescription(); } void SendConnect() anope_override { - UplinkSocket::Message() << "PASS " << Config->Uplinks[CurrentUplink]->password << " TS 6 :" << Me->GetSID(); + UplinkSocket::Message() << "PASS " << Config->Uplinks[Anope::CurrentUplink]->password << " TS 6 :" << Me->GetSID(); /* * As of October 13, 2012, ircd-hybrid-8 does support the following capabilities @@ -213,16 +206,12 @@ class HybridProto : public IRCDProto void SendLogin(User *u) anope_override { - const BotInfo *ns = findbot(Config->NickServ); - - ircdproto->SendMode(ns, u, "+d %s", u->Account()->display.c_str()); + IRCD->SendMode(NickServ, u, "+d %s", u->Account()->display.c_str()); } void SendLogout(User *u) anope_override { - const BotInfo *ns = findbot(Config->NickServ); - - ircdproto->SendMode(ns, u, "+d 0"); + IRCD->SendMode(NickServ, u, "+d 0"); } void SendChannel(Channel *c) anope_override @@ -256,13 +245,13 @@ class HybridProto : public IRCDProto struct IRCDMessageBMask : IRCDMessage { - IRCDMessageBMask() : IRCDMessage("BMASK", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + IRCDMessageBMask(Module *creator) : IRCDMessage(creator, "BMASK", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } /* 0 1 2 3 */ /* :0MC BMASK 1350157102 #channel b :*!*@*.test.com */ bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { - Channel *c = findchan(params[1]); + Channel *c = Channel::Find(params[1]); if (c) { @@ -270,20 +259,16 @@ struct IRCDMessageBMask : IRCDMessage *except = ModeManager::FindChannelModeByName(CMODE_EXCEPT), *invex = ModeManager::FindChannelModeByName(CMODE_INVITEOVERRIDE); - Anope::string bans = params[3]; - - int count = myNumToken(bans, ' '), i; - - for (i = 0; i < count; ++i) + spacesepstream bans(params[3]); + Anope::string token; + while (bans.GetToken(token)) { - Anope::string b = myStrGetToken(bans, ' ', i); - if (ban && params[2].equals_cs("b")) - c->SetModeInternal(source, ban, b); + c->SetModeInternal(source, ban, token); else if (except && params[2].equals_cs("e")) - c->SetModeInternal(source, except, b); + c->SetModeInternal(source, except, token); else if (invex && params[2].equals_cs("I")) - c->SetModeInternal(source, invex, b); + c->SetModeInternal(source, invex, token); } } @@ -291,57 +276,36 @@ struct IRCDMessageBMask : IRCDMessage } }; -struct IRCDMessageJoin : CoreIRCDMessageJoin +struct IRCDMessageEOB : IRCDMessage { - IRCDMessageJoin() : CoreIRCDMessageJoin("JOIN") { } + IRCDMessageEOB(Module *craetor) : IRCDMessage(craetor, "EOB", 0) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { - if (params.size() < 2) - return true; - - std::vector<Anope::string> p = params; - p.erase(p.begin()); - - return CoreIRCDMessageJoin::Run(source, p); + source.GetServer()->Sync(true); + return true; } }; -struct IRCDMessageMode : IRCDMessage +struct IRCDMessageJoin : Message::Join { - IRCDMessageMode(const Anope::string &n) : IRCDMessage(n, 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + IRCDMessageJoin(Module *creator) : Message::Join(creator, "JOIN") { } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { - if (params.size() > 2 && ircdproto->IsChannelValid(params[0])) - { - Channel *c = findchan(params[0]); - time_t ts = 0; - - try - { - ts = convertTo<time_t>(params[1]); - } - catch (const ConvertException &) { } - - if (c) - c->SetModesInternal(source, params[2], ts); - } - else - { - User *u = finduser(params[0]); + if (params.size() < 2) + return true; - if (u) - u->SetModesInternal("%s", params[1].c_str()); - } + std::vector<Anope::string> p = params; + p.erase(p.begin()); - return true; + return Message::Join::Run(source, p); } }; struct IRCDMessageNick : IRCDMessage { - IRCDMessageNick() : IRCDMessage("NICK", 2) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + IRCDMessageNick(Module *creator) : IRCDMessage(creator, "NICK", 2) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } /* 0 1 */ /* :0MCAAAAAB NICK newnick 1350157102 */ @@ -354,7 +318,7 @@ struct IRCDMessageNick : IRCDMessage struct IRCDMessagePass : IRCDMessage { - IRCDMessagePass() : IRCDMessage("PASS", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + IRCDMessagePass(Module *creator) : IRCDMessage(creator, "PASS", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } /* 0 1 2 3 */ /* PASS password TS 6 0MC */ @@ -367,7 +331,7 @@ struct IRCDMessagePass : IRCDMessage struct IRCDMessagePong : IRCDMessage { - IRCDMessagePong() : IRCDMessage("PONG", 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + IRCDMessagePong(Module *creator) : IRCDMessage(creator, "PONG", 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { @@ -378,7 +342,7 @@ struct IRCDMessagePong : IRCDMessage struct IRCDMessageServer : IRCDMessage { - IRCDMessageServer() : IRCDMessage("SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } /* 0 1 2 */ /* SERVER hades.arpa 1 :ircd-hybrid test server */ @@ -390,14 +354,14 @@ struct IRCDMessageServer : IRCDMessage new Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], 1, params[2], UplinkSID); - ircdproto->SendPing(Config->ServerName, params[0]); + IRCD->SendPing(Config->ServerName, params[0]); return true; } }; struct IRCDMessageSID : IRCDMessage { - IRCDMessageSID() : IRCDMessage("SID", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + IRCDMessageSID(Module *creator) : IRCDMessage(creator, "SID", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } /* 0 1 2 3 */ /* :0MC SID hades.arpa 2 4XY :ircd-hybrid test server */ @@ -406,64 +370,37 @@ struct IRCDMessageSID : IRCDMessage unsigned int hops = params[1].is_pos_number_only() ? convertTo<unsigned>(params[1]) : 0; new Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], hops, params[3], params[2]); - ircdproto->SendPing(Config->ServerName, params[0]); + IRCD->SendPing(Config->ServerName, params[0]); return true; } }; -struct IRCDMessageSjoin : IRCDMessage +struct IRCDMessageSJoin : IRCDMessage { - IRCDMessageSjoin() : IRCDMessage("SJOIN", 2) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + IRCDMessageSJoin(Module *creator) : IRCDMessage(creator, "SJOIN", 2) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { - Channel *c = findchan(params[1]); - time_t ts = Anope::string(params[0]).is_pos_number_only() ? convertTo<time_t>(params[0]) : 0; - bool keep_their_modes = true; - - if (!c) - { - c = new Channel(params[1], ts); - c->SetFlag(CH_SYNCING); - } - /* Our creation time is newer than what the server gave us */ - else if (c->creation_time > ts) - { - c->creation_time = ts; - c->Reset(); - } - /* Their TS is newer than ours, our modes > theirs, unset their modes if need be */ - else if (ts > c->creation_time) - keep_their_modes = false; - - /* If we need to keep their modes, and this SJOIN string contains modes */ - if (keep_their_modes && params.size() >= 3) - { - Anope::string modes; - + 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()); - if (!modes.empty()) - modes.erase(modes.begin()); - - /* Set the modes internally */ - c->SetModesInternal(source, modes); - } + std::list<Message::Join::SJoinUser> users; spacesepstream sep(params[params.size() - 1]); Anope::string buf; while (sep.GetToken(buf)) { - std::list<ChannelMode *> Status; - char ch; + Message::Join::SJoinUser sju; /* Get prefixes from the nick */ - while ((ch = ModeManager::GetStatusChar(buf[0]))) + for (char ch; (ch = ModeManager::GetStatusChar(buf[0]));) { buf.erase(buf.begin()); - ChannelMode *cm = ModeManager::FindChannelModeByChar(ch); if (!cm) @@ -472,66 +409,60 @@ struct IRCDMessageSjoin : IRCDMessage continue; } - if (keep_their_modes) - Status.push_back(cm); + sju.first.SetFlag(cm->name); } - User *u = finduser(buf); - - if (!u) + sju.second = User::Find(buf); + if (!sju.second) { - Log(LOG_DEBUG) << "SJOIN for nonexistant user " << buf << " on " << c->name; + Log(LOG_DEBUG) << "SJOIN for nonexistant user " << buf << " on " << params[1]; continue; } - EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnPreJoinChannel, OnPreJoinChannel(u, c)); - - /* Add the user to the channel */ - c->JoinUser(u); - - /* - * Update their status internally on the channel - * This will enforce secureops etc on the user - */ - for (std::list<ChannelMode *>::iterator it = Status.begin(), it_end = Status.end(); it != it_end; ++it) - c->SetModeInternal(source, *it, buf); + users.push_back(sju); + } - /* Now set whatever modes this user is allowed to have on the channel */ - chan_set_correct_modes(u, c, 1, true); + time_t ts = Anope::string(params[0]).is_pos_number_only() ? convertTo<time_t>(params[0]) : Anope::CurTime; + Message::Join::SJoin(source, params[1], ts, modes, users); - /* - * Check to see if modules want the user to join, if they do - * check to see if they are allowed to join (CheckKick will kick/ban them) - * Don't trigger OnJoinChannel event then as the user will be destroyed - */ - if (MOD_RESULT != EVENT_STOP && c->ci && c->ci->CheckKick(u)) - continue; + return true; + } +}; - FOREACH_MOD(I_OnJoinChannel, OnJoinChannel(u, c)); - } +struct IRCDMessageSVSMode : IRCDMessage +{ + IRCDMessageSVSMode(Module *creator) : IRCDMessage(creator, "SVSMODE", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + /* + * parv[0] = nickname + * parv[1] = TS + * parv[2] = mode + * parv[3] = optional argument (services id) + */ + bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + { + User *u = User::Find(params[0]); + if (!u) + return true; - /* Channel is done syncing */ - if (c->HasFlag(CH_SYNCING)) - { - /* Unset the syncing flag */ - c->UnsetFlag(CH_SYNCING); - c->Sync(); - } + if (!params[1].is_pos_number_only() || convertTo<time_t>(params[1]) != u->timestamp) + return true; + u->SetModesInternal("%s", params[2].c_str()); return true; } }; struct IRCDMessageTBurst : IRCDMessage { - IRCDMessageTBurst() : IRCDMessage("TBURST", 5) { } + IRCDMessageTBurst(Module *creator) : IRCDMessage(creator, "TBURST", 5) { } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { - Anope::string setter = myStrGetToken(params[3], '!', 0); + Anope::string setter; + sepstream(params[3], '!').GetToken(setter, 0); time_t topic_time = Anope::string(params[2]).is_pos_number_only() ? convertTo<time_t>(params[2]) : Anope::CurTime; - Channel *c = findchan(params[1]); + Channel *c = Channel::Find(params[1]); if (c) c->ChangeTopicInternal(setter, params[4], topic_time); @@ -542,7 +473,7 @@ struct IRCDMessageTBurst : IRCDMessage struct IRCDMessageTMode : IRCDMessage { - IRCDMessageTMode() : IRCDMessage("TMODE", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + IRCDMessageTMode(Module *creator) : IRCDMessage(creator, "TMODE", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { @@ -554,7 +485,7 @@ struct IRCDMessageTMode : IRCDMessage } catch (const ConvertException &) { } - Channel *c = findchan(params[1]); + Channel *c = Channel::Find(params[1]); Anope::string modes = params[2]; for (unsigned i = 3; i < params.size(); ++i) @@ -569,7 +500,7 @@ struct IRCDMessageTMode : IRCDMessage struct IRCDMessageUID : IRCDMessage { - IRCDMessageUID() : IRCDMessage("UID", 10) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + IRCDMessageUID(Module *creator) : IRCDMessage(creator, "UID", 10) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } /* 0 1 2 3 4 5 6 7 8 9 */ /* :0MC UID Steve 1 1350157102 +oi ~steve resolved.host 10.0.0.1 0MCAAAAAB 1350157108 :Mining all the time */ @@ -586,22 +517,22 @@ struct IRCDMessageUID : IRCDMessage params[9], params[2].is_pos_number_only() ? convertTo<time_t>(params[2]) : 0, params[3], params[7]); - if (user && nickserv) + if (user && NickServService) { const NickAlias *na = NULL; if (params[8] != "0") - na = findnick(params[8]); + na = NickAlias::Find(params[8]); if (na) { user->Login(na->nc); if (!Config->NoNicknameOwnership && na->nc->HasFlag(NI_UNCONFIRMED) == false) - user->SetMode(findbot(Config->NickServ), UMODE_REGISTERED); + user->SetMode(NickServ, UMODE_REGISTERED); } else - nickserv->Validate(user); + NickServService->Validate(user); } return true; @@ -613,33 +544,35 @@ class ProtoHybrid : public Module HybridProto ircd_proto; /* Core message handlers */ - CoreIRCDMessageAway core_message_away; - CoreIRCDMessageCapab core_message_capab; - CoreIRCDMessageError core_message_error; - CoreIRCDMessageKick core_message_kick; - CoreIRCDMessageKill core_message_kill; - CoreIRCDMessageMOTD core_message_motd; - CoreIRCDMessagePart core_message_part; - CoreIRCDMessagePing core_message_ping; - CoreIRCDMessagePrivmsg core_message_privmsg; - CoreIRCDMessageQuit core_message_quit; - CoreIRCDMessageSQuit core_message_squit; - CoreIRCDMessageStats core_message_stats; - CoreIRCDMessageTime core_message_time; - CoreIRCDMessageTopic core_message_topic; - CoreIRCDMessageVersion core_message_version; - CoreIRCDMessageWhois core_message_whois; + Message::Away message_away; + Message::Capab message_capab; + Message::Error message_error; + Message::Kick message_kick; + Message::Kill message_kill; + Message::Mode message_mode; + Message::MOTD message_motd; + Message::Part message_part; + Message::Ping message_ping; + Message::Privmsg message_privmsg; + Message::Quit message_quit; + Message::SQuit message_squit; + Message::Stats message_stats; + Message::Time message_time; + Message::Topic message_topic; + Message::Version message_version; + Message::Whois message_whois; /* Our message handlers */ IRCDMessageBMask message_bmask; + IRCDMessageEOB message_eob; IRCDMessageJoin message_join; - IRCDMessageMode message_mode, message_svsmode; IRCDMessageNick message_nick; IRCDMessagePass message_pass; IRCDMessagePong message_pong; IRCDMessageServer message_server; IRCDMessageSID message_sid; - IRCDMessageSjoin message_sjoin; + IRCDMessageSJoin message_sjoin; + IRCDMessageSVSMode message_svsmode; IRCDMessageTBurst message_tburst; IRCDMessageTMode message_tmode; IRCDMessageUID message_uid; @@ -663,12 +596,15 @@ class ProtoHybrid : public Module /* v/h/o/a/q */ ModeManager::AddChannelMode(new ChannelModeStatus(CMODE_VOICE, 'v', '+', 0)); - ModeManager::AddChannelMode(new ChannelModeStatus(CMODE_OP, 'o', '@', 1)); + ModeManager::AddChannelMode(new ChannelModeStatus(CMODE_HALFOP, 'h', '%', 1)); + ModeManager::AddChannelMode(new ChannelModeStatus(CMODE_OP, 'o', '@', 2)); + + /* l/k */ + ModeManager::AddChannelMode(new ChannelModeParam(CMODE_LIMIT, 'l')); + ModeManager::AddChannelMode(new ChannelModeKey('k')); /* Add channel modes */ ModeManager::AddChannelMode(new ChannelMode(CMODE_INVITE, 'i')); - ModeManager::AddChannelMode(new ChannelModeKey('k')); - ModeManager::AddChannelMode(new ChannelModeParam(CMODE_LIMIT, 'l')); ModeManager::AddChannelMode(new ChannelMode(CMODE_MODERATED, 'm')); ModeManager::AddChannelMode(new ChannelMode(CMODE_NOEXTERNAL, 'n')); ModeManager::AddChannelMode(new ChannelMode(CMODE_PRIVATE, 'p')); @@ -681,8 +617,15 @@ class ProtoHybrid : public Module } public: - ProtoHybrid(const Anope::string &modname, const Anope::string &creator) : - Module(modname, creator, PROTOCOL), message_mode("MODE"), message_svsmode("SVSMODE") + ProtoHybrid(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL), + message_away(this), message_capab(this), message_error(this), message_kick(this), message_kill(this), + message_mode(this), message_motd(this), message_part(this), message_ping(this), message_privmsg(this), + message_quit(this), message_squit(this), message_stats(this), message_time(this), message_topic(this), + message_version(this), message_whois(this), + + message_bmask(this), message_eob(this), message_join(this), + message_nick(this), message_pass(this), message_pong(this), message_server(this), message_sid(this), + message_sjoin(this), message_svsmode(this), message_tburst(this), message_tmode(this), message_uid(this) { this->SetAuthor("Anope"); this->AddModes(); @@ -691,7 +634,7 @@ public: if (Config->Numeric.empty()) { - Anope::string numeric = ts6_sid_retrieve(); + Anope::string numeric = Servers::TS6_SID_Retrieve(); Me->SetSID(numeric); Config->Numeric = numeric; } @@ -700,10 +643,14 @@ public: it->second->GenerateUID(); } + IRCDProto *GetIRCDProto() anope_override + { + return &ircd_proto; + } + void OnUserNickChange(User *u, const Anope::string &) anope_override { u->RemoveModeInternal(ModeManager::FindUserModeByName(UMODE_REGISTERED)); - ircdproto->SendLogout(u); } }; diff --git a/modules/protocol/inspircd-ts6.h b/modules/protocol/inspircd-ts6.h deleted file mode 100644 index 7e0fe971d..000000000 --- a/modules/protocol/inspircd-ts6.h +++ /dev/null @@ -1,817 +0,0 @@ -/* Inspircd 1.2+ generic TS6 functions - * - * (C) 2003-2012 Anope Team - * Contact us at team@anope.org - * - * Please read COPYING and README for further details. - * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. - */ - -class ChannelModeFlood : public ChannelModeParam -{ - public: - ChannelModeFlood(char modeChar, bool minusNoArg) : ChannelModeParam(CMODE_FLOOD, modeChar, minusNoArg) { } - - bool IsValid(const Anope::string &value) const anope_override - { - try - { - Anope::string rest; - if (!value.empty() && value[0] != ':' && convertTo<int>(value[0] == '*' ? value.substr(1) : value, rest, false) > 0 && rest[0] == ':' && rest.length() > 1 && convertTo<int>(rest.substr(1), rest, false) > 0 && rest.empty()) - return true; - } - catch (const ConvertException &) { } - - return false; - } -}; - -class InspIRCdTS6Proto : public IRCDProto -{ - private: - void SendChgIdentInternal(const Anope::string &nick, const Anope::string &vIdent) - { - if (!has_chgidentmod) - Log() << "CHGIDENT not loaded!"; - else - UplinkSocket::Message(findbot(Config->HostServ)) << "CHGIDENT " << nick << " " << vIdent; - } - - void SendChgHostInternal(const Anope::string &nick, const Anope::string &vhost) - { - if (!has_chghostmod) - Log() << "CHGHOST not loaded!"; - else - UplinkSocket::Message(Me) << "CHGHOST " << nick << " " << vhost; - } - - void SendAddLine(const Anope::string &type, const Anope::string &mask, time_t duration, const Anope::string &addedby, const Anope::string &reason) - { - UplinkSocket::Message(Me) << "ADDLINE " << type << " " << mask << " " << addedby << " " << Anope::CurTime << " " << duration << " :" << reason; - } - - void SendDelLine(const Anope::string &type, const Anope::string &mask) - { - UplinkSocket::Message(Me) << "DELLINE " << type << " " << mask; - } - - protected: - InspIRCdTS6Proto(const Anope::string &name) : IRCDProto(name) - { - DefaultPseudoclientModes = "+I"; - CanSVSNick = true; - CanSetVHost = true; - CanSetVIdent = true; - CanSQLine = true; - CanSZLine = true; - CanSVSHold = true; - CanCertFP = true; - RequiresID = true; - MaxModes = 20; - } - - void SendGlobalNotice(const BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override - { - UplinkSocket::Message(bi) << "NOTICE $" << dest->GetName() << " :" << msg; - } - - void SendGlobalPrivmsg(const 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 */ - if (x->IsRegex() && has_rlinemod) - { - Anope::string mask = x->Mask; - size_t h = x->Mask.find('#'); - if (h != Anope::string::npos) - mask = mask.replace(h, 1, ' '); - SendDelLine("R", mask); - return; - } - else if (x->IsRegex() || x->HasNickOrReal()) - return; - - SendDelLine("G", x->Mask); - } - - void SendTopic(BotInfo *whosets, Channel *c) anope_override - { - if (has_svstopic_topiclock) - { - 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(whosets) << "FTOPIC " << c->name << " " << ts << " " << c->topic_setter << " :" << c->topic; - } - } - - void SendVhostDel(User *u) anope_override - { - if (u->HasMode(UMODE_CLOAK)) - this->SendChgHostInternal(u->nick, u->chost); - else - this->SendChgHostInternal(u->nick, u->host); - - if (has_chgidentmod && u->GetIdent() != u->GetVIdent()) - this->SendChgIdentInternal(u->nick, u->GetIdent()); - } - - 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; - - const BotInfo *bi = findbot(Config->OperServ); - /* InspIRCd may support regex bans, if they do we can send this and forget about it */ - if (x->IsRegex() && has_rlinemod) - { - Anope::string mask = x->Mask; - size_t h = x->Mask.find('#'); - if (h != Anope::string::npos) - mask = mask.replace(h, 1, ' '); - 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->UID); - old->manager->AddXLine(x); - - Log(bi, "akill") << "AKILL: Added an akill for " << x->Mask << " because " << u->GetMask() << "#" << u->realname << " matches " << old->Mask; - } - - /* ZLine if we can instead */ - try - { - if (x->GetUser() == "*") - { - sockaddrs(x->GetHost()); - ircdproto->SendSZLine(u, x); - return; - } - } - catch (const SocketException &) { } - 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 - { - UplinkSocket::Message() << "PUSH " << dest << " ::" << Me->GetName() << " " << numeric << " " << dest << " " << buf; - } - - void SendModeInternal(const BotInfo *source, const Channel *dest, const Anope::string &buf) anope_override - { - UplinkSocket::Message(source) << "FMODE " << dest->name << " " << dest->creation_time << " " << buf; - } - - void SendModeInternal(const BotInfo *bi, const User *u, const Anope::string &buf) anope_override - { - UplinkSocket::Message(bi) << "MODE " << u->GetUID() << " " << buf; - } - - void SendClientIntroduction(const 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; - } - - /* SERVER services-dev.chatspike.net password 0 :Description here */ - void SendServer(const Server *server) anope_override - { - UplinkSocket::Message() << "SERVER " << server->GetName() << " " << Config->Uplinks[CurrentUplink]->password << " " << server->GetHops() << " " << server->GetSID() << " :" << server->GetDescription(); - } - - /* JOIN */ - void SendJoin(const 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. - */ - UserContainer *uc = c->FindUser(user); - if (uc != NULL) - uc->Status->ClearFlags(); - - BotInfo *setter = findbot(user->nick); - for (unsigned i = 0; i < ModeManager::ChannelModes.size(); ++i) - if (cs.HasFlag(ModeManager::ChannelModes[i]->Name)) - c->SetMode(setter, ModeManager::ChannelModes[i], user->GetUID(), false); - } - } - - /* UNSQLINE */ - void SendSQLineDel(const XLine *x) anope_override - { - SendDelLine("Q", x->Mask); - } - - /* SQLINE */ - void SendSQLine(User *, 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()); - } - - /* Functions that use serval cmd functions */ - - 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 SendConnect() anope_override - { - SendServer(Me); - UplinkSocket::Message(Me) << "BURST"; - Module *enc = ModuleManager::FindFirstOf(ENCRYPTION); - UplinkSocket::Message(Me) << "VERSION :Anope-" << Anope::Version() << " " << Config->ServerName << " :" << ircdproto->GetProtocolName() << " - (" << (enc ? enc->name : "unknown") << ") -- " << Anope::VersionBuildString(); - } - - /* SVSHOLD - set */ - void SendSVSHold(const Anope::string &nick) anope_override - { - const BotInfo *bi = findbot(Config->NickServ); - if (bi) - UplinkSocket::Message(bi) << "SVSHOLD " << nick << " " << Config->NSReleaseTimeout << " :Being held for registered user"; - } - - /* SVSHOLD - release */ - void SendSVSHoldDel(const Anope::string &nick) anope_override - { - const BotInfo *bi = findbot(Config->NickServ); - if (bi) - UplinkSocket::Message(bi) << "SVSHOLD " << nick; - } - - /* UNSZLINE */ - void SendSZLineDel(const XLine *x) anope_override - { - SendDelLine("Z", x->GetHost()); - } - - /* SZLINE */ - void SendSZLine(User *, 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 BotInfo *source, const Anope::string &nick, const Anope::string &chan, const Anope::string &) anope_override - { - User *u = finduser(nick); - UplinkSocket::Message(source) << "SVSJOIN " << u->GetUID() << " " << chan; - } - - void SendSWhois(const BotInfo *, const Anope::string &who, const Anope::string &mask) anope_override - { - User *u = finduser(who); - - UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " swhois :" << mask; - } - - void SendBOB() anope_override - { - UplinkSocket::Message(Me) << "BURST " << Anope::CurTime; - } - - void SendEOB() anope_override - { - UplinkSocket::Message(Me) << "ENDBURST"; - } - - void SendGlobopsInternal(const BotInfo *source, const Anope::string &buf) - { - if (has_globopsmod) - UplinkSocket::Message(source) << "SNONOTICE g :" << buf; - else - UplinkSocket::Message(source) << "SNONOTICE A :" << buf; - } - - void SendLogin(User *u) anope_override - { - if (!u->Account() || u->Account()->HasFlag(NI_UNCONFIRMED)) - return; - - UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " accountname :" << u->Account()->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) << " :"; - } - - bool IsNickValid(const Anope::string &nick) anope_override - { - /* InspIRCd, like TS6, uses UIDs on collision, so... */ - if (isdigit(nick[0])) - return false; - - return true; - } - - void SendOper(User *u) anope_override - { - } -}; - -struct IRCDMessageEndburst : IRCDMessage -{ - IRCDMessageEndburst() : IRCDMessage("ENDBURST", 0) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - - bool 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); - return true; - } -}; - -struct IRCDMessageFHost : IRCDMessage -{ - IRCDMessageFHost(const Anope::string &n) : IRCDMessage(n, 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - source.GetUser()->SetDisplayedHost(params[0]); - return true; - } -}; - -struct IRCDMessageFJoin : IRCDMessage -{ - IRCDMessageFJoin() : IRCDMessage("FJOIN", 2) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - Channel *c = findchan(params[0]); - time_t ts = Anope::string(params[1]).is_pos_number_only() ? convertTo<time_t>(params[1]) : 0; - bool keep_their_modes = true; - - if (!c) - { - c = new Channel(params[0], ts); - c->SetFlag(CH_SYNCING); - } - /* Our creation time is newer than what the server gave us */ - else if (c->creation_time > ts) - { - c->creation_time = ts; - c->Reset(); - } - /* Their TS is newer than ours, our modes > theirs, unset their modes if need be */ - else if (ts > c->creation_time) - keep_their_modes = false; - - /* If we need to keep their modes, and this FJOIN string contains modes */ - if (keep_their_modes && params.size() >= 3) - { - Anope::string modes; - for (unsigned i = 2; i < params.size() - 1; ++i) - modes += " " + params[i]; - if (!modes.empty()) - modes.erase(modes.begin()); - /* Set the modes internally */ - c->SetModesInternal(source, modes); - } - - spacesepstream sep(params[params.size() - 1]); - Anope::string buf; - while (sep.GetToken(buf)) - { - std::list<ChannelMode *> Status; - - /* Loop through prefixes and find modes for them */ - while (buf[0] != ',') - { - ChannelMode *cm = ModeManager::FindChannelModeByChar(buf[0]); - if (!cm) - { - Log() << "Received unknown mode prefix " << buf[0] << " in FJOIN string"; - buf.erase(buf.begin()); - continue; - } - - buf.erase(buf.begin()); - if (keep_their_modes) - Status.push_back(cm); - } - buf.erase(buf.begin()); - - User *u = finduser(buf); - if (!u) - { - Log(LOG_DEBUG) << "FJOIN for nonexistant user " << buf << " on " << c->name; - continue; - } - - EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnPreJoinChannel, OnPreJoinChannel(u, c)); - - /* Add the user to the channel */ - c->JoinUser(u); - - /* Update their status internally on the channel - * This will enforce secureops etc on the user - */ - for (std::list<ChannelMode *>::iterator it = Status.begin(), it_end = Status.end(); it != it_end; ++it) - c->SetModeInternal(source, *it, buf); - - /* Now set whatever modes this user is allowed to have on the channel */ - chan_set_correct_modes(u, c, 1, true); - - /* Check to see if modules want the user to join, if they do - * check to see if they are allowed to join (CheckKick will kick/ban them) - * Don't trigger OnJoinChannel event then as the user will be destroyed - */ - if (MOD_RESULT != EVENT_STOP && c->ci && c->ci->CheckKick(u)) - continue; - - FOREACH_MOD(I_OnJoinChannel, OnJoinChannel(u, c)); - } - - /* Channel is done syncing */ - if (c->HasFlag(CH_SYNCING)) - { - /* Unset the syncing flag */ - c->UnsetFlag(CH_SYNCING); - c->Sync(); - } - - return true; - } -}; - -struct IRCDMessageFMode : IRCDMessage -{ - IRCDMessageFMode() : IRCDMessage("FMODE", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - bool 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 = findchan(params[0]); - time_t ts; - - try - { - ts = convertTo<time_t>(params[1]); - } - catch (const ConvertException &) - { - ts = 0; - } - - if (c) - c->SetModesInternal(source, modes, ts); - - return true; - } -}; - -struct IRCDMessageFTopic : IRCDMessage -{ - IRCDMessageFTopic() : IRCDMessage("FTOPIC", 4) { } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - /* :source FTOPIC channel topicts setby :topic */ - - Channel *c = findchan(params[0]); - if (c) - c->ChangeTopicInternal(params[2], params[3], Anope::string(params[1]).is_pos_number_only() ? convertTo<time_t>(params[1]) : Anope::CurTime); - - return true; - } -}; - -struct IRCDMessageIdle : IRCDMessage -{ - IRCDMessageIdle() : IRCDMessage("IDLE", 1) { } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - const BotInfo *bi = findbot(params[0]); - if (bi) - UplinkSocket::Message(bi) << "IDLE " << source.GetSource() << " " << start_time << " " << (Anope::CurTime - bi->lastmsg); - return true; - } -}; - -/* - * source = numeric of the sending server - * params[0] = uuid - * params[1] = metadata name - * params[2] = data - */ -struct IRCDMessageMetadata : IRCDMessage -{ - IRCDMessageMetadata() : IRCDMessage("METADATA", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - if (isdigit(params[0][0])) - { - if (params[1].equals_cs("accountname")) - { - User *u = finduser(params[0]); - NickCore *nc = findcore(params[2]); - if (u && nc) - { - u->Login(nc); - - const BotInfo *bi = findbot(Config->NickServ); - const NickAlias *user_na = findnick(u->nick); - if (!Config->NoNicknameOwnership && nickserv && user_na && user_na->nc == nc && user_na->nc->HasFlag(NI_UNCONFIRMED) == false) - u->SetMode(bi, UMODE_REGISTERED); - - /* Sometimes a user connects, we send them the usual "this nickname is registered" mess (if - * their server isn't syncing) and then we receive this.. so tell them about it. - */ - if (u->server->IsSynced() && bi) - u->SendMessage(bi, _("You have been logged in as \2%s\2."), nc->display.c_str()); - } - } - - /* - * 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 = finduser(params[0]); - if (!u) - return true; - std::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(I_OnFingerprint, OnFingerprint(u)); - } - } - } - else if (params[0][0] == '#') - { - } - else if (params[0] == "*") - { - // Wed Oct 3 15:40:27 2012: S[14] O :20D METADATA * modules :-m_svstopic.so - - 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 true; - - bool plus = (params[2][0] == '+'); - if (!plus && params[2][0] != '-') - return true; - - bool required = false; - Anope::string 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")) - has_chghostmod = plus; - else if (module.equals_cs("m_chgident.so")) - has_chgidentmod = plus; - else if (module.equals_cs("m_svshold.so")) - ircdproto->CanSVSHold = plus; - else if (module.equals_cs("m_rline.so")) - has_rlinemod = plus; - else if (module.equals_cs("m_topiclock.so")) - has_svstopic_topiclock = plus; - else - return true; - - if (required) - { - if (!plus) - Log() << "Warning: InspIRCd unloaded module " << module << ", Anope won't function correctly without it"; - } - else - { - Log() << "InspIRCd " << (plus ? "loaded" : "unloaded") << " module " << module << ", adjusted functionality"; - } - - } - } - - return true; - } -}; - -struct IRCDMessageMode : IRCDMessage -{ - IRCDMessageMode() : IRCDMessage("MODE", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - if (ircdproto->IsChannelValid(params[0])) - { - Channel *c = findchan(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 = source.GetUser(); - // This can happen with server-origin modes. - if (!u) - u = finduser(params[0]); - // if it's still null, drop it like fire. - // most likely situation was that server introduced a nick which we subsequently akilled - if (u) - u->SetModesInternal("%s", params[1].c_str()); - } - - return true; - } -}; - -struct IRCDMessageNick : IRCDMessage -{ - IRCDMessageNick() : IRCDMessage("NICK", 2) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - source.GetUser()->ChangeNick(params[0]); - return true; - } -}; - -struct IRCDMessageOperType : IRCDMessage -{ - IRCDMessageOperType() : IRCDMessage("OPERTYPE", 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_USER); } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - /* opertype is equivalent to mode +o because servers - dont do this directly */ - User *u = source.GetUser(); - if (!u->HasMode(UMODE_OPER)) - u->SetModesInternal("+o"); - - return true; - } -}; - -struct IRCDMessageRSQuit : IRCDMessage -{ - IRCDMessageRSQuit() : IRCDMessage("RSQUIT", 1) { } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - Server *s = Server::Find(params[0]); - if (!s) - return true; - - /* On InspIRCd we must send a SQUIT when we recieve RSQUIT for a server we have juped */ - if (s->HasFlag(SERVER_JUPED)) - UplinkSocket::Message(Me) << "SQUIT " << s->GetSID() << " :" << (params.size() > 1 ? params[1].c_str() : ""); - - FOREACH_MOD(I_OnServerQuit, OnServerQuit(s)); - - s->Delete(s->GetName() + " " + s->GetUplink()->GetName()); - - return true; - } -}; - -struct IRCDMessageServer : IRCDMessage -{ - IRCDMessageServer() : IRCDMessage("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 - */ - bool 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]); - return true; - } -}; - -struct IRCDMessageTime : IRCDMessage -{ - IRCDMessageTime() : IRCDMessage("TIME", 2) { } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - UplinkSocket::Message(Me) << "TIME " << source.GetSource() << " " << params[1] << " " << Anope::CurTime; - return true; - } -}; - -struct IRCDMessageUID : IRCDMessage -{ - IRCDMessageUID() : IRCDMessage("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 - */ - bool 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]; - - User *u = new User(params[2], params[5], params[3], params[4], params[6], source.GetServer(), params[params.size() - 1], ts, modes, params[0]); - if (u->server->IsSynced() && nickserv) - nickserv->Validate(u); - - return true; - } -}; - diff --git a/modules/protocol/inspircd11.cpp b/modules/protocol/inspircd11.cpp index 1ac97ddcc..aaaec9fef 100644 --- a/modules/protocol/inspircd11.cpp +++ b/modules/protocol/inspircd11.cpp @@ -45,7 +45,7 @@ class InspIRCdProto : public IRCDProto { if (nick.empty() || vIdent.empty()) return; - UplinkSocket::Message(findbot(Config->OperServ)) << "CHGIDENT " << nick << " " << vIdent; + UplinkSocket::Message(OperServ) << "CHGIDENT " << nick << " " << vIdent; } else Log() << "CHGIDENT not loaded!"; @@ -57,7 +57,7 @@ class InspIRCdProto : public IRCDProto { if (nick.empty() || vhost.empty()) return; - UplinkSocket::Message(findbot(Config->OperServ)) << "CHGHOST " << nick << " " << vhost; + UplinkSocket::Message(OperServ) << "CHGHOST " << nick << " " << vhost; } else Log() << "CHGHOST not loaded!"; @@ -84,13 +84,13 @@ class InspIRCdProto : public IRCDProto if (x->GetUser() == "*") { sockaddrs(x->GetHost()); - ircdproto->SendSZLineDel(x); + IRCD->SendSZLineDel(x); return; } } catch (const SocketException &) { } - UplinkSocket::Message(findbot(Config->OperServ)) << "GLINE " << x->Mask; + UplinkSocket::Message(OperServ) << "GLINE " << x->mask; } void SendTopic(BotInfo *whosets, Channel *c) anope_override @@ -128,10 +128,10 @@ class InspIRCdProto : public IRCDProto 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->UID); + x = new XLine("*@" + u->host, old->by, old->expires, old->reason, old->id); old->manager->AddXLine(x); - Log(findbot(Config->OperServ), "akill") << "AKILL: Added an akill for " << x->Mask << " because " << u->GetMask() << "#" << u->realname << " matches " << old->Mask; + Log(OperServ, "akill") << "AKILL: Added an akill for " << x->mask << " because " << u->GetMask() << "#" << u->realname << " matches " << old->mask; } /* ZLine if we can instead */ @@ -140,17 +140,17 @@ class InspIRCdProto : public IRCDProto if (x->GetUser() == "*") { sockaddrs(x->GetHost()); - ircdproto->SendSZLine(u, x); + IRCD->SendSZLine(u, x); return; } } catch (const SocketException &) { } // 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) + time_t timeleft = x->expires - Anope::CurTime; + if (timeleft > 172800 || !x->expires) timeleft = 172800; - UplinkSocket::Message(Me) << "ADDLINE G " << x->Mask << " " << x->By << " " << Anope::CurTime << " " << timeleft << " :" << x->GetReason(); + UplinkSocket::Message(Me) << "ADDLINE G " << x->mask << " " << x->by << " " << Anope::CurTime << " " << timeleft << " :" << x->GetReason(); } void SendSVSKillInternal(const BotInfo *source, User *user, const Anope::string &buf) anope_override @@ -214,11 +214,11 @@ class InspIRCdProto : public IRCDProto */ UserContainer *uc = c->FindUser(user); if (uc != NULL) - uc->Status->ClearFlags(); + uc->status->ClearFlags(); - BotInfo *setter = findbot(user->nick); + BotInfo *setter = BotInfo::Find(user->nick); for (unsigned i = 0; i < ModeManager::ChannelModes.size(); ++i) - if (cs.HasFlag(ModeManager::ChannelModes[i]->Name)) + if (cs.HasFlag(ModeManager::ChannelModes[i]->name)) c->SetMode(setter, ModeManager::ChannelModes[i], user->GetUID(), false); } } @@ -226,17 +226,17 @@ class InspIRCdProto : public IRCDProto /* UNSQLINE */ void SendSQLineDel(const XLine *x) anope_override { - UplinkSocket::Message(findbot(Config->OperServ)) << "QLINE " << x->Mask; + UplinkSocket::Message(OperServ) << "QLINE " << x->mask; } /* SQLINE */ void SendSQLine(User *, 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) + time_t timeleft = x->expires - Anope::CurTime; + if (timeleft > 172800 || !x->expires) timeleft = 172800; - UplinkSocket::Message(Me) << "ADDLINE Q " << x->Mask << " " << x->By << " " << Anope::CurTime << " " << timeleft << " :" << x->GetReason(); + UplinkSocket::Message(Me) << "ADDLINE Q " << x->mask << " " << x->by << " " << Anope::CurTime << " " << timeleft << " :" << x->GetReason(); } /* Functions that use serval cmd functions */ @@ -251,7 +251,7 @@ class InspIRCdProto : public IRCDProto void SendConnect() anope_override { - current_pass = Config->Uplinks[CurrentUplink]->password; + current_pass = Config->Uplinks[Anope::CurrentUplink]->password; SendServer(Me); UplinkSocket::Message() << "BURST"; Module *enc = ModuleManager::FindFirstOf(ENCRYPTION); @@ -261,29 +261,29 @@ class InspIRCdProto : public IRCDProto /* SVSHOLD - set */ void SendSVSHold(const Anope::string &nick) anope_override { - UplinkSocket::Message(findbot(Config->OperServ)) << "SVSHOLD " << nick << " " << Config->NSReleaseTimeout << "s :Being held for registered user"; + UplinkSocket::Message(OperServ) << "SVSHOLD " << nick << " " << Config->NSReleaseTimeout << "s :Being held for registered user"; } /* SVSHOLD - release */ void SendSVSHoldDel(const Anope::string &nick) anope_override { - UplinkSocket::Message(findbot(Config->OperServ)) << "SVSHOLD " << nick; + UplinkSocket::Message(OperServ) << "SVSHOLD " << nick; } /* UNSZLINE */ void SendSZLineDel(const XLine *x) anope_override { - UplinkSocket::Message(findbot(Config->OperServ)) << "ZLINE " << x->GetHost(); + UplinkSocket::Message(OperServ) << "ZLINE " << x->GetHost(); } /* SZLINE */ void SendSZLine(User *, 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) + time_t timeleft = x->expires - Anope::CurTime; + if (timeleft > 172800 || !x->expires) timeleft = 172800; - UplinkSocket::Message(Me) << "ADDLINE Z " << x->GetHost() << " " << x->By << " " << Anope::CurTime << " " << timeleft << " :" << x->GetReason(); + UplinkSocket::Message(Me) << "ADDLINE Z " << x->GetHost() << " " << x->by << " " << Anope::CurTime << " " << timeleft << " :" << x->GetReason(); } void SendSVSJoin(const BotInfo *source, const Anope::string &nick, const Anope::string &chan, const Anope::string &) anope_override @@ -334,11 +334,11 @@ class ChannelModeFlood : public ChannelModeParam } }; -struct IRCDMessageCapab : IRCDMessage +struct IRCDMessageCapab : Message::Capab { - IRCDMessageCapab() : IRCDMessage("CAPAB", 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + IRCDMessageCapab(Module *creator) : Message::Capab(creator, "CAPAB") { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - bool Run(MessageSource &, const std::vector<Anope::string> ¶ms) anope_override + bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { if (params[0].equals_cs("START")) { @@ -348,7 +348,7 @@ struct IRCDMessageCapab : IRCDMessage has_chghostmod = false; has_chgidentmod = false; has_hidechansmod = false; - ircdproto->CanSVSHold = false; + IRCD->CanSVSHold = false; } else if (params[0].equals_cs("MODULES") && params.size() > 1) { @@ -357,7 +357,7 @@ struct IRCDMessageCapab : IRCDMessage if (params[1].find("m_services.so") != Anope::string::npos) has_servicesmod = true; if (params[1].find("m_svshold.so") != Anope::string::npos) - ircdproto->CanSVSHold = true; + IRCD->CanSVSHold = true; if (params[1].find("m_chghost.so") != Anope::string::npos) has_chghostmod = true; if (params[1].find("m_chgident.so") != Anope::string::npos) @@ -531,7 +531,7 @@ struct IRCDMessageCapab : IRCDMessage else if (capab.find("MAXMODES=") != Anope::string::npos) { Anope::string maxmodes(capab.begin() + 9, capab.end()); - ircdproto->MaxModes = maxmodes.is_pos_number_only() ? convertTo<unsigned>(maxmodes) : 3; + IRCD->MaxModes = maxmodes.is_pos_number_only() ? convertTo<unsigned>(maxmodes) : 3; } } } @@ -540,25 +540,25 @@ struct IRCDMessageCapab : IRCDMessage if (!has_globopsmod) { UplinkSocket::Message() << "ERROR :m_globops is not loaded. This is required by Anope"; - quitmsg = "ERROR: Remote server does not have the m_globops module loaded, and this is required."; - quitting = true; + Anope::QuitReason = "ERROR: Remote server does not have the m_globops module loaded, and this is required."; + Anope::Quitting = true; return false; } if (!has_servicesmod) { UplinkSocket::Message() << "ERROR :m_services is not loaded. This is required by Anope"; - quitmsg = "ERROR: Remote server does not have the m_services module loaded, and this is required."; - quitting = true; + Anope::QuitReason = "ERROR: Remote server does not have the m_services module loaded, and this is required."; + Anope::Quitting = true; return false; } if (!has_hidechansmod) { UplinkSocket::Message() << "ERROR :m_hidechans.so is not loaded. This is required by Anope"; - quitmsg = "ERROR: Remote server deos not have the m_hidechans module loaded, and this is required."; - quitting = true; + Anope::QuitReason = "ERROR: Remote server deos not have the m_hidechans module loaded, and this is required."; + Anope::Quitting = true; return false; } - if (!ircdproto->CanSVSHold) + if (!IRCD->CanSVSHold) Log() << "SVSHOLD missing, Usage disabled until module is loaded."; if (!has_chghostmod) Log() << "CHGHOST missing, Usage disabled until module is loaded."; @@ -566,17 +566,17 @@ struct IRCDMessageCapab : IRCDMessage Log() << "CHGIDENT missing, Usage disabled until module is loaded."; } - return true; + return Message::Capab::Run(source, params); } }; struct IRCDMessageChgIdent : IRCDMessage { - IRCDMessageChgIdent(const Anope::string &n) : IRCDMessage(n, 2) { } + IRCDMessageChgIdent(Module *creator, const Anope::string &n) : IRCDMessage(creator, n, 2) { } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { - User *u = finduser(params[0]); + User *u = User::Find(params[0]); if (!u) { Log(LOG_DEBUG) << "CHGIDENT for nonexistent user " << params[0]; @@ -590,7 +590,7 @@ struct IRCDMessageChgIdent : IRCDMessage struct IRCDMessageChgName : IRCDMessage { - IRCDMessageChgName(const Anope::string &n) : IRCDMessage(n, 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + IRCDMessageChgName(Module *creator, const Anope::string &n) : IRCDMessage(creator, n, 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { @@ -601,7 +601,7 @@ struct IRCDMessageChgName : IRCDMessage struct IRCDMessageEndBurst : IRCDMessage { - IRCDMessageEndBurst() : IRCDMessage("ENDBURST", 0) { } + IRCDMessageEndBurst(Module *creator) : IRCDMessage(creator, "ENDBURST", 0) { } bool Run(MessageSource &, const std::vector<Anope::string> ¶ms) anope_override { @@ -612,7 +612,7 @@ struct IRCDMessageEndBurst : IRCDMessage struct IRCDMessageFHost : IRCDMessage { - IRCDMessageFHost(const Anope::string &n) : IRCDMessage(n, 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + IRCDMessageFHost(Module *creator, const Anope::string &n) : IRCDMessage(creator, n, 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { @@ -623,94 +623,47 @@ struct IRCDMessageFHost : IRCDMessage struct IRCDMessageFJoin : IRCDMessage { - IRCDMessageFJoin() : IRCDMessage("FJOIN", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + IRCDMessageFJoin(Module *creator) : IRCDMessage(creator, "FJOIN", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { - Channel *c = findchan(params[0]); - time_t ts = Anope::string(params[1]).is_pos_number_only() ? convertTo<time_t>(params[1]) : 0; - bool keep_their_modes = true; - - if (!c) - { - c = new Channel(params[0], ts); - c->SetFlag(CH_SYNCING); - } - /* Our creation time is newer than what the server gave us */ - else if (c->creation_time > ts) - { - c->creation_time = ts; - c->Reset(); - } - /* Their TS is newer than ours, our modes > theirs, unset their modes if need be */ - else if (ts > c->creation_time) - keep_their_modes = false; + std::list<Message::Join::SJoinUser> users; spacesepstream sep(params[params.size() - 1]); Anope::string buf; + while (sep.GetToken(buf)) { - std::list<ChannelMode *> Status; - char ch; + Message::Join::SJoinUser sju; /* Loop through prefixes */ - while ((ch = ModeManager::GetStatusChar(buf[0]))) + for (char ch; (ch = ModeManager::GetStatusChar(buf[0]));) { ChannelMode *cm = ModeManager::FindChannelModeByChar(ch); + buf.erase(buf.begin()); if (!cm) { - Log() << "Received unknown mode prefix " << buf[0] << " in FJOIN string"; - buf.erase(buf.begin()); + Log() << "Received unknown mode prefix " << ch << " in FJOIN string"; continue; } - buf.erase(buf.begin()); - if (keep_their_modes) - Status.push_back(cm); + sju.first.SetFlag(cm->name); } /* Erase the , */ buf.erase(buf.begin()); - User *u = finduser(buf); - if (!u) + sju.second = User::Find(buf); + if (!sju.second) { - Log(LOG_DEBUG) << "FJOIN for nonexistant user " << buf << " on " << c->name; + Log(LOG_DEBUG) << "FJOIN for nonexistant user " << buf << " on " << params[0]; continue; } - EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnPreJoinChannel, OnPreJoinChannel(u, c)); - - /* Add the user to the channel */ - c->JoinUser(u); - - /* Update their status internally on the channel - * This will enforce secureops etc on the user - */ - for (std::list<ChannelMode *>::iterator it = Status.begin(), it_end = Status.end(); it != it_end; ++it) - c->SetModeInternal(source, *it, buf); - - /* Now set whatever modes this user is allowed to have on the channel */ - chan_set_correct_modes(u, c, 1, true); - - /* Check to see if modules want the user to join, if they do - * check to see if they are allowed to join (CheckKick will kick/ban them) - * Don't trigger OnJoinChannel event then as the user will be destroyed - */ - if (MOD_RESULT != EVENT_STOP && c->ci && c->ci->CheckKick(u)) - continue; - - FOREACH_MOD(I_OnJoinChannel, OnJoinChannel(u, c)); } - /* Channel is done syncing */ - if (c->HasFlag(CH_SYNCING)) - { - /* Unset the syncing flag */ - c->UnsetFlag(CH_SYNCING); - c->Sync(); - } + 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, "", users); return true; } @@ -718,13 +671,13 @@ struct IRCDMessageFJoin : IRCDMessage struct IRCDMessageFMode : IRCDMessage { - IRCDMessageFMode() : IRCDMessage("FMODE", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + IRCDMessageFMode(Module *creator) : IRCDMessage(creator, "FMODE", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { /* :source FMODE #test 12345678 +nto foo */ - Channel *c = findchan(params[0]); + Channel *c = Channel::Find(params[0]); if (!c) return true; time_t ts = Anope::string(params[1]).is_pos_number_only() ? convertTo<time_t>(params[1]) : 0; @@ -742,11 +695,11 @@ struct IRCDMessageFMode : IRCDMessage struct IRCDMessageFTopic : IRCDMessage { - IRCDMessageFTopic() : IRCDMessage("FTOPIC", 4) { } + IRCDMessageFTopic(Module *creator) : IRCDMessage(creator, "FTOPIC", 4) { } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { - Channel *c = findchan(params[0]); + Channel *c = Channel::Find(params[0]); if (c) c->ChangeTopicInternal(params[2], params[3], Anope::string(params[1]).is_pos_number_only() ? convertTo<time_t>(params[1]) : Anope::CurTime); @@ -756,25 +709,25 @@ struct IRCDMessageFTopic : IRCDMessage struct IRCDMessageIdle : IRCDMessage { - IRCDMessageIdle() : IRCDMessage("IDLE", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + IRCDMessageIdle(Module *creator) : IRCDMessage(creator, "IDLE", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { - const BotInfo *bi = findbot(params[0]); - UplinkSocket::Message(bi) << "IDLE " << source.GetSource() << " " << start_time << " " << (bi ? Anope::CurTime - bi->lastmsg : 0); + const BotInfo *bi = BotInfo::Find(params[0]); + UplinkSocket::Message(bi) << "IDLE " << source.GetSource() << " " << Anope::StartTime << " " << (bi ? Anope::CurTime - bi->lastmsg : 0); return true; } }; struct IRCDMessageMode : IRCDMessage { - IRCDMessageMode() : IRCDMessage("MODE", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + IRCDMessageMode(Module *creator) : IRCDMessage(creator, "MODE", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { - if (ircdproto->IsChannelValid(params[0])) + if (IRCD->IsChannelValid(params[0])) { - Channel *c = findchan(params[0]); + Channel *c = Channel::Find(params[0]); time_t ts; try @@ -791,7 +744,7 @@ struct IRCDMessageMode : IRCDMessage } else { - User *u = finduser(params[0]); + User *u = User::Find(params[0]); if (u) u->SetModesInternal("%s", params[1].c_str()); } @@ -802,7 +755,7 @@ struct IRCDMessageMode : IRCDMessage struct IRCDMessageNick : IRCDMessage { - IRCDMessageNick() : IRCDMessage("NICK", 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + IRCDMessageNick(Module *creator) : IRCDMessage(creator, "NICK", 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { @@ -811,19 +764,19 @@ struct IRCDMessageNick : IRCDMessage time_t ts = Anope::string(params[0]).is_pos_number_only() ? convertTo<time_t>(params[0]) : Anope::CurTime; User *user = new User(params[1], params[4], params[2], params[3], params[6], source.GetServer(), params[7], ts, params[5]); - if (nickserv) + if (NickServService) { - NickAlias *na = findnick(user->nick); + NickAlias *na = NickAlias::Find(user->nick); Anope::string *svidbuf = na ? na->nc->GetExt<ExtensibleItemClass<Anope::string> *>("authenticationtoken") : NULL; if (na && svidbuf && *svidbuf == params[0]) { NickCore *nc = na->nc; user->Login(nc); if (!Config->NoNicknameOwnership && na->nc->HasFlag(NI_UNCONFIRMED) == false) - user->SetMode(findbot(Config->NickServ), UMODE_REGISTERED); + user->SetMode(NickServ, UMODE_REGISTERED); } - else if (nickserv) - nickserv->Validate(user); + else + NickServService->Validate(user); } } else if (params.size() == 1 && source.GetUser()) @@ -835,7 +788,7 @@ struct IRCDMessageNick : IRCDMessage struct IRCDMessageOperType : IRCDMessage { - IRCDMessageOperType() : IRCDMessage("OPERTYPE", 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_USER); } + IRCDMessageOperType(Module *creator) : IRCDMessage(creator, "OPERTYPE", 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_USER); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { @@ -851,7 +804,7 @@ struct IRCDMessageOperType : IRCDMessage struct IRCDMessageRSQuit : IRCDMessage { - IRCDMessageRSQuit() : IRCDMessage("RSQUIT", 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + IRCDMessageRSQuit(Module *creator) : IRCDMessage(creator, "RSQUIT", 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { @@ -873,7 +826,7 @@ struct IRCDMessageRSQuit : IRCDMessage struct IRCDMessageServer : IRCDMessage { - IRCDMessageServer() : IRCDMessage("SERVER", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { @@ -888,22 +841,21 @@ class ProtoInspIRCd : public Module InspIRCdProto ircd_proto; /* Core message handlers */ - CoreIRCDMessageAway core_message_away; - CoreIRCDMessageCapab core_message_capab; - CoreIRCDMessageError core_message_error; - CoreIRCDMessageJoin core_message_join; - CoreIRCDMessageKick core_message_kick; - CoreIRCDMessageKill core_message_kill; - CoreIRCDMessageMOTD core_message_motd; - CoreIRCDMessagePart core_message_part; - CoreIRCDMessagePing core_message_ping; - CoreIRCDMessagePrivmsg core_message_privmsg; - CoreIRCDMessageQuit core_message_quit; - CoreIRCDMessageSQuit core_message_squit; - CoreIRCDMessageStats core_message_stats; - CoreIRCDMessageTime core_message_time; - CoreIRCDMessageTopic core_message_topic; - CoreIRCDMessageVersion core_message_version; + Message::Away message_away; + Message::Error message_error; + Message::Join message_join; + Message::Kick message_kick; + Message::Kill message_kill; + Message::MOTD message_motd; + Message::Part message_part; + Message::Ping message_ping; + Message::Privmsg message_privmsg; + Message::Quit message_quit; + Message::SQuit message_squit; + Message::Stats message_stats; + Message::Time message_time; + Message::Topic message_topic; + Message::Version message_version; /* Our message handlers */ IRCDMessageCapab message_capab; @@ -934,19 +886,30 @@ class ProtoInspIRCd : public Module public: ProtoInspIRCd(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL), - message_chgident("CHGIDENT"), message_setident("SETIDENT"), - message_chgname("CHGNAME"), message_setname("SETNAME"), - message_fhost("FHOST"), message_sethost("SETHOST") + message_away(this), message_error(this), message_join(this), message_kick(this), message_kill(this), + message_motd(this), message_part(this), message_ping(this), message_privmsg(this), message_quit(this), + message_squit(this), message_stats(this), message_time(this), message_topic(this), message_version(this), + + message_capab(this), message_chgident(this, "CHGIDENT"), message_setident(this, "SETIDENT"), + message_chgname(this, "CHGNAME"), message_setname(this, "SETNAME"), message_endburst(this), + message_fhost(this, "FHOST"), message_sethost(this, "SETHOST"), 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) { this->SetAuthor("Anope"); - Capab.insert("NOQUIT"); + Servers::Capab.insert("NOQUIT"); this->AddModes(); ModuleManager::Attach(I_OnUserNickChange, this); } + IRCDProto *GetIRCDProto() anope_override + { + return &ircd_proto; + } + void OnUserNickChange(User *u, const Anope::string &) anope_override { u->RemoveModeInternal(ModeManager::FindUserModeByName(UMODE_REGISTERED)); diff --git a/modules/protocol/inspircd12.cpp b/modules/protocol/inspircd12.cpp index 3d925bd4a..09ba57f00 100644 --- a/modules/protocol/inspircd12.cpp +++ b/modules/protocol/inspircd12.cpp @@ -13,22 +13,354 @@ #include "module.h" -/* inspircd-ts6.h uses these */ static bool has_globopsmod = false; static bool has_chghostmod = false; static bool has_chgidentmod = false; static bool has_rlinemod = false; static bool has_svstopic_topiclock = false; -//static unsigned int spanningtree_proto_ver = 1201; -#include "inspircd-ts6.h" - static bool has_servicesmod = false; static bool has_hidechansmod = false; -class InspIRCd12Proto : public InspIRCdTS6Proto +class ChannelModeFlood : public ChannelModeParam +{ + public: + ChannelModeFlood(char modeChar, bool minusNoArg) : ChannelModeParam(CMODE_FLOOD, modeChar, minusNoArg) { } + + bool IsValid(const Anope::string &value) const anope_override + { + try + { + Anope::string rest; + if (!value.empty() && value[0] != ':' && convertTo<int>(value[0] == '*' ? value.substr(1) : value, rest, false) > 0 && rest[0] == ':' && rest.length() > 1 && convertTo<int>(rest.substr(1), rest, false) > 0 && rest.empty()) + return true; + } + catch (const ConvertException &) { } + + return false; + } +}; + +class InspIRCd12Proto : public IRCDProto { + private: + void SendChgIdentInternal(const Anope::string &nick, const Anope::string &vIdent) + { + if (!has_chgidentmod) + Log() << "CHGIDENT not loaded!"; + else + UplinkSocket::Message(HostServ) << "CHGIDENT " << nick << " " << vIdent; + } + + void SendChgHostInternal(const Anope::string &nick, const Anope::string &vhost) + { + if (!has_chghostmod) + Log() << "CHGHOST not loaded!"; + else + UplinkSocket::Message(Me) << "CHGHOST " << nick << " " << vhost; + } + + void SendAddLine(const Anope::string &type, const Anope::string &mask, time_t duration, const Anope::string &addedby, const Anope::string &reason) + { + UplinkSocket::Message(Me) << "ADDLINE " << type << " " << mask << " " << addedby << " " << Anope::CurTime << " " << duration << " :" << reason; + } + + void SendDelLine(const Anope::string &type, const Anope::string &mask) + { + UplinkSocket::Message(Me) << "DELLINE " << type << " " << mask; + } + public: - InspIRCd12Proto() : InspIRCdTS6Proto("InspIRCd 1.2") { } + InspIRCd12Proto() : IRCDProto("InspIRCd 1.2") + { + DefaultPseudoclientModes = "+I"; + CanSVSNick = true; + CanSetVHost = true; + CanSetVIdent = true; + CanSQLine = true; + CanSZLine = true; + CanSVSHold = true; + CanCertFP = true; + RequiresID = true; + MaxModes = 20; + } + + void SendGlobalNotice(const BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override + { + UplinkSocket::Message(bi) << "NOTICE $" << dest->GetName() << " :" << msg; + } + + void SendGlobalPrivmsg(const 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 */ + if (x->IsRegex() && has_rlinemod) + { + Anope::string mask = x->mask; + size_t h = x->mask.find('#'); + if (h != Anope::string::npos) + mask = mask.replace(h, 1, ' '); + SendDelLine("R", mask); + return; + } + else if (x->IsRegex() || x->HasNickOrReal()) + return; + + SendDelLine("G", x->mask); + } + + void SendTopic(BotInfo *whosets, Channel *c) anope_override + { + if (has_svstopic_topiclock) + { + 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(whosets) << "FTOPIC " << c->name << " " << ts << " " << c->topic_setter << " :" << c->topic; + } + } + + void SendVhostDel(User *u) anope_override + { + if (u->HasMode(UMODE_CLOAK)) + this->SendChgHostInternal(u->nick, u->chost); + else + this->SendChgHostInternal(u->nick, u->host); + + if (has_chgidentmod && u->GetIdent() != u->GetVIdent()) + this->SendChgIdentInternal(u->nick, u->GetIdent()); + } + + 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 */ + if (x->IsRegex() && has_rlinemod) + { + Anope::string mask = x->mask; + size_t h = x->mask.find('#'); + if (h != Anope::string::npos) + mask = mask.replace(h, 1, ' '); + 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(OperServ, "akill") << "AKILL: Added an akill for " << x->mask << " because " << u->GetMask() << "#" << u->realname << " matches " << old->mask; + } + + /* ZLine if we can instead */ + try + { + if (x->GetUser() == "*") + { + sockaddrs(x->GetHost()); + IRCD->SendSZLine(u, x); + return; + } + } + catch (const SocketException &) { } + 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 + { + UplinkSocket::Message() << "PUSH " << dest << " ::" << Me->GetName() << " " << numeric << " " << dest << " " << buf; + } + + void SendModeInternal(const BotInfo *source, const Channel *dest, const Anope::string &buf) anope_override + { + UplinkSocket::Message(source) << "FMODE " << dest->name << " " << dest->creation_time << " " << buf; + } + + void SendModeInternal(const BotInfo *bi, const User *u, const Anope::string &buf) anope_override + { + UplinkSocket::Message(bi) << "MODE " << u->GetUID() << " " << buf; + } + + void SendClientIntroduction(const 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; + } + + /* SERVER services-dev.chatspike.net password 0 :Description here */ + void SendServer(const Server *server) anope_override + { + UplinkSocket::Message() << "SERVER " << server->GetName() << " " << Config->Uplinks[Anope::CurrentUplink]->password << " " << server->GetHops() << " " << server->GetSID() << " :" << server->GetDescription(); + } + + /* JOIN */ + void SendJoin(const 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. + */ + UserContainer *uc = c->FindUser(user); + if (uc != NULL) + uc->status->ClearFlags(); + + BotInfo *setter = BotInfo::Find(user->nick); + for (unsigned i = 0; i < ModeManager::ChannelModes.size(); ++i) + if (cs.HasFlag(ModeManager::ChannelModes[i]->name)) + c->SetMode(setter, ModeManager::ChannelModes[i], user->GetUID(), false); + } + } + + /* UNSQLINE */ + void SendSQLineDel(const XLine *x) anope_override + { + SendDelLine("Q", x->mask); + } + + /* SQLINE */ + void SendSQLine(User *, 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()); + } + + /* Functions that use serval cmd functions */ + + 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 SendConnect() anope_override + { + SendServer(Me); + UplinkSocket::Message(Me) << "BURST"; + Module *enc = ModuleManager::FindFirstOf(ENCRYPTION); + UplinkSocket::Message(Me) << "VERSION :Anope-" << Anope::Version() << " " << Config->ServerName << " :" << IRCD->GetProtocolName() << " - (" << (enc ? enc->name : "unknown") << ") -- " << Anope::VersionBuildString(); + } + + /* SVSHOLD - set */ + void SendSVSHold(const Anope::string &nick) anope_override + { + UplinkSocket::Message(NickServ) << "SVSHOLD " << nick << " " << Config->NSReleaseTimeout << " :Being held for registered user"; + } + + /* SVSHOLD - release */ + void SendSVSHoldDel(const Anope::string &nick) anope_override + { + UplinkSocket::Message(NickServ) << "SVSHOLD " << nick; + } + + /* UNSZLINE */ + void SendSZLineDel(const XLine *x) anope_override + { + SendDelLine("Z", x->GetHost()); + } + + /* SZLINE */ + void SendSZLine(User *, 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 BotInfo *source, const Anope::string &nick, const Anope::string &chan, const Anope::string &) anope_override + { + User *u = User::Find(nick); + UplinkSocket::Message(source) << "SVSJOIN " << u->GetUID() << " " << chan; + } + + void SendSWhois(const BotInfo *, 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; + } + + void SendEOB() anope_override + { + UplinkSocket::Message(Me) << "ENDBURST"; + } + + void SendGlobopsInternal(const BotInfo *source, const Anope::string &buf) + { + if (has_globopsmod) + UplinkSocket::Message(source) << "SNONOTICE g :" << buf; + else + UplinkSocket::Message(source) << "SNONOTICE A :" << buf; + } + + void SendLogin(User *u) anope_override + { + if (!u->Account() || u->Account()->HasFlag(NI_UNCONFIRMED)) + return; + + UplinkSocket::Message(Me) << "METADATA " << u->GetUID() << " accountname :" << u->Account()->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 SendOper(User *u) anope_override + { + } }; class InspIRCdExtBan : public ChannelModeList @@ -44,7 +376,7 @@ class InspIRCdExtBan : public ChannelModeList { Anope::string real_mask = mask.substr(2); - Entry en(this->Name, real_mask); + Entry en(this->name, real_mask); if (en.Matches(u)) return true; } @@ -52,7 +384,7 @@ class InspIRCdExtBan : public ChannelModeList { Anope::string real_mask = mask.substr(2); - Channel *c = findchan(real_mask); + Channel *c = Channel::Find(real_mask); if (c != NULL && c->FindUser(u) != NULL) return true; } @@ -82,9 +414,9 @@ class InspIRCdExtBan : public ChannelModeList } }; -struct IRCDMessageCapab : IRCDMessage +struct IRCDMessageCapab : Message::Capab { - IRCDMessageCapab() : IRCDMessage("CAPAB", 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + IRCDMessageCapab(Module *creator) : Message::Capab(creator, "CAPAB") { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { @@ -96,7 +428,7 @@ struct IRCDMessageCapab : IRCDMessage has_chghostmod = false; has_chgidentmod = false; has_hidechansmod = false; - ircdproto->CanSVSHold = false; + IRCD->CanSVSHold = false; } else if (params[0].equals_cs("MODULES") && params.size() > 1) { @@ -105,7 +437,7 @@ struct IRCDMessageCapab : IRCDMessage if (params[1].find("m_services_account.so") != Anope::string::npos) has_servicesmod = true; if (params[1].find("m_svshold.so") != Anope::string::npos) - ircdproto->CanSVSHold = true; + IRCD->CanSVSHold = true; if (params[1].find("m_chghost.so") != Anope::string::npos) has_chghostmod = true; if (params[1].find("m_chgident.so") != Anope::string::npos) @@ -113,7 +445,7 @@ struct IRCDMessageCapab : IRCDMessage if (params[1].find("m_hidechans.so") != Anope::string::npos) has_hidechansmod = true; if (params[1].find("m_servprotect.so") != Anope::string::npos) - ircdproto->DefaultPseudoclientModes = "+Ik"; + IRCD->DefaultPseudoclientModes = "+Ik"; if (params[1].find("m_rline.so") != Anope::string::npos) has_rlinemod = true; } @@ -383,7 +715,7 @@ struct IRCDMessageCapab : IRCDMessage else if (capab.find("MAXMODES=") != Anope::string::npos) { Anope::string maxmodes(capab.begin() + 9, capab.end()); - ircdproto->MaxModes = maxmodes.is_pos_number_only() ? convertTo<unsigned>(maxmodes) : 3; + IRCD->MaxModes = maxmodes.is_pos_number_only() ? convertTo<unsigned>(maxmodes) : 3; } } } @@ -392,25 +724,25 @@ struct IRCDMessageCapab : IRCDMessage if (!has_globopsmod) { UplinkSocket::Message() << "ERROR :m_globops is not loaded. This is required by Anope"; - quitmsg = "Remote server does not have the m_globops module loaded, and this is required."; - quitting = true; + Anope::QuitReason = "Remote server does not have the m_globops module loaded, and this is required."; + Anope::Quitting = true; return false; } if (!has_servicesmod) { UplinkSocket::Message() << "ERROR :m_services_account.so is not loaded. This is required by Anope"; - quitmsg = "ERROR: Remote server does not have the m_services_account module loaded, and this is required."; - quitting = true; + Anope::QuitReason = "ERROR: Remote server does not have the m_services_account module loaded, and this is required."; + Anope::Quitting = true; return false; } if (!has_hidechansmod) { UplinkSocket::Message() << "ERROR :m_hidechans.so is not loaded. This is required by Anope"; - quitmsg = "ERROR: Remote server does not have the m_hidechans module loaded, and this is required."; - quitting = true; + Anope::QuitReason = "ERROR: Remote server does not have the m_hidechans module loaded, and this is required."; + Anope::Quitting = true; return false; } - if (!ircdproto->CanSVSHold) + if (!IRCD->CanSVSHold) Log() << "SVSHOLD missing, Usage disabled until module is loaded."; if (!has_chghostmod) Log() << "CHGHOST missing, Usage disabled until module is loaded."; @@ -418,17 +750,19 @@ struct IRCDMessageCapab : IRCDMessage Log() << "CHGIDENT missing, Usage disabled until module is loaded."; } - return true; + Servers::Capab.insert("NOQUIT"); + + return Message::Capab::Run(source, params); } }; struct IRCDMessageChgIdent : IRCDMessage { - IRCDMessageChgIdent() : IRCDMessage("CHGIDENT", 2) { } + IRCDMessageChgIdent(Module *creator) : IRCDMessage(creator, "CHGIDENT", 2) { } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { - User *u = finduser(params[0]); + User *u = User::Find(params[0]); if (u) u->SetIdent(params[1]); return true; @@ -437,7 +771,7 @@ struct IRCDMessageChgIdent : IRCDMessage struct IRCDMessageChgName : IRCDMessage { - IRCDMessageChgName(const Anope::string &n) : IRCDMessage(n, 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + IRCDMessageChgName(Module *creator, const Anope::string &n) : IRCDMessage(creator, n, 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { @@ -446,9 +780,345 @@ struct IRCDMessageChgName : IRCDMessage } }; +struct IRCDMessageEndburst : IRCDMessage +{ + IRCDMessageEndburst(Module *creator) : IRCDMessage(creator, "ENDBURST", 0) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + + bool 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); + return true; + } +}; + +struct IRCDMessageFHost : IRCDMessage +{ + IRCDMessageFHost(Module *creator, const Anope::string &n) : IRCDMessage(creator, n, 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + + bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + { + source.GetUser()->SetDisplayedHost(params[0]); + return true; + } +}; + +struct IRCDMessageFJoin : IRCDMessage +{ + IRCDMessageFJoin(Module *creator) : IRCDMessage(creator, "FJOIN", 2) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + bool 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]) != ',';) + { + ChannelMode *cm = ModeManager::FindChannelModeByChar(c); + if (!cm) + { + Log() << "Received unknown mode prefix " << c << " in FJOIN string"; + continue; + } + + sju.first.SetFlag(cm->name); + } + /* Erase the , */ + buf.erase(buf.begin()); + + sju.second = User::Find(buf); + if (!sju.second) + { + Log(LOG_DEBUG) << "FJOIN for nonexistant 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, "", users); + + return true; + } +}; + +struct IRCDMessageFMode : IRCDMessage +{ + IRCDMessageFMode(Module *creator) : IRCDMessage(creator, "FMODE", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + bool 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); + + return true; + } +}; + +struct IRCDMessageFTopic : IRCDMessage +{ + IRCDMessageFTopic(Module *creator) : IRCDMessage(creator, "FTOPIC", 4) { } + + bool 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(params[2], params[3], Anope::string(params[1]).is_pos_number_only() ? convertTo<time_t>(params[1]) : Anope::CurTime); + + return true; + } +}; + +struct IRCDMessageIdle : IRCDMessage +{ + IRCDMessageIdle(Module *creator) : IRCDMessage(creator, "IDLE", 1) { } + + bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + { + const BotInfo *bi = BotInfo::Find(params[0]); + if (bi) + UplinkSocket::Message(bi) << "IDLE " << source.GetSource() << " " << Anope::StartTime << " " << (Anope::CurTime - bi->lastmsg); + return true; + } +}; + +/* + * source = numeric of the sending server + * params[0] = uuid + * params[1] = metadata name + * params[2] = data + */ +struct IRCDMessageMetadata : IRCDMessage +{ + IRCDMessageMetadata(Module *creator) : IRCDMessage(creator, "METADATA", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + + bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + { + 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); + + const NickAlias *user_na = NickAlias::Find(u->nick); + if (!Config->NoNicknameOwnership && user_na && user_na->nc == nc && user_na->nc->HasFlag(NI_UNCONFIRMED) == false) + u->SetMode(NickServ, UMODE_REGISTERED); + + /* Sometimes a user connects, we send them the usual "this nickname is registered" mess (if + * their server isn't syncing) and then we receive this.. so tell them about it. + */ + if (u->server->IsSynced() && NickServ) + u->SendMessage(NickServ, _("You have been logged in as \2%s\2."), nc->display.c_str()); + } + } + + /* + * 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 true; + std::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(I_OnFingerprint, OnFingerprint(u)); + } + } + } + else if (params[0][0] == '#') + { + } + else if (params[0] == "*") + { + // Wed Oct 3 15:40:27 2012: S[14] O :20D METADATA * modules :-m_svstopic.so + + 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 true; + + bool plus = (params[2][0] == '+'); + if (!plus && params[2][0] != '-') + return true; + + bool required = false; + Anope::string 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")) + has_chghostmod = plus; + else if (module.equals_cs("m_chgident.so")) + has_chgidentmod = plus; + else if (module.equals_cs("m_svshold.so")) + IRCD->CanSVSHold = plus; + else if (module.equals_cs("m_rline.so")) + has_rlinemod = plus; + else if (module.equals_cs("m_topiclock.so")) + has_svstopic_topiclock = plus; + else + return true; + + if (required) + { + if (!plus) + Log() << "Warning: InspIRCd unloaded module " << module << ", Anope won't function correctly without it"; + } + else + { + Log() << "InspIRCd " << (plus ? "loaded" : "unloaded") << " module " << module << ", adjusted functionality"; + } + + } + } + + return true; + } +}; + +struct IRCDMessageMode : IRCDMessage +{ + IRCDMessageMode(Module *creator) : IRCDMessage(creator, "MODE", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + + bool 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 = source.GetUser(); + // This can happen with server-origin modes. + if (!u) + u = User::Find(params[0]); + // if it's still null, drop it like fire. + // most likely situation was that server introduced a nick which we subsequently akilled + if (u) + u->SetModesInternal("%s", params[1].c_str()); + } + + return true; + } +}; + +struct IRCDMessageNick : IRCDMessage +{ + IRCDMessageNick(Module *creator) : IRCDMessage(creator, "NICK", 2) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + + bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + { + source.GetUser()->ChangeNick(params[0]); + return true; + } +}; + +struct IRCDMessageOperType : IRCDMessage +{ + IRCDMessageOperType(Module *creator) : IRCDMessage(creator, "OPERTYPE", 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_USER); } + + bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + { + /* opertype is equivalent to mode +o because servers + dont do this directly */ + User *u = source.GetUser(); + if (!u->HasMode(UMODE_OPER)) + u->SetModesInternal("+o"); + + return true; + } +} +; +struct IRCDMessageRSQuit : IRCDMessage +{ + IRCDMessageRSQuit(Module *creator) : IRCDMessage(creator, "RSQUIT", 1) { } + + bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + { + Server *s = Server::Find(params[0]); + if (!s) + return true; + + /* On InspIRCd we must send a SQUIT when we recieve RSQUIT for a server we have juped */ + if (s->HasFlag(SERVER_JUPED)) + UplinkSocket::Message(Me) << "SQUIT " << s->GetSID() << " :" << (params.size() > 1 ? params[1].c_str() : ""); + + FOREACH_MOD(I_OnServerQuit, OnServerQuit(s)); + + s->Delete(s->GetName() + " " + s->GetUplink()->GetName()); + + return true; + } +}; + struct IRCDMessageSetIdent : IRCDMessage { - IRCDMessageSetIdent() : IRCDMessage("SETIDENT", 0) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + IRCDMessageSetIdent(Module *creator) : IRCDMessage(creator, "SETIDENT", 0) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { @@ -457,28 +1127,94 @@ struct IRCDMessageSetIdent : IRCDMessage } }; +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 + */ + bool 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]); + return true; + } +}; + +struct IRCDMessageTime : IRCDMessage +{ + IRCDMessageTime(Module *creator) : IRCDMessage(creator, "TIME", 2) { } + + bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + { + UplinkSocket::Message(Me) << "TIME " << source.GetSource() << " " << params[1] << " " << Anope::CurTime; + return true; + } +}; + +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 + */ + bool 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]; + + User *u = new User(params[2], params[5], params[3], params[4], params[6], source.GetServer(), params[params.size() - 1], ts, modes, params[0]); + if (u->server->IsSynced() && NickServService) + NickServService->Validate(u); + + return true; + } +}; + class ProtoInspIRCd : public Module { InspIRCd12Proto ircd_proto; /* Core message handlers */ - CoreIRCDMessageAway core_message_away; - CoreIRCDMessageCapab core_message_capab; - CoreIRCDMessageError core_message_error; - CoreIRCDMessageJoin core_message_join; - CoreIRCDMessageKick core_message_kick; - CoreIRCDMessageKill core_message_kill; - CoreIRCDMessageMOTD core_message_motd; - CoreIRCDMessagePart core_message_part; - CoreIRCDMessagePing core_message_ping; - CoreIRCDMessagePrivmsg core_message_privmsg; - CoreIRCDMessageQuit core_message_quit; - CoreIRCDMessageSQuit core_message_squit; - CoreIRCDMessageStats core_message_stats; - CoreIRCDMessageTopic core_message_topic; - CoreIRCDMessageVersion core_message_version; - - /* inspircd-ts6.h message handlers */ + Message::Away message_away; + Message::Error message_error; + Message::Join message_join; + Message::Kick message_kick; + Message::Kill message_kill; + Message::MOTD message_motd; + Message::Part message_part; + Message::Ping message_ping; + Message::Privmsg message_privmsg; + Message::Quit message_quit; + Message::SQuit message_squit; + Message::Stats message_stats; + Message::Topic message_topic; + Message::Version message_version; + + /* Our message handlers */ + IRCDMessageChgIdent message_chgident; + IRCDMessageChgName message_setname, message_chgname; + IRCDMessageCapab message_capab; IRCDMessageEndburst message_endburst; IRCDMessageFHost message_fhost, message_sethost; IRCDMessageFJoin message_sjoin; @@ -490,31 +1226,30 @@ class ProtoInspIRCd : public Module IRCDMessageNick message_nick; IRCDMessageOperType message_opertype; IRCDMessageRSQuit message_rsquit; + IRCDMessageSetIdent message_setident; IRCDMessageServer message_server; IRCDMessageTime message_time; IRCDMessageUID message_uid; - /* Our message handlers */ - IRCDMessageChgIdent message_chgident; - IRCDMessageChgName message_setname, message_chgname; - IRCDMessageCapab message_capab; - IRCDMessageSetIdent message_setident; - public: ProtoInspIRCd(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL), - message_fhost("FHOST"), message_sethost("SETHOST"), - message_setname("SETNAME"), message_chgname("FNAME") + message_away(this), message_error(this), message_join(this), message_kick(this), message_kill(this), + message_motd(this), message_part(this), message_ping(this), message_privmsg(this), message_quit(this), + message_squit(this), message_stats(this), message_topic(this), message_version(this), + + message_chgident(this), message_setname(this, "SETNAME"), message_chgname(this, "FNAME"), message_capab(this), message_endburst(this), + message_fhost(this, "FHOST"), message_sethost(this, "SETHOST"), message_sjoin(this), message_fmode(this), message_ftopic(this), + message_idle(this), message_metadata(this), message_mode(this), message_nick(this), message_opertype(this), message_rsquit(this), + message_setident(this), message_server(this), message_time(this), message_uid(this) { this->SetAuthor("Anope"); - Capab.insert("NOQUIT"); - Implementation i[] = { I_OnUserNickChange, I_OnServerSync }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); if (Config->Numeric.empty()) { - Anope::string numeric = ts6_sid_retrieve(); + Anope::string numeric = Servers::TS6_SID_Retrieve(); Me->SetSID(numeric); Config->Numeric = numeric; } @@ -523,22 +1258,27 @@ class ProtoInspIRCd : public Module it->second->GenerateUID(); } + IRCDProto *GetIRCDProto() anope_override + { + return &ircd_proto; + } + void OnUserNickChange(User *u, const Anope::string &) anope_override { /* InspIRCd 1.2 doesn't set -r on nick change, remove -r here. Note that if we have to set +r later * this will cancel out this -r, resulting in no mode changes. */ - u->RemoveMode(findbot(Config->NickServ), UMODE_REGISTERED); + u->RemoveMode(NickServ, UMODE_REGISTERED); } void OnServerSync(Server *s) anope_override { - if (nickserv) + if (NickServService) for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) { User *u = it->second; if (u->server == s && !u->IsIdentified()) - nickserv->Validate(u); + NickServService->Validate(u); } } }; diff --git a/modules/protocol/inspircd20.cpp b/modules/protocol/inspircd20.cpp index 9bb3d9e1a..85cfd9088 100644 --- a/modules/protocol/inspircd20.cpp +++ b/modules/protocol/inspircd20.cpp @@ -13,29 +13,67 @@ #include "module.h" -/* inspircd-ts6.h uses these */ static bool has_chghostmod = false; static bool has_chgidentmod = false; -static bool has_globopsmod = true; // Not a typo static bool has_rlinemod = false; static bool has_svstopic_topiclock = false; static unsigned int spanningtree_proto_ver = 0; -#include "inspircd-ts6.h" - static bool has_servicesmod = false; -class InspIRCd20Proto : public InspIRCdTS6Proto +static IRCDProto *insp12; + +class InspIRCd20Proto : public IRCDProto { public: - InspIRCd20Proto() : InspIRCdTS6Proto("InspIRCd 2.0") { } + InspIRCd20Proto() : IRCDProto("InspIRCd 2.0") + { + DefaultPseudoclientModes = "+I"; + CanSVSNick = true; + CanSetVHost = true; + CanSetVIdent = true; + CanSQLine = true; + CanSZLine = true; + CanSVSHold = true; + CanCertFP = true; + RequiresID = true; + MaxModes = 20; + } void SendConnect() anope_override { UplinkSocket::Message() << "CAPAB START 1202"; UplinkSocket::Message() << "CAPAB CAPABILITIES :PROTOCOL=1202"; UplinkSocket::Message() << "CAPAB END"; - InspIRCdTS6Proto::SendConnect(); + insp12->SendConnect(); } + + void SendGlobalNotice(const BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override { insp12->SendGlobalNotice(bi, dest, msg); } + void SendGlobalPrivmsg(const 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(BotInfo *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 BotInfo *source, const Channel *dest, const Anope::string &buf) anope_override { insp12->SendModeInternal(source, dest, buf); } + void SendModeInternal(const BotInfo *bi, const User *u, const Anope::string &buf) anope_override { insp12->SendModeInternal(bi, u, buf); } + void SendClientIntroduction(const User *u) anope_override { insp12->SendClientIntroduction(u); } + void SendServer(const Server *server) anope_override { insp12->SendServer(server); } + void SendJoin(const 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) anope_override { insp12->SendSVSHold(nick); } + 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 BotInfo *source, const Anope::string &nick, const Anope::string &chan, const Anope::string &other) anope_override { insp12->SendSVSJoin(source, nick, chan, other); } + void SendSWhois(const BotInfo *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 BotInfo *source, const Anope::string &buf) { insp12->SendGlobopsInternal(source, buf); } + void SendLogin(User *u) anope_override { insp12->SendLogin(u); } + void SendLogout(User *u) anope_override { insp12->SendLogout(u); } + void SendChannel(Channel *c) anope_override { insp12->SendChannel(c); } }; class InspIRCdExtBan : public ChannelModeList @@ -51,7 +89,7 @@ class InspIRCdExtBan : public ChannelModeList { Anope::string real_mask = mask.substr(3); - Entry en(this->Name, real_mask); + Entry en(this->name, real_mask); if (en.Matches(u)) return true; } @@ -65,16 +103,16 @@ class InspIRCdExtBan : public ChannelModeList char modeChar = ModeManager::GetStatusChar(channel[0]); channel.erase(channel.begin()); cm = ModeManager::FindChannelModeByChar(modeChar); - if (cm != NULL && cm->Type != MODE_STATUS) + if (cm != NULL && cm->type != MODE_STATUS) cm = NULL; } - Channel *c = findchan(channel); + Channel *c = Channel::Find(channel); if (c != NULL) { UserContainer *uc = c->FindUser(u); if (uc != NULL) - if (cm == NULL || uc->Status->HasFlag(cm->Name)) + if (cm == NULL || uc->status->HasFlag(cm->name)) return true; } } @@ -111,9 +149,28 @@ class InspIRCdExtBan : public ChannelModeList } }; -struct IRCDMessageCapab : IRCDMessage +class ChannelModeFlood : public ChannelModeParam { - IRCDMessageCapab() : IRCDMessage("CAPAB", 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + public: + ChannelModeFlood(char modeChar, bool minusNoArg) : ChannelModeParam(CMODE_FLOOD, modeChar, minusNoArg) { } + + bool IsValid(const Anope::string &value) const anope_override + { + try + { + Anope::string rest; + if (!value.empty() && value[0] != ':' && convertTo<int>(value[0] == '*' ? value.substr(1) : value, rest, false) > 0 && rest[0] == ':' && rest.length() > 1 && convertTo<int>(rest.substr(1), rest, false) > 0 && rest.empty()) + return true; + } + catch (const ConvertException &) { } + + return false; + } +}; + +struct IRCDMessageCapab : Message::Capab +{ + IRCDMessageCapab(Module *creator) : Message::Capab(creator, "CAPAB") { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { @@ -125,8 +182,8 @@ struct IRCDMessageCapab : IRCDMessage if (spanningtree_proto_ver < 1202) { UplinkSocket::Message() << "ERROR :Protocol mismatch, no or invalid protocol version given in CAPAB START"; - quitmsg = "Protocol mismatch, no or invalid protocol version given in CAPAB START"; - quitting = true; + Anope::QuitReason = "Protocol mismatch, no or invalid protocol version given in CAPAB START"; + Anope::Quitting = true; return false; } @@ -135,7 +192,7 @@ struct IRCDMessageCapab : IRCDMessage has_chghostmod = false; has_chgidentmod = false; has_svstopic_topiclock = false; - ircdproto->CanSVSHold = false; + IRCD->CanSVSHold = false; } else if (params[0].equals_cs("CHANMODES") && params.size() > 1) { @@ -275,7 +332,7 @@ struct IRCDMessageCapab : IRCDMessage else if (modename.equals_cs("servprotect")) { um = new UserMode(UMODE_PROTECTED, modechar[0]); - ircdproto->DefaultPseudoclientModes += "k"; + IRCD->DefaultPseudoclientModes += "k"; } else if (modename.equals_cs("showwhois")) um = new UserMode(UMODE_WHOIS, modechar[0]); @@ -302,7 +359,7 @@ struct IRCDMessageCapab : IRCDMessage while (ssep.GetToken(module)) { if (module.equals_cs("m_svshold.so")) - ircdproto->CanSVSHold = true; + IRCD->CanSVSHold = true; else if (module.find("m_rline.so") == 0) { has_rlinemod = true; @@ -392,7 +449,7 @@ struct IRCDMessageCapab : IRCDMessage else if (capab.find("MAXMODES=") != Anope::string::npos) { Anope::string maxmodes(capab.begin() + 9, capab.end()); - ircdproto->MaxModes = maxmodes.is_pos_number_only() ? convertTo<unsigned>(maxmodes) : 3; + IRCD->MaxModes = maxmodes.is_pos_number_only() ? convertTo<unsigned>(maxmodes) : 3; } else if (capab.find("PREFIX=") != Anope::string::npos) { @@ -403,7 +460,7 @@ struct IRCDMessageCapab : IRCDMessage for (size_t t = 0, end = modes.length(); t < end; ++t) { ChannelMode *cm = ModeManager::FindChannelModeByChar(modes[t]); - if (cm == NULL || cm->Type != MODE_STATUS) + if (cm == NULL || cm->type != MODE_STATUS) { Log() << "CAPAB PREFIX gave unknown channel status mode " << modes[t]; continue; @@ -420,18 +477,18 @@ struct IRCDMessageCapab : IRCDMessage if (!has_servicesmod) { UplinkSocket::Message() << "ERROR :m_services_account.so is not loaded. This is required by Anope"; - quitmsg = "ERROR: Remote server does not have the m_services_account module loaded, and this is required."; - quitting = true; + Anope::QuitReason = "ERROR: Remote server does not have the m_services_account module loaded, and this is required."; + Anope::Quitting = true; return false; } if (!ModeManager::FindUserModeByName(UMODE_PRIV)) { UplinkSocket::Message() << "ERROR :m_hidechans.so is not loaded. This is required by Anope"; - quitmsg = "ERROR: Remote server does not have the m_hidechans module loaded, and this is required."; - quitting = true; + Anope::QuitReason = "ERROR: Remote server does not have the m_hidechans module loaded, and this is required."; + Anope::Quitting = true; return false; } - if (!ircdproto->CanSVSHold) + if (!IRCD->CanSVSHold) Log() << "SVSHOLD missing, Usage disabled until module is loaded."; if (!has_chghostmod) Log() << "CHGHOST missing, Usage disabled until module is loaded."; @@ -441,15 +498,15 @@ struct IRCDMessageCapab : IRCDMessage Log() << "m_topiclock missing, server side topic locking disabled until module is loaded."; } - return true; + Servers::Capab.insert("NOQUIT"); + + return Message::Capab::Run(source, params); } }; struct IRCDMessageEncap : IRCDMessage { - Module *me; - - IRCDMessageEncap(Module *m) : IRCDMessage("ENCAP", 4), me(m) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + IRCDMessageEncap(Module *creator) : IRCDMessage(creator, "ENCAP", 4) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { @@ -458,7 +515,7 @@ struct IRCDMessageEncap : IRCDMessage if (params[1] == "CHGIDENT") { - User *u = finduser(params[2]); + User *u = User::Find(params[2]); if (!u || u->server != Me) return true; @@ -467,7 +524,7 @@ struct IRCDMessageEncap : IRCDMessage } else if (params[1] == "CHGHOST") { - User *u = finduser(params[2]); + User *u = User::Find(params[2]); if (!u || u->server != Me) return true; @@ -476,7 +533,7 @@ struct IRCDMessageEncap : IRCDMessage } else if (params[1] == "CHGNAME") { - User *u = finduser(params[2]); + User *u = User::Find(params[2]); if (!u || u->server != Me) return true; @@ -502,7 +559,7 @@ struct IRCDMessageEncap : IRCDMessage { UplinkSocket::Message(Me) << "ENCAP " << this->uid.substr(0, 3) << " SASL " << Me->GetSID() << " " << this->uid << " " << " D F"; - Log(findbot(Config->NickServ)) << "A user failed to identify for account " << this->GetAccount() << " using SASL"; + Log(NickServ) << "A user failed to identify for account " << this->GetAccount() << " using SASL"; } }; @@ -534,7 +591,7 @@ struct IRCDMessageEncap : IRCDMessage if (acc.empty() || pass.empty()) return true; - IdentifyRequest *req = new InspIRCDSASLIdentifyRequest(me, params[2], acc, pass); + IdentifyRequest *req = new InspIRCDSASLIdentifyRequest(this->owner, params[2], acc, pass); FOREACH_MOD(I_OnCheckAuthentication, OnCheckAuthentication(NULL, req)); req->Dispatch(); } @@ -546,7 +603,7 @@ struct IRCDMessageEncap : IRCDMessage struct IRCDMessageFIdent : IRCDMessage { - IRCDMessageFIdent() : IRCDMessage("FIDENT", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + IRCDMessageFIdent(Module *creator) : IRCDMessage(creator, "FIDENT", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { @@ -557,40 +614,31 @@ struct IRCDMessageFIdent : IRCDMessage class ProtoInspIRCd : public Module { + Module *m_insp12; + InspIRCd20Proto ircd_proto; /* Core message handlers */ - CoreIRCDMessageAway core_message_away; - CoreIRCDMessageCapab core_message_capab; - CoreIRCDMessageError core_message_error; - CoreIRCDMessageJoin core_message_join; - CoreIRCDMessageKick core_message_kick; - CoreIRCDMessageKill core_message_kill; - CoreIRCDMessageMOTD core_message_motd; - CoreIRCDMessagePart core_message_part; - CoreIRCDMessagePing core_message_ping; - CoreIRCDMessagePrivmsg core_message_privmsg; - CoreIRCDMessageQuit core_message_quit; - CoreIRCDMessageSQuit core_message_squit; - CoreIRCDMessageStats core_message_stats; - CoreIRCDMessageTopic core_message_topic; - CoreIRCDMessageVersion core_message_version; - - /* inspircd-ts6.h message handlers */ - IRCDMessageEndburst message_endburst; - IRCDMessageFHost message_fhost; - IRCDMessageFJoin message_sjoin; - IRCDMessageFMode message_fmode; - IRCDMessageFTopic message_ftopic; - IRCDMessageIdle message_idle; - IRCDMessageMetadata message_metadata; - IRCDMessageMode message_mode; - IRCDMessageNick message_nick; - IRCDMessageOperType message_opertype; - IRCDMessageRSQuit message_rsquit; - IRCDMessageServer message_server; - IRCDMessageTime message_time; - IRCDMessageUID message_uid; + Message::Away message_away; + Message::Error message_error; + Message::Join message_join; + Message::Kick message_kick; + Message::Kill message_kill; + Message::MOTD message_motd; + Message::Part message_part; + Message::Ping message_ping; + Message::Privmsg message_privmsg; + Message::Quit message_quit; + Message::SQuit message_squit; + Message::Stats message_stats; + Message::Topic message_topic; + Message::Version message_version; + + /* InspIRCd 1.2 message handlers */ + ServiceAlias message_endburst, message_fhost, message_sjoin, message_fmode, + message_ftopic, message_idle, message_metadata, message_mode, + message_nick, message_opertype, message_rsquit, message_server, + message_time, message_uid; /* Our message handlers */ IRCDMessageCapab message_capab; @@ -604,24 +652,51 @@ class ProtoInspIRCd : public Module public: ProtoInspIRCd(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL), - message_fhost("FHOST"), message_encap(this) + message_away(this), message_error(this), message_join(this), message_kick(this), message_kill(this), + message_motd(this), message_part(this), message_ping(this), message_privmsg(this), message_quit(this), + message_squit(this), message_stats(this), message_topic(this), message_version(this), + + message_endburst("IRCDMessage", "inspircd20/endburst", "inspircd12/endburst"), + message_fhost("IRCDMessage", "inspircd20/fhost", "inspircd12/fhost"), + message_sjoin("IRCDMessage", "inspircd20/sjoin", "inspircd12/sjoin"), + message_fmode("IRCDMessage", "inspircd20/mode", "inspircd12/fmode"), + message_ftopic("IRCDMessage", "inspircd20/ftopic", "inspircd12/ftopic"), + message_idle("IRCDMessage", "inspircd20/idle", "inspircd12/idle"), + message_metadata("IRCDMessage", "inspircd20/metadata", "inspircd12/metadata"), + message_mode("IRCDMessage", "inspircd20/mode", "inspircd12/mode"), + message_nick("IRCDMessage", "inspircd20/nick", "inspircd12/nick"), + message_opertype("IRCDMessage", "inspircd20/opertype", "inspircd12/opertype"), + message_rsquit("IRCDMessage", "inspircd20/rsquit", "inspircd12/rsquit"), + message_server("IRCDMessage", "inspircd20/server", "inspircd12/server"), + message_time("IRCDMessage", "inspircd20/time", "inspircd12/time"), + message_uid("IRCDMessage", "inspircd20/uid", "inspircd12/uid"), + + message_capab(this), message_encap(this), message_fident(this) { this->SetAuthor("Anope"); - Capab.insert("NOQUIT"); + 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"); + insp12 = m_insp12->GetIRCDProto(); + if (!insp12) + throw ModuleException("No protocol interface for insp12"); + ModuleManager::DetachAll(m_insp12); Implementation i[] = { I_OnUserNickChange, I_OnServerSync, I_OnChannelCreate, I_OnChanRegistered, I_OnDelChan, I_OnMLock, I_OnUnMLock, I_OnSetChannelOption }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); + } - if (Config->Numeric.empty()) - { - Anope::string numeric = ts6_sid_retrieve(); - Me->SetSID(numeric); - Config->Numeric = numeric; - } + ~ProtoInspIRCd() + { + ModuleManager::UnloadModule(m_insp12, NULL); + } - for (botinfo_map::iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) - it->second->GenerateUID(); + IRCDProto *GetIRCDProto() anope_override + { + return &ircd_proto; } void OnUserNickChange(User *u, const Anope::string &) anope_override @@ -631,13 +706,7 @@ class ProtoInspIRCd : public Module void OnServerSync(Server *s) anope_override { - if (nickserv) - for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) - { - User *u = it->second; - if (u->server == s && !u->IsIdentified()) - nickserv->Validate(u); - } + m_insp12->OnServerSync(s); } void OnChannelCreate(Channel *c) anope_override @@ -673,9 +742,9 @@ class ProtoInspIRCd : public Module EventReturn OnMLock(ChannelInfo *ci, ModeLock *lock) anope_override { ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name); - if (cm && ci->c && (cm->Type == MODE_REGULAR || cm->Type == MODE_PARAM) && Config->UseServerSideMLock) + if (cm && ci->c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Config->UseServerSideMLock) { - Anope::string modes = ci->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "") + cm->ModeChar; + Anope::string modes = ci->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "") + cm->mchar; SendChannelMetadata(ci->c, "mlock", modes); } @@ -685,9 +754,9 @@ class ProtoInspIRCd : public Module EventReturn OnUnMLock(ChannelInfo *ci, ModeLock *lock) anope_override { ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name); - if (cm && ci->c && (cm->Type == MODE_REGULAR || cm->Type == MODE_PARAM) && Config->UseServerSideMLock) + if (cm && ci->c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Config->UseServerSideMLock) { - Anope::string modes = ci->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "").replace_all_cs(cm->ModeChar, ""); + Anope::string modes = ci->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "").replace_all_cs(cm->mchar, ""); SendChannelMetadata(ci->c, "mlock", modes); } diff --git a/modules/protocol/ngircd.cpp b/modules/protocol/ngircd.cpp index f822922fa..28d534d2a 100644 --- a/modules/protocol/ngircd.cpp +++ b/modules/protocol/ngircd.cpp @@ -28,15 +28,15 @@ class ngIRCdProto : public IRCDProto 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) + time_t timeleft = x->expires - Anope::CurTime; + if (timeleft > 172800 || !x->expires) timeleft = 172800; - UplinkSocket::Message(Me) << "GLINE " << x->Mask << " " << timeleft << " :" << x->GetReason() << " (" << x->By << ")"; + UplinkSocket::Message(Me) << "GLINE " << x->mask << " " << timeleft << " :" << x->GetReason() << " (" << x->by << ")"; } void SendAkillDel(const XLine *x) anope_override { - UplinkSocket::Message(Me) << "GLINE " << x->Mask; + UplinkSocket::Message(Me) << "GLINE " << x->mask; } void SendChannel(Channel *c) anope_override @@ -53,7 +53,7 @@ class ngIRCdProto : public IRCDProto void SendConnect() anope_override { - UplinkSocket::Message() << "PASS " << Config->Uplinks[CurrentUplink]->password << " 0210-IRC+ Anope|" << Anope::VersionShort() << ":CLHMSo P"; + UplinkSocket::Message() << "PASS " << Config->Uplinks[Anope::CurrentUplink]->password << " 0210-IRC+ Anope|" << Anope::VersionShort() << ":CLHMSo P"; /* Make myself known to myself in the serverlist */ SendServer(Me); /* finish the enhanced server handshake and register the connection */ @@ -95,11 +95,11 @@ class ngIRCdProto : public IRCDProto */ UserContainer *uc = c->FindUser(user); if (uc != NULL) - uc->Status->ClearFlags(); + uc->status->ClearFlags(); - BotInfo *setter = findbot(user->nick); + BotInfo *setter = BotInfo::Find(user->nick); for (unsigned i = 0; i < ModeManager::ChannelModes.size(); ++i) - if (cs.HasFlag(ModeManager::ChannelModes[i]->Name)) + if (cs.HasFlag(ModeManager::ChannelModes[i]->name)) c->SetMode(setter, ModeManager::ChannelModes[i], user->GetUID(), false); } } @@ -176,7 +176,7 @@ class ngIRCdProto : public IRCDProto struct IRCDMessage005 : IRCDMessage { - IRCDMessage005() : IRCDMessage("005", 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + IRCDMessage005(Module *creator) : IRCDMessage(creator, "005", 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } // Please see <http://www.irc.org/tech_docs/005.html> for details. bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override @@ -193,7 +193,7 @@ struct IRCDMessage005 : IRCDMessage if (parameter == "MODES") { unsigned maxmodes = convertTo<unsigned>(data); - ircdproto->MaxModes = maxmodes; + IRCD->MaxModes = maxmodes; } else if (parameter == "NICKLEN") { @@ -212,7 +212,7 @@ struct IRCDMessage005 : IRCDMessage struct IRCDMessage376 : IRCDMessage { - IRCDMessage376() : IRCDMessage("376", 2) { } + IRCDMessage376(Module *creator) : IRCDMessage(creator, "376", 2) { } /* * :ngircd.dev.anope.de 376 services.anope.de :End of MOTD command @@ -230,7 +230,7 @@ struct IRCDMessage376 : IRCDMessage struct IRCDMessageChaninfo : IRCDMessage { - IRCDMessageChaninfo() : IRCDMessage("CHANINFO", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + IRCDMessageChaninfo(Module *creator) : IRCDMessage(creator, "CHANINFO", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } /* * CHANINFO is used by servers to inform each other about a channel: its @@ -252,7 +252,7 @@ struct IRCDMessageChaninfo : IRCDMessage bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { - Channel *c = findchan(params[0]); + Channel *c = Channel::Find(params[0]); if (!c) c = new Channel(params[0]); @@ -284,9 +284,9 @@ struct IRCDMessageChaninfo : IRCDMessage } }; -struct IRCDMessageJoin : IRCDMessage +struct IRCDMessageJoin : Message::Join { - IRCDMessageJoin() : IRCDMessage("JOIN", 1) { } + IRCDMessageJoin(Module *creator) : Message::Join(creator, "JOIN") { } /* * <@po||ux> DukeP: RFC 2813, 4.2.1: the JOIN command on server-server links @@ -296,7 +296,6 @@ struct IRCDMessageJoin : IRCDMessage */ bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { - Channel *chan; User *user = source.GetUser(); size_t pos = params[0].find('\7'); Anope::string channel, modes; @@ -311,41 +310,16 @@ struct IRCDMessageJoin : IRCDMessage channel = params[0]; } - chan = findchan(channel); - /* Channel doesn't exist, create it */ - if (!chan) - { - chan = new Channel(channel, Anope::CurTime); - chan->SetFlag(CH_SYNCING); - } - - EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnPreJoinChannel, OnPreJoinChannel(user, chan)); + std::vector<Anope::string> new_params; + new_params.push_back(channel); - /* Join the user to the channel */ - chan->JoinUser(user); + Message::Join::Run(source, new_params); if (!modes.empty()) - chan->SetModesInternal(source, modes); - - /* Set the proper modes on the user */ - chan_set_correct_modes(user, chan, 1, true); - - /* Modules may want to allow this user in the channel, check. - * If not, CheckKick will kick/ban them, don't call OnJoinChannel after this as the user will have - * been destroyed - */ - if (MOD_RESULT != EVENT_STOP && (!chan->ci || !chan->ci->CheckKick(user))) - { - FOREACH_MOD(I_OnJoinChannel, OnJoinChannel(user, chan)); - } - - /* Channel is done syncing */ - if (chan->HasFlag(CH_SYNCING)) { - /* Unset the syncing flag */ - chan->UnsetFlag(CH_SYNCING); - chan->Sync(); + Channel *c = Channel::Find(channel); + if (c) + c->SetModesInternal(source, modes); } return true; @@ -395,7 +369,7 @@ struct IRCDMessageMetadata : IRCDMessage struct IRCDMessageMode : IRCDMessage { - IRCDMessageMode() : IRCDMessage("MODE", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + IRCDMessageMode(Module *creator) : IRCDMessage(creator, "MODE", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } /* * Received: :DukeP MODE #anope +b *!*@*.aol.com @@ -412,16 +386,16 @@ struct IRCDMessageMode : IRCDMessage for (size_t i = 2; i < params.size(); ++i) modes += " " + params[i]; - if (ircdproto->IsChannelValid(params[0])) + if (IRCD->IsChannelValid(params[0])) { - Channel *c = findchan(params[0]); + Channel *c = Channel::Find(params[0]); if (c) c->SetModesInternal(source, modes); } else { - User *u = finduser(params[0]); + User *u = User::Find(params[0]); if (u) u->SetModesInternal("%s", params[1].c_str()); @@ -432,7 +406,7 @@ struct IRCDMessageMode : IRCDMessage struct IRCDMessageNick : IRCDMessage { - IRCDMessageNick() : IRCDMessage("NICK", 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + IRCDMessageNick(Module *creator) : IRCDMessage(creator, "NICK", 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } /* * NICK - NEW @@ -464,8 +438,8 @@ struct IRCDMessageNick : IRCDMessage { // a new user is connecting to the network User *user = new User(params[0], params[2], params[3], "", "", source.GetServer(), params[6], Anope::CurTime, params[5], ""); - if (user && nickserv) - nickserv->Validate(user); + if (user && NickServService) + NickServService->Validate(user); } else { @@ -477,7 +451,7 @@ struct IRCDMessageNick : IRCDMessage struct IRCDMessageNJoin : IRCDMessage { - IRCDMessageNJoin() : IRCDMessage("NJOIN",2) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }; + IRCDMessageNJoin(Module *creator) : IRCDMessage(creator, "NJOIN",2) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }; /* * RFC 2813, 4.2.2: Njoin Message: @@ -492,76 +466,46 @@ struct IRCDMessageNJoin : IRCDMessage */ bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { - Channel *c = findchan(params[0]); + std::list<Message::Join::SJoinUser> users; + commasepstream sep(params[1]); Anope::string buf; - - if (!c) - { - c = new Channel(params[0], Anope::CurTime); - c->SetFlag(CH_SYNCING); - } - while (sep.GetToken(buf)) { - std::list<ChannelMode *> Status; - char ch; + + Message::Join::SJoinUser sju; /* Get prefixes from the nick */ - while ((ch = ModeManager::GetStatusChar(buf[0]))) + for (char ch; (ch = ModeManager::GetStatusChar(buf[0]));) { - buf.erase(buf.begin()); ChannelMode *cm = ModeManager::FindChannelModeByChar(ch); + buf.erase(buf.begin()); if (!cm) { Log(LOG_DEBUG) << "Received unknown mode prefix " << ch << " in NJOIN string."; continue; } - Status.push_back(cm); + + sju.first.SetFlag(cm->name); } - User *u = finduser(buf); - if (!u) + + sju.second = User::Find(buf); + if (!sju.second) { - Log(LOG_DEBUG) << "NJOIN for nonexistant user " << buf << " on " << c->name; + Log(LOG_DEBUG) << "NJOIN for nonexistant user " << buf << " on " << params[0]; continue; } + } - EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnPreJoinChannel, OnPreJoinChannel(u, c)); + Message::Join::SJoin(source, params[0], 0, "", users); - /* Add the user to the Channel */ - c->JoinUser(u); - - /* Update their status internally on the channel - * This will enforce secureops etc on the user - */ - for (std::list<ChannelMode *>::iterator it = Status.begin(), it_end = Status.end(); it != it_end; ++it) - c->SetModeInternal(source, *it, buf); - /* Now set whatever modes this user is allowed to have on the channel */ - chan_set_correct_modes(u, c, 1, true); - - /* Check to see if modules want the user to join, if they do - * check to see if they are allowed to join (CheckKick will kick/ban them) - * Don't trigger OnJoinChannel event then as the user will be destroyed - */ - if (MOD_RESULT != EVENT_STOP && c->ci && c->ci->CheckKick(u)) - continue; - - FOREACH_MOD(I_OnJoinChannel, OnJoinChannel(u, c)); - } /* while */ - - if (c->HasFlag(CH_SYNCING)) - { - c->UnsetFlag(CH_SYNCING); - c->Sync(); - } return true; } }; struct IRCDMessagePong : IRCDMessage { - IRCDMessagePong() : IRCDMessage("PONG", 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + IRCDMessagePong(Module *creator) : IRCDMessage(creator, "PONG", 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } /* * ngIRCd does not send an EOB, so we send a PING immediately @@ -578,7 +522,7 @@ struct IRCDMessagePong : IRCDMessage struct IRCDMessageServer : IRCDMessage { - IRCDMessageServer() : IRCDMessage("SERVER", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } /* * SERVER tolsun.oulu.fi 1 :Experimental server @@ -624,19 +568,19 @@ struct IRCDMessageServer : IRCDMessage * when receiving a new server and then finish sync once we * get a pong back from that server. */ - ircdproto->SendPing(Config->ServerName, params[0]); + IRCD->SendPing(Config->ServerName, params[0]); return true; } }; struct IRCDMessageTopic : IRCDMessage { - IRCDMessageTopic() : IRCDMessage("TOPIC", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + IRCDMessageTopic(Module *creator) : IRCDMessage(creator, "TOPIC", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } // Received: :DukeP TOPIC #anope :test bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { - Channel *c = findchan(params[0]); + Channel *c = Channel::Find(params[0]); if (!c) { Log(LOG_DEBUG) << "TOPIC for nonexistant channel " << params[0]; @@ -654,19 +598,19 @@ class ProtongIRCd : public Module ngIRCdProto ircd_proto; /* Core message handlers */ - CoreIRCDMessageCapab core_message_capab; - CoreIRCDMessageError core_message_error; - CoreIRCDMessageKick core_message_kick; - CoreIRCDMessageKill core_message_kill; - CoreIRCDMessageMOTD core_message_motd; - CoreIRCDMessagePart core_message_part; - CoreIRCDMessagePing core_message_ping; - CoreIRCDMessagePrivmsg core_message_privmsg, core_message_squery; - CoreIRCDMessageQuit core_message_quit; - CoreIRCDMessageSQuit core_message_squit; - CoreIRCDMessageStats core_message_stats; - CoreIRCDMessageTime core_message_time; - CoreIRCDMessageVersion core_message_version; + Message::Capab message_capab; + Message::Error message_error; + Message::Kick message_kick; + Message::Kill message_kill; + Message::MOTD message_motd; + Message::Part message_part; + Message::Ping message_ping; + Message::Privmsg message_privmsg, message_squery; + Message::Quit message_quit; + Message::SQuit message_squit; + Message::Stats message_stats; + Message::Time message_time; + Message::Version message_version; /* Our message handlers */ IRCDMessage005 message_005; @@ -728,11 +672,17 @@ class ProtongIRCd : public Module public: ProtongIRCd(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL), - core_message_squery("SQUERY") + message_capab(this), message_error(this), message_kick(this), message_kill(this), message_motd(this), + message_part(this), message_ping(this), message_privmsg(this), message_squery(this, "SQUERY"), + message_quit(this), message_squit(this), message_stats(this), message_time(this), message_version(this), + + message_005(this), message_376(this), message_chaninfo(this), message_join(this), message_mode(this), + message_nick(this), message_njoin(this), message_pong(this), message_server(this), message_topic(this) + { this->SetAuthor("Anope"); - Capab.insert("QS"); + Servers::Capab.insert("QS"); this->AddModes(); @@ -740,6 +690,11 @@ class ProtongIRCd : public Module ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); } + IRCDProto *GetIRCDProto() anope_override + { + return &ircd_proto; + } + void OnUserNickChange(User *u, const Anope::string &) anope_override { u->RemoveModeInternal(ModeManager::FindUserModeByName(UMODE_REGISTERED)); diff --git a/modules/protocol/plexus.cpp b/modules/protocol/plexus.cpp index 432cc3c02..53efdbd88 100644 --- a/modules/protocol/plexus.cpp +++ b/modules/protocol/plexus.cpp @@ -12,6 +12,7 @@ #include "module.h" static Anope::string UplinkSID; +static IRCDProto *hybrid; class PlexusProto : public IRCDProto { @@ -31,51 +32,17 @@ class PlexusProto : public IRCDProto MaxModes = 4; } - void SendGlobalNotice(const BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override - { - UplinkSocket::Message(bi) << "NOTICE $$" << dest->GetName() << " :" << msg; - } - - void SendGlobalPrivmsg(const BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override - { - UplinkSocket::Message(bi) << "PRIVMSG $$" << dest->GetName() << " :" << msg; - } - - void SendGlobopsInternal(const BotInfo *source, const Anope::string &buf) anope_override - { - UplinkSocket::Message(source) << "OPERWALL :" << buf; - } - - void SendSQLine(User *, const XLine *x) anope_override - { - UplinkSocket::Message(Me) << "RESV * " << x->Mask << " :" << x->GetReason(); - } - - void SendSGLineDel(const XLine *x) anope_override - { - const BotInfo *bi = findbot(Config->OperServ); - UplinkSocket::Message(bi) << "UNXLINE * " << x->Mask; - } - - void SendSGLine(User *, const XLine *x) anope_override - { - const BotInfo *bi = findbot(Config->OperServ); - UplinkSocket::Message(bi) << "XLINE * " << x->Mask << " 0 :" << x->GetReason(); - } - - void SendAkillDel(const XLine *x) anope_override - { - if (x->IsRegex() || x->HasNickOrReal()) - return; - - const BotInfo *bi = findbot(Config->OperServ); - UplinkSocket::Message(bi) << "UNKLINE * " << x->GetUser() << " " << x->GetHost(); - } - - void SendSQLineDel(const XLine *x) anope_override - { - UplinkSocket::Message(Me) << "UNRESV * " << x->Mask; - } + void SendGlobalNotice(const BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override { hybrid->SendGlobalNotice(bi, dest, msg); } + void SendGlobalPrivmsg(const BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override { hybrid->SendGlobalPrivmsg(bi, dest, msg); } + void SendGlobopsInternal(const BotInfo *source, const Anope::string &buf) anope_override { hybrid->SendGlobopsInternal(source, buf); } + void SendSQLine(User *u, const XLine *x) anope_override { hybrid->SendSQLine(u, x); } + void SendSQLineDel(const XLine *x) anope_override { hybrid->SendSQLineDel(x); } + void SendSGLineDel(const XLine *x) anope_override { hybrid->SendSGLineDel(x); } + void SendSGLine(User *u, const XLine *x) anope_override { hybrid->SendSGLine(u, x); } + void SendAkillDel(const XLine *x) anope_override { hybrid->SendAkillDel(x); } + void SendAkill(User *u, XLine *x) anope_override { hybrid->SendAkill(u, x); } + void SendServer(const Server *server) anope_override { hybrid->SendServer(server); } + void SendChannel(Channel *c) anope_override { hybrid->SendChannel(c); } void SendJoin(const User *user, Channel *c, const ChannelStatus *status) anope_override { @@ -89,82 +56,38 @@ class PlexusProto : public IRCDProto */ UserContainer *uc = c->FindUser(user); if (uc != NULL) - uc->Status->ClearFlags(); + uc->status->ClearFlags(); - BotInfo *setter = findbot(user->nick); + BotInfo *setter = BotInfo::Find(user->nick); for (unsigned i = 0; i < ModeManager::ChannelModes.size(); ++i) - if (cs.HasFlag(ModeManager::ChannelModes[i]->Name)) + if (cs.HasFlag(ModeManager::ChannelModes[i]->name)) c->SetMode(setter, ModeManager::ChannelModes[i], user->GetUID(), false); } } - void SendAkill(User *u, XLine *x) anope_override - { - const BotInfo *bi = findbot(Config->OperServ); - - 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 */ - XLine *xline = new XLine("*@" + u->host, old->By, old->Expires, old->Reason, old->UID); - old->manager->AddXLine(xline); - x = xline; - - Log(bi, "akill") << "AKILL: Added an akill for " << x->Mask << " because " << u->GetMask() << "#" << u->realname << " matches " << old->Mask; - } - - // 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; - UplinkSocket::Message(bi) << "KLINE * " << timeleft << " " << x->GetUser() << " " << x->GetHost() << " :" << x->GetReason(); - } - - void SendServer(const Server *server) anope_override + void SendForceNickChange(const User *u, const Anope::string &newnick, time_t when) anope_override { - if (server == Me) - UplinkSocket::Message() << "SERVER " << server->GetName() << " " << server->GetHops() << " :" << server->GetDescription(); - else - UplinkSocket::Message(Me) << "SID " << server->GetName() << " " << server->GetHops() << " " << server->GetSID() << " :" << server->GetDescription(); + UplinkSocket::Message(Me) << "ENCAP " << u->server->GetName() << " SVSNICK " << u->GetUID() << " " << u->timestamp << " " << newnick << " " << when; } - void SendForceNickChange(const User *u, const Anope::string &newnick, time_t when) anope_override + void SendVhost(User *u, const Anope::string &ident, const Anope::string &host) anope_override { - UplinkSocket::Message(Me) << "ENCAP " << u->server->GetName() << " SVSNICK " << u->GetUID() << " " << u->timestamp << " " << newnick << " " << when; + if (!ident.empty()) + UplinkSocket::Message(Me) << "ENCAP * CHGIDENT " << u->GetUID() << " " << ident; + UplinkSocket::Message(Me) << "ENCAP * CHGHOST " << u->GetUID() << " " << host; } void SendVhostDel(User *u) anope_override { - const BotInfo *bi = findbot(Config->HostServ); if (u->HasMode(UMODE_CLOAK)) - u->RemoveMode(bi, UMODE_CLOAK); + u->RemoveMode(HostServ, UMODE_CLOAK); else this->SendVhost(u, u->GetIdent(), u->chost); } - void SendVhost(User *u, const Anope::string &ident, const Anope::string &host) anope_override - { - if (!ident.empty()) - UplinkSocket::Message(Me) << "ENCAP * CHGIDENT " << u->GetUID() << " " << ident; - UplinkSocket::Message(Me) << "ENCAP * CHGHOST " << u->GetUID() << " " << host; - } - void SendConnect() anope_override { - UplinkSocket::Message() << "PASS " << Config->Uplinks[CurrentUplink]->password << " TS 6 :" << Me->GetSID(); + UplinkSocket::Message() << "PASS " << Config->Uplinks[Anope::CurrentUplink]->password << " TS 6 :" << Me->GetSID(); /* CAPAB * QS - Can handle quit storm removal * EX - Can do channel +e exemptions @@ -227,53 +150,11 @@ class PlexusProto : public IRCDProto { UplinkSocket::Message(bi) << "ENCAP * TOPIC " << c->name << " " << c->topic_setter << " " << c->topic_ts << " :" << c->topic; } - - void SendChannel(Channel *c) anope_override - { - Anope::string modes = c->GetModes(true, true); - if (modes.empty()) - modes = "+"; - UplinkSocket::Message(Me) << "SJOIN " << c->creation_time << " " << c->name << " " << modes << " :"; - } -}; - -struct IRCDMessageBMask : IRCDMessage -{ - IRCDMessageBMask() : IRCDMessage("BMASK", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - /* :42X BMASK 1106409026 #ircops b :*!*@*.aol.com */ - /* 0 1 2 3 */ - Channel *c = findchan(params[1]); - - if (c) - { - ChannelMode *ban = ModeManager::FindChannelModeByName(CMODE_BAN), - *except = ModeManager::FindChannelModeByName(CMODE_EXCEPT), - *invex = ModeManager::FindChannelModeByName(CMODE_INVITEOVERRIDE); - - Anope::string bans = params[3]; - int count = myNumToken(bans, ' '), i; - for (i = 0; i < count; ++i) - { - Anope::string b = myStrGetToken(bans, ' ', i); - if (ban && params[2].equals_cs("b")) - c->SetModeInternal(source, ban, b); - else if (except && params[2].equals_cs("e")) - c->SetModeInternal(source, except, b); - if (invex && params[2].equals_cs("I")) - c->SetModeInternal(source, invex, b); - } - } - - return true; - } }; struct IRCDMessageEncap : IRCDMessage { - IRCDMessageEncap() : IRCDMessage("ENCAP", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + IRCDMessageEncap(Module *creator) : IRCDMessage(creator, "ENCAP", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { @@ -286,14 +167,14 @@ struct IRCDMessageEncap : IRCDMessage */ if (params[1].equals_cs("SU")) { - User *u = finduser(params[2]); - const NickAlias *user_na = findnick(params[2]); - NickCore *nc = findcore(params[3]); + User *u = User::Find(params[2]); + const NickAlias *user_na = NickAlias::Find(params[2]); + NickCore *nc = NickCore::Find(params[3]); if (u && nc) { u->Login(nc); if (!Config->NoNicknameOwnership && user_na && user_na->nc == nc && user_na->nc->HasFlag(NI_UNCONFIRMED) == false) - u->SetMode(findbot(Config->NickServ), UMODE_REGISTERED); + u->SetMode(NickServ, UMODE_REGISTERED); } } @@ -306,7 +187,7 @@ struct IRCDMessageEncap : IRCDMessage */ else if (params[1].equals_cs("CERTFP")) { - User *u = finduser(params[2]); + User *u = User::Find(params[2]); if (u) { u->fingerprint = params[3]; @@ -317,82 +198,9 @@ struct IRCDMessageEncap : IRCDMessage } }; -struct IRCDMessageEOB : IRCDMessage -{ - IRCDMessageEOB() : IRCDMessage("EOB", 0) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - source.GetServer()->Sync(true); - return true; - } -}; - -struct IRCDMessageJoin : CoreIRCDMessageJoin -{ - IRCDMessageJoin() : CoreIRCDMessageJoin("JOIN") { } - - /* - * params[0] = ts - * params[1] = channel - */ - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - if (params.size() < 2) - return true; - - std::vector<Anope::string> p = params; - p.erase(p.begin()); - - return CoreIRCDMessageJoin::Run(source, p); - } -}; - -struct IRCDMessageMode : IRCDMessage -{ - IRCDMessageMode() : IRCDMessage("MODE", 3) { } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - if (ircdproto->IsChannelValid(params[0])) - { - // 0 = channel, 1 = ts, 2 = modes - Channel *c = findchan(params[0]); - time_t ts = 0; - try - { - ts = convertTo<time_t>(params[1]); - } - catch (const ConvertException &) { } - - if (c) - c->SetModesInternal(source, params[2], ts); - } - else - { - User *u = finduser(params[0]); - if (u) - u->SetModesInternal("%s", params[1].c_str()); - } - - return true; - } -}; - -struct IRCDMessageNick : IRCDMessage -{ - IRCDMessageNick() : IRCDMessage("NICK", 2) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - source.GetUser()->ChangeNick(params[0]); - return true; - } -}; - struct IRCDMessagePass : IRCDMessage { - IRCDMessagePass() : IRCDMessage("PASS", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + IRCDMessagePass(Module *creator) : IRCDMessage(creator, "PASS", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { @@ -403,206 +211,25 @@ struct IRCDMessagePass : IRCDMessage struct IRCDMessageServer : IRCDMessage { - IRCDMessageServer() : IRCDMessage("SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + /* 0 1 2 */ + /* SERVER hades.arpa 1 :ircd-hybrid test server */ bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { - // Servers other then our immediate uplink are introduced via SID + /* Servers other than our immediate uplink are introduced via SID */ if (params[1] != "1") return true; - new Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], 1, params[2], UplinkSID); - return true; - } -}; - -struct IRCDMessageSID : IRCDMessage -{ - IRCDMessageSID() : IRCDMessage("SID", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - - /* :42X SID trystan.nomadirc.net 2 43X :ircd-plexus test server */ - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - unsigned int hops = params[1].is_pos_number_only() ? convertTo<unsigned>(params[1]) : 0; - new Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], hops, params[3], params[2]); - return true; - } -}; - -struct IRCDMessageSJoin : IRCDMessage -{ - IRCDMessageSJoin() : IRCDMessage("SJOIN", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - Channel *c = findchan(params[1]); - time_t ts = Anope::string(params[0]).is_pos_number_only() ? convertTo<time_t>(params[0]) : 0; - bool keep_their_modes = true; - - if (!c) - { - c = new Channel(params[1], ts); - c->SetFlag(CH_SYNCING); - } - /* Our creation time is newer than what the server gave us */ - else if (c->creation_time > ts) - { - c->creation_time = ts; - c->Reset(); - } - /* Their TS is newer than ours, our modes > theirs, unset their modes if need be */ - else if (ts > c->creation_time) - keep_their_modes = false; - - /* If we need to keep their modes, and this SJOIN string contains modes */ - if (keep_their_modes && params.size() >= 3) - { - Anope::string modes; - for (unsigned i = 2; i < params.size() - 1; ++i) - modes += " " + params[i]; - if (!modes.empty()) - modes.erase(modes.begin()); - /* Set the modes internally */ - c->SetModesInternal(source, modes); - } - - spacesepstream sep(params[params.size() - 1]); - Anope::string buf; - while (sep.GetToken(buf)) - { - std::list<ChannelMode *> Status; - char ch; - - /* Get prefixes from the nick */ - while ((ch = ModeManager::GetStatusChar(buf[0]))) - { - buf.erase(buf.begin()); - ChannelMode *cm = ModeManager::FindChannelModeByChar(ch); - if (!cm) - { - Log() << "Received unknown mode prefix " << ch << " in SJOIN string"; - continue; - } - - if (keep_their_modes) - Status.push_back(cm); - } - - User *u = finduser(buf); - if (!u) - { - Log(LOG_DEBUG) << "SJOIN for nonexistant user " << buf << " on " << c->name; - continue; - } - - EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnPreJoinChannel, OnPreJoinChannel(u, c)); - - /* Add the user to the channel */ - c->JoinUser(u); - - /* Update their status internally on the channel - * This will enforce secureops etc on the user - */ - for (std::list<ChannelMode *>::iterator it = Status.begin(), it_end = Status.end(); it != it_end; ++it) - c->SetModeInternal(source, *it, buf); - - /* Now set whatever modes this user is allowed to have on the channel */ - chan_set_correct_modes(u, c, 1, true); - - /* Check to see if modules want the user to join, if they do - * check to see if they are allowed to join (CheckKick will kick/ban them) - * Don't trigger OnJoinChannel event then as the user will be destroyed - */ - if (MOD_RESULT != EVENT_STOP && c->ci && c->ci->CheckKick(u)) - continue; - - FOREACH_MOD(I_OnJoinChannel, OnJoinChannel(u, c)); - } - - /* Channel is done syncing */ - if (c->HasFlag(CH_SYNCING)) - { - /* Unset the syncing flag */ - c->UnsetFlag(CH_SYNCING); - c->Sync(); - } - return true; - } -}; - -struct IRCDMessageTBurst : IRCDMessage -{ - IRCDMessageTBurst() : IRCDMessage("TBURST", 5) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - // 0 1 2 3 4 - // :rizon.server TBURST 1298674830 #lol 1298674833 Adam!Adam@i.has.a.spoof :lol - // chan ts topic ts - - Channel *c = findchan(params[1]); - - try - { - if (!c || c->creation_time < convertTo<time_t>(params[0])) - return true; - } - catch (const ConvertException &) - { - return true; - } - - Anope::string setter = myStrGetToken(params[3], '!', 0); - time_t topic_time = Anope::string(params[2]).is_pos_number_only() ? convertTo<time_t>(params[2]) : Anope::CurTime; - c->ChangeTopicInternal(setter, params.size() > 4 ? params[4] : "", topic_time); - - return true; - } -}; - -struct IRCDMessageTMode : IRCDMessage -{ - IRCDMessageTMode() : IRCDMessage("TMODE", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - time_t ts = 0; - try - { - ts = convertTo<time_t>(params[0]); - } - catch (const ConvertException &) { } - Channel *c = findchan(params[1]); - Anope::string modes = params[2]; - for (unsigned i = 3; i < params.size(); ++i) - modes += " " + params[i]; - - if (c) - c->SetModesInternal(source, modes, ts); - - return true; - } -}; - -struct IRCDMessageTopic : IRCDMessage -{ - IRCDMessageTopic() : IRCDMessage("TOPIC", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - Channel *c = findchan(params[0]); - if (!c) - return true; + new Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], 1, params[2], UplinkSID); - c->ChangeTopicInternal(params[1], params[3], Anope::string(params[2]).is_pos_number_only() ? convertTo<time_t>(params[2]) : Anope::CurTime); return true; } }; struct IRCDMessageUID : IRCDMessage { - IRCDMessageUID() : IRCDMessage("UID", 11) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + IRCDMessageUID(Module *creator) : IRCDMessage(creator, "UID", 11) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } /* params[0] = nick @@ -628,12 +255,12 @@ struct IRCDMessageUID : IRCDMessage User *user = new User(params[0], params[4], params[9], params[5], ip, source.GetServer(), params[10], params[2].is_pos_number_only() ? convertTo<time_t>(params[2]) : 0, params[3], params[7]); if (params[8] != "0" && params[8].is_pos_number_only() && convertTo<time_t>(params[8]) == user->timestamp) { - NickAlias *na = findnick(user->nick); + NickAlias *na = NickAlias::Find(user->nick); if (na) user->Login(na->nc); } - else if (user && user->server->IsSynced() && nickserv) - nickserv->Validate(user); + else if (user && user->server->IsSynced() && NickServService) + NickServService->Validate(user); return true; } @@ -641,127 +268,117 @@ struct IRCDMessageUID : IRCDMessage class ProtoPlexus : public Module { + Module *m_hybrid; + PlexusProto ircd_proto; /* Core message handlers */ - CoreIRCDMessageAway core_message_away; - CoreIRCDMessageCapab core_message_capab; - CoreIRCDMessageError core_message_error; - CoreIRCDMessageKick core_message_kick; - CoreIRCDMessageKill core_message_kill; - CoreIRCDMessageMOTD core_message_motd; - CoreIRCDMessagePart core_message_part; - CoreIRCDMessagePing core_message_ping; - CoreIRCDMessagePrivmsg core_message_privmsg; - CoreIRCDMessageQuit core_message_quit; - CoreIRCDMessageSQuit core_message_squit; - CoreIRCDMessageStats core_message_stats; - CoreIRCDMessageTime core_message_time; - CoreIRCDMessageTopic core_message_topic; - CoreIRCDMessageVersion core_message_version; - CoreIRCDMessageWhois core_message_whois; + Message::Away message_away; + Message::Capab message_capab; + Message::Error message_error; + Message::Kick message_kick; + Message::Kill message_kill; + Message::Mode message_mode; + Message::MOTD message_motd; + Message::Part message_part; + Message::Ping message_ping; + Message::Privmsg message_privmsg; + Message::Quit message_quit; + Message::SQuit message_squit; + Message::Stats message_stats; + Message::Time message_time; + Message::Topic message_topic; + Message::Version message_version; + Message::Whois message_whois; + + /* Hybrid message handlers */ + ServiceAlias message_bmask, message_eob, message_join, message_nick, message_sid, message_sjoin, + message_tburst, message_tmode; /* Our message handlers */ - IRCDMessageBMask message_bmask; IRCDMessageEncap message_encap; - IRCDMessageEOB message_eob; - IRCDMessageJoin message_join; - IRCDMessageMode message_mode; - IRCDMessageNick message_nick; IRCDMessagePass message_pass; IRCDMessageServer message_server; - IRCDMessageSID message_sid; - IRCDMessageSJoin message_sjoin; - IRCDMessageTBurst message_tburst; - IRCDMessageTMode message_tmode; - IRCDMessageTopic message_topic; IRCDMessageUID message_uid; void AddModes() { /* Add user modes */ - ModeManager::AddUserMode(new UserMode(UMODE_ADMIN, 'a')); - ModeManager::AddUserMode(new UserMode(UMODE_INVIS, 'i')); - ModeManager::AddUserMode(new UserMode(UMODE_OPER, 'o')); - ModeManager::AddUserMode(new UserMode(UMODE_SNOMASK, 's')); - ModeManager::AddUserMode(new UserMode(UMODE_WALLOPS, 'w')); + ModeManager::RemoveUserMode(ModeManager::FindUserModeByName(UMODE_HIDEOPER)); ModeManager::AddUserMode(new UserMode(UMODE_NOCTCP, 'C')); ModeManager::AddUserMode(new UserMode(UMODE_DEAF, 'D')); ModeManager::AddUserMode(new UserMode(UMODE_SOFTCALLERID, 'G')); ModeManager::AddUserMode(new UserMode(UMODE_NETADMIN, 'N')); - ModeManager::AddUserMode(new UserMode(UMODE_REGPRIV, 'R')); ModeManager::AddUserMode(new UserMode(UMODE_SSL, 'S')); ModeManager::AddUserMode(new UserMode(UMODE_WEBIRC, 'W')); ModeManager::AddUserMode(new UserMode(UMODE_CALLERID, 'g')); ModeManager::AddUserMode(new UserMode(UMODE_PRIV, 'p')); - ModeManager::AddUserMode(new UserMode(UMODE_REGISTERED, 'r')); ModeManager::AddUserMode(new UserMode(UMODE_CLOAK, 'x')); ModeManager::AddUserMode(new UserMode(UMODE_PROTECTED, 'U')); - /* b/e/I */ - ModeManager::AddChannelMode(new ChannelModeList(CMODE_BAN, 'b')); - ModeManager::AddChannelMode(new ChannelModeList(CMODE_EXCEPT, 'e')); - ModeManager::AddChannelMode(new ChannelModeList(CMODE_INVITEOVERRIDE, 'I')); - - /* l/k */ - ModeManager::AddChannelMode(new ChannelModeKey('k')); - ModeManager::AddChannelMode(new ChannelModeParam(CMODE_LIMIT, 'l')); - /* v/h/o/a/q */ - ModeManager::AddChannelMode(new ChannelModeStatus(CMODE_VOICE, 'v', '+', 0)); - ModeManager::AddChannelMode(new ChannelModeStatus(CMODE_HALFOP, 'h', '%', 1)); - ModeManager::AddChannelMode(new ChannelModeStatus(CMODE_OP, 'o', '@', 2)); ModeManager::AddChannelMode(new ChannelModeStatus(CMODE_PROTECT, 'a', '&', 3)); ModeManager::AddChannelMode(new ChannelModeStatus(CMODE_OWNER, 'q', '~', 4)); /* Add channel modes */ + ModeManager::RemoveChannelMode(ModeManager::FindChannelModeByName(CMODE_REGISTERED)); ModeManager::AddChannelMode(new ChannelMode(CMODE_BANDWIDTH, 'B')); ModeManager::AddChannelMode(new ChannelMode(CMODE_NOCTCP, 'C')); ModeManager::AddChannelMode(new ChannelMode(CMODE_REGMODERATED, 'M')); ModeManager::AddChannelMode(new ChannelMode(CMODE_NONOTICE, 'N')); - ModeManager::AddChannelMode(new ChannelModeOper('O')); - ModeManager::AddChannelMode(new ChannelMode(CMODE_REGISTEREDONLY, 'R')); - ModeManager::AddChannelMode(new ChannelMode(CMODE_SSL, 'S')); - ModeManager::AddChannelMode(new ChannelMode(CMODE_BLOCKCOLOR, 'c')); - ModeManager::AddChannelMode(new ChannelMode(CMODE_INVITE, 'i')); - ModeManager::AddChannelMode(new ChannelMode(CMODE_MODERATED, 'm')); - ModeManager::AddChannelMode(new ChannelMode(CMODE_NOEXTERNAL, 'n')); - ModeManager::AddChannelMode(new ChannelMode(CMODE_PRIVATE, 'p')); - ModeManager::AddChannelMode(new ChannelMode(CMODE_SECRET, 's')); - ModeManager::AddChannelMode(new ChannelMode(CMODE_TOPIC, 't')); ModeManager::AddChannelMode(new ChannelMode(CMODE_PERM, 'z')); } public: - ProtoPlexus(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL) + ProtoPlexus(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL), + message_away(this), message_capab(this), message_error(this), message_kick(this), message_kill(this), + message_mode(this), message_motd(this), message_part(this), message_ping(this), message_privmsg(this), message_quit(this), + message_squit(this), message_stats(this), message_time(this), message_topic(this), message_version(this), message_whois(this), + + message_bmask("IRCDMessage", "plexus/bmask", "hybrid/bmask"), message_eob("IRCDMessage", "plexus/eob", "hybrid/eob"), + message_join("IRCDMessage", "plexus/join", "hybrid/join"), message_nick("IRCDMessage", "plexus/nick", "hybrid/nick"), + message_sid("IRCDMessage", "plexus/sid", "hybrid/sid"), + message_sjoin("IRCDMessage", "plexus/sjoin", "hybrid/sjoin"), message_tburst("IRCDMessage", "plexus/tburst", "hybrid/tburst"), + message_tmode("IRCDMessage", "plexus/tmode", "hybrid/tmode"), + + message_encap(this), message_pass(this), message_server(this), message_uid(this) { this->SetAuthor("Anope"); + if (ModuleManager::LoadModule("hybrid", User::Find(creator)) != MOD_ERR_OK) + throw ModuleException("Unable to load hybrid"); + m_hybrid = ModuleManager::FindModule("hybrid"); + if (!m_hybrid) + throw ModuleException("Unable to find hybrid"); + hybrid = m_hybrid->GetIRCDProto(); + if (!hybrid) + throw ModuleException("No protocol interface for hybrid"); + this->AddModes(); Implementation i[] = { I_OnServerSync }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); + } - if (Config->Numeric.empty()) - { - Anope::string numeric = ts6_sid_retrieve(); - Me->SetSID(numeric); - Config->Numeric = numeric; - } + ~ProtoPlexus() + { + ModuleManager::UnloadModule(m_hybrid, NULL); + } - for (botinfo_map::iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) - it->second->GenerateUID(); + IRCDProto *GetIRCDProto() anope_override + { + return &ircd_proto; } void OnServerSync(Server *s) anope_override { - if (nickserv) + if (NickServService) for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) { User *u = it->second; if (u->server == s && !u->IsIdentified()) - nickserv->Validate(u); + NickServService->Validate(u); } } }; diff --git a/modules/protocol/ratbox.cpp b/modules/protocol/ratbox.cpp index 3ae4b6e17..32226fae7 100644 --- a/modules/protocol/ratbox.cpp +++ b/modules/protocol/ratbox.cpp @@ -12,6 +12,7 @@ #include "module.h" static Anope::string UplinkSID; +static IRCDProto *hybrid; class RatboxProto : public IRCDProto { @@ -26,112 +27,24 @@ class RatboxProto : public IRCDProto MaxModes = 4; } - void SendGlobalNotice(const BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override - { - UplinkSocket::Message(bi) << "NOTICE $$" << dest->GetName() << " :" << msg; - } - - void SendGlobalPrivmsg(const BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override - { - UplinkSocket::Message(bi) << "PRIVMSG $$" << dest->GetName() << " :" << msg; - } - - void SendGlobopsInternal(const BotInfo *source, const Anope::string &buf) anope_override - { - UplinkSocket::Message(source) << "OPERWALL :" << buf; - } - - void SendSQLine(User *, const XLine *x) anope_override - { - UplinkSocket::Message(Me) << "RESV * " << x->Mask << " :" << x->GetReason(); - } - - void SendSGLineDel(const XLine *x) anope_override - { - const BotInfo *bi = findbot(Config->OperServ); - UplinkSocket::Message(bi) << "UNXLINE * " << x->Mask; - } - - void SendSGLine(User *, const XLine *x) anope_override - { - const BotInfo *bi = findbot(Config->OperServ); - UplinkSocket::Message(bi) << "XLINE * " << x->Mask << " 0 :" << x->GetReason(); - } - - void SendAkillDel(const XLine *x) anope_override - { - if (x->IsRegex() || x->HasNickOrReal()) - return; - - const BotInfo *bi = findbot(Config->OperServ); - UplinkSocket::Message(bi) << "UNKLINE * " << x->GetUser() << " " << x->GetHost(); - } - - void SendSQLineDel(const XLine *x) anope_override - { - UplinkSocket::Message(Me) << "UNRESV * " << x->Mask; - } - - void SendJoin(const User *user, Channel *c, const ChannelStatus *status) anope_override - { - /* Note that we must send our modes with the SJOIN and - * can not add them to the mode stacker because ratbox - * does not allow *any* client to op itself - */ - UplinkSocket::Message() << "SJOIN " << c->creation_time << " " << c->name << " +" << c->GetModes(true, true) << " :" << (status != NULL ? status->BuildModePrefixList() : "") << user->GetUID(); - /* And update our internal status for this user since this is not going through our mode handling system */ - if (status != NULL) - { - UserContainer *uc = c->FindUser(user); - if (uc != NULL) - *uc->Status = *status; - } - } - - void SendAkill(User *u, XLine *x) anope_override - { - const BotInfo *bi = findbot(Config->OperServ); - - 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 */ - XLine *xline = new XLine("*@" + u->host, old->By, old->Expires, old->Reason, old->UID); - old->manager->AddXLine(xline); - x = xline; - - Log(bi, "akill") << "AKILL: Added an akill for " << x->Mask << " because " << u->GetMask() << "#" << u->realname << " matches " << old->Mask; - } - - // 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; - UplinkSocket::Message(bi) << "KLINE * " << timeleft << " " << x->GetUser() << " " << x->GetHost() << " :" << x->GetReason(); - } - - /* SERVER name hop descript */ - void SendServer(const Server *server) anope_override - { - UplinkSocket::Message() << "SERVER " << server->GetName() << " " << server->GetHops() << " :" << server->GetDescription(); - } + void SendGlobalNotice(const BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override { hybrid->SendGlobalNotice(bi, dest, msg); } + void SendGlobalPrivmsg(const BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override { hybrid->SendGlobalPrivmsg(bi, dest, msg); } + void SendGlobopsInternal(const BotInfo *source, const Anope::string &buf) anope_override { hybrid->SendGlobopsInternal(source, buf); } + void SendSQLine(User *u, const XLine *x) anope_override { hybrid->SendSQLine(u, x); } + void SendSGLine(User *u, const XLine *x) anope_override { hybrid->SendSGLine(u, x); } + void SendSGLineDel(const XLine *x) anope_override { hybrid->SendSGLineDel(x); } + void SendAkill(User *u, XLine *x) anope_override { hybrid->SendAkill(u, x); } + void SendAkillDel(const XLine *x) anope_override { hybrid->SendAkillDel(x); } + void SendSQLineDel(const XLine *x) anope_override { hybrid->SendSQLineDel(x); } + void SendJoin(const User *user, Channel *c, const ChannelStatus *status) anope_override { hybrid->SendJoin(user, c, status); } + void SendServer(const Server *server) anope_override { hybrid->SendServer(server); } + void SendModeInternal(const BotInfo *bi, const User *u, const Anope::string &buf) anope_override { hybrid->SendModeInternal(bi, u, buf); } + void SendChannel(Channel *c) anope_override { hybrid->SendChannel(c); } + void SendTopic(BotInfo *bi, Channel *c) anope_override { hybrid->SendTopic(bi, c); } void SendConnect() anope_override { - UplinkSocket::Message() << "PASS " << Config->Uplinks[CurrentUplink]->password << " TS 6 :" << Me->GetSID(); + UplinkSocket::Message() << "PASS " << Config->Uplinks[Anope::CurrentUplink]->password << " TS 6 :" << Me->GetSID(); /* QS - Can handle quit storm removal EX - Can do channel +e exemptions @@ -162,11 +75,6 @@ class RatboxProto : public IRCDProto UplinkSocket::Message(Me) << "UID " << u->nick << " 1 " << u->timestamp << " " << modes << " " << u->GetIdent() << " " << u->host << " 0 " << u->GetUID() << " :" << u->realname; } - void SendModeInternal(const BotInfo *bi, const User *u, const Anope::string &buf) anope_override - { - UplinkSocket::Message(bi) << "SVSMODE " << u->nick << " " << buf; - } - void SendLogin(User *u) anope_override { if (!u->Account()) @@ -179,157 +87,36 @@ class RatboxProto : public IRCDProto { UplinkSocket::Message(Me) << "ENCAP * SU " << u->GetUID(); } - - void SendChannel(Channel *c) anope_override - { - Anope::string modes = c->GetModes(true, true); - if (modes.empty()) - modes = "+"; - UplinkSocket::Message() << "SJOIN " << c->creation_time << " " << c->name << " " << modes << " :"; - } - - bool IsNickValid(const Anope::string &nick) anope_override - { - /* TS6 Save extension -Certus */ - if (isdigit(nick[0])) - return false; - - return true; - } - - void SendTopic(BotInfo *bi, Channel *c) anope_override - { - bool needjoin = c->FindUser(bi) == NULL; - if (needjoin) - { - ChannelStatus status; - status.SetFlag(CMODE_OP); - bi->Join(c, &status); - } - IRCDProto::SendTopic(bi, c); - if (needjoin) - bi->Part(c); - } -}; - -struct IRCDMessageBMask : IRCDMessage -{ - IRCDMessageBMask() : IRCDMessage("BMASK", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - /* :42X BMASK 1106409026 #ircops b :*!*@*.aol.com */ - /* 0 1 2 3 */ - Channel *c = findchan(params[1]); - - if (c) - { - ChannelMode *ban = ModeManager::FindChannelModeByName(CMODE_BAN), - *except = ModeManager::FindChannelModeByName(CMODE_EXCEPT), - *invex = ModeManager::FindChannelModeByName(CMODE_INVITEOVERRIDE); - - Anope::string bans = params[3]; - int count = myNumToken(bans, ' '), i; - for (i = 0; i < count; ++i) - { - Anope::string b = myStrGetToken(bans, ' ', i); - if (ban && params[2].equals_cs("b")) - c->SetModeInternal(source, ban, b); - else if (except && params[2].equals_cs("e")) - c->SetModeInternal(source, except, b); - if (invex && params[2].equals_cs("I")) - c->SetModeInternal(source, invex, b); - } - } - - return true; - } }; struct IRCDMessageEncap : IRCDMessage { - IRCDMessageEncap() : IRCDMessage("ENCAP", 3) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + IRCDMessageEncap(Module *creator) : IRCDMessage(creator, "ENCAP", 3) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } // Debug: Received: :00BAAAAAB ENCAP * LOGIN Adam bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { - if (params[1] == "LOGIN") + if (params[1] == "LOGIN" || params[1] == "SU") { User *u = source.GetUser(); - NickCore *nc = findcore(params[2]); + NickCore *nc = NickCore::Find(params[2]); if (!nc) return true; u->Login(nc); - const NickAlias *user_na = findnick(u->nick); + const NickAlias *user_na = NickAlias::Find(u->nick); if (!Config->NoNicknameOwnership && user_na && user_na->nc == nc && user_na->nc->HasFlag(NI_UNCONFIRMED) == false) - u->SetMode(findbot(Config->NickServ), UMODE_REGISTERED); - } - - return true; - } -}; - -struct IRCDMessageJoin : CoreIRCDMessageJoin -{ - IRCDMessageJoin() : CoreIRCDMessageJoin("JOIN") { } - - /* - * params[0] = ts - * params[1] = channel - * params[2] = modes - */ - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - if (params.size() < 2) - return true; - - std::vector<Anope::string> p = params; - p.erase(p.begin()); - - return CoreIRCDMessageJoin::Run(source, p); - } -}; - -struct IRCDMessageMode : IRCDMessage -{ - IRCDMessageMode() : IRCDMessage("MODE", 2) { } - - // Received: :42CAAAIHS MODE 42CAAAIHS :+ao - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - if (ircdproto->IsChannelValid(params[0])) - { - Channel *c = findchan(params[0]); - if (c) - c->SetModesInternal(source, params[1]); - } - else - { - User *u = finduser(params[0]); - if (u) - u->SetModesInternal("%s", params[1].c_str()); + u->SetMode(NickServ, UMODE_REGISTERED); } return true; } }; -struct IRCDMessageNick : IRCDMessage -{ - IRCDMessageNick() : IRCDMessage("NICK", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - source.GetUser()->ChangeNick(params[0]); - return true; - } -}; - struct IRCDMessagePass : IRCDMessage { - IRCDMessagePass() : IRCDMessage("PASS", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + IRCDMessagePass(Module *creator) : IRCDMessage(creator, "PASS", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { @@ -338,20 +125,9 @@ struct IRCDMessagePass : IRCDMessage } }; -struct IRCDMessagePong : IRCDMessage -{ - IRCDMessagePong() : IRCDMessage("PONG", 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - source.GetServer()->Sync(false); - return true; - } -}; - struct IRCDMessageServer : IRCDMessage { - IRCDMessageServer() : IRCDMessage("SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } // SERVER hades.arpa 1 :ircd-ratbox test server bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override @@ -360,166 +136,33 @@ struct IRCDMessageServer : IRCDMessage if (params[1] != "1") return true; new Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], 1, params[2], UplinkSID); - ircdproto->SendPing(Config->ServerName, params[0]); - return true; - } -}; - -struct IRCDMessageSID : IRCDMessage -{ - IRCDMessageSID() : IRCDMessage("SID", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - /* :42X SID trystan.nomadirc.net 2 43X :ircd-ratbox test server */ - unsigned int hops = params[1].is_pos_number_only() ? convertTo<unsigned>(params[1]) : 0; - new Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], hops, params[3], params[2]); - ircdproto->SendPing(Config->ServerName, params[0]); - return true; - } -}; - -struct IRCDMessageSjoin : IRCDMessage -{ - IRCDMessageSjoin() : IRCDMessage("SJOIN", 2) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - Channel *c = findchan(params[1]); - time_t ts = Anope::string(params[0]).is_pos_number_only() ? convertTo<time_t>(params[0]) : 0; - bool keep_their_modes = true; - - if (!c) - { - c = new Channel(params[1], ts); - c->SetFlag(CH_SYNCING); - } - /* Our creation time is newer than what the server gave us */ - else if (c->creation_time > ts) - { - c->creation_time = ts; - c->Reset(); - } - /* Their TS is newer than ours, our modes > theirs, unset their modes if need be */ - else if (ts > c->creation_time) - keep_their_modes = false; - - /* If we need to keep their modes, and this SJOIN string contains modes */ - if (keep_their_modes && params.size() >= 3) - { - Anope::string modes; - for (unsigned i = 2; i < params.size() - 1; ++i) - modes += " " + params[i]; - if (!modes.empty()) - modes.erase(modes.begin()); - /* Set the modes internally */ - c->SetModesInternal(source, modes); - } - - spacesepstream sep(params[params.size() - 1]); - Anope::string buf; - while (sep.GetToken(buf)) - { - std::list<ChannelMode *> Status; - char ch; - - /* Get prefixes from the nick */ - while ((ch = ModeManager::GetStatusChar(buf[0]))) - { - buf.erase(buf.begin()); - ChannelMode *cm = ModeManager::FindChannelModeByChar(ch); - if (!cm) - { - Log() << "Received unknown mode prefix " << ch << " in SJOIN string"; - continue; - } - - if (keep_their_modes) - Status.push_back(cm); - } - - User *u = finduser(buf); - if (!u) - { - Log(LOG_DEBUG) << "SJOIN for nonexistant user " << buf << " on " << c->name; - continue; - } - - EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnPreJoinChannel, OnPreJoinChannel(u, c)); - - /* Add the user to the channel */ - c->JoinUser(u); - - /* Update their status internally on the channel - * This will enforce secureops etc on the user - */ - for (std::list<ChannelMode *>::iterator it = Status.begin(), it_end = Status.end(); it != it_end; ++it) - c->SetModeInternal(source, *it, buf); - - /* Now set whatever modes this user is allowed to have on the channel */ - chan_set_correct_modes(u, c, 1, true); - - /* Check to see if modules want the user to join, if they do - * check to see if they are allowed to join (CheckKick will kick/ban them) - * Don't trigger OnJoinChannel event then as the user will be destroyed - */ - if (MOD_RESULT != EVENT_STOP && c->ci && c->ci->CheckKick(u)) - continue; - - FOREACH_MOD(I_OnJoinChannel, OnJoinChannel(u, c)); - } - - /* Channel is done syncing */ - if (c->HasFlag(CH_SYNCING)) - { - /* Unset the syncing flag */ - c->UnsetFlag(CH_SYNCING); - c->Sync(); - } - + IRCD->SendPing(Config->ServerName, params[0]); return true; } }; struct IRCDMessageTBurst : IRCDMessage { - IRCDMessageTBurst() : IRCDMessage("TBURST", 4) { } + IRCDMessageTBurst(Module *creator) : IRCDMessage(creator, "TB", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + /* + * params[0] = channel + * params[1] = ts + * params[2] = topic OR who set the topic + * params[3] = topic if params[2] isnt the topic + */ bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { - Anope::string setter = myStrGetToken(params[2], '!', 0); time_t topic_time = Anope::string(params[1]).is_pos_number_only() ? convertTo<time_t>(params[1]) : Anope::CurTime; - Channel *c = findchan(params[0]); + Channel *c = Channel::Find(params[0]); if (!c) return true; - c->ChangeTopicInternal(setter, params[3], topic_time); - - return true; - } -}; - -struct IRCDMessageTMode : IRCDMessage -{ - IRCDMessageTMode() : IRCDMessage("TMODE", 3) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } - - bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override - { - time_t ts = 0; - try - { - ts = convertTo<time_t>(params[0]); - } - catch (const ConvertException &) { } - Channel *c = findchan(params[1]); - Anope::string modes = params[2]; - for (unsigned i = 3; i < params.size(); ++i) - modes += " " + params[i]; + const Anope::string &setter = params.size() == 4 ? params[2] : "", + topic = params.size() == 4 ? params[3] : params[2]; - if (c) - c->SetModesInternal(source, modes, ts); + c->ChangeTopicInternal(setter, topic, topic_time); return true; } @@ -527,15 +170,15 @@ struct IRCDMessageTMode : IRCDMessage struct IRCDMessageUID : IRCDMessage { - IRCDMessageUID() : IRCDMessage("UID", 9) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + IRCDMessageUID(Module *creator) : IRCDMessage(creator, "UID", 9) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } // :42X UID Adam 1 1348535644 +aow Adam 192.168.0.5 192.168.0.5 42XAAAAAB :Adam bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { /* Source is always the server */ User *user = new User(params[0], params[4], params[5], "", params[6], source.GetServer(), params[8], params[2].is_pos_number_only() ? convertTo<time_t>(params[2]) : 0, params[3], params[7]); - if (user && user->server->IsSynced() && nickserv) - nickserv->Validate(user); + if (user && user->server->IsSynced() && NickServService) + NickServService->Validate(user); return true; } @@ -543,99 +186,105 @@ struct IRCDMessageUID : IRCDMessage class ProtoRatbox : public Module { + Module *m_hybrid; + RatboxProto ircd_proto; /* Core message handlers */ - CoreIRCDMessageAway core_message_away; - CoreIRCDMessageCapab core_message_capab; - CoreIRCDMessageError core_message_error; - CoreIRCDMessageKick core_message_kick; - CoreIRCDMessageKill core_message_kill; - CoreIRCDMessageMOTD core_message_motd; - CoreIRCDMessagePart core_message_part; - CoreIRCDMessagePing core_message_ping; - CoreIRCDMessagePrivmsg core_message_privmsg; - CoreIRCDMessageQuit core_message_quit; - CoreIRCDMessageSQuit core_message_squit; - CoreIRCDMessageStats core_message_stats; - CoreIRCDMessageTime core_message_time; - CoreIRCDMessageTopic core_message_topic; - CoreIRCDMessageVersion core_message_version; - CoreIRCDMessageWhois core_message_whois; + Message::Away message_away; + Message::Capab message_capab; + Message::Error message_error; + Message::Kick message_kick; + Message::Kill message_kill; + Message::Mode message_mode; + Message::MOTD message_motd; + Message::Part message_part; + Message::Ping message_ping; + Message::Privmsg message_privmsg; + Message::Quit message_quit; + Message::SQuit message_squit; + Message::Stats message_stats; + Message::Time message_time; + Message::Topic message_topic; + Message::Version message_version; + Message::Whois message_whois; + + /* Hybrid message handlers */ + ServiceAlias message_bmask, message_join, message_nick, message_pong, message_sid, + message_sjoin, message_tmode; /* Our message handlers */ - IRCDMessageBMask message_bmask; IRCDMessageEncap message_encap; - IRCDMessageJoin message_join; - IRCDMessageMode message_mode; - IRCDMessageNick message_nick; IRCDMessagePass message_pass; - IRCDMessagePong message_pong; IRCDMessageServer message_server; - IRCDMessageSID message_sid; - IRCDMessageSjoin message_sjoin; IRCDMessageTBurst message_tburst; - IRCDMessageTMode message_tmode; IRCDMessageUID message_uid; void AddModes() { - /* Add user modes */ - ModeManager::AddUserMode(new UserMode(UMODE_ADMIN, 'a')); - ModeManager::AddUserMode(new UserMode(UMODE_INVIS, 'i')); - ModeManager::AddUserMode(new UserMode(UMODE_OPER, 'o')); - ModeManager::AddUserMode(new UserMode(UMODE_SNOMASK, 's')); - ModeManager::AddUserMode(new UserMode(UMODE_WALLOPS, 'w')); - - /* b/e/I */ - ModeManager::AddChannelMode(new ChannelModeList(CMODE_BAN, 'b')); - ModeManager::AddChannelMode(new ChannelModeList(CMODE_EXCEPT, 'e')); - ModeManager::AddChannelMode(new ChannelModeList(CMODE_INVITEOVERRIDE, 'I')); + /* user modes */ + ModeManager::RemoveUserMode(ModeManager::FindUserModeByName(UMODE_HIDEOPER)); + ModeManager::RemoveUserMode(ModeManager::FindUserModeByName(UMODE_REGPRIV)); /* v/h/o/a/q */ - ModeManager::AddChannelMode(new ChannelModeStatus(CMODE_VOICE, 'v', '+', 0)); - ModeManager::AddChannelMode(new ChannelModeStatus(CMODE_OP, 'o', '@', 1)); - - /* Add channel modes */ - ModeManager::AddChannelMode(new ChannelMode(CMODE_INVITE, 'i')); - ModeManager::AddChannelMode(new ChannelModeKey('k')); - ModeManager::AddChannelMode(new ChannelModeParam(CMODE_LIMIT, 'l')); - ModeManager::AddChannelMode(new ChannelMode(CMODE_MODERATED, 'm')); - ModeManager::AddChannelMode(new ChannelMode(CMODE_NOEXTERNAL, 'n')); - ModeManager::AddChannelMode(new ChannelMode(CMODE_PRIVATE, 'p')); - ModeManager::AddChannelMode(new ChannelMode(CMODE_SECRET, 's')); - ModeManager::AddChannelMode(new ChannelMode(CMODE_TOPIC, 't')); + ModeManager::RemoveChannelMode(ModeManager::FindChannelModeByName(CMODE_HALFOP)); + + /* channel modes */ + ModeManager::RemoveChannelMode(ModeManager::FindChannelModeByName(CMODE_REGISTERED)); + ModeManager::RemoveChannelMode(ModeManager::FindChannelModeByName(CMODE_OPERONLY)); + ModeManager::RemoveChannelMode(ModeManager::FindChannelModeByName(CMODE_REGISTEREDONLY)); + ModeManager::RemoveChannelMode(ModeManager::FindChannelModeByName(CMODE_SSL)); } public: - ProtoRatbox(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL) + ProtoRatbox(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL), + message_away(this), message_capab(this), message_error(this), message_kick(this), message_kill(this), + message_mode(this), message_motd(this), message_part(this), message_ping(this), message_privmsg(this), + message_quit(this), message_squit(this), message_stats(this), message_time(this), message_topic(this), + message_version(this), message_whois(this), + + message_bmask("IRCDMessage", "ratbox/bmask", "hybrid/bmask"), message_join("IRCDMessage", "ratbox/join", "hybrid/join"), + message_nick("IRCDMessage", "ratbox/nick", "hybrid/nick"), message_pong("IRCDMessage", "ratbox/pong", "hybrid/pong"), + message_sid("IRCDMessage", "ratbox/sid", "hybrid/sid"), message_sjoin("IRCDMessage", "ratbox/sjoin", "hybrid/sjoin"), + message_tmode("IRCDMessage", "ratbox/tmode", "hybrid/tmode"), + + message_encap(this), message_pass(this), message_server(this), message_tburst(this), message_uid(this) { this->SetAuthor("Anope"); + if (ModuleManager::LoadModule("hybrid", User::Find(creator)) != MOD_ERR_OK) + throw ModuleException("Unable to load hybrid"); + m_hybrid = ModuleManager::FindModule("hybrid"); + if (!m_hybrid) + throw ModuleException("Unable to find hybrid"); + hybrid = m_hybrid->GetIRCDProto(); + if (!hybrid) + throw ModuleException("No protocol interface for hybrid"); + this->AddModes(); Implementation i[] = { I_OnServerSync }; ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); + } - if (Config->Numeric.empty()) - { - Anope::string numeric = ts6_sid_retrieve(); - Me->SetSID(numeric); - Config->Numeric = numeric; - } + ~ProtoRatbox() + { + ModuleManager::UnloadModule(m_hybrid, NULL); + } - for (botinfo_map::iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) - it->second->GenerateUID(); + IRCDProto *GetIRCDProto() anope_override + { + return &ircd_proto; } void OnServerSync(Server *s) anope_override { - if (nickserv) + if (NickServService) for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) { User *u = it->second; if (u->server == s && !u->IsIdentified()) - nickserv->Validate(u); + NickServService->Validate(u); } } }; diff --git a/modules/protocol/unreal.cpp b/modules/protocol/unreal.cpp index d07c5eaec..5e7a9f194 100644 --- a/modules/protocol/unreal.cpp +++ b/modules/protocol/unreal.cpp @@ -48,7 +48,7 @@ class UnrealIRCdProto : public IRCDProto if (x->GetUser() == "*") { sockaddrs(x->GetHost()); - ircdproto->SendSZLineDel(x); + IRCD->SendSZLineDel(x); return; } } @@ -74,11 +74,10 @@ class UnrealIRCdProto : public IRCDProto void SendVhostDel(User *u) anope_override { - const BotInfo *bi = findbot(Config->HostServ); - u->RemoveMode(bi, UMODE_CLOAK); - u->RemoveMode(bi, UMODE_VHOST); + u->RemoveMode(HostServ, UMODE_CLOAK); + u->RemoveMode(HostServ, UMODE_VHOST); ModeManager::ProcessModes(); - u->SetMode(bi, UMODE_CLOAK); + u->SetMode(HostServ, UMODE_CLOAK); } void SendAkill(User *u, XLine *x) anope_override @@ -100,11 +99,11 @@ class UnrealIRCdProto : public IRCDProto return; /* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */ - XLine *xline = new XLine("*@" + u->host, old->By, old->Expires, old->Reason, old->UID); + XLine *xline = new XLine("*@" + u->host, old->by, old->expires, old->reason, old->id); old->manager->AddXLine(xline); x = xline; - Log(findbot(Config->OperServ), "akill") << "AKILL: Added an akill for " << x->Mask << " because " << u->GetMask() << "#" << u->realname << " matches " << old->Mask; + Log(OperServ, "akill") << "AKILL: Added an akill for " << x->mask << " because " << u->GetMask() << "#" << u->realname << " matches " << old->mask; } /* ZLine if we can instead */ @@ -113,17 +112,17 @@ class UnrealIRCdProto : public IRCDProto if (x->GetUser() == "*") { sockaddrs(x->GetHost()); - ircdproto->SendSZLine(u, x); + IRCD->SendSZLine(u, x); return; } } catch (const SocketException &) { } // 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) + time_t timeleft = x->expires - Anope::CurTime; + if (timeleft > 172800 || !x->expires) timeleft = 172800; - UplinkSocket::Message() << "BD + G " << x->GetUser() << " " << x->GetHost() << " " << x->By << " " << Anope::CurTime + timeleft << " " << x->Created << " :" << x->GetReason(); + UplinkSocket::Message() << "BD + G " << x->GetUser() << " " << x->GetHost() << " " << x->by << " " << Anope::CurTime + timeleft << " " << x->created << " :" << x->GetReason(); } void SendSVSKillInternal(const BotInfo *source, User *user, const Anope::string &buf) anope_override @@ -165,11 +164,11 @@ class UnrealIRCdProto : public IRCDProto */ UserContainer *uc = c->FindUser(user); if (uc != NULL) - uc->Status->ClearFlags(); + uc->status->ClearFlags(); - BotInfo *setter = findbot(user->nick); + BotInfo *setter = BotInfo::Find(user->nick); for (unsigned i = 0; i < ModeManager::ChannelModes.size(); ++i) - if (cs.HasFlag(ModeManager::ChannelModes[i]->Name)) + if (cs.HasFlag(ModeManager::ChannelModes[i]->name)) c->SetMode(setter, ModeManager::ChannelModes[i], user->GetUID(), false); } } @@ -178,7 +177,7 @@ class UnrealIRCdProto : public IRCDProto */ void SendSQLineDel(const XLine *x) anope_override { - UplinkSocket::Message() << "d " << x->Mask; + UplinkSocket::Message() << "d " << x->mask; } /* SQLINE */ @@ -188,7 +187,7 @@ class UnrealIRCdProto : public IRCDProto */ void SendSQLine(User *, const XLine *x) anope_override { - UplinkSocket::Message() << "c " << x->Mask << " :" << x->GetReason(); + UplinkSocket::Message() << "c " << x->mask << " :" << x->GetReason(); } /* @@ -239,7 +238,7 @@ class UnrealIRCdProto : public IRCDProto UplinkSocket::Message() << "PROTOCTL NICKv2 VHP UMODE2 NICKIP SJOIN SJOIN2 SJ3 NOQUIT TKLEXT ESVID MLOCK VL"; else UplinkSocket::Message() << "PROTOCTL NICKv2 VHP UMODE2 NICKIP SJOIN SJOIN2 SJ3 NOQUIT TKLEXT ESVID MLOCK"; - UplinkSocket::Message() << "PASS :" << Config->Uplinks[CurrentUplink]->password; + UplinkSocket::Message() << "PASS :" << Config->Uplinks[Anope::CurrentUplink]->password; SendServer(Me); } @@ -261,7 +260,7 @@ class UnrealIRCdProto : public IRCDProto */ void SendSGLineDel(const XLine *x) anope_override { - UplinkSocket::Message() << "BR - :" << x->Mask; + UplinkSocket::Message() << "BR - :" << x->mask; } /* UNSZLINE */ @@ -274,10 +273,10 @@ class UnrealIRCdProto : public IRCDProto void SendSZLine(User *, 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) + time_t timeleft = x->expires - Anope::CurTime; + if (timeleft > 172800 || !x->expires) timeleft = 172800; - UplinkSocket::Message() << "BD + Z * " << x->GetHost() << " " << x->By << " " << Anope::CurTime + timeleft << " " << x->Created << " :" << x->GetReason(); + UplinkSocket::Message() << "BD + Z * " << x->GetHost() << " " << x->by << " " << Anope::CurTime + timeleft << " " << x->created << " :" << x->GetReason(); } /* SGLINE */ @@ -288,7 +287,7 @@ class UnrealIRCdProto : public IRCDProto { Anope::string edited_reason = x->GetReason(); edited_reason = edited_reason.replace_all_cs(" ", "_"); - UplinkSocket::Message() << "BR + " << edited_reason << " :" << x->Mask; + UplinkSocket::Message() << "BR + " << edited_reason << " :" << x->mask; } /* svsjoin @@ -323,7 +322,7 @@ class UnrealIRCdProto : public IRCDProto if (nick.equals_ci("ircd") || nick.equals_ci("irc")) return false; - return true; + return IRCDProto::IsNickValid(nick); } bool IsChannelValid(const Anope::string &chan) anope_override @@ -339,17 +338,15 @@ class UnrealIRCdProto : public IRCDProto if (!u->Account()) return; - const BotInfo *ns = findbot(Config->NickServ); - if (Capab.count("ESVID") > 0) - ircdproto->SendMode(ns, u, "+d %s", u->Account()->display.c_str()); + if (Servers::Capab.count("ESVID") > 0) + IRCD->SendMode(NickServ, u, "+d %s", u->Account()->display.c_str()); else - ircdproto->SendMode(ns, u, "+d %d", u->timestamp); + IRCD->SendMode(NickServ, u, "+d %d", u->timestamp); } void SendLogout(User *u) anope_override { - const BotInfo *ns = findbot(Config->NickServ); - ircdproto->SendMode(ns, u, "+d 0"); + IRCD->SendMode(NickServ, u, "+d 0"); } void SendChannel(Channel *c) anope_override @@ -392,16 +389,16 @@ class UnrealExtBan : public ChannelModeList char modeChar = ModeManager::GetStatusChar(channel[0]); channel.erase(channel.begin()); cm = ModeManager::FindChannelModeByChar(modeChar); - if (cm != NULL && cm->Type != MODE_STATUS) + if (cm != NULL && cm->type != MODE_STATUS) cm = NULL; } - Channel *c = findchan(channel); + Channel *c = Channel::Find(channel); if (c != NULL) { UserContainer *uc = c->FindUser(u); if (uc != NULL) - if (cm == NULL || uc->Status->HasFlag(cm->Name)) + if (cm == NULL || uc->status->HasFlag(cm->name)) return true; } } @@ -409,7 +406,7 @@ class UnrealExtBan : public ChannelModeList { Anope::string real_mask = mask.substr(3); - Entry en(this->Name, real_mask); + Entry en(this->name, real_mask); if (en.Matches(u)) return true; } @@ -494,9 +491,9 @@ class ChannelModeUnrealSSL : public ChannelMode } }; -struct IRCDMessageCapab : CoreIRCDMessageCapab +struct IRCDMessageCapab : Message::Capab { - IRCDMessageCapab() : CoreIRCDMessageCapab("PROTOCTL") { } + IRCDMessageCapab(Module *creator) : Message::Capab(creator, "PROTOCTL") { } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { @@ -645,17 +642,17 @@ struct IRCDMessageCapab : CoreIRCDMessageCapab } } - return CoreIRCDMessageCapab::Run(source, params); + return Message::Capab::Run(source, params); } }; struct IRCDMessageChgHost : IRCDMessage { - IRCDMessageChgHost() : IRCDMessage("CHGHOST", 2) { } + IRCDMessageChgHost(Module *creator) : IRCDMessage(creator, "CHGHOST", 2) { } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { - User *u = finduser(params[0]); + User *u = User::Find(params[0]); if (u) u->SetDisplayedHost(params[1]); return true; @@ -664,11 +661,11 @@ struct IRCDMessageChgHost : IRCDMessage struct IRCDMessageChgIdent : IRCDMessage { - IRCDMessageChgIdent() : IRCDMessage("CHGIDENT", 2) { } + IRCDMessageChgIdent(Module *creator) : IRCDMessage(creator, "CHGIDENT", 2) { } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { - User *u = finduser(params[0]); + User *u = User::Find(params[0]); if (u) u->SetVIdent(params[1]); return true; @@ -677,11 +674,11 @@ struct IRCDMessageChgIdent : IRCDMessage struct IRCDMessageChgName : IRCDMessage { - IRCDMessageChgName() : IRCDMessage("CHGNAME", 2) { } + IRCDMessageChgName(Module *creator) : IRCDMessage(creator, "CHGNAME", 2) { } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { - User *u = finduser(params[0]); + User *u = User::Find(params[0]); if (u) u->SetRealname(params[1]); return true; @@ -690,7 +687,7 @@ struct IRCDMessageChgName : IRCDMessage struct IRCDMessageMode : IRCDMessage { - IRCDMessageMode(const Anope::string &mname) : IRCDMessage(mname, 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + IRCDMessageMode(Module *creator, const Anope::string &mname) : IRCDMessage(creator, mname, 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { @@ -699,10 +696,11 @@ struct IRCDMessageMode : IRCDMessage for (unsigned i = 2; i < params.size() - (server_source ? 1 : 0); ++i) modes += " " + params[i]; - if (ircdproto->IsChannelValid(params[0])) + if (IRCD->IsChannelValid(params[0])) { - Channel *c = findchan(params[0]); + Channel *c = Channel::Find(params[0]); time_t ts = 0; + try { if (server_source) @@ -715,7 +713,7 @@ struct IRCDMessageMode : IRCDMessage } else { - User *u = finduser(params[0]); + User *u = User::Find(params[0]); if (u) u->SetModesInternal("%s", params[1].c_str()); } @@ -736,18 +734,18 @@ struct IRCDMessageMode : IRCDMessage */ struct IRCDMessageNetInfo : IRCDMessage { - IRCDMessageNetInfo() : IRCDMessage("NETINFO", 8) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + IRCDMessageNetInfo(Module *creator) : IRCDMessage(creator, "NETINFO", 8) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { - UplinkSocket::Message() << "AO " << maxusercnt << " " << Anope::CurTime << " " << convertTo<int>(params[2]) << " " << params[3] << " 0 0 0 :" << params[7]; + UplinkSocket::Message() << "AO " << MaxUserCount << " " << Anope::CurTime << " " << convertTo<int>(params[2]) << " " << params[3] << " 0 0 0 :" << params[7]; return true; } }; struct IRCDMessageNick : IRCDMessage { - IRCDMessageNick() : IRCDMessage("NICK", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + IRCDMessageNick(Module *creator) : IRCDMessage(creator, "NICK", 2) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } /* ** NICK - new @@ -807,21 +805,21 @@ struct IRCDMessageNick : IRCDMessage else if (params[6].is_pos_number_only()) { if (convertTo<time_t>(params[6]) == user->timestamp) - na = findnick(user->nick); + na = NickAlias::Find(user->nick); } else { - na = findnick(params[6]); + na = NickAlias::Find(params[6]); } if (na) { user->Login(na->nc); - if (!Config->NoNicknameOwnership && na->nc->HasFlag(NI_UNCONFIRMED) == false && nickserv) - user->SetMode(findbot(Config->NickServ), UMODE_REGISTERED); + if (!Config->NoNicknameOwnership && na->nc->HasFlag(NI_UNCONFIRMED) == false) + user->SetMode(NickServ, UMODE_REGISTERED); } - else if (nickserv) - nickserv->Validate(user); + else if (NickServService) + NickServService->Validate(user); } else source.GetUser()->ChangeNick(params[0]); @@ -841,7 +839,7 @@ struct IRCDMessageNick : IRCDMessage */ struct IRCDMessagePong : IRCDMessage { - IRCDMessagePong() : IRCDMessage("PONG", 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + IRCDMessagePong(Module *creator) : IRCDMessage(creator, "PONG", 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { @@ -878,13 +876,11 @@ struct IRCDMessageSASL : IRCDMessage UplinkSocket::Message() << "SASL " << this->uid.substr(0, p) << " " << this->uid << " D F"; - Log(findbot(Config->NickServ)) << "A user failed to identify for account " << this->GetAccount() << " using SASL"; + Log(NickServ) << "A user failed to identify for account " << this->GetAccount() << " using SASL"; } }; - Module *me; - - IRCDMessageSASL(Module *m) : IRCDMessage("SASL", 4), me(m) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + IRCDMessageSASL(Module *creator) : IRCDMessage(creator, "SASL", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } /* Received: :irc.foonet.com SASL services.localhost.net irc.foonet.com!1.57290 S PLAIN * uid @@ -920,7 +916,7 @@ struct IRCDMessageSASL : IRCDMessage if (acc.empty() || pass.empty()) return true; - IdentifyRequest *req = new UnrealSASLIdentifyRequest(me, params[1], acc, pass); + IdentifyRequest *req = new UnrealSASLIdentifyRequest(this->owner, params[1], acc, pass); FOREACH_MOD(I_OnCheckAuthentication, OnCheckAuthentication(NULL, req)); req->Dispatch(); } @@ -931,7 +927,7 @@ struct IRCDMessageSASL : IRCDMessage struct IRCDMessageSDesc : IRCDMessage { - IRCDMessageSDesc() : IRCDMessage("SDESC", 1) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + IRCDMessageSDesc(Module *creator) : IRCDMessage(creator, "SDESC", 1) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { @@ -942,7 +938,7 @@ struct IRCDMessageSDesc : IRCDMessage struct IRCDMessageSetHost : IRCDMessage { - IRCDMessageSetHost() : IRCDMessage("SETHOST", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + IRCDMessageSetHost(Module *creator) : IRCDMessage(creator, "SETHOST", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { @@ -960,7 +956,7 @@ struct IRCDMessageSetHost : IRCDMessage struct IRCDMessageSetIdent : IRCDMessage { - IRCDMessageSetIdent() : IRCDMessage("SETIDENT", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + IRCDMessageSetIdent(Module *creator) : IRCDMessage(creator, "SETIDENT", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { @@ -972,11 +968,11 @@ struct IRCDMessageSetIdent : IRCDMessage struct IRCDMessageSetName : IRCDMessage { - IRCDMessageSetName() : IRCDMessage("SETNAME", 1) { } + IRCDMessageSetName(Module *creator) : IRCDMessage(creator, "SETNAME", 1) { } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { - User *u = finduser(params[0]); + User *u = User::Find(params[0]); if (u) u->SetRealname(params[1]); return true; @@ -985,7 +981,7 @@ struct IRCDMessageSetName : IRCDMessage struct IRCDMessageServer : IRCDMessage { - IRCDMessageServer() : IRCDMessage("SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + IRCDMessageServer(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { @@ -993,16 +989,15 @@ struct IRCDMessageServer : IRCDMessage if (params[1].equals_cs("1")) { - Anope::string vl = myStrGetToken(params[2], ' ', 0); - Anope::string upnumeric = myStrGetToken(vl, '-', 2); - Anope::string desc = myStrGetTokenRemainder(params[2], ' ', 1); + Anope::string desc; + spacesepstream(params[2]).GetTokenRemainder(desc, 1); new Server(source.GetServer() == NULL ? Me : source.GetServer(), params[0], hops, desc); } else new Server(source.GetServer(), params[0], hops, params[2]); - ircdproto->SendPing(Config->ServerName, params[0]); + IRCD->SendPing(Config->ServerName, params[0]); return true; } @@ -1010,44 +1005,20 @@ struct IRCDMessageServer : IRCDMessage struct IRCDMessageSJoin : IRCDMessage { - IRCDMessageSJoin() : IRCDMessage("SJOIN", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + IRCDMessageSJoin(Module *creator) : IRCDMessage(creator, "SJOIN", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); SetFlag(IRCDMESSAGE_SOFT_LIMIT); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { - Channel *c = findchan(params[1]); - time_t ts = Anope::string(params[0]).is_pos_number_only() ? convertTo<time_t>(params[0]) : 0; - bool keep_their_modes = true; - - if (!c) - { - c = new Channel(params[1], ts); - c->SetFlag(CH_SYNCING); - } - /* Our creation time is newer than what the server gave us */ - else if (c->creation_time > ts) - { - c->creation_time = ts; - c->Reset(); - } - /* Their TS is newer than ours, our modes > theirs, unset their modes if need be */ - else if (ts > c->creation_time) - keep_their_modes = false; - - /* If we need to keep their modes, and this SJOIN string contains modes */ - if (keep_their_modes && params.size() >= 4) - { - Anope::string modes; + Anope::string modes; + if (params.size() >= 4) for (unsigned i = 2; i < params.size() - 1; ++i) modes += " " + params[i]; - if (!modes.empty()) - modes.erase(modes.begin()); - /* Set the modes internally */ - c->SetModesInternal(source, modes); - } + if (!modes.empty()) + modes.erase(modes.begin()); + + std::list<Anope::string> bans, excepts, invites; + std::list<Message::Join::SJoinUser> users; - ChannelMode *ban = ModeManager::FindChannelModeByName(CMODE_BAN), - *except = ModeManager::FindChannelModeByName(CMODE_EXCEPT), - *invex = ModeManager::FindChannelModeByName(CMODE_INVITEOVERRIDE); spacesepstream sep(params[params.size() - 1]); Anope::string buf; while (sep.GetToken(buf)) @@ -1056,82 +1027,72 @@ struct IRCDMessageSJoin : IRCDMessage if (buf[0] == '&') { buf.erase(buf.begin()); - if (keep_their_modes && ban) - c->SetModeInternal(source, ban, buf); + bans.push_back(buf); } /* Except */ else if (buf[0] == '"') { buf.erase(buf.begin()); - if (keep_their_modes && except) - c->SetModeInternal(source, except, buf); + excepts.push_back(buf); } /* Invex */ else if (buf[0] == '\'') { buf.erase(buf.begin()); - if (keep_their_modes && invex) - c->SetModeInternal(source, invex, buf); + invites.push_back(buf); } else { - std::list<ChannelMode *> Status; - char ch; + Message::Join::SJoinUser sju; /* Get prefixes from the nick */ - while ((ch = ModeManager::GetStatusChar(buf[0]))) + for (char ch; (ch = ModeManager::GetStatusChar(buf[0]));) { buf.erase(buf.begin()); ChannelMode *cm = ModeManager::FindChannelModeByChar(ch); if (!cm) { - Log() << "Received unknown mode prefix " << ch << " in SJOIN string"; + Log(LOG_DEBUG) << "Received unknown mode prefix " << ch << " in SJOIN string"; continue; } - if (keep_their_modes) - Status.push_back(cm); + sju.first.SetFlag(cm->name); } - User *u = finduser(buf); - if (!u) + sju.second = User::Find(buf); + if (!sju.second) { - Log(LOG_DEBUG) << "SJOIN for nonexistant user " << buf << " on " << c->name; + Log(LOG_DEBUG) << "SJOIN for nonexistant user " << buf << " on " << params[1]; continue; } - EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnPreJoinChannel, OnPreJoinChannel(u, c)); - - /* Add the user to the channel */ - c->JoinUser(u); - - /* Update their status internally on the channel - * This will enforce secureops etc on the user - */ - for (std::list<ChannelMode *>::iterator it = Status.begin(), it_end = Status.end(); it != it_end; ++it) - c->SetModeInternal(source, *it, buf); - - /* Now set whatever modes this user is allowed to have on the channel */ - chan_set_correct_modes(u, c, 1, true); - - /* Check to see if modules want the user to join, if they do - * check to see if they are allowed to join (CheckKick will kick/ban them) - * Don't trigger OnJoinChannel event then as the user will be destroyed - */ - if (MOD_RESULT != EVENT_STOP && c->ci && c->ci->CheckKick(u)) - continue; - - FOREACH_MOD(I_OnJoinChannel, OnJoinChannel(u, c)); + users.push_back(sju); } } + + time_t ts = Anope::string(params[0]).is_pos_number_only() ? convertTo<time_t>(params[0]) : Anope::CurTime; + Message::Join::SJoin(source, params[1], ts, modes, users); - /* Channel is done syncing */ - if (c->HasFlag(CH_SYNCING)) + if (!bans.empty() || !excepts.empty() || !invites.empty()) { - /* Unset the syncing flag */ - c->UnsetFlag(CH_SYNCING); - c->Sync(); + Channel *c = Channel::Find(params[1]); + + if (!c || c->creation_time != ts) + return true; + + ChannelMode *ban = ModeManager::FindChannelModeByName(CMODE_BAN), + *except = ModeManager::FindChannelModeByName(CMODE_EXCEPT), + *invex = ModeManager::FindChannelModeByName(CMODE_INVITEOVERRIDE); + + if (ban) + for (std::list<Anope::string>::iterator it = bans.begin(), it_end = bans.end(); it != it_end; ++it) + c->SetModeInternal(source, ban, *it); + if (except) + for (std::list<Anope::string>::iterator it = excepts.begin(), it_end = excepts.end(); it != it_end; ++it) + c->SetModeInternal(source, except, *it); + if (invex) + for (std::list<Anope::string>::iterator it = invites.begin(), it_end = invites.end(); it != it_end; ++it) + c->SetModeInternal(source, invex, *it); } return true; @@ -1140,7 +1101,7 @@ struct IRCDMessageSJoin : IRCDMessage struct IRCDMessageTopic : IRCDMessage { - IRCDMessageTopic() : IRCDMessage("TOPIC", 4) { } + IRCDMessageTopic(Module *creator) : IRCDMessage(creator, "TOPIC", 4) { } /* ** source = sender prefix @@ -1151,7 +1112,7 @@ struct IRCDMessageTopic : IRCDMessage */ bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { - Channel *c = findchan(params[0]); + Channel *c = Channel::Find(params[0]); if (c) c->ChangeTopicInternal(params[1], params[3], Anope::string(params[2]).is_pos_number_only() ? convertTo<time_t>(params[2]) : Anope::CurTime); @@ -1162,7 +1123,7 @@ struct IRCDMessageTopic : IRCDMessage struct IRCDMessageUmode2 : IRCDMessage { - IRCDMessageUmode2() : IRCDMessage("UMODE2", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } + IRCDMessageUmode2(Module *creator) : IRCDMessage(creator, "UMODE2", 1) { SetFlag(IRCDMESSAGE_REQUIRE_USER); } bool Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { @@ -1176,22 +1137,21 @@ class ProtoUnreal : public Module UnrealIRCdProto ircd_proto; /* Core message handlers */ - CoreIRCDMessageAway core_message_away; - CoreIRCDMessageError core_message_error; - CoreIRCDMessageJoin core_message_join; - CoreIRCDMessageKick core_message_kick; - CoreIRCDMessageKill core_message_kill; - CoreIRCDMessageMOTD core_message_motd; - CoreIRCDMessagePart core_message_part; - CoreIRCDMessagePing core_message_ping; - CoreIRCDMessagePrivmsg core_message_privmsg; - CoreIRCDMessageQuit core_message_quit; - CoreIRCDMessageSQuit core_message_squit; - CoreIRCDMessageStats core_message_stats; - CoreIRCDMessageTime core_message_time; - CoreIRCDMessageTopic core_message_topic; - CoreIRCDMessageVersion core_message_version; - CoreIRCDMessageWhois core_message_whois; + Message::Away message_away; + Message::Error message_error; + Message::Join message_join; + Message::Kick message_kick; + Message::Kill message_kill; + Message::MOTD message_motd; + Message::Part message_part; + Message::Ping message_ping; + Message::Privmsg message_privmsg; + Message::Quit message_quit; + Message::SQuit message_squit; + Message::Stats message_stats; + Message::Time message_time; + Message::Version message_version; + Message::Whois message_whois; /* Our message handlers */ IRCDMessageCapab message_capab; @@ -1252,7 +1212,15 @@ class ProtoUnreal : public Module public: ProtoUnreal(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL), - message_mode("MODE"), message_svsmode("SVSMODE"), message_svs2mode("SVS2MODE"), message_sasl(this) + message_away(this), message_error(this), message_join(this), message_kick(this), message_kill(this), + message_motd(this), message_part(this), message_ping(this), message_privmsg(this), message_quit(this), + message_squit(this), message_stats(this), message_time(this), message_version(this), + message_whois(this), + + message_capab(this), message_chghost(this), message_chgident(this), message_chgname(this), message_mode(this, "MODE"), + message_svsmode(this, "SVSMODE"), message_svs2mode(this, "SVS2MODE"), message_netinfo(this), message_nick(this), message_pong(this), + message_sasl(this), message_sdesc(this), message_sethost(this), message_setident(this), message_setname(this), message_server(this), + message_sjoin(this), message_topic(this), message_umode2(this) { this->SetAuthor("Anope"); @@ -1263,15 +1231,21 @@ class ProtoUnreal : public Module ModuleManager::SetPriority(this, PRIORITY_FIRST); } + IRCDProto *GetIRCDProto() anope_override + { + return &ircd_proto; + } + void OnUserNickChange(User *u, const Anope::string &) anope_override { u->RemoveModeInternal(ModeManager::FindUserModeByName(UMODE_REGISTERED)); - ircdproto->SendLogout(u); + if (Servers::Capab.count("ESVID") == 0) + IRCD->SendLogout(u); } void OnChannelCreate(Channel *c) anope_override { - if (Config->UseServerSideMLock && Capab.count("MLOCK") > 0 && c->ci) + if (Config->UseServerSideMLock && Servers::Capab.count("MLOCK") > 0 && c->ci) { Anope::string modes = c->ci->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", ""); UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(c->creation_time) << " " << c->ci->name << " " << modes; @@ -1296,9 +1270,9 @@ class ProtoUnreal : public Module EventReturn OnMLock(ChannelInfo *ci, ModeLock *lock) anope_override { ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name); - if (cm && ci->c && (cm->Type == MODE_REGULAR || cm->Type == MODE_PARAM) && Capab.count("MLOCK") > 0 && Config->UseServerSideMLock) + if (cm && ci->c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0 && Config->UseServerSideMLock) { - Anope::string modes = ci->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "") + cm->ModeChar; + Anope::string modes = ci->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "") + cm->mchar; UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->name << " " << modes; } @@ -1308,9 +1282,9 @@ class ProtoUnreal : public Module EventReturn OnUnMLock(ChannelInfo *ci, ModeLock *lock) anope_override { ChannelMode *cm = ModeManager::FindChannelModeByName(lock->name); - if (cm && ci->c && (cm->Type == MODE_REGULAR || cm->Type == MODE_PARAM) && Capab.count("MLOCK") > 0 && Config->UseServerSideMLock) + if (cm && ci->c && (cm->type == MODE_REGULAR || cm->type == MODE_PARAM) && Servers::Capab.count("MLOCK") > 0 && Config->UseServerSideMLock) { - Anope::string modes = ci->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "").replace_all_cs(cm->ModeChar, ""); + Anope::string modes = ci->GetMLockAsString(false).replace_all_cs("+", "").replace_all_cs("-", "").replace_all_cs(cm->mchar, ""); UplinkSocket::Message(Me) << "MLOCK " << static_cast<long>(ci->c->creation_time) << " " << ci->name << " " << modes; } |