From d33a0f75a5c0c584fbb7cc0076da36d494f39494 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 22 Nov 2012 00:50:33 -0500 Subject: Pretty large coding style cleanup, in source doc cleanup, and allow protocol mods to depend on each other --- modules/protocol/bahamut.cpp | 225 ++++------- modules/protocol/hybrid.cpp | 341 +++++++--------- modules/protocol/inspircd-ts6.h | 817 -------------------------------------- modules/protocol/inspircd11.cpp | 249 +++++------- modules/protocol/inspircd12.cpp | 854 +++++++++++++++++++++++++++++++++++++--- modules/protocol/inspircd20.cpp | 243 ++++++++---- modules/protocol/ngircd.cpp | 193 ++++----- modules/protocol/plexus.cpp | 573 +++++---------------------- modules/protocol/ratbox.cpp | 555 +++++--------------------- modules/protocol/unreal.cpp | 318 +++++++-------- 10 files changed, 1704 insertions(+), 2664 deletions(-) delete mode 100644 modules/protocol/inspircd-ts6.h (limited to 'modules/protocol') 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 ¶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 ¶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(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 ¶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(params[2]) : 0, params[3]); - if (user && nickserv) + if (user && NickServService) { const NickAlias *na; - if (user->timestamp == convertTo(params[7]) && (na = findnick(user->nick))) + if (user->timestamp == convertTo(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 ¶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 ¶ms) anope_override { - Channel *c = findchan(params[1]); - time_t ts = Anope::string(params[0]).is_pos_number_only() ? convertTo(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 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 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::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(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 ¶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(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 ¶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 ¶ms) anope_override { - if (params.size() < 2) - return true; - - std::vector 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 ¶ms) anope_override { - if (params.size() > 2 && ircdproto->IsChannelValid(params[0])) - { - Channel *c = findchan(params[0]); - time_t ts = 0; - - try - { - ts = convertTo(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 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 ¶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(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 ¶ms) anope_override { - Channel *c = findchan(params[1]); - time_t ts = Anope::string(params[0]).is_pos_number_only() ? convertTo(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 users; spacesepstream sep(params[params.size() - 1]); Anope::string buf; while (sep.GetToken(buf)) { - std::list 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::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(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 ¶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(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 ¶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(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 ¶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(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(value[0] == '*' ? value.substr(1) : value, rest, false) > 0 && rest[0] == ':' && rest.length() > 1 && convertTo(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 ¶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 ¶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 ¶ms) anope_override - { - Channel *c = findchan(params[0]); - time_t ts = Anope::string(params[1]).is_pos_number_only() ? convertTo(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 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::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 ¶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(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 ¶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(params[1]) : Anope::CurTime); - - return true; - } -}; - -struct IRCDMessageIdle : IRCDMessage -{ - IRCDMessageIdle() : IRCDMessage("IDLE", 1) { } - - bool Run(MessageSource &source, const std::vector ¶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 ¶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 ¶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 ¶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 ¶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 ¶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 ¶ms) anope_override - { - unsigned int hops = Anope::string(params[2]).is_pos_number_only() ? convertTo(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 ¶ms) anope_override - { - UplinkSocket::Message(Me) << "TIME " << source.GetSource() << " " << params[1] << " " << Anope::CurTime; - return true; - } -}; - -struct IRCDMessageUID : IRCDMessage -{ - IRCDMessageUID() : IRCDMessage("UID", 8) { Set