diff options
author | Adam- <Adam-@5417fbe8-f217-4b02-8779-1006273d7864> | 2009-11-11 06:03:25 +0000 |
---|---|---|
committer | Adam- <Adam-@5417fbe8-f217-4b02-8779-1006273d7864> | 2009-11-11 06:03:25 +0000 |
commit | b9190ebc16253254cb649faae76119eec3e14b8e (patch) | |
tree | e1cc12269825f020a14877be1ecfbfa959781710 | |
parent | 86e43f1f144cfd04b039a844959af1f7aec3e6da (diff) |
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
-rw-r--r-- | include/account.h | 30 | ||||
-rw-r--r-- | include/extern.h | 6 | ||||
-rw-r--r-- | include/regchannel.h | 12 | ||||
-rw-r--r-- | include/services.h | 82 | ||||
-rw-r--r-- | src/channels.c | 227 | ||||
-rw-r--r-- | src/chanserv.c | 148 | ||||
-rw-r--r-- | src/core/cs_drop.c | 2 | ||||
-rw-r--r-- | src/core/cs_forbid.c | 4 | ||||
-rw-r--r-- | src/core/cs_register.c | 2 | ||||
-rw-r--r-- | src/core/cs_set.c | 4 | ||||
-rw-r--r-- | src/core/ns_drop.c | 4 | ||||
-rw-r--r-- | src/core/ns_forbid.c | 27 | ||||
-rw-r--r-- | src/core/ns_group.c | 21 | ||||
-rw-r--r-- | src/core/ns_register.c | 46 | ||||
-rw-r--r-- | src/nickalias.cpp | 105 | ||||
-rw-r--r-- | src/nickcore.cpp | 75 | ||||
-rw-r--r-- | src/nickserv.c | 344 | ||||
-rw-r--r-- | src/regchannel.cpp | 93 | ||||
-rw-r--r-- | src/timers.cpp | 2 |
19 files changed, 591 insertions, 643 deletions
diff --git a/include/account.h b/include/account.h index 075b15e9e..b2ba04950 100644 --- a/include/account.h +++ b/include/account.h @@ -69,13 +69,10 @@ enum NickCoreFlag class NickRequest { public: - NickRequest() - { - next = prev = NULL; - nick = passcode = email = NULL; - *password = 0; - requested = lastmail = 0; - } + NickRequest(const std::string &nickname); + + ~NickRequest(); + NickRequest *next, *prev; char *nick; char *passcode; @@ -90,7 +87,15 @@ class NickCore; class CoreExport NickAlias : public Extensible, public Flags<NickNameFlag> { public: - NickAlias(); + /** Default constructor + * @param nickname The nick + * @param nickcore The nickcofe for this nick + */ + NickAlias(const std::string &nickname, NickCore *nickcore); + + /** Default destructor + */ + ~NickAlias(); NickAlias *next, *prev; char *nick; /* Nickname */ @@ -105,7 +110,14 @@ class CoreExport NickAlias : public Extensible, public Flags<NickNameFlag> class CoreExport NickCore : public Extensible, public Flags<NickCoreFlag> { public: - NickCore(); + /** Default constructor + * @param display The display nick + */ + NickCore(const std::string &nickdisplay); + + /** Default destructor + */ + ~NickCore(); NickCore *next, *prev; diff --git a/include/extern.h b/include/extern.h index 21a4987ff..f64ab78d6 100644 --- a/include/extern.h +++ b/include/extern.h @@ -73,8 +73,6 @@ E void bot_raw_mode(User * requester, ChannelInfo * ci, const char *mode, char * E Channel *chanlist[1024]; E void chan_adduser2(User * user, Channel * c); -E void chan_delete(Channel * c); -E Channel *chan_create(const char *chan, time_t ts); E Channel *join_user_update(User * user, Channel * chan, const char *name, time_t chants); E void get_channel_stats(long *nrec, long *memuse); @@ -132,7 +130,6 @@ E LevelInfo levelinfo[]; E void get_chanserv_stats(long *nrec, long *memuse); -E int delchan(ChannelInfo * ci); E void alpha_insert_chan(ChannelInfo * ci); E void reset_levels(ChannelInfo * ci); E void cs_init(); @@ -167,7 +164,6 @@ E void stick_mask(ChannelInfo * ci, AutoKick * akick); E void stick_all(ChannelInfo * ci); E int levelinfo_maxwidth; -E ChannelInfo *makechan(const char *chan); E char *get_mlock_modes(ChannelInfo * ci, int complete); /**** compat.c ****/ @@ -605,7 +601,6 @@ E NickAlias *nalists[1024]; E NickCore *nclists[1024]; E NickRequest *nrlists[1024]; E NickRequest *findrequestnick(const char *nick); -E int delnickrequest(NickRequest * nr); E unsigned int guestnum; E void insert_requestnick(NickRequest * nr); E void alpha_insert_alias(NickAlias * na); @@ -632,7 +627,6 @@ E int nick_identified(User * u); E void expire_nicks(); E void expire_requests(); EI int ns_do_register(User * u); -E int delnick(NickAlias * na); E NickAlias *findnick(const char *nick); E NickAlias *findnick(const std::string &nick); E NickCore *findcore(const char *nick); diff --git a/include/regchannel.h b/include/regchannel.h index c094ac2af..33908cb3a 100644 --- a/include/regchannel.h +++ b/include/regchannel.h @@ -69,7 +69,17 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag> std::bitset<128> mlock_off; /* Modes mlocked off */ public: - ChannelInfo(); + // XXX Hack for defcon, though this really isn't needed now and should be destroyed + ChannelInfo() { } + + /** Default constructor + * @param chname The channel name + */ + ChannelInfo(const std::string &chname); + + /** Default destructor + */ + ~ChannelInfo(); ChannelInfo *next, *prev; char name[CHANMAX]; diff --git a/include/services.h b/include/services.h index 1680d4d1a..8ec13d225 100644 --- a/include/services.h +++ b/include/services.h @@ -946,12 +946,15 @@ class CoreExport Channel : public Extensible std::map<ChannelModeName, std::string> Params; public: - Channel() { } + /** Default constructor + * @param name The channel name + * @param ts The time the channel was created + */ + Channel(const std::string &name, time_t ts = time(NULL)); - ~Channel() - { - Params.clear(); - } + /** Default destructor + */ + ~Channel(); Channel *next, *prev; char name[CHANMAX]; @@ -1784,4 +1787,73 @@ E std::list<std::pair<std::string, std::string> > svsopers_in_config; */ E std::list<OperType *> MyOperTypes; +/*************************************************************************/ + +#include "timers.h" + +/** Timer for colliding nicks to force people off of nicknames + */ +class NickServCollide : public Timer +{ + public: + /* NickAlias of the nick who were kicking off */ + NickAlias *na; + /* Return for the std::map::insert */ + std::pair<std::map<NickAlias *, NickServCollide *>::iterator, bool> it; + + /** Default constructor + * @param nickalias The nick alias were kicking off + * @param delay How long to delay before kicking the user off the nick + */ + NickServCollide(NickAlias *nickalias, time_t delay); + + /** Default destructor + */ + ~NickServCollide(); + + /** Called when the delay is up + * @param t The current time + */ + void Tick(time_t t); + + /** Clear all timers for a nick + * @param na The nick to remove the timers for + */ + static void ClearTimers(NickAlias *na); +}; + +/** Timers for releasing nicks to be available for use + */ +class NickServRelease : public Timer +{ + public: + /* The nick */ + NickAlias *na; + /* The uid of the services enforcer client (used for TS6 ircds) */ + std::string uid; + /* Return for std::map::insert */ + std::pair<std::map<NickAlias *, NickServRelease *>::iterator, bool> it; + + /** Default constructor + * @param nickalias The nick + * @param delay The delay before the nick is released + */ + NickServRelease(NickAlias *nickalias, time_t delay); + + /** Default destructor + */ + ~NickServRelease(); + + /** Called when the delay is up + * @param t The current time + */ + void Tick(time_t t); + + /** Clear all timers for a nick + * @param na The nick to remove the timers for + * @param dorelase true to actually call release(), false to just remove the timers + */ + static void ClearTimers(NickAlias *na, bool dorelease = false); +}; + #endif /* SERVICES_H */ diff --git a/src/channels.c b/src/channels.c index 919628358..b8f0e081d 100644 --- a/src/channels.c +++ b/src/channels.c @@ -22,6 +22,107 @@ Channel *chanlist[1024]; /*************************************************************************/ +/** Default constructor + * @param name The channel name + * @param ts The time the channel was created + */ +Channel::Channel(const std::string &name, time_t ts) +{ + Channel **list; + + if (name.empty()) + throw CoreException("A channel without a name ?"); + + strscpy(this->name, name.c_str(), sizeof(this->name)); + list = &chanlist[HASH(this->name)]; + this->prev = NULL; + this->next = *list; + if (*list) + (*list)->prev = this; + *list = this; + + this->creation_time = ts; + this->topic = NULL; + *this->topic_setter = 0; + this->bans = this->excepts = this->invites = NULL; + this->users = NULL; + this->usercount = 0; + this->bd = NULL; + this->server_modetime = this->chanserv_modetime = 0; + this->server_modecount = this->chanserv_modecount = this->bouncy_modes = this->topic_sync = 0; + + this->ci = cs_findchan(this->name); + if (this->ci) + { + this->ci->c = this; + + check_modes(this); + stick_all(this->ci); + } + + if (serv_uplink && is_sync(serv_uplink) && (!(this->topic_sync))) + restore_topic(name.c_str()); + + FOREACH_MOD(I_OnChannelCreate, OnChannelCreate(this)); +} + +/** Default destructor + */ +Channel::~Channel() +{ + BanData *bd, *next; + + FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this)); + + if (debug) + alog("debug: Deleting channel %s", this->name); + + for (bd = this->bd; bd; bd = next) + { + if (bd->mask) + delete [] bd->mask; + next = bd->next; + delete bd; + } + + if (this->ci) + this->ci->c = NULL; + + if (this->topic) + delete [] this->topic; + + if (this->bans && this->bans->count) + { + while (this->bans->entries) + entry_delete(this->bans, this->bans->entries); + } + + if (ModeManager::FindChannelModeByName(CMODE_EXCEPT)) + { + if (this->excepts && this->excepts->count) + { + while (this->excepts->entries) + entry_delete(this->excepts, this->excepts->entries); + } + } + + if (ModeManager::FindChannelModeByName(CMODE_INVITEOVERRIDE)) + { + if (this->invites && this->invites->count) + { + while (this->invites->entries) + entry_delete(this->invites, this->invites->entries); + } + } + + if (this->next) + this->next->prev = this->prev; + if (this->prev) + this->prev->next = this->next; + else + chanlist[HASH(this->name)] = this->next; +} + /** * See if a channel has a mode * @param Name The mode name @@ -77,7 +178,7 @@ void Channel::RemoveMode(ChannelModeName Name) if (s_BotServ && ci->bi && usercount == BSMinUsers - 1) ircdproto->SendPart(ci->bi, name, NULL); if (!users) - chan_delete(this); + delete this; } FOREACH_MOD(I_OnChannelModeUnset, OnChannelModeUnset(this, Name)); @@ -348,7 +449,7 @@ void chan_deluser(User * user, Channel * c) ircdproto->SendPart(c->ci->bi, c->name, NULL); if (!c->users) - chan_delete(c); + delete c; } /*************************************************************************/ @@ -1866,126 +1967,6 @@ void chan_adduser2(User * user, Channel * c) /*************************************************************************/ -/* This creates the channel structure (was originally in - chan_adduser, but splitted to make it more efficient to use for - SJOINs). */ - -Channel *chan_create(const char *chan, time_t ts) -{ - Channel *c; - Channel **list; - - if (debug) - alog("debug: Creating channel %s", chan); - c = new Channel; - strscpy(c->name, chan, sizeof(c->name)); - list = &chanlist[HASH(c->name)]; - c->prev = NULL; - c->next = *list; - if (*list) - (*list)->prev = c; - *list = c; - c->creation_time = ts; - c->topic = NULL; - *c->topic_setter = 0; - c->topic_time = 0; - c->bans = c->excepts = c->invites = NULL; - c->users = NULL; - c->usercount = 0; - c->bd = NULL; - c->server_modetime = c->chanserv_modetime = 0; - c->server_modecount = c->chanserv_modecount = c->bouncy_modes = c->topic_sync = 0; - /* Store ChannelInfo pointer in channel record */ - c->ci = cs_findchan(chan); - if (c->ci) - c->ci->c = c; - /* Restore locked modes and saved topic */ - if (c->ci) { - check_modes(c); - stick_all(c->ci); - } - - if (serv_uplink && is_sync(serv_uplink) && (!(c->topic_sync))) { - restore_topic(chan); - } - - /* A channel set as persistant when it was not created has just - * been created, mark it as persistant - */ - ChannelMode *cm = ModeManager::FindChannelModeByName(CMODE_PERM); - if (cm && c->ci && c->ci->HasFlag(CI_PERSIST) && !c->HasMode(CMODE_PERM)) - { - ircdproto->SendMode(whosends(c->ci), c->name, "+%c", cm->ModeChar); - c->SetMode(CMODE_PERM); - } - - FOREACH_MOD(I_OnChannelCreate, OnChannelCreate(c)); - - return c; -} - -/*************************************************************************/ - -/* This destroys the channel structure, freeing everything in it. */ - -void chan_delete(Channel * c) -{ - BanData *bd, *next; - - FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(c)); - - if (debug) - alog("debug: Deleting channel %s", c->name); - - for (bd = c->bd; bd; bd = next) { - if (bd->mask) - delete [] bd->mask; - next = bd->next; - delete bd; - } - - if (c->ci) - c->ci->c = NULL; - - if (c->topic) - delete [] c->topic; - - if (c->bans && c->bans->count) { - while (c->bans->entries) { - entry_delete(c->bans, c->bans->entries); - } - } - - if (ModeManager::FindChannelModeByName(CMODE_EXCEPT)) - { - if (c->excepts && c->excepts->count) { - while (c->excepts->entries) { - entry_delete(c->excepts, c->excepts->entries); - } - } - } - - if (ModeManager::FindChannelModeByName(CMODE_INVITEOVERRIDE)) - { - if (c->invites && c->invites->count) { - while (c->invites->entries) { - entry_delete(c->invites, c->invites->entries); - } - } - } - - if (c->next) - c->next->prev = c->prev; - if (c->prev) - c->prev->next = c->next; - else - chanlist[HASH(c->name)] = c->next; - - delete c; -} - -/*************************************************************************/ - Channel *join_user_update(User * user, Channel * chan, const char *name, time_t chants) { @@ -1993,7 +1974,7 @@ Channel *join_user_update(User * user, Channel * chan, const char *name, /* If it's a new channel, so we need to create it first. */ if (!chan) - chan = chan_create(name, chants); + chan = new Channel(name, chants); else { // Check chants against 0, as not every ircd sends JOIN with a TS. diff --git a/src/chanserv.c b/src/chanserv.c index c52cd9d07..491c60e48 100644 --- a/src/chanserv.c +++ b/src/chanserv.c @@ -347,12 +347,13 @@ void load_cs_dbase() while ((c = getc_db(f)) != 0) { if (c != 1) fatal("Invalid format in %s", ChanDBName); - ci = new ChannelInfo(); + char channame[CHANMAX]; + SAFE(read = read_buffer(channame, f)); + ci = new ChannelInfo(channame); *last = ci; last = &ci->next; ci->prev = prev; prev = ci; - SAFE(read = read_buffer(ci->name, f)); SAFE(read_string(&s, f)); if (s) { ci->founder = findcore(s); @@ -596,7 +597,7 @@ void load_cs_dbase() if (!(ci->HasFlag(CI_FORBIDDEN)) && !ci->founder) { alog("%s: database load: Deleting founderless channel %s", s_ChanServ, ci->name); - delchan(ci); + delete ci; continue; } } @@ -1439,7 +1440,7 @@ void expire_chans() char *chname = sstrdup(ci->name); alog("Expiring channel %s (founder: %s)", ci->name, (ci->founder ? ci->founder->display : "(none)")); - delchan(ci); + delete ci; FOREACH_MOD(I_OnChanExpire, OnChanExpire(chname)); delete [] chname; } @@ -1466,7 +1467,7 @@ void cs_remove_nick(const NickCore * nc) NickCore *nc2 = ci->successor; if (!nc2->IsServicesOper() && CSMaxReg && nc2->channelcount >= CSMaxReg) { alog("%s: Successor (%s) of %s owns too many channels, " "deleting channel", s_ChanServ, nc2->display, ci->name); - delchan(ci); + delete ci; continue; } else { alog("%s: Transferring foundership of %s from deleted " "nick %s to successor %s", s_ChanServ, ci->name, nc->display, nc2->display); @@ -1487,7 +1488,7 @@ void cs_remove_nick(const NickCore * nc) } } - delchan(ci); + delete ci; continue; } } @@ -1609,141 +1610,6 @@ void alpha_insert_chan(ChannelInfo * ci) ptr->prev = ci; } -/*************************************************************************/ - -/* Add a channel to the database. Returns a pointer to the new ChannelInfo - * structure if the channel was successfully registered, NULL otherwise. - * Assumes channel does not already exist. */ - -ChannelInfo *makechan(const char *chan) -{ - int i; - ChannelInfo *ci; - - ci = new ChannelInfo(); - strscpy(ci->name, chan, CHANMAX); - ci->time_registered = time(NULL); - reset_levels(ci); - ci->ttb = new int16[2 * TTB_SIZE]; - for (i = 0; i < TTB_SIZE; i++) - ci->ttb[i] = 0; - alpha_insert_chan(ci); - return ci; -} - -/*************************************************************************/ - -/* Remove a channel from the ChanServ database. Return 1 on success, 0 - * otherwise. */ - -int delchan(ChannelInfo * ci) -{ - unsigned i; - NickCore *nc; - - if (!ci) { - if (debug) { - alog("debug: delchan called with NULL values"); - } - return 0; - } - - FOREACH_MOD(I_OnDelChan, OnDelChan(ci)); - - nc = ci->founder; - - if (debug >= 2) { - alog("debug: delchan removing %s", ci->name); - } - - if (ci->bi) { - ci->bi->chancount--; - } - - if (debug >= 2) { - alog("debug: delchan top of removing the bot"); - } - if (ci->c) { - if (ci->bi && ci->c->usercount >= BSMinUsers) { - ircdproto->SendPart(ci->bi, ci->c->name, NULL); - } - ci->c->ci = NULL; - } - if (debug >= 2) { - alog("debug: delchan() Bot has been removed moving on"); - } - - if (ci->next) - ci->next->prev = ci->prev; - if (ci->prev) - ci->prev->next = ci->next; - else - chanlists[static_cast<unsigned char>(tolower(ci->name[1]))] = ci->next; - if (ci->desc) - delete [] ci->desc; - if (ci->url) - delete [] ci->url; - if (ci->email) - delete [] ci->email; - if (ci->entry_message) - delete [] ci->entry_message; - - if (ci->last_topic) - delete [] ci->last_topic; - if (ci->forbidby) - delete [] ci->forbidby; - if (ci->forbidreason) - delete [] ci->forbidreason; - ci->ClearAkick(); - if (ci->levels) - delete [] ci->levels; - if (debug >= 2) { - alog("debug: delchan() top of the memo list"); - } - if (!ci->memos.memos.empty()) { - for (i = 0; i < ci->memos.memos.size(); ++i) { - if (ci->memos.memos[i]->text) - delete [] ci->memos.memos[i]->text; - delete ci->memos.memos[i]; - } - ci->memos.memos.clear(); - } - if (debug >= 2) { - alog("debug: delchan() done with the memo list"); - } - if (ci->ttb) - delete [] ci->ttb; - - if (debug >= 2) { - alog("debug: delchan() top of the badword list"); - } - for (i = 0; i < ci->bwcount; i++) { - if (ci->badwords[i].word) - delete [] ci->badwords[i].word; - } - if (ci->badwords) - free(ci->badwords); - if (debug >= 2) { - alog("debug: delchan() done with the badword list"); - } - - - if (debug >= 2) { - alog("debug: delchan() calling on moduleCleanStruct()"); - } - - delete ci; - if (nc) - nc->channelcount--; - - if (debug >= 2) { - alog("debug: delchan() all done"); - } - return 1; -} - -/*************************************************************************/ - /* Reset channel access level values to their default state. */ void reset_levels(ChannelInfo * ci) diff --git a/src/core/cs_drop.c b/src/core/cs_drop.c index 7de9b7327..5d4c43bfb 100644 --- a/src/core/cs_drop.c +++ b/src/core/cs_drop.c @@ -75,7 +75,7 @@ class CommandCSDrop : public Command s_ChanServ, ci->name, u->nick, u->GetIdent().c_str(), u->host, (ci->founder ? ci->founder->display : "(none)")); - delchan(ci); + delete ci; /* We must make sure that the Services admin has not normally the right to * drop the channel before issuing the wallops. diff --git a/src/core/cs_forbid.c b/src/core/cs_forbid.c index 9eefe4cfc..c4c916c1b 100644 --- a/src/core/cs_forbid.c +++ b/src/core/cs_forbid.c @@ -50,9 +50,9 @@ class CommandCSForbid : public Command } if ((ci = cs_findchan(chan)) != NULL) - delchan(ci); + delete ci; - ci = makechan(chan); + ci = new ChannelInfo(chan); if (!ci) { alog("%s: Valid FORBID for %s by %s failed", s_ChanServ, ci->name, u->nick); diff --git a/src/core/cs_register.c b/src/core/cs_register.c index 0ea7e58dc..dbe421110 100644 --- a/src/core/cs_register.c +++ b/src/core/cs_register.c @@ -53,7 +53,7 @@ class CommandCSRegister : public Command notice_lang(s_ChanServ, u, CHAN_MUST_BE_CHANOP); else if (CSMaxReg && u->nc->channelcount >= CSMaxReg && !u->nc->HasPriv("chanserv/no-register-limit")) notice_lang(s_ChanServ, u, u->nc->channelcount > CSMaxReg ? CHAN_EXCEEDED_CHANNEL_LIMIT : CHAN_REACHED_CHANNEL_LIMIT, CSMaxReg); - else if (!(ci = makechan(chan))) + else if (!(ci = new ChannelInfo(chan))) { alog("%s: makechan() failed for REGISTER %s", s_ChanServ, chan); notice_lang(s_ChanServ, u, CHAN_REGISTRATION_FAILED); diff --git a/src/core/cs_set.c b/src/core/cs_set.c index 96c8ae35c..74a1590f0 100644 --- a/src/core/cs_set.c +++ b/src/core/cs_set.c @@ -511,7 +511,7 @@ class CommandCSSet : public Command /* Channel doesn't exist, create it internally */ if (!ci->c) { - chan_create(ci->name, time(NULL)); + new Channel(ci->name); if (ci->bi) bot_join(ci); } @@ -553,7 +553,7 @@ class CommandCSSet : public Command if (s_BotServ && ci->bi && ci->c->usercount == BSMinUsers - 1) ircdproto->SendPart(ci->bi, ci->c->name, NULL); if (!ci->c->users) - chan_delete(ci->c); + delete ci->c; /* No channel mode, no BotServ, but using ChanServ as the botserv bot * which was assigned when persist was set on diff --git a/src/core/ns_drop.c b/src/core/ns_drop.c index 1e15aa292..430c57d03 100644 --- a/src/core/ns_drop.c +++ b/src/core/ns_drop.c @@ -45,7 +45,7 @@ class CommandNSDrop : public Command if (WallDrop) ircdproto->SendGlobops(s_NickServ, "\2%s\2 used DROP on \2%s\2", u->nick, nick); alog("%s: %s!%s@%s dropped nickname %s (e-mail: %s)", s_NickServ, u->nick, u->GetIdent().c_str(), u->host, nr->nick, nr->email); - delnickrequest(nr); + delete nr; notice_lang(s_NickServ, u, NICK_X_DROPPED, nick); } else @@ -73,7 +73,7 @@ class CommandNSDrop : public Command ircdproto->SendSQLineDel(na->nick); alog("%s: %s!%s@%s dropped nickname %s (group %s) (e-mail: %s)", s_NickServ, u->nick, u->GetIdent().c_str(), u->host, na->nick, na->nc->display, na->nc->email ? na->nc->email : "none"); - delnick(na); + delete na; FOREACH_MOD(I_OnNickDrop, OnNickDrop(my_nick ? my_nick : nick)); diff --git a/src/core/ns_forbid.c b/src/core/ns_forbid.c index 524dab5e3..4fe0412d9 100644 --- a/src/core/ns_forbid.c +++ b/src/core/ns_forbid.c @@ -15,8 +15,6 @@ #include "module.h" -NickAlias *makenick(const char *nick); - class CommandNSForbid : public Command { public: @@ -50,9 +48,9 @@ class CommandNSForbid : public Command notice_lang(s_NickServ, u, ACCESS_DENIED); return MOD_CONT; } - delnick(na); + delete na; } - na = makenick(nick); + na = new NickAlias(nick, new NickCore(nick)); if (na) { na->SetFlag(NS_FORBIDDEN); @@ -119,25 +117,4 @@ class NSForbid : public Module } }; -NickAlias *makenick(const char *nick) -{ - NickAlias *na; - NickCore *nc; - - /* First make the core */ - nc = new NickCore(); - nc->display = sstrdup(nick); - slist_init(&nc->aliases); - insert_core(nc); - alog("%s: group %s has been created", s_NickServ, nc->display); - - /* Then make the alias */ - na = new NickAlias; - na->nick = sstrdup(nick); - na->nc = nc; - slist_add(&nc->aliases, na); - alpha_insert_alias(na); - return na; -} - MODULE_INIT(NSForbid) diff --git a/src/core/ns_group.c b/src/core/ns_group.c index 5e6354598..f079e2a99 100644 --- a/src/core/ns_group.c +++ b/src/core/ns_group.c @@ -15,8 +15,6 @@ #include "module.h" -NickAlias *makealias(const char *nick, NickCore *nc); - class CommandNSGroup : public Command { public: @@ -96,7 +94,7 @@ class CommandNSGroup : public Command * If not, check that it is valid. */ if (findnick(u->nick)) - delnick(findnick(u->nick)); + delete findnick(u->nick); else { int prefixlen = strlen(NSGuestNickPrefix); @@ -108,7 +106,8 @@ class CommandNSGroup : public Command return MOD_CONT; } } - na = makealias(u->nick, target->nc); + + na = new NickAlias(u->nick, target->nc); if (na) { @@ -230,18 +229,4 @@ class NSGroup : public Module } }; -/* Creates a new alias in NickServ database. */ -NickAlias *makealias(const char *nick, NickCore *nc) -{ - NickAlias *na; - - /* Just need to make the alias */ - na = new NickAlias; - na->nick = sstrdup(nick); - na->nc = nc; - slist_add(&nc->aliases, na); - alpha_insert_alias(na); - return na; -} - MODULE_INIT(NSGroup) diff --git a/src/core/ns_register.c b/src/core/ns_register.c index 1a1d2b2eb..27cb51786 100644 --- a/src/core/ns_register.c +++ b/src/core/ns_register.c @@ -15,8 +15,6 @@ #include "module.h" -NickRequest *makerequest(const char *nick); -NickAlias *makenick(const char *nick); int do_sendregmail(User *u, NickRequest *nr); class CommandNSConfirm : public Command @@ -24,8 +22,7 @@ class CommandNSConfirm : public Command protected: CommandReturn ActuallyConfirmNick(User *u, NickRequest *nr, bool force) { - NickAlias *na; - na = makenick(nr->nick); + NickAlias *na = new NickAlias(nr->nick, new NickCore(nr->nick)); if (!na) { @@ -69,7 +66,7 @@ class CommandNSConfirm : public Command notice_lang(s_NickServ, u, NICK_REGISTERED, u->nick, na->nc->GetAccess(0).c_str()); else notice_lang(s_NickServ, u, NICK_REGISTERED_NO_MASK, u->nick); - delnickrequest(nr); + delete nr; ircdproto->SendAccountLogin(u, u->nc); ircdproto->SetAutoIdentificationToken(u); @@ -87,7 +84,7 @@ class CommandNSConfirm : public Command User *user = finduser(nr->nick); /* Delrequest must be called before validate_user */ - delnickrequest(nr); + delete nr; if (user) { validate_user(user); @@ -268,7 +265,7 @@ class CommandNSRegister : public CommandNSConfirm for (idx = 0; idx < 9; ++idx) passcode[idx] = chars[1 + static_cast<int>((static_cast<float>(max - min)) * getrandom16() / 65536.0) + min]; passcode[idx] = '\0'; - nr = makerequest(u->nick); + nr = new NickRequest(u->nick); nr->passcode = sstrdup(passcode); strscpy(nr->password, pass, PASSMAX); enc_encrypt_in_place(nr->password, PASSMAX); @@ -287,7 +284,7 @@ class CommandNSRegister : public CommandNSConfirm { alog("%s: Unable to send registration verification mail", s_NickServ); notice_lang(s_NickServ, u, NICK_REG_UNABLE); - delnickrequest(nr); /* Delete the NickRequest if we couldnt send the mail */ + delete nr; return MOD_CONT; } } @@ -387,39 +384,6 @@ class NSRegister : public Module /*************************************************************************/ -NickRequest *makerequest(const char *nick) -{ - NickRequest *nr; - - nr = new NickRequest; - nr->nick = sstrdup(nick); - insert_requestnick(nr); - alog("%s: Nick %s has been requested", s_NickServ, nr->nick); - return nr; -} - -/* Creates a full new nick (alias + core) in NickServ database. */ -NickAlias *makenick(const char *nick) -{ - NickAlias *na; - NickCore *nc; - - /* First make the core */ - nc = new NickCore(); - nc->display = sstrdup(nick); - slist_init(&nc->aliases); - insert_core(nc); - alog("%s: group %s has been created", s_NickServ, nc->display); - - /* Then make the alias */ - na = new NickAlias; - na->nick = sstrdup(nick); - na->nc = nc; - slist_add(&nc->aliases, na); - alpha_insert_alias(na); - return na; -} - int do_sendregmail(User *u, NickRequest *nr) { MailInfo *mail = NULL; diff --git a/src/nickalias.cpp b/src/nickalias.cpp index 314d808e4..b4b07c6bd 100644 --- a/src/nickalias.cpp +++ b/src/nickalias.cpp @@ -1,10 +1,111 @@ #include "services.h" +#include "modules.h" -NickAlias::NickAlias() +#define HASH(nick) ((tolower((nick)[0])&31)<<5 | (tolower((nick)[1])&31)) + +NickRequest::NickRequest(const std::string &nickname) +{ + if (nickname.empty()) + throw CoreException("Empty nick passed to NickRequest constructor"); + + next = prev = NULL; + passcode = email = NULL; + *password = 0; + requested = lastmail = 0; + + this->nick = sstrdup(nickname.c_str()); + insert_requestnick(this); // till this is destroyed / redone in STL +} + +NickRequest::~NickRequest() +{ + FOREACH_MOD(I_OnDelNickRequest, OnDelNickRequest(this)); + + nrlists[HASH(this->nick)] = this->next; + if (this->nick) + delete [] this->nick; + if (this->passcode) + delete [] this->passcode; + if (this->email) + delete [] this->email; +} + +/** Default constructor + * @param nick The nick + * @param nickcore The nickcofe for this nick + */ +NickAlias::NickAlias(const std::string &nickname, NickCore *nickcore) { + if (nickname.empty()) + throw CoreException("Empty nick passed to NickAlias constructor"); + else if (!nickcore) + throw CoreException("Empty nickcore passed to NickAlias constructor"); + next = prev = NULL; nick = last_quit = last_realname = last_usermask = NULL; time_registered = last_seen = 0; - nc = NULL; + + this->nick = sstrdup(nickname.c_str()); + this->nc = nickcore; + slist_add(&nc->aliases, this); + alpha_insert_alias(this); +} + +/** Default destructor + */ +NickAlias::~NickAlias() +{ + User *u = NULL; + + /* First thing to do: remove any timeout belonging to the nick we're deleting */ + NickServCollide::ClearTimers(this); + NickServRelease::ClearTimers(this, true); + + FOREACH_MOD(I_OnDelNick, OnDelNick(this)); + + /* Second thing to do: look for an user using the alias + * being deleted, and make appropriate changes */ + if ((u = finduser(this->nick))) + { + if (ircd->modeonunreg) + common_svsmode(finduser(this->nick), ircd->modeonunreg, "1"); + u->nc = NULL; + } + + delHostCore(this->nick); /* delete any vHost's for this nick */ + + /* Accept nicks that have no core, because of database load functions */ + if (this->nc) + { + /* Next: see if our core is still useful. */ + slist_remove(&this->nc->aliases, this); + if (this->nc->aliases.count == 0) + { + delete this->nc; + this->nc = NULL; + } + else + { + /* Display updating stuff */ + if (!stricmp(this->nick, this->nc->display)) + change_core_display(this->nc); + } + } + + /* Remove us from the aliases list */ + if (this->next) + this->next->prev = this->prev; + if (this->prev) + this->prev->next = this->next; + else + nalists[HASH(this->nick)] = this->next; + + delete [] this->nick; + if (this->last_usermask) + delete [] this->last_usermask; + if (this->last_realname) + delete [] this->last_realname; + if (this->last_quit) + delete [] this->last_quit; } diff --git a/src/nickcore.cpp b/src/nickcore.cpp index f772b0732..c607fffba 100644 --- a/src/nickcore.cpp +++ b/src/nickcore.cpp @@ -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) diff --git a/src/nickserv.c b/src/nickserv.c index ed3541227..36b17aa84 100644 --- a/src/nickserv.c +++ b/src/nickserv.c @@ -31,124 +31,106 @@ unsigned int guestnum; /* Current guest number */ /*************************************************************************/ -class NickServCollide; -class NickServRelease; - static std::map<NickAlias *, NickServCollide *> NickServCollides; static std::map<NickAlias *, NickServRelease *> NickServReleases; -class NickServCollide : public Timer +NickServCollide::NickServCollide(NickAlias *nickalias, time_t delay) : Timer(delay), na(nickalias) { - public: - NickAlias *na; - std::pair<std::map<NickAlias *, NickServCollide *>::iterator, bool> it; - - NickServCollide(NickAlias *nickalias, time_t delay) : Timer(delay), na(nickalias) + /* Erase the current collide and use the new one */ + std::map<NickAlias *, NickServCollide *>::iterator nit = NickServCollides.find(nickalias); + if (nit != NickServCollides.end()) { - /* Erase the current collide and use the new one */ - std::map<NickAlias *, NickServCollide *>::iterator nit = NickServCollides.find(nickalias); - if (nit != NickServCollides.end()) - { - TimerManager::DelTimer(nit->second); - } - - it = NickServCollides.insert(std::make_pair(nickalias, this)); + TimerManager::DelTimer(nit->second); } - ~NickServCollide() - { - if (it.second) - { - NickServCollides.erase(it.first); - } - } + it = NickServCollides.insert(std::make_pair(nickalias, this)); +} - void Tick(time_t ctime) +NickServCollide::~NickServCollide() +{ + if (it.second) { - /* If they identified or don't exist anymore, don't kill them. */ - User *u = finduser(na->nick); - if (!u || u->nc == na->nc || u->my_signon > this->GetSetTime()) - return; - - /* The RELEASE timeout will always add to the beginning of the - * list, so we won't see it. Which is fine because it can't be - * triggered yet anyway. */ - collide(na, 1); + NickServCollides.erase(it.first); } +} - static void ClearTimers(NickAlias *na) - { - std::map<NickAlias *, NickServCollide *>::iterator i = NickServCollides.find(na); - NickServCollide *t; - - if (i != NickServCollides.end()) - { - t = i->second; +void NickServCollide::Tick(time_t ctime) +{ + /* If they identified or don't exist anymore, don't kill them. */ + User *u = finduser(na->nick); + if (!u || u->nc == na->nc || u->my_signon > this->GetSetTime()) + return; - TimerManager::DelTimer(t); - } - } -}; + /* The RELEASE timeout will always add to the beginning of the + * list, so we won't see it. Which is fine because it can't be + * triggered yet anyway. */ + collide(na, 1); +} -class NickServRelease : public Timer +void NickServCollide::ClearTimers(NickAlias *na) { - public: - NickAlias *na; - std::string uid; - std::pair<std::map<NickAlias *, NickServRelease *>::iterator, bool> it; + std::map<NickAlias *, NickServCollide *>::iterator i = NickServCollides.find(na); + NickServCollide *t; - NickServRelease(NickAlias *nickalias, time_t delay) : Timer(delay), na(nickalias) + if (i != NickServCollides.end()) { - /* Erase the current release timer and use the new one */ - std::map<NickAlias *, NickServRelease *>::iterator nit = NickServReleases.find(nickalias); - if (nit != NickServReleases.end()) - { - TimerManager::DelTimer(nit->second); - } + t = i->second; - it = NickServReleases.insert(std::make_pair(nickalias, this)); + TimerManager::DelTimer(t); } +} - ~NickServRelease() +NickServRelease::NickServRelease(NickAlias *nickalias, time_t delay) : Timer(delay), na(nickalias) +{ + /* Erase the current release timer and use the new one */ + std::map<NickAlias *, NickServRelease *>::iterator nit = NickServReleases.find(nickalias); + if (nit != NickServReleases.end()) { - if (it.second) - { - NickServReleases.erase(it.first); - } + TimerManager::DelTimer(nit->second); } - void Tick(time_t ctime) + it = NickServReleases.insert(std::make_pair(nickalias, this)); +} + +NickServRelease::~NickServRelease() +{ + if (it.second) { - if (ircd->svshold) - { - ircdproto->SendSVSHoldDel(na->nick); - } - else - { - if (ircd->ts6 && !uid.empty()) - ircdproto->SendQuit(uid.c_str(), NULL); - else - ircdproto->SendQuit(na->nick, NULL); - } - na->UnsetFlag(NS_KILL_HELD); + NickServReleases.erase(it.first); } +} - static void ClearTimers(NickAlias *na, bool dorelease = false) +void NickServRelease::Tick(time_t ctime) +{ + if (ircd->svshold) + { + ircdproto->SendSVSHoldDel(na->nick); + } + else { - std::map<NickAlias *, NickServRelease *>::iterator i = NickServReleases.find(na); - NickServRelease *t; + if (ircd->ts6 && !uid.empty()) + ircdproto->SendQuit(uid.c_str(), NULL); + else + ircdproto->SendQuit(na->nick, NULL); + } + na->UnsetFlag(NS_KILL_HELD); +} - if (i != NickServReleases.end()) - { - t = i->second; +void NickServRelease::ClearTimers(NickAlias *na, bool dorelease) +{ + std::map<NickAlias *, NickServRelease *>::iterator i = NickServReleases.find(na); + NickServRelease *t; - if (dorelease) - release(na, 1); + if (i != NickServReleases.end()) + { + t = i->second; - TimerManager::DelTimer(t); - } + if (dorelease) + release(na, 1); + + TimerManager::DelTimer(t); } -}; +} /*************************************************************************/ /* *INDENT-OFF* */ @@ -308,8 +290,12 @@ void load_ns_req_db() { if (c != 1) fatal("Invalid format in %s", PreNickDBName); - nr = new NickRequest; - SAFE(read_string(&nr->nick, f)); + + char *s; + SAFE(read_string(&s, f)); + nr = new NickRequest(s); + delete [] s; + SAFE(read_string(&nr->passcode, f)); if (ver < 2) { @@ -365,7 +351,9 @@ void load_ns_dbase() if (c != 1) fatal("Invalid format in %s", NickDBName); - nc = new NickCore(); + SAFE(read_string(&s, f)); + nc = new NickCore(s); + delete [] s; *nclast = nc; nclast = &nc->next; nc->prev = ncprev; @@ -373,7 +361,6 @@ void load_ns_dbase() slist_init(&nc->aliases); - SAFE(read_string(&nc->display, f)); SAFE(read_buffer(nc->pass, f)); SAFE(read_string(&nc->email, f)); @@ -438,9 +425,9 @@ void load_ns_dbase() if (c != 1) fatal("Invalid format in %s", NickDBName); - na = new NickAlias(); - - SAFE(read_string(&na->nick, f)); + SAFE(read_string(&s, f)); + na = new NickAlias(s, nclists[0]); // XXXXXXXX + delete [] s; SAFE(read_string(&na->last_usermask, f)); SAFE(read_string(&na->last_realname, f)); @@ -491,7 +478,7 @@ void load_ns_dbase() if (!na->nc) { alog("%s: while loading database: %s has no core! We delete it.", s_NickServ, na->nick); - delnick(na); + delete na; continue; } @@ -810,7 +797,7 @@ void expire_nicks() na->nick, na->nc->display, (na->nc->email ? na->nc->email : "none")); tmpnick = sstrdup(na->nick); - delnick(na); + delete na; FOREACH_MOD(I_OnNickExpire, OnNickExpire(tmpnick)); delete [] tmpnick; } @@ -831,7 +818,7 @@ void expire_requests() if (NSRExpire && now - nr->requested >= NSRExpire) { alog("Request for nick %s expiring", nr->nick); - delnickrequest(nr); + delete nr; } } } @@ -1128,167 +1115,6 @@ void change_core_display(NickCore * nc) /*************************************************************************/ -/* Deletes the core. This must be called only when there is no more - * aliases for it, because no cleanup is done. - * This function removes all references to the core as well. - */ - -static int delcore(NickCore * nc) -{ - unsigned i; - User *user; - - FOREACH_MOD(I_OnDelCore, OnDelCore(nc)); - - /* Clean up this nick core from any users online using it - * (ones that /nick but remain unidentified) - */ - for (i = 0; i < 1024; ++i) - { - for (user = userlist[i]; user; user = user->next) - { - if (user->nc && user->nc == nc) - { - ircdproto->SendAccountLogout(user, user->nc); - user->nc = NULL; - FOREACH_MOD(I_OnNickLogout, OnNickLogout(user)); - } - } - } - - /* (Hopefully complete) cleanup */ - cs_remove_nick(nc); - - /* Remove the core from the list */ - if (nc->next) - nc->next->prev = nc->prev; - if (nc->prev) - nc->prev->next = nc->next; - else - nclists[HASH(nc->display)] = nc->next; - - /* Log .. */ - alog("%s: deleting nickname group %s", s_NickServ, nc->display); - - /* Now we can safely free it. */ - delete [] nc->display; - - if (nc->email) - delete [] nc->email; - if (nc->greet) - delete [] nc->greet; - if (nc->url) - delete [] nc->url; - - nc->ClearAccess(); - - if (!nc->memos.memos.empty()) - { - for (i = 0; i < nc->memos.memos.size(); ++i) - { - if (nc->memos.memos[i]->text) - delete [] nc->memos.memos[i]->text; - delete nc->memos.memos[i]; - } - nc->memos.memos.clear(); - } - - delete nc; - return 1; -} - - -/*************************************************************************/ -int delnickrequest(NickRequest * nr) -{ - if (nr) - { - FOREACH_MOD(I_OnDelNickRequest, OnDelNickRequest(nr)); - nrlists[HASH(nr->nick)] = nr->next; - if (nr->nick) - delete [] nr->nick; - if (nr->passcode) - delete [] nr->passcode; - if (nr->email) - delete [] nr->email; - delete nr; - } - - return 0; -} - -/*************************************************************************/ - -/* Deletes an alias. The core will also be deleted if it has no more - * nicks attached to it. Easy but powerful. - * Well, we must also take care that the nick being deleted is not - * the core display, and if so, change it to the next alias in the list, - * otherwise weird things will happen. - * Returns 1 on success, 0 otherwise. - */ - -int delnick(NickAlias * na) -{ - User *u = NULL; - /* First thing to do: remove any timeout belonging to the nick we're deleting */ - NickServCollide::ClearTimers(na); - NickServRelease::ClearTimers(na, true); - - FOREACH_MOD(I_OnDelNick, OnDelNick(na)); - - /* Second thing to do: look for an user using the alias - * being deleted, and make appropriate changes */ - if ((u = finduser(na->nick))) - { - if (ircd->modeonunreg) - common_svsmode(finduser(na->nick), ircd->modeonunreg, "1"); - u->nc = NULL; - } - - delHostCore(na->nick); /* delete any vHost's for this nick */ - - /* Accept nicks that have no core, because of database load functions */ - if (na->nc) - { - /* Next: see if our core is still useful. */ - slist_remove(&na->nc->aliases, na); - if (na->nc->aliases.count == 0) - { - if (!delcore(na->nc)) - return 0; - na->nc = NULL; - } - else - { - /* Display updating stuff */ - if (!stricmp(na->nick, na->nc->display)) - change_core_display(na->nc); - } - } - - /* Remove us from the aliases list */ - if (na->next) - na->next->prev = na->prev; - if (na->prev) - na->prev->next = na->next; - else - nalists[HASH(na->nick)] = na->next; - - delete [] na->nick; - if (na->last_usermask) - delete [] na->last_usermask; - if (na->last_realname) - delete [] na->last_realname; - if (na->last_quit) - delete [] na->last_quit; - - delete na; - return 1; -} - -/*************************************************************************/ -/*************************************************************************/ - /* Collide a nick. * * When connected to a network using DALnet servers, version 4.4.15 and above, diff --git a/src/regchannel.cpp b/src/regchannel.cpp index 96e2d6046..db3850d6c 100644 --- a/src/regchannel.cpp +++ b/src/regchannel.cpp @@ -13,9 +13,16 @@ */ #include "services.h" +#include "modules.h" -ChannelInfo::ChannelInfo() +/** Default constructor + * @param chname The channel name + */ +ChannelInfo::ChannelInfo(const std::string &chname) { + if (chname.empty()) + throw CoreException("Empty channel passed to ChannelInfo constructor"); + next = prev = NULL; name[0] = last_topic_setter[0] = '\0'; founder = successor = NULL; @@ -24,14 +31,14 @@ ChannelInfo::ChannelInfo() levels = NULL; entry_message = NULL; c = NULL; - bi = NULL; - ttb = NULL; bwcount = 0; badwords = NULL; capsmin = capspercent = 0; floodlines = floodsecs = 0; repeattimes = 0; + strscpy(this->name, chname.c_str(), CHANMAX); + /* If ircd doesn't exist, this is from DB load and mlock is set later */ if (ircd) mlock_on = ircd->DefMLock; @@ -50,6 +57,86 @@ ChannelInfo::ChannelInfo() bantype = CSDefBantype; memos.memomax = MSMaxMemos; last_used = time_registered = time(NULL); + + this->ttb = new int16[2 * TTB_SIZE]; + for (int i = 0; i < TTB_SIZE; i++) + this->ttb[i] = 0; + + reset_levels(this); + alpha_insert_chan(this); +} + +/** Default destructor, cleans up the channel complete and removes it from the internal list + */ +ChannelInfo::~ChannelInfo() +{ + unsigned i; + + FOREACH_MOD(I_OnDelChan, OnDelChan(this)); + + if (debug) + alog("debug: Deleting channel %s", this->name); + + if (this->bi) + this->bi->chancount--; + + if (this->c) + { + if (this->bi && this->c->usercount >= BSMinUsers) + ircdproto->SendPart(this->bi, this->c->name, NULL); + this->c->ci = NULL; + } + + if (this->next) + this->next->prev = this->prev; + if (this->prev) + this->prev->next = this->next; + else + chanlists[static_cast<unsigned char>(tolower(this->name[1]))] = this->next; + if (this->desc) + delete [] this->desc; + if (this->url) + delete [] this->url; + if (this->email) + delete [] this->email; + if (this->entry_message) + delete [] this->entry_message; + + if (this->last_topic) + delete [] this->last_topic; + if (this->forbidby) + delete [] this->forbidby; + if (this->forbidreason) + delete [] this->forbidreason; + this->ClearAkick(); + if (this->levels) + delete [] this->levels; + + if (!this->memos.memos.empty()) + { + for (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(); + } + + if (this->ttb) + delete [] this->ttb; + + for (i = 0; i < this->bwcount; i++) + { + if (this->badwords[i].word) + delete [] this->badwords[i].word; + } + + if (this->badwords) + free(this->badwords); + + if (this->founder) + this->founder->channelcount--; } /** Add an entry to the channel access list diff --git a/src/timers.cpp b/src/timers.cpp index d7c56072b..0f9f6aed5 100644 --- a/src/timers.cpp +++ b/src/timers.cpp @@ -11,7 +11,7 @@ * */ -#include "timers.h" +#include "services.h" std::vector<Timer *> TimerManager::Timers; |