diff options
| author | Adam <Adam@anope.org> | 2014-11-24 14:27:23 -0500 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2014-11-24 14:27:23 -0500 |
| commit | 42238034490fb5479d787bd1695750387d508200 (patch) | |
| tree | c93c62e0e1c936e656ae5b9ee1b62380ce2a194c /src | |
| parent | d492923610d9c9146b2a2b63de38deab2cfd4ca7 (diff) | |
Rewrite serializable to have field level granularity
Represent serializable objects in a digraph, and as a result made most
object relationships implicitly defined, and use the graph to trace
references between objects to determine relationships. Edges may
also be marked as having a dependency of the object they point to,
which allows for automatic cleanup and deletion of most objects when
no longer needed.
Additionally, this allows not having to require in-memory copies of
everything when using external databases. db_sql has been rewritten
for this and now always requires a database to function. db_sql with
MySQL now requires InnoDB to make use of transactions and foreign
key constraints.
Diffstat (limited to 'src')
| -rw-r--r-- | src/bots.cpp | 210 | ||||
| -rw-r--r-- | src/command.cpp | 16 | ||||
| -rw-r--r-- | src/config.cpp | 103 | ||||
| -rw-r--r-- | src/event.cpp | 6 | ||||
| -rw-r--r-- | src/extensible.cpp | 41 | ||||
| -rw-r--r-- | src/hashcomp.cpp | 4 | ||||
| -rw-r--r-- | src/init.cpp | 29 | ||||
| -rw-r--r-- | src/language.cpp | 4 | ||||
| -rw-r--r-- | src/logger.cpp | 22 | ||||
| -rw-r--r-- | src/mail.cpp | 16 | ||||
| -rw-r--r-- | src/main.cpp | 1 | ||||
| -rw-r--r-- | src/messages.cpp | 20 | ||||
| -rw-r--r-- | src/misc.cpp | 6 | ||||
| -rw-r--r-- | src/modulemanager.cpp | 2 | ||||
| -rw-r--r-- | src/opertype.cpp | 80 | ||||
| -rw-r--r-- | src/pipeengine.cpp | 7 | ||||
| -rw-r--r-- | src/protocol.cpp | 4 | ||||
| -rw-r--r-- | src/serialize.cpp | 318 | ||||
| -rw-r--r-- | src/servers.cpp | 16 | ||||
| -rw-r--r-- | src/uplink.cpp | 6 | ||||
| -rw-r--r-- | src/users.cpp | 108 | ||||
| -rw-r--r-- | src/version.sh | 2 | ||||
| -rw-r--r-- | src/xline.cpp | 332 |
23 files changed, 750 insertions, 603 deletions
diff --git a/src/bots.cpp b/src/bots.cpp index 6f5c66388..697115ea0 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -20,17 +20,12 @@ #include "event.h" #include "modules/chanserv.h" -Serialize::Checker<botinfo_map> BotListByNick("BotInfo"), BotListByUID("BotInfo"); - -BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const Anope::string &nhost, const Anope::string &nreal, const Anope::string &bmodes) : User(nnick, nuser, nhost, "", "", Me, nreal, Anope::CurTime, "", IRCD ? IRCD->UID_Retrieve() : "", NULL), Serializable("BotInfo"), channels("ChannelInfo"), botmodes(bmodes) +ServiceBot::ServiceBot(const Anope::string &nnick, const Anope::string &nuser, const Anope::string &nhost, const Anope::string &nreal, const Anope::string &bmodes) : LocalUser(nnick, nuser, nhost, "", "", Me, nreal, Anope::CurTime, "", IRCD ? IRCD->UID_Retrieve() : "", NULL), botmodes(bmodes) { - this->lastmsg = this->created = Anope::CurTime; + this->type = UserType::BOT; + this->lastmsg = Anope::CurTime; this->introduced = false; - this->oper_only = this->conf = false; - - (*BotListByNick)[this->nick] = this; - if (!this->uid.empty()) - (*BotListByUID)[this->uid] = this; + this->conf = false; Event::OnCreateBot(&Event::CreateBot::OnCreateBot, this); @@ -41,14 +36,15 @@ BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const A if (!tmodes.empty()) this->SetModesInternal(this, tmodes.c_str()); - XLine x(this->nick, "Reserved for services"); - IRCD->SendSQLine(NULL, &x); + //XXX + //XLine x(this->nick, "Reserved for services"); + //IRCD->SendSQLine(NULL, &x); IRCD->SendClientIntroduction(this); this->introduced = true; } } -BotInfo::~BotInfo() +ServiceBot::~ServiceBot() { Event::OnDelBot(&Event::DelBot::OnDelBot, this); @@ -58,73 +54,25 @@ BotInfo::~BotInfo() IRCD->SendQuit(this, ""); Event::OnUserQuit(&Event::UserQuit::OnUserQuit, this, ""); this->introduced = false; - XLine x(this->nick); - IRCD->SendSQLineDel(&x); - } - - for (std::set<ChanServ::Channel *>::iterator it = this->channels->begin(), it_end = this->channels->end(); it != it_end; ++it) - { - ChanServ::Channel *ci = *it; - this->UnAssign(NULL, ci); + // XXX ? + //XLine x(this->nick); + //IRCD->SendSQLineDel(&x); } - - BotListByNick->erase(this->nick); - if (!this->uid.empty()) - BotListByUID->erase(this->uid); } -void BotInfo::Serialize(Serialize::Data &data) const -{ - data["nick"] << this->nick; - data["user"] << this->ident; - data["host"] << this->host; - data["realname"] << this->realname; - data["created"] << this->created; - data["oper_only"] << this->oper_only; - - Extensible::ExtensibleSerialize(this, this, data); -} -Serializable* BotInfo::Unserialize(Serializable *obj, Serialize::Data &data) -{ - Anope::string nick, user, host, realname, flags; - - data["nick"] >> nick; - data["user"] >> user; - data["host"] >> host; - data["realname"] >> realname; - - BotInfo *bi; - if (obj) - bi = anope_dynamic_static_cast<BotInfo *>(obj); - else if (!(bi = BotInfo::Find(nick, true))) - bi = new BotInfo(nick, user, host, realname); - - data["created"] >> bi->created; - data["oper_only"] >> bi->oper_only; - - Extensible::ExtensibleUnserialize(bi, bi, data); - - return bi; -} - -void BotInfo::GenerateUID() +void ServiceBot::GenerateUID() { if (this->introduced) throw CoreException("Changing bot UID when it is introduced?"); if (!this->uid.empty()) - { - BotListByUID->erase(this->uid); UserListByUID.erase(this->uid); - } - this->uid = IRCD->UID_Retrieve(); - (*BotListByUID)[this->uid] = this; UserListByUID[this->uid] = this; } -void BotInfo::OnKill() +void ServiceBot::OnKill() { this->introduced = false; this->GenerateUID(); @@ -135,63 +83,60 @@ void BotInfo::OnKill() IRCD->SendJoin(this, cit->second->chan, &cit->second->status); } -void BotInfo::SetNewNick(const Anope::string &newnick) +void ServiceBot::SetNewNick(const Anope::string &newnick) { UserListByNick.erase(this->nick); - BotListByNick->erase(this->nick); + bi->SetNick(newnick); this->nick = newnick; UserListByNick[this->nick] = this; - (*BotListByNick)[this->nick] = this; } -const std::set<ChanServ::Channel *> &BotInfo::GetChannels() const +std::vector<ChanServ::Channel *> ServiceBot::GetChannels() const { - return this->channels; + return bi->GetRefs<ChanServ::Channel *>(ChanServ::channel); } -void BotInfo::Assign(User *u, ChanServ::Channel *ci) +void ServiceBot::Assign(User *u, ChanServ::Channel *ci) { EventReturn MOD_RESULT; MOD_RESULT = Event::OnPreBotAssign(&Event::PreBotAssign::OnPreBotAssign, u, ci, this); if (MOD_RESULT == EVENT_STOP) return; - if (ci->bi) - ci->bi->UnAssign(u, ci); + if (ci->GetBot()) + ci->GetBot()->UnAssign(u, ci); - ci->bi = this; - this->channels->insert(ci); + ci->SetBot(this); Event::OnBotAssign(&Event::BotAssign::OnBotAssign, u, ci, this); } -void BotInfo::UnAssign(User *u, ChanServ::Channel *ci) +void ServiceBot::UnAssign(User *u, ChanServ::Channel *ci) { EventReturn MOD_RESULT; MOD_RESULT = Event::OnBotUnAssign(&Event::BotUnAssign::OnBotUnAssign, u, ci); if (MOD_RESULT == EVENT_STOP) return; - if (ci->c && ci->c->FindUser(ci->bi)) + if (ci->c && ci->c->FindUser(ci->GetBot())) { if (u) - ci->bi->Part(ci->c, "UNASSIGN from " + u->nick); + ci->GetBot()->Part(ci->c, "UNASSIGN from " + u->nick); else - ci->bi->Part(ci->c); + ci->GetBot()->Part(ci->c); } - ci->bi = NULL; - this->channels->erase(ci); + ci->SetBot(nullptr); } -unsigned BotInfo::GetChannelCount() const +unsigned ServiceBot::GetChannelCount() const { - return this->channels->size(); + return GetChannels().size(); } -void BotInfo::Join(Channel *c, ChannelStatus *status) +void ServiceBot::Join(Channel *c, ChannelStatus *status) { if (c->FindUser(this) != NULL) return; @@ -203,13 +148,13 @@ void BotInfo::Join(Channel *c, ChannelStatus *status) Event::OnJoinChannel(&Event::JoinChannel::OnJoinChannel, this, c); } -void BotInfo::Join(const Anope::string &chname, ChannelStatus *status) +void ServiceBot::Join(const Anope::string &chname, ChannelStatus *status) { bool c; return this->Join(Channel::FindOrCreate(chname, c), status); } -void BotInfo::Part(Channel *c, const Anope::string &reason) +void ServiceBot::Part(Channel *c, const Anope::string &reason) { if (c->FindUser(this) == NULL) return; @@ -226,7 +171,7 @@ void BotInfo::Part(Channel *c, const Anope::string &reason) Event::OnPartChannel(&Event::PartChannel::OnPartChannel, this, cref, cname, reason); } -void BotInfo::OnMessage(User *u, const Anope::string &message) +void ServiceBot::OnMessage(User *u, const Anope::string &message) { if (this->commands.empty()) return; @@ -235,7 +180,7 @@ void BotInfo::OnMessage(User *u, const Anope::string &message) Command::Run(source, message); } -CommandInfo& BotInfo::SetCommand(const Anope::string &cname, const Anope::string &sname, const Anope::string &permission) +CommandInfo& ServiceBot::SetCommand(const Anope::string &cname, const Anope::string &sname, const Anope::string &permission) { CommandInfo ci; ci.name = sname; @@ -245,7 +190,7 @@ CommandInfo& BotInfo::SetCommand(const Anope::string &cname, const Anope::string return this->commands[cname]; } -CommandInfo *BotInfo::GetCommand(const Anope::string &cname) +CommandInfo *ServiceBot::GetCommand(const Anope::string &cname) { CommandInfo::map::iterator it = this->commands.find(cname); if (it != this->commands.end()) @@ -253,7 +198,7 @@ CommandInfo *BotInfo::GetCommand(const Anope::string &cname) return NULL; } -CommandInfo *BotInfo::FindCommand(const Anope::string &service) +CommandInfo *ServiceBot::FindCommand(const Anope::string &service) { for (auto& it : commands) { @@ -266,30 +211,71 @@ CommandInfo *BotInfo::FindCommand(const Anope::string &service) return nullptr; } -BotInfo* BotInfo::Find(const Anope::string &nick, bool nick_only) +ServiceBot* ServiceBot::Find(const Anope::string &nick, bool nick_only) { - if (!nick_only && IRCD != NULL && IRCD->RequiresID) - { - botinfo_map::iterator it = BotListByUID->find(nick); - if (it != BotListByUID->end()) - { - BotInfo *bi = it->second; - bi->QueueUpdate(); - return bi; - } - - if (IRCD->AmbiguousID) - return NULL; - } + User *u = User::Find(nick, nick_only); + if (u && u->type == UserType::BOT) + return anope_dynamic_static_cast<ServiceBot *>(u); + return nullptr; +} - botinfo_map::iterator it = BotListByNick->find(nick); - if (it != BotListByNick->end()) - { - BotInfo *bi = it->second; - bi->QueueUpdate(); - return bi; - } +void BotInfo::SetCreated(const time_t &t) +{ + Set(&BotInfoType::created, t); +} - return NULL; +time_t BotInfo::GetCreated() +{ + return Get(&BotInfoType::created); +} + +void BotInfo::SetOperOnly(const bool &b) +{ + Set(&BotInfoType::operonly, b); +} + +bool BotInfo::GetOperOnly() +{ + return Get(&BotInfoType::operonly); +} + +void BotInfo::SetNick(const Anope::string &nick) +{ + Set(&BotInfoType::nick, nick); +} + +Anope::string BotInfo::GetNick() +{ + return Get(&BotInfoType::nick); +} + +void BotInfo::SetUser(const Anope::string &user) +{ + Set(&BotInfoType::user, user); +} + +Anope::string BotInfo::GetUser() +{ + return Get(&BotInfoType::user); +} + +void BotInfo::SetHost(const Anope::string &host) +{ + Set(&BotInfoType::host, host); +} + +Anope::string BotInfo::GetHost() +{ + return Get(&BotInfoType::host); +} + +void BotInfo::SetRealName(const Anope::string &realname) +{ + Set(&BotInfoType::realname, realname); +} + +Anope::string BotInfo::GetRealName() +{ + return Get(&BotInfoType::realname); } diff --git a/src/command.cpp b/src/command.cpp index 59db22a4b..c387ddaab 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -20,7 +20,7 @@ #include "modules/botserv.h" #include "modules/chanserv.h" -CommandSource::CommandSource(const Anope::string &n, User *user, NickServ::Account *core, CommandReply *r, BotInfo *bi) : nick(n), u(user), nc(core), reply(r), +CommandSource::CommandSource(const Anope::string &n, User *user, NickServ::Account *core, CommandReply *r, ServiceBot *bi) : nick(n), u(user), nc(core), reply(r), c(NULL), service(bi) { } @@ -64,7 +64,7 @@ bool CommandSource::HasCommand(const Anope::string &cmd) if (this->u) return this->u->HasCommand(cmd); else if (this->nc && this->nc->o) - return this->nc->o->ot->HasCommand(cmd); + return this->nc->o->GetType()->HasCommand(cmd); return false; } @@ -73,7 +73,7 @@ bool CommandSource::HasPriv(const Anope::string &cmd) if (this->u) return this->u->HasPriv(cmd); else if (this->nc && this->nc->o) - return this->nc->o->ot->HasPriv(cmd); + return this->nc->o->GetType()->HasPriv(cmd); return false; } @@ -274,13 +274,17 @@ void Command::Run(CommandSource &source, const Anope::string &message) Event::OnPostCommand(&Event::PostCommand::OnPostCommand, source, c, params); } -bool Command::FindCommandFromService(const Anope::string &command_service, BotInfo* &bot, Anope::string &name) +bool Command::FindCommandFromService(const Anope::string &command_service, ServiceBot* &bot, Anope::string &name) { bot = NULL; - for (botinfo_map::iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) + for (std::pair<Anope::string, User *> p : UserListByNick) { - BotInfo *bi = it->second; + User *u = p.second; + if (u->type != UserType::BOT) + continue; + + ServiceBot *bi = anope_dynamic_static_cast<ServiceBot *>(u); for (CommandInfo::map::const_iterator cit = bi->commands.begin(), cit_end = bi->commands.end(); cit != cit_end; ++cit) { diff --git a/src/config.cpp b/src/config.cpp index d0575a88c..2bdb71f5e 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -17,6 +17,7 @@ #include "hashcomp.h" #include "event.h" #include "bots.h" +#include "modules.h" #include "modules/nickserv.h" using namespace Configuration; @@ -288,18 +289,26 @@ Conf::Conf() : Block("") if (ot == NULL) throw ConfigException("Oper block for " + nname + " has invalid oper type " + type); - Oper *o = new Oper(nname, ot); - o->require_oper = require_oper; - o->password = password; - o->certfp = certfp; - spacesepstream(host).GetTokens(o->hosts); - o->vhost = vhost; - - this->Opers.push_back(o); + Oper *o = operblock.Create(); + 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_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) - it->second->conf = false; + for (std::pair<Anope::string, User *> p : UserListByNick) + { + User *u = p.second; + if (u->type != UserType::BOT) + continue; + + ServiceBot *bi = anope_dynamic_static_cast<ServiceBot *>(u); + bi->conf = false; + } for (int i = 0; i < this->CountBlock("service"); ++i) { Block *service = this->GetBlock("service", i); @@ -317,9 +326,9 @@ Conf::Conf() : Block("") ValidateNotEmpty("service", "gecos", gecos); ValidateNoSpaces("service", "channels", channels); - BotInfo *bi = BotInfo::Find(nick, true); + ServiceBot *bi = ServiceBot::Find(nick, true); if (!bi) - bi = new BotInfo(nick, user, host, gecos, modes); + bi = new ServiceBot(nick, user, host, gecos, modes); bi->conf = true; std::vector<Anope::string> oldchannels = bi->botchannels; @@ -396,7 +405,7 @@ Conf::Conf() : Block("") LogInfo l(logage, rawio, debug); - l.bot = BotInfo::Find(log->Get<const Anope::string>("bot", "Global"), true); + l.bot = ServiceBot::Find(log->Get<const Anope::string>("bot", "Global"), true); spacesepstream(log->Get<const Anope::string>("target")).GetTokens(l.targets); spacesepstream(log->Get<const Anope::string>("source")).GetTokens(l.sources); spacesepstream(log->Get<const Anope::string>("admin")).GetTokens(l.admin); @@ -410,8 +419,15 @@ Conf::Conf() : Block("") this->LogInfos.push_back(l); } - for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) - it->second->commands.clear(); + for (std::pair<Anope::string, User *> p : UserListByNick) + { + User *u = p.second; + if (u->type != UserType::BOT) + continue; + + ServiceBot *bi = anope_dynamic_static_cast<ServiceBot *>(u); + bi->commands.clear(); + } for (int i = 0; i < this->CountBlock("command"); ++i) { Block *command = this->GetBlock("command", i); @@ -427,7 +443,7 @@ Conf::Conf() : Block("") ValidateNotEmpty("command", "name", nname); ValidateNotEmpty("command", "command", cmd); - BotInfo *bi = this->GetClient(service); + ServiceBot *bi = this->GetClient(service); if (!bi) continue; @@ -475,30 +491,21 @@ Conf::Conf() : Block("") /* Below here can't throw */ + /* Clear existing conf opers */ if (Config) - /* Clear existing conf opers */ - if (NickServ::service) - { - NickServ::nickcore_map& ncmap = NickServ::service->GetAccountList(); - for (auto& it : ncmap) - { - NickServ::Account *nc = it.second; - if (nc->o && std::find(Config->Opers.begin(), Config->Opers.end(), nc->o) != Config->Opers.end()) - nc->o = NULL; - } - } + for (Oper *o : Serialize::GetObjects<Oper *>(operblock)) + if (o->conf == Config) + o->Delete(); /* Apply new opers */ if (NickServ::service) - for (unsigned i = 0; i < this->Opers.size(); ++i) + for (Oper *o : Serialize::GetObjects<Oper *>(operblock)) { - Oper *o = this->Opers[i]; - - NickServ::Nick *na = NickServ::service->FindNick(o->name); + NickServ::Nick *na = NickServ::service->FindNick(o->GetName()); if (!na) continue; - na->nc->o = o; - Log() << "Tied oper " << na->nc->display << " to type " << o->ot->GetName(); + na->GetAccount()->o = o; + Log() << "Tied oper " << na->GetAccount()->GetDisplay() << " to type " << o->GetType()->GetName(); } if (options->Get<const Anope::string>("casemap", "ascii") == "ascii") @@ -549,8 +556,6 @@ Conf::~Conf() { for (unsigned i = 0; i < MyOperTypes.size(); ++i) delete MyOperTypes[i]; - for (unsigned i = 0; i < Opers.size(); ++i) - delete Opers[i]; } void Conf::Post(Conf *old) @@ -564,32 +569,22 @@ void Conf::Post(Conf *old) ModuleManager::LoadModule(this->ModulesAutoLoad[i], NULL); /* Apply opertype changes, as non-conf opers still point to the old oper types */ - for (unsigned i = Oper::opers.size(); i > 0; --i) + for (Oper *o : Serialize::GetObjects<Oper *>(operblock)) { - Oper *o = Oper::opers[i - 1]; - /* Oper's type is in the old config, so update it */ - if (std::find(old->MyOperTypes.begin(), old->MyOperTypes.end(), o->ot) != old->MyOperTypes.end()) + if (std::find(old->MyOperTypes.begin(), old->MyOperTypes.end(), o->GetType()) != old->MyOperTypes.end()) { - OperType *ot = o->ot; - o->ot = NULL; + OperType *ot = o->GetType(); + o->SetType(nullptr); for (unsigned j = 0; j < MyOperTypes.size(); ++j) if (ot->GetName() == MyOperTypes[j]->GetName()) - o->ot = MyOperTypes[j]; + o->SetType(MyOperTypes[j]); - if (o->ot == NULL) + if (o->GetType() == NULL) { /* Oper block has lost type */ - std::vector<Oper *>::iterator it = std::find(old->Opers.begin(), old->Opers.end(), o); - if (it != old->Opers.end()) - old->Opers.erase(it); - - it = std::find(this->Opers.begin(), this->Opers.end(), o); - if (it != this->Opers.end()) - this->Opers.erase(it); - - delete o; + o->Delete(); } } } @@ -626,11 +621,11 @@ Block *Conf::GetModule(const Anope::string &mname) return GetModule(mname); } -BotInfo *Conf::GetClient(const Anope::string &cname) +ServiceBot *Conf::GetClient(const Anope::string &cname) { Anope::map<Anope::string>::iterator it = bots.find(cname); if (it != bots.end()) - return BotInfo::Find(!it->second.empty() ? it->second : cname, true); + return ServiceBot::Find(!it->second.empty() ? it->second : cname, true); Block *block = GetModule(cname.lower()); const Anope::string &client = block->Get<const Anope::string>("client"); diff --git a/src/event.cpp b/src/event.cpp index cba56a314..9a46b4ac2 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -91,12 +91,8 @@ EventHandlers<LogMessage> Event::OnLogMessage(nullptr, "OnLogMessage"); EventHandlers<CheckModes> Event::OnCheckModes(nullptr, "OnCheckModes"); EventHandlers<ChannelSync> Event::OnChannelSync(nullptr, "OnChannelSync"); EventHandlers<SetCorrectModes> Event::OnSetCorrectModes(nullptr, "OnSetCorrectModes"); -EventHandlers<SerializeCheck> Event::OnSerializeCheck(nullptr, "OnSerializeCheck"); -EventHandlers<SerializableConstruct> Event::OnSerializableConstruct(nullptr, "OnSerializableConstruct"); -EventHandlers<SerializableDestruct> Event::OnSerializableDestruct(nullptr, "OnSerializableDestruct"); -EventHandlers<SerializableUpdate> Event::OnSerializableUpdate(nullptr, "OnSerializableUpdate"); -EventHandlers<SerializeTypeCreate> Event::OnSerializeTypeCreate(nullptr, "OnSerializeTypeCreate"); EventHandlers<Message> Event::OnMessage(nullptr, "OnMessage"); EventHandlers<CanSet> Event::OnCanSet(nullptr, "OnCanSet"); EventHandlers<CheckDelete> Event::OnCheckDelete(nullptr, "OnCheckDelete"); EventHandlers<ExpireTick> Event::OnExpireTick(nullptr, "OnExpireTick"); +EventHandlers<SerializeEvents> Event::OnSerialize(nullptr, "OnSerialize"); diff --git a/src/extensible.cpp b/src/extensible.cpp index 37206f7c1..e0e35e6ea 100644 --- a/src/extensible.cpp +++ b/src/extensible.cpp @@ -10,25 +10,25 @@ #include "extensible.h" -static std::set<ExtensibleBase *> extensible_items; +ExtensibleBase::ExtensibleBase(Module *m, const Anope::string &n) : ExtensibleBase(m, "Extensible", n) +{ +} -ExtensibleBase::ExtensibleBase(Module *m, const Anope::string &n) : Service(m, "Extensible", n) +ExtensibleBase::ExtensibleBase(Module *m, const Anope::string &t, const Anope::string &n) : Service(m, t, n) { - extensible_items.insert(this); } ExtensibleBase::~ExtensibleBase() { - extensible_items.erase(this); } Extensible::~Extensible() { while (!extension_items.empty()) - (*extension_items.begin())->Unset(this); + extension_items[0]->Unset(this); } -bool Extensible::HasExt(const Anope::string &name) const +bool Extensible::HasExtOK(const Anope::string &name) { ExtensibleRef<void *> ref(name); if (ref) @@ -38,32 +38,3 @@ bool Extensible::HasExt(const Anope::string &name) const return false; } -void Extensible::ExtensibleSerialize(const Extensible *e, const Serializable *s, Serialize::Data &data) -{ - for (std::set<ExtensibleBase *>::iterator it = e->extension_items.begin(); it != e->extension_items.end(); ++it) - { - ExtensibleBase *eb = *it; - eb->ExtensibleSerialize(e, s, data); - } -} - -void Extensible::ExtensibleUnserialize(Extensible *e, Serializable *s, Serialize::Data &data) -{ - for (std::set<ExtensibleBase *>::iterator it = extensible_items.begin(); it != extensible_items.end(); ++it) - { - ExtensibleBase *eb = *it; - eb->ExtensibleUnserialize(e, s, data); - } -} - -template<> -bool* Extensible::Extend(const Anope::string &name, const bool &what) -{ - ExtensibleRef<bool> ref(name); - if (ref) - return ref->Set(this); - - Log(LOG_DEBUG) << "Extend for nonexistant type " << name << " on " << static_cast<void *>(this); - return NULL; -} - diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp index beaf727ec..62bcc404f 100644 --- a/src/hashcomp.cpp +++ b/src/hashcomp.cpp @@ -64,8 +64,8 @@ int ci::ci_char_traits::compare(const char *str1, const char *str2, size_t n) { for (unsigned i = 0; i < n; ++i) { - register unsigned char c1 = case_map_upper[static_cast<unsigned char>(*str1)], - c2 = case_map_upper[static_cast<unsigned char>(*str2)]; + unsigned char c1 = case_map_upper[static_cast<unsigned char>(*str1)], + c2 = case_map_upper[static_cast<unsigned char>(*str2)]; if (c1 > c2) return 1; diff --git a/src/init.cpp b/src/init.cpp index 04b02cc06..305f7d584 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -20,6 +20,7 @@ #include "servers.h" #include "language.h" #include "event.h" +#include "modules.h" #ifndef _WIN32 #include <sys/wait.h> @@ -289,7 +290,7 @@ void Anope::Init(int ac, char **av) umask(DEFUMASK); #endif - Serialize::RegisterTypes(); + //Serialize::RegisterTypes(); /* Parse command line arguments */ ParseCommandLineArguments(ac, av); @@ -473,6 +474,10 @@ void Anope::Init(int ac, char **av) /* Initialize the socket engine. Note that some engines can not survive a fork(), so this must be here. */ SocketEngine::Init(); + new BotInfoType(); + new XLineType(nullptr, "XLine"); + new OperBlockType(); + /* Read configuration file; exit if there are problems. */ try { @@ -491,9 +496,14 @@ void Anope::Init(int ac, char **av) /* Create me */ Configuration::Block *block = Config->GetBlock("serverinfo"); Me = new Server(NULL, block->Get<const Anope::string>("name"), 0, block->Get<const Anope::string>("description"), block->Get<const Anope::string>("id")); - for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) + for (std::pair<Anope::string, User *> p : UserListByNick) { - it->second->server = Me; + User *u = p.second; + if (u->type != UserType::BOT) + continue; + + ServiceBot *bi = anope_dynamic_static_cast<ServiceBot *>(u); + bi->server = Me; ++Me->users; } @@ -531,8 +541,15 @@ void Anope::Init(int ac, char **av) Anope::string sid = IRCD->SID_Retrieve(); if (Me->GetSID() == Me->GetName()) Me->SetSID(sid); - for (botinfo_map::iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) - it->second->GenerateUID(); + for (std::pair<Anope::string, User *> p : UserListByNick) + { + User *u = p.second; + if (u->type != UserType::BOT) + continue; + + ServiceBot *bi = anope_dynamic_static_cast<ServiceBot *>(u); + bi->GenerateUID(); + } } /* Load up databases */ @@ -545,6 +562,6 @@ void Anope::Init(int ac, char **av) for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it) it->second->Sync(); - Serialize::CheckTypes(); + //Serialize::CheckTypes(); } diff --git a/src/language.cpp b/src/language.cpp index 675605159..b1b0d77fc 100644 --- a/src/language.cpp +++ b/src/language.cpp @@ -70,9 +70,9 @@ const char *Language::Translate(User *u, const char *string) return Translate("", string); } -const char *Language::Translate(const NickServ::Account *nc, const char *string) +const char *Language::Translate(NickServ::Account *nc, const char *string) { - return Translate(nc ? nc->language.c_str() : "", string); + return Translate(nc ? nc->GetLanguage().c_str() : "", string); } #if GETTEXT_FOUND diff --git a/src/logger.cpp b/src/logger.cpp index 9dad74a67..3a735d48d 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -78,7 +78,7 @@ const Anope::string &LogFile::GetName() const return this->filename; } -Log::Log(LogType t, const Anope::string &cat, BotInfo *b) : bi(b), u(NULL), nc(NULL), c(NULL), source(NULL), chan(NULL), ci(NULL), s(NULL), m(NULL), type(t), category(cat) +Log::Log(LogType t, const Anope::string &cat, ServiceBot *b) : bi(b), u(NULL), nc(NULL), c(NULL), source(NULL), chan(NULL), ci(NULL), s(NULL), m(NULL), type(t), category(cat) { } @@ -93,7 +93,7 @@ Log::Log(LogType t, CommandSource &src, Command *_c, ChanServ::Channel *_ci) : u size_t sl = c->name.find('/'); this->bi = NULL; if (sl != Anope::string::npos) - this->bi = BotInfo::Find(c->name.substr(0, sl), true); + this->bi = ServiceBot::Find(c->name.substr(0, sl), true); this->category = c->name; } @@ -103,23 +103,23 @@ Log::Log(User *_u, Channel *ch, const Anope::string &cat) : bi(NULL), u(_u), nc( throw CoreException("Invalid pointers passed to Log::Log"); } -Log::Log(User *_u, const Anope::string &cat, BotInfo *_bi) : bi(_bi), u(_u), nc(NULL), c(NULL), source(NULL), chan(NULL), ci(NULL), s(NULL), m(NULL), type(LOG_USER), category(cat) +Log::Log(User *_u, const Anope::string &cat, ServiceBot *_bi) : bi(_bi), u(_u), nc(NULL), c(NULL), source(NULL), chan(NULL), ci(NULL), s(NULL), m(NULL), type(LOG_USER), category(cat) { if (!u) throw CoreException("Invalid pointers passed to Log::Log"); } -Log::Log(Server *serv, const Anope::string &cat, BotInfo *_bi) : bi(_bi), u(NULL), nc(NULL), c(NULL), source(NULL), chan(NULL), ci(NULL), s(serv), m(NULL), type(LOG_SERVER), category(cat) +Log::Log(Server *serv, const Anope::string &cat, ServiceBot *_bi) : bi(_bi), u(NULL), nc(NULL), c(NULL), source(NULL), chan(NULL), ci(NULL), s(serv), m(NULL), type(LOG_SERVER), category(cat) { if (!s) throw CoreException("Invalid pointer passed to Log::Log"); } -Log::Log(BotInfo *b, const Anope::string &cat) : bi(b), u(NULL), nc(NULL), c(NULL), source(NULL), chan(NULL), ci(NULL), s(NULL), m(NULL), type(LOG_NORMAL), category(cat) +Log::Log(ServiceBot *b, const Anope::string &cat) : bi(b), u(NULL), nc(NULL), c(NULL), source(NULL), chan(NULL), ci(NULL), s(NULL), m(NULL), type(LOG_NORMAL), category(cat) { } -Log::Log(Module *mod, const Anope::string &cat, BotInfo *_bi) : bi(_bi), u(NULL), nc(NULL), c(NULL), source(NULL), chan(NULL), ci(NULL), s(NULL), m(mod), type(LOG_MODULE), category(cat) +Log::Log(Module *mod, const Anope::string &cat, ServiceBot *_bi) : bi(_bi), u(NULL), nc(NULL), c(NULL), source(NULL), chan(NULL), ci(NULL), s(NULL), m(mod), type(LOG_MODULE), category(cat) { } @@ -144,11 +144,11 @@ Anope::string Log::FormatSource() const { if (u) if (nc) - return this->u->GetMask() + " (" + this->nc->display + ")"; + return this->u->GetMask() + " (" + this->nc->Ge |
