mirror of
https://github.com/anope/anope.git
synced 2026-06-27 03:56:37 +02:00
Moved alot of stuff to constructors and destructors, instead of having functions everywhere to create and destroy objects
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2639 5417fbe8-f217-4b02-8779-1006273d7864
This commit is contained in:
+74
-1
@@ -1,8 +1,16 @@
|
||||
#include "services.h"
|
||||
#include "pseudo.h"
|
||||
|
||||
NickCore::NickCore()
|
||||
#define HASH(nick) ((tolower((nick)[0])&31)<<5 | (tolower((nick)[1])&31))
|
||||
|
||||
/** Default constructor
|
||||
* @param display The display nick
|
||||
*/
|
||||
NickCore::NickCore(const std::string &coredisplay)
|
||||
{
|
||||
if (coredisplay.empty())
|
||||
throw CoreException("Empty display passed to NickCore constructor");
|
||||
|
||||
next = prev = NULL;
|
||||
display = email = greet = url = NULL;
|
||||
ot = NULL;
|
||||
@@ -11,12 +19,77 @@ NickCore::NickCore()
|
||||
language = channelcount = 0;
|
||||
lastmail = 0;
|
||||
|
||||
this->display = sstrdup(coredisplay.c_str());
|
||||
slist_init(&this->aliases);
|
||||
insert_core(this); // till hashing is redone..
|
||||
|
||||
/* Set default nick core flags */
|
||||
for (size_t t = NI_BEGIN + 1; t != NI_END; ++t)
|
||||
if (NSDefFlags.HasFlag((NickCoreFlag)t))
|
||||
SetFlag((NickCoreFlag)t);
|
||||
}
|
||||
|
||||
/** Default destructor
|
||||
*/
|
||||
NickCore::~NickCore()
|
||||
{
|
||||
FOREACH_MOD(I_OnDelCore, OnDelCore(this));
|
||||
|
||||
/* Clean up this nick core from any users online using it
|
||||
* (ones that /nick but remain unidentified)
|
||||
*/
|
||||
User *user;
|
||||
for (int i = 0; i < 1024; ++i)
|
||||
{
|
||||
for (user = userlist[i]; user; user = user->next)
|
||||
{
|
||||
if (user->nc && user->nc == this)
|
||||
{
|
||||
ircdproto->SendAccountLogout(user, user->nc);
|
||||
user->nc = NULL;
|
||||
FOREACH_MOD(I_OnNickLogout, OnNickLogout(user));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* (Hopefully complete) cleanup */
|
||||
cs_remove_nick(this);
|
||||
|
||||
/* Remove the core from the list */
|
||||
if (this->next)
|
||||
this->next->prev = this->prev;
|
||||
if (this->prev)
|
||||
this->prev->next = this->next;
|
||||
else
|
||||
nclists[HASH(this->display)] = this->next;
|
||||
|
||||
/* Log .. */
|
||||
alog("%s: deleting nickname group %s", s_NickServ, this->display);
|
||||
|
||||
/* Now we can safely free it. */
|
||||
delete [] this->display;
|
||||
|
||||
if (this->email)
|
||||
delete [] this->email;
|
||||
if (this->greet)
|
||||
delete [] this->greet;
|
||||
if (this->url)
|
||||
delete [] this->url;
|
||||
|
||||
this->ClearAccess();
|
||||
|
||||
if (!this->memos.memos.empty())
|
||||
{
|
||||
for (unsigned i = 0; i < this->memos.memos.size(); ++i)
|
||||
{
|
||||
if (this->memos.memos[i]->text)
|
||||
delete [] this->memos.memos[i]->text;
|
||||
delete this->memos.memos[i];
|
||||
}
|
||||
this->memos.memos.clear();
|
||||
}
|
||||
}
|
||||
|
||||
bool NickCore::HasCommand(const std::string &cmdstr) const
|
||||
{
|
||||
if (!this->ot)
|
||||
|
||||
Reference in New Issue
Block a user