diff options
| author | Adam <Adam@anope.org> | 2010-09-10 20:31:31 -0400 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2010-09-10 20:31:31 -0400 |
| commit | f00e76d30a86acf0f18bcde5647eedd50de50569 (patch) | |
| tree | 04af81a883ea6e71ec36e35a2822487c7f8192c6 | |
| parent | 9eb7562bee7f2a52cf91b0ab0ebc10351f2a46f2 (diff) | |
Added Anope::CurTime to keep us from calling time() everywhere
64 files changed, 224 insertions, 240 deletions
diff --git a/include/anope.h b/include/anope.h index a2cdc2d06..51a80a598 100644 --- a/include/anope.h +++ b/include/anope.h @@ -288,6 +288,11 @@ namespace Anope static const char *const compiled = __TIME__ " " __DATE__; + /** The current system time, which is pretty close to being accurate. + * Use this unless you need very specific time checks + */ + static time_t CurTime = time(NULL); + extern CoreExport string Version(); extern CoreExport string Build(); diff --git a/include/channels.h b/include/channels.h index ec886c9ca..73c97d3aa 100644 --- a/include/channels.h +++ b/include/channels.h @@ -23,7 +23,7 @@ struct UserData void Clear() { - last_use = last_start = time(NULL); + last_use = last_start = Anope::CurTime; lines = times = 0; lastline.clear(); } @@ -77,7 +77,7 @@ class CoreExport Channel : public Extensible, public Flags<ChannelFlags> * @param name The channel name * @param ts The time the channel was created */ - Channel(const Anope::string &nname, time_t ts = time(NULL)); + Channel(const Anope::string &nname, time_t ts = Anope::CurTime); /** Default destructor */ diff --git a/include/modules.h b/include/modules.h index e1675c7e6..60a16a978 100644 --- a/include/modules.h +++ b/include/modules.h @@ -1237,7 +1237,7 @@ class CallBack : public Timer private: Module *m; public: - CallBack(Module *mod, long time_from_now, time_t now = time(NULL), bool repeating = false) : Timer(time_from_now, now, repeating), m(mod) + CallBack(Module *mod, long time_from_now, time_t now = Anope::CurTime, bool repeating = false) : Timer(time_from_now, now, repeating), m(mod) { m->CallBacks.push_back(this); } diff --git a/include/regchannel.h b/include/regchannel.h index 80b25abfb..fb6810220 100644 --- a/include/regchannel.h +++ b/include/regchannel.h @@ -171,7 +171,7 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag, * @param t The time the akick was added, defaults to now * @param lu The time the akick was last used, defaults to never */ - AutoKick *AddAkick(const Anope::string &user, NickCore *akicknc, const Anope::string &reason, time_t t = time(NULL), time_t lu = 0); + AutoKick *AddAkick(const Anope::string &user, NickCore *akicknc, const Anope::string &reason, time_t t = Anope::CurTime, time_t lu = 0); /** Add an akick entry to the channel by reason * @param user The user who added the akick @@ -180,7 +180,7 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag, * @param t The time the akick was added, defaults to now * @param lu The time the akick was last used, defaults to never */ - AutoKick *AddAkick(const Anope::string &user, const Anope::string &mask, const Anope::string &reason, time_t t = time(NULL), time_t lu = 0); + AutoKick *AddAkick(const Anope::string &user, const Anope::string &mask, const Anope::string &reason, time_t t = Anope::CurTime, time_t lu = 0); /** Get an entry from the channel akick list * @param index The index in the akick vector diff --git a/include/services.h b/include/services.h index ada2a5c6a..e0ed8709f 100644 --- a/include/services.h +++ b/include/services.h @@ -509,7 +509,7 @@ class CoreExport HostInfo * @param creator Who created the vhost * @param time When the vhost was craated */ - void SetVhost(const Anope::string &ident, const Anope::string &host, const Anope::string &creator, time_t created = time(NULL)); + void SetVhost(const Anope::string &ident, const Anope::string &host, const Anope::string &creator, time_t created = Anope::CurTime); /** Remove a users vhost **/ diff --git a/include/sockets.h b/include/sockets.h index 772a08a65..6caeea19c 100644 --- a/include/sockets.h +++ b/include/sockets.h @@ -60,8 +60,19 @@ union CoreExport sockaddrs /* The same as above but not */ inline bool operator!=(const sockaddrs &other) const { return !(*this == other); } + /** The equivalent of inet_pton + * @param type AF_INET or AF_INET6 + * @param address The address to place in the sockaddr structures + * @param pport An option port to include in the sockaddr structures + * @throws A socket exception if given invalid IPs + */ void pton(int type, const Anope::string &address, int pport = 0); + /** The equivalent of inet_ntop + * @param type AF_INET or AF_INET6 + * @param address The in_addr or in_addr6 structure + * @throws A socket exception if given an invalid structure + */ void ntop(int type, const void *src); }; diff --git a/include/timers.h b/include/timers.h index 79443d753..433f8adcd 100644 --- a/include/timers.h +++ b/include/timers.h @@ -42,7 +42,7 @@ class CoreExport Timer : public Extensible * @param now The time now * @param repeating Repeat this timer every time_from_now if this is true */ - Timer(long time_from_now, time_t now = time(NULL), bool repeating = false); + Timer(long time_from_now, time_t now = Anope::CurTime, bool repeating = false); /** Default destructor, removes the timer from the list */ @@ -103,7 +103,7 @@ class CoreExport TimerManager : public Extensible /** Tick all pending timers * @param ctime The current time */ - static void TickTimers(time_t ctime = time(NULL)); + static void TickTimers(time_t ctime = Anope::CurTime); /** Compares two timers */ diff --git a/modules/core/bs_act.cpp b/modules/core/bs_act.cpp index d52dbdb78..a3487a0ab 100644 --- a/modules/core/bs_act.cpp +++ b/modules/core/bs_act.cpp @@ -48,7 +48,7 @@ class CommandBSAct : public Command message.erase(i, 1); ircdproto->SendAction(ci->bi, ci->name, "%s", message.c_str()); - ci->bi->lastmsg = time(NULL); + ci->bi->lastmsg = Anope::CurTime; // XXX Need to be able to find if someone is overriding this. Log(LOG_COMMAND, u, this, ci) << message; diff --git a/modules/core/bs_say.cpp b/modules/core/bs_say.cpp index 916cf8fca..34524e11c 100644 --- a/modules/core/bs_say.cpp +++ b/modules/core/bs_say.cpp @@ -54,7 +54,7 @@ class CommandBSSay : public Command } ircdproto->SendPrivmsg(ci->bi, ci->name, "%s", text.c_str()); - ci->bi->lastmsg = time(NULL); + ci->bi->lastmsg = Anope::CurTime; // XXX need a way to find if someone is overriding this Log(LOG_COMMAND, u, this, ci) << text; diff --git a/modules/core/cs_topic.cpp b/modules/core/cs_topic.cpp index ebd09b385..98ca4a2ac 100644 --- a/modules/core/cs_topic.cpp +++ b/modules/core/cs_topic.cpp @@ -36,7 +36,7 @@ class CommandCSTopic : public Command { ci->last_topic = topic; ci->last_topic_setter = u->nick; - ci->last_topic_time = time(NULL); + ci->last_topic_time = Anope::CurTime; c->topic = topic; c->topic_setter = u->nick; diff --git a/modules/core/db_plain.cpp b/modules/core/db_plain.cpp index 6ac61ba11..643146f5d 100644 --- a/modules/core/db_plain.cpp +++ b/modules/core/db_plain.cpp @@ -520,7 +520,7 @@ class DBPlain : public Module if (!IsFile(DatabaseFile)) return; - time_t now = time(NULL); + time_t now = Anope::CurTime; tm *tm = localtime(&now); if (tm->tm_mday != LastDay) diff --git a/modules/core/hs_set.cpp b/modules/core/hs_set.cpp index 68407790a..ca554933c 100644 --- a/modules/core/hs_set.cpp +++ b/modules/core/hs_set.cpp @@ -72,7 +72,7 @@ class CommandHSSet : public Command return MOD_CONT; } - tmp_time = time(NULL); + tmp_time = Anope::CurTime; if ((na = findnick(nick))) { diff --git a/modules/core/hs_setall.cpp b/modules/core/hs_setall.cpp index bea594da6..715559c5a 100644 --- a/modules/core/hs_setall.cpp +++ b/modules/core/hs_setall.cpp @@ -84,7 +84,7 @@ class CommandHSSetAll : public Command return MOD_CONT; } - tmp_time = time(NULL); + tmp_time = Anope::CurTime; Log(LOG_ADMIN, u, this) << "to set the vhost for all nicks in group " << na->nc->display << " to " << (!vIdent.empty() ? vIdent + "@" : "") << hostmask; diff --git a/modules/core/ns_group.cpp b/modules/core/ns_group.cpp index 22fad9b3c..6bb187908 100644 --- a/modules/core/ns_group.cpp +++ b/modules/core/ns_group.cpp @@ -57,8 +57,8 @@ class CommandNSGroup : public Command na = findnick(u->nick); if (!(target = findnick(nick))) notice_lang(Config->s_NickServ, u, NICK_X_NOT_REGISTERED, nick.c_str()); - else if (time(NULL) < u->lastnickreg + Config->NSRegDelay) - notice_lang(Config->s_NickServ, u, NICK_GROUP_PLEASE_WAIT, (Config->NSRegDelay + u->lastnickreg) - time(NULL)); + else if (Anope::CurTime < u->lastnickreg + Config->NSRegDelay) + notice_lang(Config->s_NickServ, u, NICK_GROUP_PLEASE_WAIT, (Config->NSRegDelay + u->lastnickreg) - Anope::CurTime); else if (u->Account() && u->Account()->HasFlag(NI_SUSPENDED)) { //Alog() << Config->s_NickServ << ": " << u->GetMask() << " tried to use GROUP from SUSPENDED nick " << target->nick; @@ -113,7 +113,7 @@ class CommandNSGroup : public Command Anope::string last_usermask = u->GetIdent() + "@" + u->GetDisplayedHost(); na->last_usermask = last_usermask; na->last_realname = u->realname; - na->time_registered = na->last_seen = time(NULL); + na->time_registered = na->last_seen = Anope::CurTime; u->Login(na->nc); FOREACH_MOD(I_OnNickGroup, OnNickGroup(u, target)); @@ -122,7 +122,7 @@ class CommandNSGroup : public Command Log(LOG_COMMAND, u, this) << "makes " << u->nick << " join group of " << target->nick << " (" << target->nc->display << ") (email: " << (!target->nc->email.empty() ? target->nc->email : "none") << ")"; notice_lang(Config->s_NickServ, u, NICK_GROUP_JOINED, target->nick.c_str()); - u->lastnickreg = time(NULL); + u->lastnickreg = Anope::CurTime; check_memos(u); } diff --git a/modules/core/ns_identify.cpp b/modules/core/ns_identify.cpp index 1d4938058..e87d13d22 100644 --- a/modules/core/ns_identify.cpp +++ b/modules/core/ns_identify.cpp @@ -63,7 +63,7 @@ class CommandNSIdentify : public Command Log(LOG_COMMAND, "nickserv/identify") << "to log out of account " << u->Account()->display; na->last_realname = u->realname; - na->last_seen = time(NULL); + na->last_seen = Anope::CurTime; u->Login(na->nc); ircdproto->SendAccountLogin(u, u->Account()); diff --git a/modules/core/ns_register.cpp b/modules/core/ns_register.cpp index 48a869bb8..b95b0c68a 100644 --- a/modules/core/ns_register.cpp +++ b/modules/core/ns_register.cpp @@ -50,7 +50,7 @@ class CommandNSConfirm : public Command na->nc->AddAccess(create_mask(u)); } - na->time_registered = na->last_seen = time(NULL); + na->time_registered = na->last_seen = Anope::CurTime; na->nc->language = Config->NSDefLanguage; if (!nr->email.empty()) na->nc->email = nr->email; @@ -71,7 +71,7 @@ class CommandNSConfirm : public Command if (enc_decrypt(na->nc->pass, tmp_pass) == 1) notice_lang(Config->s_NickServ, u, NICK_PASSWORD_IS, tmp_pass.c_str()); - u->lastnickreg = time(NULL); + u->lastnickreg = Anope::CurTime; } else { @@ -201,7 +201,7 @@ class CommandNSRegister : public CommandNSConfirm return MOD_CONT; } - if (!is_oper(u) && Config->NickRegDelay && time(NULL) - u->my_signon < Config->NickRegDelay) + if (!is_oper(u) && Config->NickRegDelay && Anope::CurTime - u->my_signon < Config->NickRegDelay) { notice_lang(Config->s_NickServ, u, NICK_REG_DELAY, Config->NickRegDelay); return MOD_CONT; @@ -244,8 +244,8 @@ class CommandNSRegister : public CommandNSConfirm if (Config->NSForceEmail && email.empty()) this->OnSyntaxError(u, ""); - else if (time(NULL) < u->lastnickreg + Config->NSRegDelay) - notice_lang(Config->s_NickServ, u, NICK_REG_PLEASE_WAIT, (u->lastnickreg + Config->NSRegDelay) - time(NULL)); + else if (Anope::CurTime < u->lastnickreg + Config->NSRegDelay) + notice_lang(Config->s_NickServ, u, NICK_REG_PLEASE_WAIT, (u->lastnickreg + Config->NSRegDelay) - Anope::CurTime); else if ((na = findnick(u->nick))) { /* i.e. there's already such a nick regged */ @@ -273,7 +273,7 @@ class CommandNSRegister : public CommandNSConfirm enc_encrypt(pass, nr->password); if (!email.empty()) nr->email = email; - nr->requested = time(NULL); + nr->requested = Anope::CurTime; FOREACH_MOD(I_OnMakeNickRequest, OnMakeNickRequest(nr)); if (Config->NSEmailReg) { @@ -335,14 +335,14 @@ class CommandNSResend : public Command { if ((nr = findrequestnick(u->nick))) { - if (time(NULL) < nr->lastmail + Config->NSResendDelay) + if (Anope::CurTime < nr->lastmail + Config->NSResendDelay) { notice_lang(Config->s_NickServ, u, MAIL_LATER); return MOD_CONT; } if (!SendRegmail(u, nr)) { - nr->lastmail = time(NULL); + nr->lastmail = Anope::CurTime; notice_lang(Config->s_NickServ, u, NICK_REG_RESENT, nr->email.c_str()); Log(LOG_COMMAND, u, this) << "resend registration verification code for " << nr->nick; } diff --git a/modules/core/ns_resetpass.cpp b/modules/core/ns_resetpass.cpp index ccb597862..a0efa373c 100644 --- a/modules/core/ns_resetpass.cpp +++ b/modules/core/ns_resetpass.cpp @@ -90,7 +90,7 @@ class NSResetPass : public Module Anope::string c; if (na && na->nc->GetExtRegular("ns_resetpass_code", c) && na->nc->GetExtRegular("ns_resetpass_time", t)) { - if (t < time(NULL) - 3600) + if (t < Anope::CurTime - 3600) { na->nc->Shrink("ns_resetpass_code"); na->nc->Shrink("ns_resetpass_time"); @@ -106,7 +106,7 @@ class NSResetPass : public Module u->UpdateHost(); na->last_realname = u->realname; - na->last_seen = time(NULL); + na->last_seen = Anope::CurTime; u->Login(na->nc); ircdproto->SendAccountLogin(u, u->Account()); ircdproto->SetAutoIdentificationToken(u); @@ -162,7 +162,7 @@ static bool SendResetEmail(User *u, NickAlias *na) na->nc->Shrink("ns_resetpass_time"); na->nc->Extend("ns_resetpass_code", new ExtensibleItemRegular<Anope::string>(passcode)); - na->nc->Extend("ns_resetpass_time", new ExtensibleItemRegular<time_t>(time(NULL))); + na->nc->Extend("ns_resetpass_time", new ExtensibleItemRegular<time_t>(Anope::CurTime)); return Mail(u, na->nc, Config->s_NickServ, subject, message); } diff --git a/modules/core/ns_update.cpp b/modules/core/ns_update.cpp index baeae756c..e101158a9 100644 --- a/modules/core/ns_update.cpp +++ b/modules/core/ns_update.cpp @@ -31,7 +31,7 @@ class CommandNSUpdate : public Command check_memos(u); na->last_realname = u->realname; - na->last_seen = time(NULL); + na->last_seen = Anope::CurTime; if (ircd->vhost) do_on_id(u); notice_lang(Config->s_NickServ, u, NICK_UPDATE_SUCCESS, Config->s_NickServ.c_str()); diff --git a/modules/core/os_akill.cpp b/modules/core/os_akill.cpp index abda0348a..1f4614465 100644 --- a/modules/core/os_akill.cpp +++ b/modules/core/os_akill.cpp @@ -155,7 +155,7 @@ class CommandOSAKill : public Command return MOD_CONT; } else if (expires > 0) - expires += time(NULL); + expires += Anope::CurTime; if (params.size() <= last_param) { @@ -183,7 +183,7 @@ class CommandOSAKill : public Command buf = "does not expire"; else { - int wall_expiry = expires - time(NULL); + time_t wall_expiry = expires - Anope::CurTime; Anope::string s; if (wall_expiry >= 86400) diff --git a/modules/core/os_chankill.cpp b/modules/core/os_chankill.cpp index 04ce6603c..81b15710a 100644 --- a/modules/core/os_chankill.cpp +++ b/modules/core/os_chankill.cpp @@ -44,7 +44,7 @@ class CommandOSChanKill : public Command return MOD_CONT; } else if (expires > 0) - expires += time(NULL); + expires += Anope::CurTime; if (params.size() <= last_param) { diff --git a/modules/core/os_defcon.cpp b/modules/core/os_defcon.cpp index 711046beb..18a1ecfa0 100644 --- a/modules/core/os_defcon.cpp +++ b/modules/core/os_defcon.cpp @@ -158,7 +158,7 @@ class OSDefcon : public Module if (CheckDefCon(DEFCON_AKILL_NEW_CLIENTS)) { Log(OperServ, "operserv/defcon") << "DEFCON: adding akill for *@" << u->host; - XLine *x = SGLine->Add(NULL, NULL, "*@" + u->host, time(NULL) + Config->DefConAKILL, !Config->DefConAkillReason.empty() ? Config->DefConAkillReason : "DEFCON AKILL"); + XLine *x = SGLine->Add(NULL, NULL, "*@" + u->host, Anope::CurTime + Config->DefConAKILL, !Config->DefConAkillReason.empty() ? Config->DefConAkillReason : "DEFCON AKILL"); if (x) x->By = Config->s_OperServ; } @@ -289,7 +289,7 @@ class OSDefcon : public Module ++session->hits; if (Config->MaxSessionKill && session->hits >= Config->MaxSessionKill) { - SGLine->Add(NULL, NULL, "*@" + u->host, time(NULL) + Config->SessionAutoKillExpiry, "Session limit exceeded"); + SGLine->Add(NULL, NULL, "*@" + u->host, Anope::CurTime + Config->SessionAutoKillExpiry, "Session limit exceeded"); ircdproto->SendGlobops(OperServ, "Added a temporary AKILL for \2*@%s\2 due to excessive connections", u->host.c_str()); } } diff --git a/modules/core/os_ignore.cpp b/modules/core/os_ignore.cpp index 05ac57c9b..9cb5cf4d2 100644 --- a/modules/core/os_ignore.cpp +++ b/modules/core/os_ignore.cpp @@ -164,11 +164,9 @@ class OSIgnore : public Module void OnDatabaseWrite(void (*Write)(const Anope::string &)) { - time_t now = time(NULL); - for (std::list<IgnoreData *>::iterator ign = ignore.begin(), ign_end = ignore.end(); ign != ign_end; ) { - if ((*ign)->time && (*ign)->time <= now) + if ((*ign)->time && (*ign)->time <= Anope::CurTime) { Log(LOG_DEBUG) << "[os_ignore] Expiring ignore entry " << (*ign)->mask; delete *ign; diff --git a/modules/core/os_news.cpp b/modules/core/os_news.cpp index 8b286eebb..f77db4494 100644 --- a/modules/core/os_news.cpp +++ b/modules/core/os_news.cpp @@ -142,7 +142,7 @@ static int add_newsitem(User *u, const Anope::string &text, NewsType type) news->type = type; news->num = num + 1; news->Text = text; - news->time = time(NULL); + news->time = Anope::CurTime; news->who = u->nick; News.push_back(news); diff --git a/modules/core/os_session.cpp b/modules/core/os_session.cpp index 9f81ef12d..84619e9b3 100644 --- a/modules/core/os_session.cpp +++ b/ |
