diff options
Diffstat (limited to 'src/servers.cpp')
-rw-r--r-- | src/servers.cpp | 182 |
1 files changed, 81 insertions, 101 deletions
diff --git a/src/servers.cpp b/src/servers.cpp index b78cd19f7..5f48a5e7c 100644 --- a/src/servers.cpp +++ b/src/servers.cpp @@ -1,12 +1,20 @@ -/* Routines to maintain a list of connected servers +/* + * Anope IRC Services * - * (C) 2003-2016 Anope Team - * Contact us at team@anope.org + * Copyright (C) 2004-2016 Anope Team <team@anope.org> * - * Please read COPYING and README for further details. + * This file is part of Anope. Anope is free software; you can + * redistribute it and/or modify it under the terms of the GNU + * General Public License as published by the Free Software + * Foundation, version 2. * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see see <http://www.gnu.org/licenses/>. */ #include "services.h" @@ -14,10 +22,11 @@ #include "xline.h" #include "servers.h" #include "bots.h" -#include "regchannel.h" #include "protocol.h" #include "config.h" #include "channels.h" +#include "event.h" +#include "modules/chanserv.h" /* Anope */ Server *Me = NULL; @@ -46,93 +55,10 @@ Server::Server(Server *up, const Anope::string &sname, unsigned shops, const Ano /* Check to be sure this isn't a juped server */ if (Me == this->uplink && !juped) - { - /* Now do mode related stuff as we know what modes exist .. */ - for (botinfo_map::iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) - { - BotInfo *bi = it->second; - Anope::string modes = !bi->botmodes.empty() ? ("+" + bi->botmodes) : IRCD->DefaultPseudoclientModes; - - bi->SetModesInternal(bi, modes.c_str()); - for (unsigned i = 0; i < bi->botchannels.size(); ++i) - { - size_t h = bi->botchannels[i].find('#'); - if (h == Anope::string::npos) - continue; - Anope::string chname = bi->botchannels[i].substr(h); - Channel *c = Channel::Find(chname); - if (c && c->FindUser(bi)) - { - Anope::string want_modes = bi->botchannels[i].substr(0, h); - for (unsigned j = 0; j < want_modes.length(); ++j) - { - ChannelMode *cm = ModeManager::FindChannelModeByChar(want_modes[j]); - if (cm == NULL) - cm = ModeManager::FindChannelModeByChar(ModeManager::GetStatusChar(want_modes[j])); - if (cm && cm->type == MODE_STATUS) - { - MessageSource ms = bi; - c->SetModeInternal(ms, cm, bi->nick); - } - } - } - } - } - - IRCD->SendBOB(); - - for (unsigned i = 0; i < Me->GetLinks().size(); ++i) - { - Server *s = Me->GetLinks()[i]; - - if (s->juped) - IRCD->SendServer(s); - } - - /* We make the bots go online */ - for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) - { - User *u = it->second; - - BotInfo *bi = BotInfo::Find(u->GetUID()); - if (bi) - { - XLine x(bi->nick, "Reserved for services"); - IRCD->SendSQLine(NULL, &x); - } - - IRCD->SendClientIntroduction(u); - if (bi) - bi->introduced = true; - } - - for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it) - { - Channel *c = it->second; - - if (c->users.empty()) - IRCD->SendChannel(c); - else - for (Channel::ChanUserList::const_iterator cit = c->users.begin(), cit_end = c->users.end(); cit != cit_end; ++cit) - IRCD->SendJoin(cit->second->user, c, &cit->second->status); - - for (Channel::ModeList::const_iterator it2 = c->GetModes().begin(); it2 != c->GetModes().end(); ++it2) - { - ChannelMode *cm = ModeManager::FindChannelModeByName(it2->first); - if (!cm || cm->type != MODE_LIST) - continue; - ModeManager::StackerAdd(c->ci->WhoSends(), c, cm, true, it2->second); - } - - if (!c->topic.empty() && !c->topic_setter.empty()) - IRCD->SendTopic(c->ci->WhoSends(), c); - - c->syncing = true; - } - } + Burst(); } - FOREACH_MOD(OnNewServer, (this)); + EventManager::Get()->Dispatch(&Event::NewServer::OnNewServer, this); } Server::~Server() @@ -157,7 +83,7 @@ Server::~Server() for (unsigned i = this->links.size(); i > 0; --i) this->links[i - 1]->Delete(this->quit_reason); - + Servers::ByName.erase(this->name); if (!this->sid.empty()) Servers::ByID.erase(this->sid); @@ -167,10 +93,64 @@ void Server::Delete(const Anope::string &reason) { this->quit_reason = reason; this->quitting = true; - FOREACH_MOD(OnServerQuit, (this)); + EventManager::Get()->Dispatch(&Event::ServerQuit::OnServerQuit, this); delete this; } +void Server::Burst() +{ + IRCD->SendBOB(); + + for (unsigned i = 0; i < Me->GetLinks().size(); ++i) + { + Server *s = Me->GetLinks()[i]; + + if (s->juped) + IRCD->SendServer(s); + } + + /* We make the bots go online */ + for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + { + User *u = it->second; + + ServiceBot *bi = ServiceBot::Find(u->GetUID()); + if (bi) + { + //XLine x(bi->nick, "Reserved for services"); + //IRCD->SendSQLine(NULL, &x); + } + + IRCD->SendClientIntroduction(u); + if (bi) + bi->introduced = true; + } + + for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it) + { + Channel *c = it->second; + + if (c->users.empty()) + IRCD->SendChannel(c); + else + for (Channel::ChanUserList::const_iterator cit = c->users.begin(), cit_end = c->users.end(); cit != cit_end; ++cit) + IRCD->SendJoin(cit->second->user, c, &cit->second->status); + + for (Channel::ModeList::const_iterator it2 = c->GetModes().begin(); it2 != c->GetModes().end(); ++it2) + { + ChannelMode *cm = ModeManager::FindChannelModeByName(it2->first); + if (!cm || cm->type != MODE_LIST) + continue; + ModeManager::StackerAdd(c->ci->WhoSends(), c, cm, true, it2->second); + } + + if (!c->topic.empty() && !c->topic_setter.empty()) + IRCD->SendTopic(c->ci->WhoSends(), c); + + c->syncing = true; + } +} + const Anope::string &Server::GetName() const { return this->name; @@ -255,7 +235,7 @@ void Server::Sync(bool sync_links) Log(this, "sync") << "is done syncing"; - FOREACH_MOD(OnServerSync, (this)); + EventManager::Get()->Dispatch(&Event::ServerSync::OnServerSync, this); if (sync_links && !this->links.empty()) { @@ -267,7 +247,7 @@ void Server::Sync(bool sync_links) if (me) { - FOREACH_MOD(OnPreUplinkSync, (this)); + EventManager::Get()->Dispatch(&Event::PreUplinkSync::OnPreUplinkSync, this); } for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end;) @@ -284,7 +264,7 @@ void Server::Sync(bool sync_links) IRCD->SendEOB(); Me->Sync(false); - FOREACH_MOD(OnUplinkSync, (this)); + EventManager::Get()->Dispatch(&Event::UplinkSync::OnUplinkSync, this); if (!Anope::NoFork) { @@ -325,7 +305,7 @@ bool Server::IsQuitting() const return quitting; } -void Server::Notice(BotInfo *source, const Anope::string &message) +void Server::Notice(ServiceBot *source, const Anope::string &message) { if (Config->UsePrivmsg && Config->DefPrivmsg) IRCD->SendGlobalPrivmsg(source, this, message); @@ -336,18 +316,18 @@ void Server::Notice(BotInfo *source, const Anope::string &message) Server *Server::Find(const Anope::string &name, bool name_only) { Anope::map<Server *>::iterator it; - + if (!name_only) { it = Servers::ByID.find(name); if (it != Servers::ByID.end()) return it->second; } - + it = Servers::ByName.find(name); if (it != Servers::ByName.end()) return it->second; - + return NULL; } |