diff options
author | Adam <Adam@anope.org> | 2013-07-01 22:17:52 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2013-07-01 22:17:52 -0400 |
commit | 1a3d9a016d3adc49788bbff73aac9b3b5ea85b17 (patch) | |
tree | c0ecf92ed768473bc82ff64a7fce827245f37ba9 /src | |
parent | 518182ac9204f815258b0de91b3f884d8efa1502 (diff) |
Change extensible keys to require explicitly having a type defined for it. Completely modularize more features like bs_kick, entrymsg, log, mode, etc. Move fantasy to its own module. Move greet to its own module.
Diffstat (limited to 'src')
-rw-r--r-- | src/bots.cpp | 4 | ||||
-rw-r--r-- | src/channels.cpp | 72 | ||||
-rw-r--r-- | src/config.cpp | 4 | ||||
-rw-r--r-- | src/extensible.cpp | 101 | ||||
-rw-r--r-- | src/misc.cpp | 21 | ||||
-rw-r--r-- | src/nickalias.cpp | 13 | ||||
-rw-r--r-- | src/nickcore.cpp | 72 | ||||
-rw-r--r-- | src/regchannel.cpp | 498 | ||||
-rw-r--r-- | src/serialize.cpp | 5 | ||||
-rw-r--r-- | src/sockets.cpp | 2 | ||||
-rw-r--r-- | src/users.cpp | 5 |
11 files changed, 96 insertions, 701 deletions
diff --git a/src/bots.cpp b/src/bots.cpp index 2ff4f5340..0a65393bb 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -80,7 +80,7 @@ void BotInfo::Serialize(Serialize::Data &data) const data["created"] << this->created; data["oper_only"] << this->oper_only; - this->ExtensibleSerialize(data); + Extensible::ExtensibleSerialize(this, this, data); } Serializable* BotInfo::Unserialize(Serializable *obj, Serialize::Data &data) @@ -101,7 +101,7 @@ Serializable* BotInfo::Unserialize(Serializable *obj, Serialize::Data &data) data["created"] >> bi->created; data["oper_only"] >> bi->oper_only; - bi->ExtensibleUnserialize(data); + Extensible::ExtensibleUnserialize(bi, bi, data); return bi; } diff --git a/src/channels.cpp b/src/channels.cpp index 9fdc44a49..0b790e54e 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -35,7 +35,7 @@ Channel::Channel(const Anope::string &nname, time_t ts) this->name = nname; this->creation_time = ts; - this->syncing = false; + this->syncing = this->botchannel = false; this->server_modetime = this->chanserv_modetime = 0; this->server_modecount = this->chanserv_modecount = this->bouncy_modes = this->topic_ts = this->topic_time = 0; @@ -108,48 +108,6 @@ void Channel::CheckModes() FOREACH_RESULT(OnCheckModes, MOD_RESULT, (this)); if (MOD_RESULT == EVENT_STOP) return; - - if (this->ci) - for (ChannelInfo::ModeList::const_iterator it = this->ci->GetMLock().begin(), it_end = this->ci->GetMLock().end(); it != it_end; ++it) - { - const ModeLock *ml = it->second; - ChannelMode *cm = ModeManager::FindChannelModeByName(ml->name); - if (!cm) - continue; - - if (cm->type == MODE_REGULAR) - { - if (!this->HasMode(cm->name) && ml->set) - this->SetMode(NULL, cm); - else if (this->HasMode(cm->name) && !ml->set) - this->RemoveMode(NULL, cm); - } - else if (cm->type == MODE_PARAM) - { - /* If the channel doesnt have the mode, or it does and it isn't set correctly */ - if (ml->set) - { - Anope::string param; - this->GetParam(cm->name, param); - - if (!this->HasMode(cm->name) || (!param.empty() && !ml->param.empty() && !param.equals_cs(ml->param))) - this->SetMode(NULL, cm, ml->param); - } - else - { - if (this->HasMode(cm->name)) - this->RemoveMode(NULL, cm); - } - - } - else if (cm->type == MODE_LIST) - { - if (ml->set) - this->SetMode(NULL, cm, ml->param); - else - this->RemoveMode(NULL, cm, ml->param); - } - } } bool Channel::CheckDelete() @@ -312,7 +270,7 @@ void Channel::SetModeInternal(MessageSource &setter, ChannelMode *cm, const Anop if (cc) cc->status.AddMode(cm->mchar); - FOREACH_RESULT(OnChannelModeSet, MOD_RESULT, (this, setter, cm->name, param)); + FOREACH_RESULT(OnChannelModeSet, MOD_RESULT, (this, setter, cm, param)); /* Enforce secureops, etc */ if (enforce_mlock && MOD_RESULT != EVENT_STOP) @@ -336,7 +294,7 @@ void Channel::SetModeInternal(MessageSource &setter, ChannelMode *cm, const Anop cml->OnAdd(this, param); } - FOREACH_RESULT(OnChannelModeSet, MOD_RESULT, (this, setter, cm->name, param)); + FOREACH_RESULT(OnChannelModeSet, MOD_RESULT, (this, setter, cm, param)); /* Check if we should enforce mlock */ if (!enforce_mlock || MOD_RESULT == EVENT_STOP) @@ -377,7 +335,7 @@ void Channel::RemoveModeInternal(MessageSource &setter, ChannelMode *cm, const A if (cc) cc->status.DelMode(cm->mchar); - FOREACH_RESULT(OnChannelModeUnset, MOD_RESULT, (this, setter, cm->name, param)); + FOREACH_RESULT(OnChannelModeUnset, MOD_RESULT, (this, setter, cm, param)); if (enforce_mlock && MOD_RESULT != EVENT_STOP) this->SetCorrectModes(u, false); @@ -404,7 +362,7 @@ void Channel::RemoveModeInternal(MessageSource &setter, ChannelMode *cm, const A cml->OnDel(this, param); } - FOREACH_RESULT(OnChannelModeUnset, MOD_RESULT, (this, setter, cm->name, param)); + FOREACH_RESULT(OnChannelModeUnset, MOD_RESULT, (this, setter, cm, param)); /* Check for mlock */ if (!enforce_mlock || MOD_RESULT == EVENT_STOP) @@ -865,26 +823,6 @@ void Channel::SetCorrectModes(User *user, bool give_modes) this->RemoveMode(NULL, cm, user->GetUID()); } } - - // Check mlock - for (ChannelInfo::ModeList::const_iterator it = ci->GetMLock().begin(), it_end = ci->GetMLock().end(); it != it_end; ++it) - { - const ModeLock *ml = it->second; - ChannelMode *cm = ModeManager::FindChannelModeByName(ml->name); - if (!cm || cm->type != MODE_STATUS) - continue; - - if (Anope::Match(user->nick, ml->param) || Anope::Match(user->GetDisplayedMask(), ml->param)) - { - if (ml->set != this->HasUserStatus(user, ml->name)) - { - if (ml->set) - this->SetMode(NULL, cm, user->GetUID(), false); - else if (!ml->set) - this->RemoveMode(NULL, cm, user->GetUID(), false); - } - } - } } bool Channel::Unban(User *u, bool full) diff --git a/src/config.cpp b/src/config.cpp index 4b16d8e97..8ba56bda2 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -339,7 +339,7 @@ Conf::Conf() : Block("") if (!c) continue; // Can't happen - c->Extend("BOTCHANNEL"); + c->botchannel = true; /* Remove all existing modes */ ChanUserContainer *cu = c->FindUser(bi); @@ -377,7 +377,7 @@ Conf::Conf() : Block("") Channel *c = Channel::Find(chname); if (c) { - c->Shrink("BOTCHANNEL"); + c->botchannel = false; bi->Part(c); } } diff --git a/src/extensible.cpp b/src/extensible.cpp index 25fa7938c..9284bdbf2 100644 --- a/src/extensible.cpp +++ b/src/extensible.cpp @@ -10,96 +10,63 @@ #include "extensible.h" -Extensible::Extensible() : extension_items(NULL) -{ -} +static std::set<ExtensibleBase *> extensible_items; -Extensible::~Extensible() +ExtensibleBase::ExtensibleBase(Module *m, const Anope::string &n) : Service(m, "Extensible", n) { - if (extension_items) - { - for (extensible_map::iterator it = extension_items->begin(), it_end = extension_items->end(); it != it_end; ++it) - delete it->second; - delete extension_items; - } + extensible_items.insert(this); } -void Extensible::Extend(const Anope::string &key, ExtensibleItem *p) +ExtensibleBase::~ExtensibleBase() { - this->Shrink(key); - if (!extension_items) - extension_items = new extensible_map(); - (*this->extension_items)[key] = p; + extensible_items.erase(this); } -void Extensible::ExtendMetadata(const Anope::string &key, const Anope::string &value) +Extensible::~Extensible() { - this->Extend(key, new ExtensibleMetadata(!value.empty() ? value : "1")); + for (std::set<ExtensibleBase *>::iterator it = extension_items.begin(); it != extension_items.end(); ++it) + (*it)->Unset(this); } -bool Extensible::Shrink(const Anope::string &key) +bool Extensible::HasExt(const Anope::string &name) const { - if (!extension_items) - return false; - - extensible_map::iterator it = this->extension_items->find(key); - if (it != this->extension_items->end()) - { - delete it->second; - /* map::size_type map::erase( const key_type& key ); - * returns the number of elements removed, std::map - * is single-associative so this should only be 0 or 1 - */ - return this->extension_items->erase(key) > 0; - } + ExtensibleRef<void *> ref(name); + if (ref) + return ref->HasExt(this); + Log(LOG_DEBUG) << "HasExt for nonexistent type " << name << " on " << static_cast<const void *>(this); return false; } -bool Extensible::HasExt(const Anope::string &key) const +void Extensible::ExtensibleSerialize(const Extensible *e, const Serializable *s, Serialize::Data &data) { - return this->extension_items != NULL && this->extension_items->count(key) > 0; + 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::GetExtList(std::deque<Anope::string> &list) const +void Extensible::ExtensibleUnserialize(Extensible *e, Serializable *s, Serialize::Data &data) { - if (extension_items) - for (extensible_map::const_iterator it = extension_items->begin(), it_end = extension_items->end(); it != it_end; ++it) - list.push_back(it->first); -} + while (!e->extension_items.empty()) + (*e->extension_items.begin())->Unset(e); -void Extensible::ExtensibleSerialize(Serialize::Data &data) const -{ - if (extension_items) - for (extensible_map::const_iterator it = extension_items->begin(), it_end = extension_items->end(); it != it_end; ++it) - if (it->second && it->second->Serialize()) - data["extensible:" + it->first] << *it->second->Serialize(); -} - -void Extensible::ExtensibleUnserialize(Serialize::Data &data) -{ - /* Shrink existing extensible metadata items */ - std::deque<Anope::string> list; - this->GetExtList(list); - for (unsigned i = 0; i < list.size(); ++i) + for (std::set<ExtensibleBase *>::iterator it = extensible_items.begin(); it != extensible_items.end(); ++it) { - ExtensibleItem *item = extension_items->at(list[i]); - if (item && item->Serialize()) - this->Shrink(list[i]); + ExtensibleBase *eb = *it; + eb->ExtensibleUnserialize(e, s, data); } - - std::set<Anope::string> keys = data.KeySet(); - for (std::set<Anope::string>::iterator it = keys.begin(), it_end = keys.end(); it != it_end; ++it) - if (it->find("extensible:") == 0) - { - if (!extension_items) - extension_items = new extensible_map(); +} - Anope::string str; - data[*it] >> str; +template<> +bool* Extensible::Extend(const Anope::string &name, const bool &what) +{ + ExtensibleRef<bool> ref(name); + if (ref) + return ref->Set(this); - if (!str.empty()) - this->ExtendMetadata(it->substr(11), str); - } + Log(LOG_DEBUG) << "Shrink for nonexistant type " << name << " on " << static_cast<void *>(this); + return NULL; } diff --git a/src/misc.cpp b/src/misc.cpp index fd08ffb2a..c9e18dc66 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -220,7 +220,7 @@ void InfoFormatter::Process(std::vector<Anope::string> &buffer) Anope::string s; for (unsigned i = it->first.length(); i < this->longest; ++i) s += " "; - s += Anope::string(Language::Translate(this->nc, it->first.c_str())) + ": " + it->second; + s += Anope::string(Language::Translate(this->nc, it->first.c_str())) + ": " + Language::Translate(this->nc, it->second.c_str()); buffer.push_back(s); } @@ -234,6 +234,25 @@ Anope::string& InfoFormatter::operator[](const Anope::string &key) return this->replies.back().second; } +void InfoFormatter::AddOption(const Anope::string &opt) +{ + Anope::string *optstr = NULL; + for (std::vector<std::pair<Anope::string, Anope::string> >::iterator it = this->replies.begin(), it_end = this->replies.end(); it != it_end; ++it) + { + if (it->first == "Options") + { + optstr = &it->second; + break; + } + } + if (!optstr) + optstr = &(*this)["Options"]; + + if (!optstr->empty()) + *optstr += ", "; + *optstr += Language::Translate(nc, opt.c_str()); +} + bool Anope::IsFile(const Anope::string &filename) { struct stat fileinfo; diff --git a/src/nickalias.cpp b/src/nickalias.cpp index 1595987e4..a50284cf4 100644 --- a/src/nickalias.cpp +++ b/src/nickalias.cpp @@ -140,7 +140,7 @@ void NickAlias::Serialize(Serialize::Data &data) const data.SetType("time_registered", Serialize::Data::DT_INT); data["time_registered"] << this->time_registered; data.SetType("time_registered", Serialize::Data::DT_INT); data["last_seen"] << this->last_seen; data["nc"] << this->nc->display; - this->ExtensibleSerialize(data); + Extensible::ExtensibleSerialize(this, this, data); if (this->HasVhost()) { @@ -189,7 +189,7 @@ Serializable* NickAlias::Unserialize(Serializable *obj, Serialize::Data &data) data["last_realhost"] >> na->last_realhost; data["time_registered"] >> na->time_registered; data["last_seen"] >> na->last_seen; - na->ExtensibleUnserialize(data); + Extensible::ExtensibleUnserialize(na, na, data); Anope::string vhost_ident, vhost_host, vhost_creator; time_t vhost_time; @@ -201,15 +201,6 @@ Serializable* NickAlias::Unserialize(Serializable *obj, Serialize::Data &data) na->SetVhost(vhost_ident, vhost_host, vhost_creator, vhost_time); - /* Compat */ - Anope::string sflags; - data["flags"] >> sflags; - spacesepstream sep(sflags); - Anope::string tok; - while (sep.GetToken(tok)) - na->ExtendMetadata(tok); - /* End compat */ - return na; } diff --git a/src/nickcore.cpp b/src/nickcore.cpp index 5779767dd..9bbaae959 100644 --- a/src/nickcore.cpp +++ b/src/nickcore.cpp @@ -67,13 +67,10 @@ void NickCore::Serialize(Serialize::Data &data) const data["display"] << this->display; data["pass"] << this->pass; data["email"] << this->email; - data["greet"] << this->greet; data["language"] << this->language; - this->ExtensibleSerialize(data); + Extensible::ExtensibleSerialize(this, this, data); for (unsigned i = 0; i < this->access.size(); ++i) data["access"] << this->access[i] << " "; - for (unsigned i = 0; i < this->cert.size(); ++i) - data["cert"] << this->cert[i] << " "; data["memomax"] << this->memos.memomax; for (unsigned i = 0; i < this->memos.ignores.size(); ++i) data["memoignores"] << this->memos.ignores[i] << " "; @@ -94,9 +91,8 @@ Serializable* NickCore::Unserialize(Serializable *obj, Serialize::Data &data) data["pass"] >> nc->pass; data["email"] >> nc->email; - data["greet"] >> nc->greet; data["language"] >> nc->language; - nc->ExtensibleUnserialize(data); + Extensible::ExtensibleUnserialize(nc, nc, data); { Anope::string buf; data["access"] >> buf; @@ -105,14 +101,6 @@ Serializable* NickCore::Unserialize(Serializable *obj, Serialize::Data &data) while (sep.GetToken(buf)) nc->access.push_back(buf); } - { - Anope::string buf; - data["cert"] >> buf; - spacesepstream sep(buf); - nc->cert.clear(); - while (sep.GetToken(buf)) - nc->cert.push_back(buf); - } data["memomax"] >> nc->memos.memomax; { Anope::string buf; @@ -123,14 +111,15 @@ Serializable* NickCore::Unserialize(Serializable *obj, Serialize::Data &data) nc->memos.ignores.push_back(buf); } - /* Compat */ - Anope::string sflags; - data["flags"] >> sflags; - spacesepstream sep(sflags); - Anope::string tok; - while (sep.GetToken(tok)) - nc->ExtendMetadata(tok); - /* End compat */ + /* compat */ + bool b; + data["extensible:SECURE"] >> b; + if (b) + nc->Extend<bool>("NS_SECURE"); + data["extensible:PRIVATE"] >> b; + if (b) + nc->Extend<bool>("NS_PRIVATE"); + /* end compat */ return nc; } @@ -216,45 +205,6 @@ bool NickCore::IsOnAccess(const User *u) const return false; } -void NickCore::AddCert(const Anope::string &entry) -{ - this->cert.push_back(entry); - FOREACH_MOD(OnNickAddCert, (this, entry)); -} - -Anope::string NickCore::GetCert(unsigned entry) const -{ - if (this->cert.empty() || entry >= this->cert.size()) - return ""; - return this->cert[entry]; -} - -bool NickCore::FindCert(const Anope::string &entry) const -{ - for (unsigned i = 0, end = this->cert.size(); i < end; ++i) - if (this->cert[i] == entry) - return true; - - return false; -} - -void NickCore::EraseCert(const Anope::string &entry) -{ - for (unsigned i = 0, end = this->cert.size(); i < end; ++i) - if (this->cert[i] == entry) - { - FOREACH_MOD(OnNickEraseCert, (this, entry)); - this->cert.erase(this->cert.begin() + i); - break; - } -} - -void NickCore::ClearCert() -{ - FOREACH_MOD(OnNickClearCert, (this)); - this->cert.clear(); -} - void NickCore::AddChannelReference(ChannelInfo *ci) { ++(*this->chanaccess)[ci]; diff --git a/src/regchannel.cpp b/src/regchannel.cpp index b1f056b27..e06f53690 100644 --- a/src/regchannel.cpp +++ b/src/regchannel.cpp @@ -22,54 +22,6 @@ Serialize::Checker<registered_channel_map> RegisteredChannelList("ChannelInfo"); -BadWord::BadWord() : Serializable("BadWord") -{ -} - -BadWord::~BadWord() -{ - if (this->ci) - { - std::vector<BadWord *>::iterator it = std::find(this->ci->badwords->begin(), this->ci->badwords->end(), this); - if (it != this->ci->badwords->end()) - this->ci->badwords->erase(it); - } -} - -void BadWord::Serialize(Serialize::Data &data) const -{ - data["ci"] << this->ci->name; - data["word"] << this->word; - data.SetType("type", Serialize::Data::DT_INT); data["type"] << this->type; -} - -Serializable* BadWord::Unserialize(Serializable *obj, Serialize::Data &data) -{ - Anope::string sci, sword; - - data["ci"] >> sci; - data["word"] >> sword; - - ChannelInfo *ci = ChannelInfo::Find(sci); - if (!ci) - return NULL; - - unsigned int n; - data["type"] >> n; - - BadWord *bw; - if (obj) - { - bw = anope_dynamic_static_cast<BadWord *>(obj); - data["word"] >> bw->word; - bw->type = static_cast<BadWordType>(n); - } - else - bw = ci->AddBadWord(sword, static_cast<BadWordType>(n)); - - return bw; -} - AutoKick::AutoKick() : Serializable("AutoKick") { } @@ -145,122 +97,8 @@ Serializable* AutoKick::Unserialize(Serializable *obj, Serialize::Data &data) return ak; } -ModeLock::ModeLock(ChannelInfo *ch, bool s, const Anope::string &n, const Anope::string &p, const Anope::string &se, time_t c) : Serializable("ModeLock"), ci(ch), set(s), name(n), param(p), setter(se), created(c) -{ -} - -ModeLock::~ModeLock() -{ - if (this->ci) - this->ci->RemoveMLock(this); -} - -void ModeLock::Serialize(Serialize::Data &data) const -{ - if (!this->ci) - return; - - data["ci"] << this->ci->name; - data["set"] << this->set; - data["name"] << this->name; - data["param"] << this->param; - data["setter"] << this->setter; - data.SetType("created", Serialize::Data::DT_INT); data["created"] << this->created; -} - -Serializable* ModeLock::Unserialize(Serializable *obj, Serialize::Data &data) -{ - Anope::string sci; - - data["ci"] >> sci; - - ChannelInfo *ci = ChannelInfo::Find(sci); - if (!ci) - return NULL; - - ModeLock *ml; - if (obj) - { - ml = anope_dynamic_static_cast<ModeLock *>(obj); - - data["set"] >> ml->set; - data["name"] >> ml->name; - data["param"] >> ml->param; - data["setter"] >> ml->setter; - data["created"] >> ml->created; - return ml; - } - else - { - bool set; - data["set"] >> set; - - time_t created; - data["created"] >> created; - - Anope::string setter; - data["setter"] >> setter; - - Anope::string sname; - data["name"] >> sname; - - ml = new ModeLock(ci, set, sname, "", setter, created); - data["param"] >> ml->param; - - ci->mode_locks->insert(std::make_pair(ml->name, ml)); - return ml; - } -} - -void LogSetting::Serialize(Serialize::Data &data) const -{ - if (!ci) - return; - - data["ci"] << ci->name; - data["service_name"] << service_name; - data["command_service"] << command_service; - data["command_name"] << command_name; - data["method"] << method; - data["extra"] << extra; - data["creator"] << creator; - data.SetType("created", Serialize::Data::DT_INT); data["created"] << created; -} - -Serializable* LogSetting::Unserialize(Serializable *obj, Serialize::Data &data) -{ - Anope::string sci; - - data["ci"] >> sci; - - ChannelInfo *ci = ChannelInfo::Find(sci); - if (ci == NULL) - return NULL; - - LogSetting *ls; - if (obj) - ls = anope_dynamic_static_cast<LogSetting *>(obj); - else - { - ls = new LogSetting(); - ci->log_settings->push_back(ls); - } - - ls->ci = ci; - data["service_name"] >> ls->service_name; - data["command_service"] >> ls->command_service; - data["command_name"] >> ls->command_name; - data["method"] >> ls->method; - data["extra"] >> ls->extra; - data["creator"] >> ls->creator; - data["created"] >> ls->created; - - return ls; -} - ChannelInfo::ChannelInfo(const Anope::string &chname) : Serializable("ChannelInfo"), - access("ChanAccess"), akick("AutoKick"), - badwords("BadWord"), mode_locks("ModeLock"), log_settings("LogSetting") + access("ChanAccess"), akick("AutoKick") { if (chname.empty()) throw CoreException("Empty channel passed to ChannelInfo constructor"); @@ -270,9 +108,6 @@ ChannelInfo::ChannelInfo(const Anope::string &chname) : Serializable("ChannelInf this->c = Channel::Find(chname); if (this->c) this->c->ci = this; - this->capsmin = this->capspercent = 0; - this->floodlines = this->floodsecs = 0; - this->repeattimes = 0; this->banexpire = 0; this->bi = NULL; this->last_topic_time = 0; @@ -283,9 +118,6 @@ ChannelInfo::ChannelInfo(const Anope::string &chname) : Serializable("ChannelInf this->memos.memomax = 0; this->last_used = this->time_registered = Anope::CurTime; - for (int i = 0; i < TTB_SIZE; ++i) - this->ttb[i] = 0; - size_t old = RegisteredChannelList->size(); (*RegisteredChannelList)[this->name] = this; if (old == RegisteredChannelList->size()) @@ -295,8 +127,7 @@ ChannelInfo::ChannelInfo(const Anope::string &chname) : Serializable("ChannelInf } ChannelInfo::ChannelInfo(const ChannelInfo &ci) : Serializable("ChannelInfo"), - access("ChanAccess"), akick("AutoKick"), - badwords("BadWord"), mode_locks("ModeLock"), log_settings("LogSetting") + access("ChanAccess"), akick("AutoKick") { *this = ci; @@ -305,10 +136,6 @@ ChannelInfo::ChannelInfo(const ChannelInfo &ci) : Serializable("ChannelInfo"), this->access->clear(); this->akick->clear(); - this->badwords->clear(); - - for (int i = 0; i < TTB_SIZE; ++i) - this->ttb[i] = ci.ttb[i]; for (unsigned i = 0; i < ci.GetAccessCount(); ++i) { @@ -334,18 +161,6 @@ ChannelInfo::ChannelInfo(const ChannelInfo &ci) : Serializable("ChannelInfo"), else this->AddAkick(takick->creator, takick->mask, takick->reason, takick->addtime, takick->last_used); } - for (unsigned i = 0; i < ci.GetBadWordCount(); ++i) - { - const BadWord *bw = ci.GetBadWord(i); - this->AddBadWord(bw->word, bw->type); - } - - for (unsigned i = 0; i < ci.log_settings->size(); ++i) - { - LogSetting *l = new LogSetting(*ci.log_settings->at(i)); - l->ci = this; - this->log_settings->push_back(l); - } FOREACH_MOD(OnCreateChan, (this)); } @@ -379,14 +194,6 @@ ChannelInfo::~ChannelInfo() this->ClearAccess(); this->ClearAkick(); - this->ClearBadWords(); - - for (unsigned i = 0; i < this->log_settings->size(); ++i) - delete this->log_settings->at(i); - this->log_settings->clear(); - - while (!this->mode_locks->empty()) - delete this->mode_locks->begin()->second; if (!this->memos.memos->empty()) { @@ -413,7 +220,7 @@ void ChannelInfo::Serialize(Serialize::Data &data) const data["last_topic_setter"] << this->last_topic_setter; data.SetType("last_topic_time", Serialize::Data::DT_INT); data["last_topic_time"] << this->last_topic_time; data.SetType("bantype", Serialize::Data::DT_INT); data["bantype"] << this->bantype; - this->ExtensibleSerialize(data); + Extensible::ExtensibleSerialize(this, this, data); { Anope::string levels_buffer; for (Anope::map<int16_t>::const_iterator it = this->levels.begin(), it_end = this->levels.end(); it != it_end; ++it) @@ -422,13 +229,6 @@ void ChannelInfo::Serialize(Serialize::Data &data) const } if (this->bi) data["bi"] << this->bi->nick; - for (int i = 0; i < TTB_SIZE; ++i) - data["ttb"] << this->ttb[i] << " "; - data.SetType("capsmin", Serialize::Data::DT_INT); data["capsmin"] << this->capsmin; - data.SetType("capspercent", Serialize::Data::DT_INT); data["capspercent"] << this->capspercent; - data.SetType("floodlines", Serialize::Data::DT_INT); data["floodlines"] << this->floodlines; - data.SetType("floodsecs", Serialize::Data::DT_INT); data["floodsecs"] << this->floodsecs; - data.SetType("repeattimes", Serialize::Data::DT_INT); data["repeattimes"] << this->repeattimes; data.SetType("banexpire", Serialize::Data::DT_INT); data["banexpire"] << this->banexpire; data["memomax"] << this->memos.memomax; for (unsigned i = 0; i < this->memos.ignores.size(); ++i) @@ -451,7 +251,7 @@ Serializable* ChannelInfo::Unserialize(Serializable *obj, Serialize::Data &data) else ci = new ChannelInfo(sname); - ci->ExtensibleUnserialize(data); + Extensible::ExtensibleUnserialize(ci, ci, data); ci->SetFounder(NickCore::Find(sfounder)); ci->SetSuccessor(NickCore::Find(ssuccessor)); @@ -477,23 +277,6 @@ Serializable* ChannelInfo::Unserialize(Serializable *obj, Serialize::Data &data) else if (ci->bi) ci->bi->UnAssign(NULL, ci); } - { - Anope::string ttb, tok; - data["ttb"] >> ttb; - spacesepstream sep(ttb); - for (int i = 0; sep.GetToken(tok) && i < TTB_SIZE; ++i) - try - { - ci->ttb[i] = convertTo<int16_t>(tok); - } - catch (const ConvertException &) { } - - } - data["capsmin"] >> ci->capsmin; - data["capspercent"] >> ci->capspercent; - data["floodlines"] >> ci->floodlines; - data["floodsecs"] >> ci->floodsecs; - data["repeattimes"] >> ci->repeattimes; data["banexpire"] >> ci->banexpire; data["memomax"] >> ci->memos.memomax; { @@ -505,18 +288,15 @@ Serializable* ChannelInfo::Unserialize(Serializable *obj, Serialize::Data &data) ci->memos.ignores.push_back(buf); } - /* Compat */ - Anope::string sflags, sbotflags; - data["flags"] >> sflags; - data["botflags"] >> sbotflags; - spacesepstream sep(sflags); - Anope::string tok; - while (sep.GetToken(tok)) - ci->ExtendMetadata(tok); - spacesepstream sep2(sbotflags); - while (sep2.GetToken(tok)) - ci->ExtendMetadata("BS_" + tok); - /* End compat */ + /* compat */ + bool b; + data["extensible:SECURE"] >> b; + if (b) + ci->Extend<bool>("CS_SECURE"); + data["extensible:PRIVATE"] >> b; + if (b) + ci->Extend<bool>("CS_PRIVATE"); + /* end compat */ return ci; } @@ -603,7 +383,7 @@ AccessGroup ChannelInfo::AccessFor(const User *u) return group; const NickCore *nc = u->Account(); - if (nc == NULL && !this->HasExt("SECURE") && u->IsRecognized()) + if (nc == NULL && !this->HasExt("NS_SECURE") && u->IsRecognized()) { const NickAlias *na = NickAlias::Find(u->nick); if (na != NULL) @@ -756,256 +536,6 @@ void ChannelInfo::ClearAkick() delete this->akick->back(); } -BadWord* ChannelInfo::AddBadWord(const Anope::string &word, BadWordType type) -{ - BadWord *bw = new BadWord(); - bw->ci = this; - bw->word = word; - bw->type = type; - - this->badwords->push_back(bw); - - FOREACH_MOD(OnBadWordAdd, (this, bw)); - - return bw; -} - -BadWord* ChannelInfo::GetBadWord(unsigned index) const -{ - if (this->badwords->empty() || index >= this->badwords->size()) - return NULL; - - BadWord *bw = (*this->badwords)[index]; - bw->QueueUpdate(); - return bw; -} - -unsigned ChannelInfo::GetBadWordCount() const -{ - return this->badwords->size(); -} - -void ChannelInfo::EraseBadWord(unsigned index) -{ - if (this->badwords->empty() || index >= this->badwords->size()) - return; - - FOREACH_MOD(OnBadWordDel, (this, (*this->badwords)[index])); - - delete this->badwords->at(index); -} - -void ChannelInfo::ClearBadWords() -{ - while (!this->badwords->empty()) - delete this->badwords->back(); -} - -bool ChannelInfo::HasMLock(ChannelMode *mode, const Anope::string ¶m, bool status) const -{ - if (!mode) - return false; - - std::multimap<Anope::string, ModeLock *>::const_iterator it = this->mode_locks->find(mode->name); - - if (it != this->mode_locks->end()) - { - if (mode->type != MODE_REGULAR) - { - std::multimap<Anope::string, ModeLock *>::const_iterator it_end = this->mode_locks->upper_bound(mode->name); - - for (; it != it_end; ++it) - { - const ModeLock *ml = it->second; - if (ml->param == param) - return true; - } - } - else - return it->second->set == status; - } - return false; -} - -bool ChannelInfo::SetMLock(ChannelMode *mode, bool status, const Anope::string ¶m, Anope::string setter, time_t created) -{ - if (!mode) - return false; - - if (setter.empty()) - setter = this->founder ? this->founder->display : "Unknown"; - std::pair<Anope::string, ModeLock *> ml = std::make_pair(mode->name, new ModeLock(this, status, mode->name, param, setter, created)); - - EventReturn MOD_RESULT; - FOREACH_RESULT(OnMLock, MOD_RESULT, (this, ml.second)); - if (MOD_RESULT == EVENT_STOP) - return false; - - /* First, remove this */ - if (mode->type == MODE_REGULAR || mode->type == MODE_PARAM) - { - for (ChannelInfo::ModeList::const_iterator it; (it = this->mode_locks->find(mode->name)) != this->mode_locks->end();) - delete it->second; - this->mode_locks->erase(mode->name); - } - else - { - // For list or status modes, we must check the parameter - ChannelInfo::ModeList::iterator it = this->mode_locks->find(mode->name); - if (it != this->mode_locks->end()) - { - ChannelInfo::ModeList::iterator it_end = this->mode_locks->upper_bound(mode->name); - for (; it != it_end; ++it) - { - const ModeLock *modelock = it->second; - if (modelock->param == param) - { - delete it->second; - break; - } - } - } - } - - this->mode_locks->insert(ml); - - return true; -} - -bool ChannelInfo::RemoveMLock(ChannelMode *mode, bool status, const Anope::string ¶m) -{ - if (!mode) - return false; - - if (mode->type == MODE_REGULAR || mode->type == MODE_PARAM) - { - ChannelInfo::ModeList::iterator it = this->mode_locks->find(mode->name), it_end = this->mode_locks->upper_bound(mode->name), it_next = it; - if (it != this->mode_locks->end()) - for (; it != it_end; it = it_next) - { - const ModeLock *ml = it->second; - ++it_next; - - if (status != ml->set) - continue; - - EventReturn MOD_RESULT; - FOREACH_RESULT(OnUnMLock, MOD_RESULT, (this, it->second)); - if (MOD_RESULT != EVENT_STOP) - { - delete it->second; - return true; - } - } - return false; - } - else - { - // For list or status modes, we must check the parameter - ChannelInfo::ModeList::iterator it = this->mode_locks->find(mode->name); - if (it != this->mode_locks->end()) - { - ChannelInfo::ModeList::iterator it_end = this->mode_locks->upper_bound(mode->name); - for (; it != it_end; ++it) - { - const ModeLock *ml = it->second; - if (ml->set == status && ml->param == param) - { - EventReturn MOD_RESULT; - FOREACH_RESULT(OnUnMLock, MOD_RESULT, (this, it->second)); - if (MOD_RESULT == EVENT_STOP) - return false; - delete it->second; - return true; - } - } - } - - return false; - } -} - -void ChannelInfo::RemoveMLock(ModeLock *mlock) -{ - ChannelInfo::ModeList::iterator it = this->mode_locks->find(mlock->name); - if (it != this->mode_locks->end()) - for (; it != this->mode_locks->upper_bound(mlock->name); ++it) - if (it->second == mlock) - { - this->mode_locks->erase(it); - break; - } -} - -void ChannelInfo::ClearMLock() -{ - while (!this->mode_locks->empty()) - delete this->mode_locks->begin()->second; - this->mode_locks->clear(); -} - -const ChannelInfo::ModeList &ChannelInfo::GetMLock() const -{ - return this->mode_locks; -} - -std::pair<ChannelInfo::ModeList::iterator, ChannelInfo::ModeList::iterator> ChannelInfo::GetModeList(const Anope::string &mname) -{ - ChannelInfo::ModeList::iterator it = this->mode_locks->find(mname), it_end = it; - if (it != this->mode_locks->end()) - it_end = this->mode_locks->upper_bound(mname); - return std::make_pair(it, it_end); -} - -const ModeLock *ChannelInfo::GetMLock(const Anope::string &mname, const Anope::string ¶m) -{ - ChannelInfo::ModeList::iterator it = this->mode_locks->find(mname); - if (it != this->mode_locks->end()) - { - if (param.empty()) - return it->second; - else - { - ChannelInfo::ModeList::iterator it_end = this->mode_locks->upper_bound(mname); - for (; it != it_end; ++it) - { - if (Anope::Match(param, it->second->param)) - return it->second; - } - } - } - - return NULL; -} - -Anope::string ChannelInfo::GetMLockAsString(bool complete) const -{ - Anope::string pos = "+", neg = "-", params; - - for (ChannelInfo::ModeList::const_iterator it = this->GetMLock().begin(), it_end = this->GetMLock().end(); it != it_end; ++it) - { - const ModeLock *ml = it->second; - ChannelMode *cm = ModeManager::FindChannelModeByName(ml->name); - if (!cm || cm->type == MODE_LIST || cm->type == MODE_STATUS) - continue; - - if (ml->set) - pos += cm->mchar; - else - neg += cm->mchar; - - if (complete && !ml->param.empty() && cm->type == MODE_PARAM) - params += " " + ml->param; - } - - if (pos.length() == 1) - pos.clear(); - if (neg.length() == 1) - neg.clear(); - - return pos + neg + params; -} - int16_t ChannelInfo::GetLevel(const Anope::string &priv) const { if (PrivilegeManager::FindPrivilege(priv) == NULL) diff --git a/src/serialize.cpp b/src/serialize.cpp index ef79bc396..a957f3046 100644 --- a/src/serialize.cpp +++ b/src/serialize.cpp @@ -30,9 +30,8 @@ std::list<Serializable *> *Serializable::SerializableItems; void Serialize::RegisterTypes() { static Type nc("NickCore", NickCore::Unserialize), na("NickAlias", NickAlias::Unserialize), bi("BotInfo", BotInfo::Unserialize), - ci("ChannelInfo", ChannelInfo::Unserialize), access("ChanAccess", ChanAccess::Unserialize), logsetting("LogSetting", LogSetting::Unserialize), - modelock("ModeLock", ModeLock::Unserialize), akick("AutoKick", AutoKick::Unserialize), badword("BadWord", BadWord::Unserialize), - memo("Memo", Memo::Unserialize), xline("XLine", XLine::Unserialize); + ci("ChannelInfo", ChannelInfo::Unserialize), access("ChanAccess", ChanAccess::Unserialize), + akick("AutoKick", AutoKick::Unserialize), memo("Memo", Memo::Unserialize), xline("XLine", XLine::Unserialize); } void Serialize::CheckTypes() diff --git a/src/sockets.cpp b/src/sockets.cpp index e136324f9..e3065a1e8 100644 --- a/src/sockets.cpp +++ b/src/sockets.cpp @@ -259,7 +259,7 @@ bool cidr::match(const sockaddrs &other) if (byte) { uint8_t m = ~0 << (8 - byte); - return *ip & m == *their_ip & m; + return (*ip & m) == (*their_ip & m); } return true; diff --git a/src/users.cpp b/src/users.cpp index cd3c6b50f..7f9a49049 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -301,7 +301,6 @@ void User::Identify(NickAlias *na) } this->Login(na->nc); - IRCD->SendLogin(this); FOREACH_MOD(OnNickIdentify, (this)); @@ -336,6 +335,8 @@ void User::Login(NickCore *core) this->UpdateHost(); + IRCD->SendLogin(this); + if (this->server->IsSynced()) Log(this, "account") << "is now identified as " << this->nc->display; @@ -378,7 +379,7 @@ bool User::IsRecognized(bool check_secure) const { const NickAlias *na = NickAlias::Find(this->nick); - if (!na || na->nc->HasExt("SECURE")) + if (!na || na->nc->HasExt("NS_SECURE")) return false; } |