diff options
author | Adam <Adam@anope.org> | 2016-10-15 16:25:57 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2016-10-15 16:25:57 -0400 |
commit | 1ba242179fee46583098f48421af39ce9a8985a1 (patch) | |
tree | a276cd7bd53e7270c86ab3744bd6a568a016501b /src | |
parent | 696239e93391f3dfd6459857fb02a6006048093a (diff) |
Various improvements/bugfixes to extdb stuff
Diffstat (limited to 'src')
-rw-r--r-- | src/bots.cpp | 21 | ||||
-rw-r--r-- | src/config.cpp | 169 | ||||
-rw-r--r-- | src/init.cpp | 3 | ||||
-rw-r--r-- | src/service_manager.cpp | 8 | ||||
-rw-r--r-- | src/xline.cpp | 3 |
5 files changed, 119 insertions, 85 deletions
diff --git a/src/bots.cpp b/src/bots.cpp index 07d6ec858..2ba7bda67 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -37,15 +37,6 @@ ServiceBot::ServiceBot(const Anope::string &nnick, const Anope::string &nuser, c this->lastmsg = Anope::CurTime; this->introduced = false; - bi = Serialize::New<BotInfo *>(); - bi->bot = this; - - bi->SetNick(nnick); - bi->SetUser(nuser); - bi->SetHost(nhost); - bi->SetRealName(nreal); - bi->SetCreated(Anope::CurTime); - EventManager::Get()->Dispatch(&Event::CreateBot::OnCreateBot, this); // If we're synchronised with the uplink already, send the bot. @@ -65,8 +56,11 @@ ServiceBot::ServiceBot(const Anope::string &nnick, const Anope::string &nuser, c ServiceBot::~ServiceBot() { - bi->bot = nullptr; - bi->Delete(); + if (bi != nullptr) + { + bi->bot = nullptr; + bi->Delete(); + } EventManager::Get()->Dispatch(&Event::DelBot::OnDelBot, this); @@ -109,7 +103,8 @@ void ServiceBot::SetNewNick(const Anope::string &newnick) { UserListByNick.erase(this->nick); - bi->SetNick(newnick); + if (bi != nullptr) + bi->SetNick(newnick); this->nick = newnick; UserListByNick[this->nick] = this; @@ -117,7 +112,7 @@ void ServiceBot::SetNewNick(const Anope::string &newnick) std::vector<ChanServ::Channel *> ServiceBot::GetChannels() const { - return bi->GetRefs<ChanServ::Channel *>(); + return bi != nullptr ? bi->GetRefs<ChanServ::Channel *>() : std::vector<ChanServ::Channel *>(); } void ServiceBot::Assign(User *u, ChanServ::Channel *ci) diff --git a/src/config.cpp b/src/config.cpp index 0f083e3f8..6d671401e 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -317,72 +317,7 @@ Conf::Conf() : Block("") this->MyOperTypes.push_back(ot); } - for (int i = 0; i < this->CountBlock("oper"); ++i) - { - Block *oper = this->GetBlock("oper", i); - - const Anope::string &nname = oper->Get<Anope::string>("name"), - &type = oper->Get<Anope::string>("type"), - &password = oper->Get<Anope::string>("password"), - &certfp = oper->Get<Anope::string>("certfp"), - &host = oper->Get<Anope::string>("host"), - &vhost = oper->Get<Anope::string>("vhost"); - bool require_oper = oper->Get<bool>("require_oper"); - - ValidateNotEmpty("oper", "name", nname); - ValidateNotEmpty("oper", "type", type); - - OperType *ot = NULL; - for (unsigned j = 0; j < this->MyOperTypes.size(); ++j) - if (this->MyOperTypes[j]->GetName() == type) - ot = this->MyOperTypes[j]; - if (ot == NULL) - throw ConfigException("Oper block for " + nname + " has invalid oper type " + type); - - Oper *o = Serialize::New<Oper *>(); - o->conf = this; - o->SetName(nname); - o->SetType(ot); - o->SetRequireOper(require_oper); - o->SetPassword(password); - o->SetCertFP(certfp); - o->SetHost(host); - o->SetVhost(vhost); - } - - for (BotInfo *bi : Serialize::GetObjects<BotInfo *>()) - bi->conf = nullptr; - for (int i = 0; i < this->CountBlock("service"); ++i) - { - Block *service = this->GetBlock("service", i); - - const Anope::string &nick = service->Get<Anope::string>("nick"), - &user = service->Get<Anope::string>("user"), - &host = service->Get<Anope::string>("host"), - &gecos = service->Get<Anope::string>("gecos"), - &modes = service->Get<Anope::string>("modes"), - &channels = service->Get<Anope::string>("channels"); - - ValidateNotEmpty("service", "nick", nick); - ValidateNotEmpty("service", "user", user); - ValidateNotEmpty("service", "host", host); - ValidateNotEmpty("service", "gecos", gecos); - ValidateNoSpaces("service", "channels", channels); - - if (User *u = User::Find(nick, true)) - { - if (u->type != UserType::BOT) - { - u->Kill(Me, "Nickname required by services"); - } - } - - ServiceBot *sb = ServiceBot::Find(nick, true); - if (!sb) - sb = new ServiceBot(nick, user, host, gecos, modes); - - sb->bi->conf = service; - } + this->LoadBots(); for (int i = 0; i < this->CountBlock("log"); ++i) { @@ -635,6 +570,9 @@ void Conf::Post(Conf *old) if (std::find(old->ModulesAutoLoad.begin(), old->ModulesAutoLoad.end(), this->ModulesAutoLoad[i]) == old->ModulesAutoLoad.end()) ModuleManager::LoadModule(this->ModulesAutoLoad[i], NULL); + LoadOpers(); + ApplyBots(); + ModeManager::Apply(old); /* Apply opertype changes, as non-conf opers still point to the old oper types */ @@ -699,6 +637,105 @@ void Conf::Post(Conf *old) } } +void Conf::LoadBots() +{ + for (BotInfo *bi : Serialize::GetObjects<BotInfo *>()) + bi->conf = nullptr; + for (int i = 0; i < this->CountBlock("service"); ++i) + { + Block *service = this->GetBlock("service", i); + + const Anope::string &nick = service->Get<Anope::string>("nick"), + &user = service->Get<Anope::string>("user"), + &host = service->Get<Anope::string>("host"), + &gecos = service->Get<Anope::string>("gecos"), + &modes = service->Get<Anope::string>("modes"), + &channels = service->Get<Anope::string>("channels"); + + ValidateNotEmpty("service", "nick", nick); + ValidateNotEmpty("service", "user", user); + ValidateNotEmpty("service", "host", host); + ValidateNotEmpty("service", "gecos", gecos); + ValidateNoSpaces("service", "channels", channels); + + if (User *u = User::Find(nick, true)) + { + if (u->type != UserType::BOT) + { + u->Kill(Me, "Nickname required by services"); + } + } + + ServiceBot *sb = ServiceBot::Find(nick, true); + if (!sb) + sb = new ServiceBot(nick, user, host, gecos, modes); + } +} + +void Conf::ApplyBots() +{ + for (std::pair<Anope::string, User *> p : UserListByNick) + { + User *u = p.second; + if (u->type != UserType::BOT) + continue; + + ServiceBot *sb = anope_dynamic_static_cast<ServiceBot *>(u); + if (sb->bi != nullptr) + continue; + + sb->bi = Serialize::New<BotInfo *>(); + sb->bi->bot = sb; + + sb->bi->SetNick(sb->nick); + sb->bi->SetUser(sb->GetIdent()); + sb->bi->SetHost(sb->host); + sb->bi->SetRealName(sb->realname); + sb->bi->SetCreated(Anope::CurTime); + } +} + +void Conf::LoadOpers() +{ + for (int i = 0; i < this->CountBlock("oper"); ++i) + { + Block *oper = this->GetBlock("oper", i); + + const Anope::string &nname = oper->Get<Anope::string>("name"), + &type = oper->Get<Anope::string>("type"), + &password = oper->Get<Anope::string>("password"), + &certfp = oper->Get<Anope::string>("certfp"), + &host = oper->Get<Anope::string>("host"), + &vhost = oper->Get<Anope::string>("vhost"); + bool require_oper = oper->Get<bool>("require_oper"); + + ValidateNotEmpty("oper", "name", nname); + ValidateNotEmpty("oper", "type", type); + + OperType *ot = NULL; + for (unsigned j = 0; j < this->MyOperTypes.size(); ++j) + if (this->MyOperTypes[j]->GetName() == type) + ot = this->MyOperTypes[j]; + if (ot == NULL) + { + Log() << "Oper block for " << nname << " has invalid oper type " << type; + continue; + } + + Oper *o = Serialize::New<Oper *>(); + o->conf = this; + o->SetName(nname); + o->SetType(ot); + o->SetRequireOper(require_oper); + o->SetPassword(password); + o->SetCertFP(certfp); + o->SetHost(host); + o->SetVhost(vhost); + + Log(LOG_DEBUG) << "Creating oper " << nname << " of type " << ot->GetName(); + } +} + Block *Conf::GetModule(Module *m) { if (!m) diff --git a/src/init.cpp b/src/init.cpp index ec23a7b4b..9ee720ebd 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -543,6 +543,9 @@ void Anope::Init(int ac, char **av) for (int i = 0; i < Config->CountBlock("module"); ++i) ModuleManager::LoadModule(Config->GetBlock("module", i)->Get<Anope::string>("name"), NULL); + Config->LoadOpers(); + Config->ApplyBots(); + #ifndef _WIN32 /* We won't background later, so we should setuid now */ if (Anope::NoFork) diff --git a/src/service_manager.cpp b/src/service_manager.cpp index ef26fb13b..abebd1c3d 100644 --- a/src/service_manager.cpp +++ b/src/service_manager.cpp @@ -82,7 +82,7 @@ void ServiceManager::Register(Service *service) throw ModuleException("Service of type " + service->GetType() + " with name " + service->GetName() + " already exists"); } - Log(LOG_DEBUG_2) << "Service registered: " << service->GetType() << " " << service->GetName() << " address " << static_cast<void *>(this) << " by " << service->GetOwner(); + Log(LOG_DEBUG_3) << "Service registered: " << service->GetType() << " " << service->GetName() << " address " << static_cast<void *>(this) << " by " << service->GetOwner(); services.push_back(service); @@ -91,7 +91,7 @@ void ServiceManager::Register(Service *service) void ServiceManager::Unregister(Service *service) { - Log(LOG_DEBUG_2) << "Service unregistered: " << service->GetType() << " " << service->GetName() << " address " << static_cast<void *>(service) << " by " << service->GetOwner(); + Log(LOG_DEBUG_3) << "Service unregistered: " << service->GetType() << " " << service->GetName() << " address " << static_cast<void *>(service) << " by " << service->GetOwner(); auto it = std::find(services.begin(), services.end(), service); if (it != services.end()) @@ -107,13 +107,13 @@ void ServiceManager::Lookup(ServiceReferenceBase *reference) if (reference->GetName().empty()) { std::vector<Service *> services = this->FindServices(reference->GetType()); - Log(LOG_DEBUG_2) << "Service lookup " << static_cast<void *>(reference) << " type " << reference->GetType() << " name " << reference->GetName() << ": " << services.size() << " services"; + Log(LOG_DEBUG_3) << "Service lookup " << static_cast<void *>(reference) << " type " << reference->GetType() << " name " << reference->GetName() << ": " << services.size() << " services"; reference->SetServices(services); } else { Service *service = this->FindService(reference->GetType(), reference->GetName()); - Log(LOG_DEBUG_2) << "Service lookup " << static_cast<void *>(reference) << " type " << reference->GetType() << " name " << reference->GetName() << ": " << service; + Log(LOG_DEBUG_3) << "Service lookup " << static_cast<void *>(reference) << " type " << reference->GetType() << " name " << reference->GetName() << ": " << service; reference->SetService(service); } } diff --git a/src/xline.cpp b/src/xline.cpp index df65ae7dd..7d26461b4 100644 --- a/src/xline.cpp +++ b/src/xline.cpp @@ -215,9 +215,8 @@ XLineManager *XLine::GetManager() return ServiceManager::Get()->FindService<XLineManager *>(GetType()); } -void XLineType::Mask::SetField(XLine *s, const Anope::string &value) +void XLineType::Mask::OnSet(XLine *s, const Anope::string &value) { - Serialize::Field<XLine, Anope::string>::SetField(s, value); s->Recache(); } |