diff options
author | Sadie Powell <sadie@witchery.services> | 2024-03-09 12:20:15 +0000 |
---|---|---|
committer | Sadie Powell <sadie@witchery.services> | 2024-03-09 22:22:55 +0000 |
commit | 272104af957b3dc38c11137d6c1e63f86e2cf64c (patch) | |
tree | b226c491f6987a5aaf59c7f861f656fa8be39c63 | |
parent | 51e95d72e3ca49bcb549cb27e8d6b489b8b0c7dd (diff) |
Modernize the initialisation of NickAlias and NickCore.
-rw-r--r-- | include/account.h | 13 | ||||
-rw-r--r-- | src/nickalias.cpp | 14 | ||||
-rw-r--r-- | src/nickcore.cpp | 25 |
3 files changed, 24 insertions, 28 deletions
diff --git a/include/account.h b/include/account.h index 55ed44669..9a862c3b1 100644 --- a/include/account.h +++ b/include/account.h @@ -33,7 +33,7 @@ class CoreExport NickAlias final , public Extensible { Anope::string vhost_ident, vhost_host, vhost_creator; - time_t vhost_created; + time_t vhost_created = 0; public: Anope::string nick; @@ -43,8 +43,9 @@ public: Anope::string last_usermask; /* Last uncloaked usermask, requires nickserv/auspex to see */ Anope::string last_realhost; - time_t time_registered; - time_t last_seen; + time_t time_registered = Anope::CurTime; + time_t last_seen = Anope::CurTime; + /* Account this nick is tied to. Multiple nicks can be tied to a single account. */ Serialize::Reference<NickCore> nc; @@ -136,14 +137,14 @@ public: Serialize::Checker<std::vector<NickAlias *> > aliases; /* Set if this user is a services operator. o->ot must exist. */ - Oper *o; + Oper *o = nullptr; /* Unsaved data */ /* Number of channels registered by this account */ - uint16_t channelcount; + uint16_t channelcount = 0; /* Last time an email was sent to this user */ - time_t lastmail; + time_t lastmail = 0; /* Users online now logged into this account */ std::list<User *> users; diff --git a/src/nickalias.cpp b/src/nickalias.cpp index bdded5dba..cfd59094d 100644 --- a/src/nickalias.cpp +++ b/src/nickalias.cpp @@ -20,22 +20,20 @@ Serialize::Checker<nickalias_map> NickAliasList("NickAlias"); -NickAlias::NickAlias(const Anope::string &nickname, NickCore *nickcore) : Serializable("NickAlias") +NickAlias::NickAlias(const Anope::string &nickname, NickCore *nickcore) + : Serializable("NickAlias") + , nick(nickname) + , nc(nickcore) { if (nickname.empty()) throw CoreException("Empty nick passed to NickAlias constructor"); else if (!nickcore) throw CoreException("Empty nickcore passed to NickAlias constructor"); - this->time_registered = this->last_seen = Anope::CurTime; - this->nick = nickname; - this->nc = nickcore; nickcore->aliases->push_back(this); - size_t old = NickAliasList->size(); - (*NickAliasList)[this->nick] = this; - if (old == NickAliasList->size()) - Log(LOG_DEBUG) << "Duplicate nick " << nickname << " in nickalias table"; + if (!NickAliasList->insert_or_assign(this->nick, this).second) + Log(LOG_DEBUG) << "Duplicate nick " << this->nick << " in NickAlias table"; if (this->nc->o == NULL) { diff --git a/src/nickcore.cpp b/src/nickcore.cpp index 77f4aaddf..c60a238b4 100644 --- a/src/nickcore.cpp +++ b/src/nickcore.cpp @@ -18,25 +18,22 @@ Serialize::Checker<nickcore_map> NickCoreList("NickCore"); nickcoreid_map NickCoreIdList; -NickCore::NickCore(const Anope::string &coredisplay, uint64_t coreid) : Serializable("NickCore"), chanaccess("ChannelInfo"), aliases("NickAlias") +NickCore::NickCore(const Anope::string &coredisplay, uint64_t coreid) + : Serializable("NickCore") + , chanaccess("ChannelInfo") + , id(coreid) + , display(coredisplay) + , aliases("NickAlias") { if (coredisplay.empty()) throw CoreException("Empty display passed to NickCore constructor"); - this->o = NULL; - this->channelcount = 0; - this->lastmail = 0; + if (!NickCoreList->insert_or_assign(this->display, this).second) + Log(LOG_DEBUG) << "Duplicate account " << this->display << " in NickCore table"; - this->display = coredisplay; - this->id = coreid; - - size_t old = NickCoreList->size(); - (*NickCoreList)[this->display] = this; - if (old == NickCoreList->size()) - Log(LOG_DEBUG) << "Duplicate account " << coredisplay << " in nickcore table?"; - - if (this->id) - NickCoreIdList[this->id] = this; + // Upgrading users may not have an account identifier. + if (this->id && !NickCoreIdList.insert_or_assign(this->id, this).second) + Log(LOG_DEBUG) << "Duplicate account id " << this->id << " in NickCore table"; FOREACH_MOD(OnNickCoreCreate, (this)); } |