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 /modules/pseudoclients/nickserv/nick.cpp | |
| 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 'modules/pseudoclients/nickserv/nick.cpp')
| -rw-r--r-- | modules/pseudoclients/nickserv/nick.cpp | 242 |
1 files changed, 118 insertions, 124 deletions
diff --git a/modules/pseudoclients/nickserv/nick.cpp b/modules/pseudoclients/nickserv/nick.cpp index acba58b1e..0ac55ff93 100644 --- a/modules/pseudoclients/nickserv/nick.cpp +++ b/modules/pseudoclients/nickserv/nick.cpp @@ -11,188 +11,182 @@ */ #include "module.h" -#include "nick.h" +#include "nicktype.h" -NickImpl::NickImpl(const Anope::string &nickname, NickServ::Account* nickcore) +NickImpl::~NickImpl() { - if (nickname.empty()) - throw CoreException("Empty nick passed to NickServ::Nick constructor"); - else if (!nickcore) - throw CoreException("Empty nickcore passed to NickServ::Nick constructor"); - - this->time_registered = this->last_seen = Anope::CurTime; - this->nick = nickname; - this->nc = nickcore; - nickcore->aliases->push_back(this); - - NickServ::nickalias_map &map = NickServ::service->GetNickList(); - NickServ::Nick* &na = map[this->nick]; - if (na) - Log(LOG_DEBUG) << "Duplicate nick " << nickname << " in nickalias table"; - na = this; - - if (this->nc->o == NULL) - { - Oper *o = Oper::Find(this->nick); - if (o == NULL) - o = Oper::Find(this->nc->display); - nickcore->o = o; - if (this->nc->o != NULL) - Log() << "Tied oper " << this->nc->display << " to type " << this->nc->o->ot->GetName(); - } + /* Remove us from the aliases list */ + NickServ::nickalias_map &map = NickServ::service->GetNickMap(); + map.erase(GetNick()); } -NickImpl::~NickImpl() +void NickImpl::Delete() { Event::OnDelNick(&Event::DelNick::OnDelNick, this); - /* Accept nicks that have no core, because of database load functions */ - if (this->nc) + if (this->GetAccount()) { /* Next: see if our core is still useful. */ - std::vector<NickServ::Nick *>::iterator it = std::find(this->nc->aliases->begin(), this->nc->aliases->end(), this); - if (it != this->nc->aliases->end()) - this->nc->aliases->erase(it); - if (this->nc->aliases->empty()) + std::vector<NickServ::Nick *> aliases = this->GetAccount()->GetRefs<NickServ::Nick *>(NickServ::nick); + + auto it = std::find(aliases.begin(), aliases.end(), this); + if (it != aliases.end()) + aliases.erase(it); + + if (aliases.empty()) { - delete this->nc; - this->nc = NULL; + /* just me */ + this->GetAccount()->Delete(); } else { /* Display updating stuff */ - if (this->nick.equals_ci(this->nc->display)) - this->nc->SetDisplay(this->nc->aliases->front()); + if (GetNick().equals_ci(this->GetAccount()->GetDisplay())) + this->GetAccount()->SetDisplay(aliases[0]); } } - /* Remove us from the aliases list */ - NickServ::nickalias_map &map = NickServ::service->GetNickList(); - map.erase(this->nick); + return Serialize::Object::Delete(); } -void NickImpl::SetVhost(const Anope::string &ident, const Anope::string &host, const Anope::string &creator, time_t created) +Anope::string NickImpl::GetNick() { - this->vhost_ident = ident; - this->vhost_host = host; - this->vhost_creator = creator; - this->vhost_created = created; + return Get<Anope::string>(&NickType::nick); } -void NickImpl::RemoveVhost() +void NickImpl::SetNick(const Anope::string &nick) { - this->vhost_ident.clear(); - this->vhost_host.clear(); - this->vhost_creator.clear(); - this->vhost_created = 0; + Set(&NickType::nick, nick); } -bool NickImpl::HasVhost() const +Anope::string NickImpl::GetLastQuit() { - return !this->vhost_host.empty(); + return Get(&NickType::last_quit); } -const Anope::string &NickImpl::GetVhostIdent() const +void NickImpl::SetLastQuit(const Anope::string &lq) { - return this->vhost_ident; + Set(&NickType::last_quit, lq); } -const Anope::string &NickImpl::GetVhostHost() const +Anope::string NickImpl::GetLastRealname() { - return this->vhost_host; + return Get(&NickType::last_realname); } -const Anope::string &NickImpl::GetVhostCreator() const +void NickImpl::SetLastRealname(const Anope::string &lr) { - return this->vhost_creator; + Set(&NickType::last_realname, lr); } -time_t NickImpl::GetVhostCreated() const +Anope::string NickImpl::GetLastUsermask() { - return this->vhost_created; + return Get(&NickType::last_usermask); } -void NickImpl::Serialize(Serialize::Data &data) const +void NickImpl::SetLastUsermask(const Anope::string &lu) { - data["nick"] << this->nick; - data["last_quit"] << this->last_quit; - data["last_realname"] << this->last_realname; - data["last_usermask"] << this->last_usermask; - data["last_realhost"] << this->last_realhost; - data.SetType("time_registered", Serialize::Data::DT_INT); data["time_registered"] << this->time_registered; - data.SetType("last_seen", Serialize::Data::DT_INT); data["last_seen"] << this->last_seen; - data["nc"] << this->nc->display; + Set(&NickType::last_usermask, lu); +} - if (this->HasVhost()) - { - data["vhost_ident"] << this->GetVhostIdent(); - data["vhost_host"] << this->GetVhostHost(); - data["vhost_creator"] << this->GetVhostCreator(); - data["vhost_time"] << this->GetVhostCreated(); - } +Anope::string NickImpl::GetLastRealhost() +{ + return Get(&NickType::last_realhost); +} - Extensible::ExtensibleSerialize(this, this, data); +void NickImpl::SetLastRealhost(const Anope::string &lr) +{ + Set(&NickType::last_realhost, lr); } -Serializable* NickImpl::Unserialize(Serializable *obj, Serialize::Data &data) +time_t NickImpl::GetTimeRegistered() { - Anope::string snc, snick; + return Get(&NickType::time_registered); +} - data["nc"] >> snc; - data["nick"] >> snick; +void NickImpl::SetTimeRegistered(const time_t &tr) +{ + Set(&NickType::time_registered, tr); +} - NickServ::Account *core = NickServ::FindAccount(snc); - if (core == NULL) - return NULL; +time_t NickImpl::GetLastSeen() +{ + return Get(&NickType::last_seen); +} - NickServ::Nick *na; - if (obj) - na = anope_dynamic_static_cast<NickServ::Nick *>(obj); - else - na = new NickImpl(snick, core); +void NickImpl::SetLastSeen(const time_t &ls) +{ + Set(&NickType::last_seen, ls); +} - if (na->nc != core) - { - std::vector<NickServ::Nick *>::iterator it = std::find(na->nc->aliases->begin(), na->nc->aliases->end(), na); - if (it != na->nc->aliases->end()) - na->nc->aliases->erase(it); +NickServ::Account *NickImpl::GetAccount() +{ + return Get(&NickType::nc); +} - if (na->nc->aliases->empty()) - delete na->nc; - else if (na->nick.equals_ci(na->nc->display)) - na->nc->SetDisplay(na->nc->aliases->front()); +void NickImpl::SetAccount(NickServ::Account *acc) +{ + Set(&NickType::nc, acc); +} - na->nc = core; - core->aliases->push_back(na); - } +void NickImpl::SetVhost(const Anope::string &ident, const Anope::string &host, const Anope::string &creator, time_t created) +{ + Set(&NickType::vhost_ident, ident); + Set(&NickType::vhost_host, host); + Set(&NickType::vhost_creator, creator); + Set(&NickType::vhost_created, created); +} + +void NickImpl::RemoveVhost() +{ + Anope::string e; + Set(&NickType::vhost_ident, e); + Set(&NickType::vhost_host, e); + Set(&NickType::vhost_creator, e); + Set(&NickType::vhost_created, 0); +} - data["last_quit"] >> na->last_quit; - data["last_realname"] >> na->last_realname; - data["last_usermask"] >> na->last_usermask; - data["last_realhost"] >> na->last_realhost; - data["time_registered"] >> na->time_registered; - data["last_seen"] >> na->last_seen; +bool NickImpl::HasVhost() +{ + return !GetVhostHost().empty(); +} + +Anope::string NickImpl::GetVhostIdent() +{ + return Get(&NickType::vhost_ident); +} - Anope::string vhost_ident, vhost_host, vhost_creator; - time_t vhost_time; +void NickImpl::SetVhostIdent(const Anope::string &i) +{ + Set(&NickType::vhost_ident, i); +} - data["vhost_ident"] >> vhost_ident; - data["vhost_host"] >> vhost_host; - data["vhost_creator"] >> vhost_creator; - data["vhost_time"] >> vhost_time; +Anope::string NickImpl::GetVhostHost() +{ + return Get(&NickType::vhost_host); +} - na->SetVhost(vhost_ident, vhost_host, vhost_creator, vhost_time); +void NickImpl::SetVhostHost(const Anope::string &h) +{ + Set(&NickType::vhost_host, h); +} - Extensible::ExtensibleUnserialize(na, na, data); +Anope::string NickImpl::GetVhostCreator() +{ + return Get(&NickType::vhost_creator); +} - /* compat */ - bool b; - b = false; - data["extensible:NO_EXPIRE"] >> b; - if (b) - na->Extend<bool>("NS_NO_EXPIRE"); - /* end compat */ +void NickImpl::SetVhostCreator(const Anope::string &c) +{ + Set(&NickType::vhost_creator, c); +} - return na; +time_t NickImpl::GetVhostCreated() +{ + return Get(&NickType::vhost_created); } +void NickImpl::SetVhostCreated(const time_t &cr) +{ + Set(&NickType::vhost_created, cr); +} |
