From a36f14c1bfca63ba744ab310af775cf6d5b81179 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 29 Dec 2010 19:59:26 -0500 Subject: [PATCH 1/4] Automatically quit bots when they are deleted --- modules/core/bs_bot.cpp | 4 ---- modules/core/ss_main.cpp | 1 - src/bots.cpp | 8 ++++++++ src/nickserv.cpp | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/modules/core/bs_bot.cpp b/modules/core/bs_bot.cpp index a449ef23a..e59f683dd 100644 --- a/modules/core/bs_bot.cpp +++ b/modules/core/bs_bot.cpp @@ -294,10 +294,6 @@ class CommandBSBot : public Command FOREACH_MOD(I_OnBotDelete, OnBotDelete(bi)); - ircdproto->SendQuit(bi, "Quit: Help! I'm being deleted by %s!", source.u->nick.c_str()); - XLine x(bi->nick); - ircdproto->SendSQLineDel(&x); - Log(LOG_ADMIN, source.u, this) << "DEL " << bi->nick; source.Reply(BOT_BOT_DELETED, nick.c_str()); diff --git a/modules/core/ss_main.cpp b/modules/core/ss_main.cpp index b228ad33e..8ee7611d3 100644 --- a/modules/core/ss_main.cpp +++ b/modules/core/ss_main.cpp @@ -57,7 +57,6 @@ class SSMain : public Module for (CommandMap::iterator it = statserv->Commands.begin(), it_end = statserv->Commands.end(); it != it_end; ++it) this->DelCommand(statserv, it->second); - ircdproto->SendQuit(statserv, "Quit due to module unload."); delete statserv; } } diff --git a/src/bots.cpp b/src/bots.cpp index 07ea91b3a..1f7b118d8 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -64,6 +64,14 @@ BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const A BotInfo::~BotInfo() { + // If we're synchronised with the uplink already, send the bot. + if (Me && Me->IsSynced()) + { + ircdproto->SendQuit(this, NULL); + XLine x(this->nick); + ircdproto->SendSQLineDel(&x); + } + for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end; ++it) { ChannelInfo *ci = it->second; diff --git a/src/nickserv.cpp b/src/nickserv.cpp index 6212c7d3e..63abf59b3 100644 --- a/src/nickserv.cpp +++ b/src/nickserv.cpp @@ -68,7 +68,7 @@ NickServRelease::~NickServRelease() { NickServReleases.erase(this->nick); - ircdproto->SendQuit(debug_cast(this), NULL); + ircdproto->SendQuit(this, NULL); } void NickServRelease::Tick(time_t) From d36e53f702f6f166e862c88dd2399bef91e9d1d5 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 29 Dec 2010 20:19:37 -0500 Subject: [PATCH 2/4] Added a ConvertException to be thrown when convertTo fails --- include/services.h | 14 +++++++++++--- modules/protocol/unreal32.cpp | 2 +- src/misc.cpp | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/include/services.h b/include/services.h index 5448d9170..d233da5b8 100644 --- a/include/services.h +++ b/include/services.h @@ -357,12 +357,20 @@ template class Flags /*************************************************************************/ +class ConvertException : public CoreException +{ + public: + ConvertException(const Anope::string &reason = "") : CoreException(reason) { } + + virtual ~ConvertException() throw() { } +}; + template inline Anope::string stringify(const T &x) { std::ostringstream stream; if (!(stream << x)) - throw CoreException("Stringify fail"); + throw ConvertException("Stringify fail"); return stream.str(); } @@ -374,11 +382,11 @@ template inline void convert(const Anope::string &s, T &x, Anope::st char c; bool res = i >> x; if (!res) - throw CoreException("Convert fail"); + throw ConvertException("Convert fail"); if (failIfLeftoverChars) { if (i.get(c)) - throw CoreException("Convert fail"); + throw ConvertException("Convert fail"); } else { diff --git a/modules/protocol/unreal32.cpp b/modules/protocol/unreal32.cpp index 4c0d79ee2..2993580c7 100644 --- a/modules/protocol/unreal32.cpp +++ b/modules/protocol/unreal32.cpp @@ -977,7 +977,7 @@ bool ChannelModeFlood::IsValid(const Anope::string &value) const if (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 CoreException &) { } // convertTo fail + catch (const ConvertException &) { } /* '['<1 letter>[optional: '#'+1 letter],[next..]']'':' */ size_t end_bracket = value.find(']', 1); diff --git a/src/misc.cpp b/src/misc.cpp index 97006469a..a8b1d5ca6 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -228,7 +228,7 @@ time_t dotime(const Anope::string &s) } } } - catch (const CoreException &) { } + catch (const ConvertException &) { } return 0; } From 72b8f4609b147b9b9a222c14bfc4ae100cc7f250 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 29 Dec 2010 23:12:26 -0500 Subject: [PATCH 3/4] Use empty SJOINs when allowed to create empty permanent channels --- include/services.h | 5 +++++ modules/protocol/bahamut.cpp | 7 ++++--- modules/protocol/inspircd-ts6.h | 5 +++++ modules/protocol/inspircd11.cpp | 3 --- modules/protocol/plexus.cpp | 8 +++++--- modules/protocol/ratbox.cpp | 8 +++++--- modules/protocol/unreal32.cpp | 21 ++++++++++++++++++--- src/channels.cpp | 20 ++++++-------------- src/chanserv.cpp | 2 +- src/regchannel.cpp | 19 +++++++++++++++---- 10 files changed, 64 insertions(+), 34 deletions(-) diff --git a/include/services.h b/include/services.h index d233da5b8..33c35ab51 100644 --- a/include/services.h +++ b/include/services.h @@ -995,6 +995,11 @@ class CoreExport IRCDProto * @param u The user */ virtual void SetAutoIdentificationToken(User *u) { } + + /** Send a channel creation message to the uplink. + * On most TS6 IRCds this is a SJOIN with no nick + */ + virtual void SendChannel(Channel *c, const Anope::string &modes) { } }; class CoreExport IRCdMessage diff --git a/modules/protocol/bahamut.cpp b/modules/protocol/bahamut.cpp index 28939c7fb..21d351f0c 100644 --- a/modules/protocol/bahamut.cpp +++ b/modules/protocol/bahamut.cpp @@ -280,6 +280,10 @@ class BahamutIRCdProto : public IRCDProto ircdproto->SendMode(NickServ, u, "+d %d", u->timestamp); } + void SendChannel(Channel *c, const Anope::string &modes) + { + send_cmd("", "SJOIN %ld %s %s :", static_cast(c->creation_time), c->name.c_str(), modes.c_str()); + } }; class BahamutIRCdMessage : public IRCdMessage @@ -378,9 +382,6 @@ class BahamutIRCdMessage : public IRCdMessage { c->creation_time = ts; c->Reset(); - - /* Reset mlock */ - check_modes(c); } /* Their TS is newer than ours, our modes > theirs, unset their modes if need be */ else if (ts > c->creation_time) diff --git a/modules/protocol/inspircd-ts6.h b/modules/protocol/inspircd-ts6.h index 4146e27fc..18f046d76 100644 --- a/modules/protocol/inspircd-ts6.h +++ b/modules/protocol/inspircd-ts6.h @@ -230,6 +230,11 @@ class InspIRCdTS6Proto : public IRCDProto send_cmd(Config->Numeric, "METADATA %s accountname :", u->GetUID().c_str()); } + void SendChannel(Channel *c, const Anope::string &modes) + { + send_cmd(Config->Numeric, "FJOIN %s %ld %s :", c->name.c_str(), static_cast(c->creation_time), modes.c_str()); + } + bool IsNickValid(const Anope::string &nick) { /* InspIRCd, like TS6, uses UIDs on collision, so... */ diff --git a/modules/protocol/inspircd11.cpp b/modules/protocol/inspircd11.cpp index 270a3e013..e642d8f50 100644 --- a/modules/protocol/inspircd11.cpp +++ b/modules/protocol/inspircd11.cpp @@ -607,9 +607,6 @@ class InspircdIRCdMessage : public IRCdMessage { c->creation_time = ts; c->Reset(); - - /* Reset mlock */ - check_modes(c); } /* Their TS is newer than ours, our modes > theirs, unset their modes if need be */ else if (ts > c->creation_time) diff --git a/modules/protocol/plexus.cpp b/modules/protocol/plexus.cpp index 8e025f59e..05633ead4 100644 --- a/modules/protocol/plexus.cpp +++ b/modules/protocol/plexus.cpp @@ -247,6 +247,11 @@ class PlexusProto : public IRCDProto { send_cmd(bi->GetUID(), "ENCAP * TOPIC %s %s %lu :%s", c->name.c_str(), c->topic_setter.c_str(), static_cast(c->topic_time + 1), c->topic.c_str()); } + + void SendChannel(Channel *c, const Anope::string &modes) + { + send_cmd(Config->Numeric, "SJOIN %ld %s %s :", static_cast(c->creation_time), c->name.c_str(), modes.c_str()); + } }; class PlexusIRCdMessage : public IRCdMessage @@ -357,9 +362,6 @@ class PlexusIRCdMessage : public IRCdMessage { c->creation_time = ts; c->Reset(); - - /* Reset mlock */ - check_modes(c); } /* Their TS is newer than ours, our modes > theirs, unset their modes if need be */ else if (ts > c->creation_time) diff --git a/modules/protocol/ratbox.cpp b/modules/protocol/ratbox.cpp index 914010b98..43debc78d 100644 --- a/modules/protocol/ratbox.cpp +++ b/modules/protocol/ratbox.cpp @@ -232,6 +232,11 @@ class RatboxProto : public IRCDProto send_cmd(Config->Numeric, "ENCAP * SU %s", u->GetUID().c_str()); } + void SendChannel(Channel *c, const Anope::string &modes) + { + send_cmd("", "SJOIN %ld %s %s :", static_cast(c->creation_time), c->name.c_str(), modes.c_str()); + } + bool IsNickValid(const Anope::string &nick) { /* TS6 Save extension -Certus */ @@ -377,9 +382,6 @@ class RatboxIRCdMessage : public IRCdMessage { c->creation_time = ts; c->Reset(); - - /* Reset mlock */ - check_modes(c); } /* Their TS is newer than ours, our modes > theirs, unset their modes if need be */ else if (ts > c->creation_time) diff --git a/modules/protocol/unreal32.cpp b/modules/protocol/unreal32.cpp index 2993580c7..cc4fc23df 100644 --- a/modules/protocol/unreal32.cpp +++ b/modules/protocol/unreal32.cpp @@ -375,6 +375,24 @@ class UnrealIRCdProto : public IRCDProto { ircdproto->SendMode(NickServ, u, "+d 1"); } + + void SendChannel(Channel *c, const Anope::string &modes) + { + /* Unreal does not support updating a channels TS without actually joining a user, + * so we will join and part us now + */ + BotInfo *bi = whosends(c->ci); + if (c->FindUser(bi) == NULL) + { + bi->Join(c, true); + bi->Part(c); + } + else + { + bi->Part(c); + bi->Join(c, true); + } + } }; class Unreal32IRCdMessage : public IRCdMessage @@ -695,9 +713,6 @@ class Unreal32IRCdMessage : public IRCdMessage { c->creation_time = ts; c->Reset(); - - /* Reset mlock */ - check_modes(c); } /* Their TS is newer than ours, our modes > theirs, unset their modes if need be */ else if (ts > c->creation_time) diff --git a/src/channels.cpp b/src/channels.cpp index 8873931f5..fcd78faed 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -87,6 +87,9 @@ void Channel::Reset() check_modes(this); for (CUserList::const_iterator it = this->users.begin(), it_end = this->users.end(); it != it_end; ++it) chan_set_correct_modes((*it)->user, this, 1); + + if (this->ci) + this->ci->RestoreTopic(); } void Channel::Sync() @@ -117,12 +120,12 @@ void Channel::JoinUser(User *user) uc->Status = Status; this->users.push_back(uc); - bool update_ts = false; if (this->ci && this->ci->HasFlag(CI_PERSIST) && this->creation_time > this->ci->time_registered) { Log(LOG_DEBUG) << "Changing TS of " << this->name << " from " << this->creation_time << " to " << this->ci->time_registered; this->creation_time = this->ci->time_registered; - update_ts = true; + ircdproto->SendChannel(this, ""); + this->Reset(); } if (this->ci && check_access(user, this->ci, CA_MEMO) && this->ci->memos.memos.size() > 0) @@ -142,7 +145,7 @@ void Channel::JoinUser(User *user) * legit users - Rob **/ if (this->users.size() >= Config->BSMinUsers && !this->FindUser(this->ci->bi)) - this->ci->bi->Join(this, update_ts); + this->ci->bi->Join(this, false); /* Only display the greet if the main uplink we're connected * to has synced, or we'll get greet-floods when the net * recovers from a netsplit. -GD @@ -153,17 +156,6 @@ void Channel::JoinUser(User *user) this->ci->bi->lastmsg = Anope::CurTime; } } - - /* Update the TS, unless I'm joining a bot already */ - if (update_ts && user->server != Me) - { - /* Send the updated TS */ - if (!this->FindUser(whosends(this->ci))) - { - whosends(this->ci)->Join(this, update_ts); - whosends(this->ci)->Part(this); - } - } } /** Remove a user internally from the channel diff --git a/src/chanserv.cpp b/src/chanserv.cpp index 35fd8975c..43d4d3b61 100644 --- a/src/chanserv.cpp +++ b/src/chanserv.cpp @@ -273,7 +273,7 @@ void check_modes(Channel *c) } } - else if (cm->Type == MODE_LIST) // XXX we still need better list code... + else if (cm->Type == MODE_LIST) { if (ml.set) c->SetMode(NULL, cm, ml.param); diff --git a/src/regchannel.cpp b/src/regchannel.cpp index 17c141ea7..0b67daf9a 100644 --- a/src/regchannel.cpp +++ b/src/regchannel.cpp @@ -563,10 +563,21 @@ void ChannelInfo::LoadMLock() if (this->HasFlag(CI_PERSIST) && !this->c) { this->c = new Channel(this->name, this->time_registered); - if (!this->bi && ChanServ && ModeManager::FindChannelModeByName(CMODE_PERM) == NULL) - ChanServ->Assign(NULL, this); - else if (this->bi) - this->bi->Join(c); + if (ModeManager::FindChannelModeByName(CMODE_PERM) != NULL) + { + /* At this point, CMODE_PERM *must* be locked on the channel, so this is fine */ + ircdproto->SendChannel(this->c, get_mlock_modes(this, true)); + } + else + { + if (!this->bi) + { + this->bi = whosends(this); + ++this->bi->chancount; + } + this->bi->Join(this->c); + } + check_modes(this->c); this->CheckTopic(); } From 03cc9eb5c597e37239debac25a7ed6ad4f4d9411 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 29 Dec 2010 23:30:28 -0500 Subject: [PATCH 4/4] Assign bots to new empty permanent channels on IRCds without permchannel mode not just join --- src/regchannel.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/regchannel.cpp b/src/regchannel.cpp index 0b67daf9a..7ff3e753a 100644 --- a/src/regchannel.cpp +++ b/src/regchannel.cpp @@ -571,11 +571,9 @@ void ChannelInfo::LoadMLock() else { if (!this->bi) - { - this->bi = whosends(this); - ++this->bi->chancount; - } - this->bi->Join(this->c); + whosends(this)->Assign(NULL, this); + if (this->c->FindUser(this->bi) == NULL) + this->bi->Join(this->c); } check_modes(this->c);