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 &nickna |
