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/modules/core/os_session.cpp @@ -114,7 +114,7 @@ class ExceptionViewCallback : public ExceptionListCallback char timebuf[32]; struct tm tm; - time_t t = time(NULL); + time_t t = Anope::CurTime; tm = *localtime(exceptions[index]->time ? &exceptions[index]->time : &t); strftime_lang(timebuf, sizeof(timebuf), u, STRFTIME_SHORT_DATE_FORMAT, &tm); @@ -249,7 +249,7 @@ class CommandOSException : public Command return MOD_CONT; } else if (expires > 0) - expires += time(NULL); + expires += Anope::CurTime; int limit = !limitstr.empty() && limitstr.is_number_only() ? convertTo<int>(limitstr) : -1; diff --git a/modules/core/os_snline.cpp b/modules/core/os_snline.cpp index 30be073b5..10c813dd9 100644 --- a/modules/core/os_snline.cpp +++ b/modules/core/os_snline.cpp @@ -153,7 +153,7 @@ class CommandOSSNLine : public Command return MOD_CONT; } else if (expires > 0) - expires += time(NULL); + expires += Anope::CurTime; if (param.empty()) { @@ -200,7 +200,7 @@ class CommandOSSNLine : 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_sqline.cpp b/modules/core/os_sqline.cpp index e014d6c82..68a28347a 100644 --- a/modules/core/os_sqline.cpp +++ b/modules/core/os_sqline.cpp @@ -152,7 +152,7 @@ class CommandOSSQLine : public Command return MOD_CONT; } else if (expires > 0) - expires += time(NULL); + expires += Anope::CurTime; if (params.size() <= last_param) { @@ -180,7 +180,7 @@ class CommandOSSQLine : 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_stats.cpp b/modules/core/os_stats.cpp index d965c7dc5..332b6ba4f 100644 --- a/modules/core/os_stats.cpp +++ b/modules/core/os_stats.cpp @@ -130,7 +130,7 @@ class CommandOSStats : public Command CommandReturn DoStatsUptime(User *u) { char timebuf[64]; - time_t uptime = time(NULL) - start_time; + time_t uptime = Anope::CurTime - start_time; int days = uptime / 86400, hours = (uptime / 3600) % 24, mins = (uptime / 60) % 60, secs = uptime % 60; notice_lang(Config->s_OperServ, u, OPER_STATS_CURRENT_USERS, usercnt, opcnt); struct tm *tm = localtime(&maxusertime); diff --git a/modules/core/os_svsnick.cpp b/modules/core/os_svsnick.cpp index a459691b0..537b32b6a 100644 --- a/modules/core/os_svsnick.cpp +++ b/modules/core/os_svsnick.cpp @@ -59,7 +59,7 @@ class CommandOSSVSNick : public Command { notice_lang(Config->s_OperServ, u, OPER_SVSNICK_NEWNICK, nick.c_str(), newnick.c_str()); ircdproto->SendGlobops(OperServ, "%s used SVSNICK to change %s to %s", u->nick.c_str(), nick.c_str(), newnick.c_str()); - ircdproto->SendForceNickChange(u2, newnick, time(NULL)); + ircdproto->SendForceNickChange(u2, newnick, Anope::CurTime); } return MOD_CONT; } diff --git a/modules/core/os_szline.cpp b/modules/core/os_szline.cpp index 6174d4c43..0d024282a 100644 --- a/modules/core/os_szline.cpp +++ b/modules/core/os_szline.cpp @@ -152,7 +152,7 @@ class CommandOSSZLine : public Command return MOD_CONT; } else if (expires > 0) - expires += time(NULL); + expires += Anope::CurTime; if (params.size() <= last_param) { @@ -180,7 +180,7 @@ class CommandOSSZLine : 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/extra/cs_appendtopic.cpp b/modules/extra/cs_appendtopic.cpp index 387c55f73..e331d46c6 100644 --- a/modules/extra/cs_appendtopic.cpp +++ b/modules/extra/cs_appendtopic.cpp @@ -85,7 +85,7 @@ class CommandCSAppendTopic : 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/extra/db_mysql.cpp b/modules/extra/db_mysql.cpp index 4920e9b00..eb55a3952 100644 --- a/modules/extra/db_mysql.cpp +++ b/modules/extra/db_mysql.cpp @@ -338,13 +338,11 @@ class DBMySQL : public Module } else { - time_t now = time(NULL); - - if (now - Config->UpdateTimeout > lastwarn) + if (Anope::CurTime - Config->UpdateTimeout > lastwarn) { ircdproto->SendGlobops(OperServ, "Unable to locate SQL reference, is m_mysql loaded? Going to readonly..."); readonly = this->ro = true; - this->lastwarn = now; + this->lastwarn = Anope::CurTime; } } } @@ -478,8 +476,8 @@ class DBMySQL : public Module na->last_quit = r.Get(i, "last_quit"); na->last_realname = r.Get(i, "last_realname"); na->last_usermask = r.Get(i, "last_usermask"); - na->time_registered = r.Get(i, "time_registered").is_pos_number_only() ? convertTo<time_t>(r.Get(i, "time_registered")) : time(NULL); - na->last_seen = r.Get(i, "last_seen").is_pos_number_only() ? convertTo<time_t>(r.Get(i, "last_seen")) : time(NULL); + na->time_registered = r.Get(i, "time_registered").is_pos_number_only() ? convertTo<time_t>(r.Get(i, "time_registered")) : Anope::CurTime; + na->last_seen = r.Get(i, "last_seen").is_pos_number_only() ? convertTo<time_t>(r.Get(i, "last_seen")) : Anope::CurTime; spacesepstream sep(r.Get(i, "flags")); Anope::string buf; @@ -518,7 +516,7 @@ class DBMySQL : public Module if (!bi) bi = new BotInfo(r.Get(i, "nick"), r.Get(i, "user"), r.Get(i, "host")); bi->realname = r.Get(i, "rname"); - bi->created = r.Get(i, "created").is_pos_number_only() ? convertTo<time_t>(r.Get(i, "creeated")) : time(NULL); + bi->created = r.Get(i, "created").is_pos_number_only() ? convertTo<time_t>(r.Get(i, "creeated")) : Anope::CurTime; spacesepstream sep(r.Get(i, "flags")); Anope::string buf; @@ -569,11 +567,11 @@ class DBMySQL : public Module if (!r.Get(i, "successor").empty()) ci->successor = findcore(r.Get(i, "successor")); ci->desc = r.Get(i, "descr"); - ci->time_registered = r.Get(i, "time_registered").is_pos_number_only() ? convertTo<time_t>(r.Get(i, "time_registered")) : time(NULL); - ci->last_used = r.Get(i, "last_used").is_pos_number_only() ? convertTo<time_t>(r.Get(i, "last_used")) : time(NULL); + ci->time_registered = r.Get(i, "time_registered").is_pos_number_only() ? convertTo<time_t>(r.Get(i, "time_registered")) : Anope::CurTime; + ci->last_used = r.Get(i, "last_used").is_pos_number_only() ? convertTo<time_t>(r.Get(i, "last_used")) : Anope::CurTime; ci->last_topic = r.Get(i, "last_topic"); ci->last_topic_setter = r.Get(i, "last_topic_setter"); - ci->last_topic_time = r.Get(i, "last_topic_time").is_number_only() ? convertTo<int>(r.Get(i, "last_topic_time")) : time(NULL); + ci->last_topic_time = r.Get(i, "last_topic_time").is_number_only() ? convertTo<int>(r.Get(i, "last_topic_time")) : Anope::CurTime; ci->forbidby = r.Get(i, "forbidby"); ci->forbidreason = r.Get(i, "forbidreason"); ci->bantype = r.Get(i, "bantype").is_number_only() ? convertTo<int>(r.Get(i, "bantype")) : 2; @@ -706,7 +704,7 @@ class DBMySQL : public Module continue; } - ci->AddAccess(nc, atoi(r.Get(i, "level").c_str()), r.Get(i, "creator"), (r.Get(i, "last_seen").is_pos_number_only() ? convertTo<time_t>(r.Get(i, "last_seen")) : time(NULL))); + ci->AddAccess(nc, atoi(r.Get(i, "level").c_str()), r.Get(i, "creator"), (r.Get(i, "last_seen").is_pos_number_only() ? convertTo<time_t>(r.Get(i, "last_seen")) : Anope::CurTime)); } r = SQL->RunQuery("SELECT * FROM `anope_cs_akick`"); @@ -777,7 +775,7 @@ class DBMySQL : public Module nr->password = r.Get(i, "passcode"); nr->password = r.Get(i, "password"); nr->email = r.Get(i, "email"); - nr->requested = r.Get(i, "requested").is_pos_number_only() ? convertTo<time_t>(r.Get(i, "requested")) : time(NULL); + nr->requested = r.Get(i, "requested").is_pos_number_only() ? convertTo<time_t>(r.Get(i, "requested")) : Anope::CurTime; } r = SQL->RunQuery("SELECT * FROM `anope_ms_info`"); @@ -812,7 +810,7 @@ class DBMySQL : public Module } else m->number = 1; - m->time = r.Get(i, "time").is_pos_number_only() ? convertTo<time_t>(r.Get(i, "time")) : time(NULL); + m->time = r.Get(i, "time").is_pos_number_only() ? convertTo<time_t>(r.Get(i, "time")) : Anope::CurTime; m->text = r.Get(i, "text"); if (!r.Get(i, "flags").empty()) @@ -843,8 +841,8 @@ class DBMySQL : public Module Anope::string host = r.Get(i, "host"); Anope::string by = r.Get(i, "by"); Anope::string reason = r.Get(i, "reason"); - time_t seton = r.Get(i, "seton").is_pos_number_only() ? convertTo<time_t>(r.Get(i, "seton")) : time(NULL); - time_t expires = r.Get(i, "expires").is_pos_number_only() ? convertTo<time_t>(r.Get(i, "expires")) : time(NULL); + time_t seton = r.Get(i, "seton").is_pos_number_only() ? convertTo<time_t>(r.Get(i, "seton")) : Anope::CurTime; + time_t expires = r.Get(i, "expires").is_pos_number_only() ? convertTo<time_t>(r.Get(i, "expires")) : Anope::CurTime; XLine *x = SGLine->Add(NULL, NULL, user + "@" + host, expires, reason); if (x) @@ -861,8 +859,8 @@ class DBMySQL : public Module Anope::string mask = r.Get(i, "mask"); Anope::string by = r.Get(i, "xby"); Anope::string reason = r.Get(i, "reason"); - time_t seton = r.Get(i, "seton").is_pos_number_only() ? convertTo<time_t>(r.Get(i, "seton")) : time(NULL); - time_t expires = r.Get(i, "expires").is_pos_number_only() ? convertTo<time_t>(r.Get(i, "expires")) : time(NULL); + time_t seton = r.Get(i, "seton").is_pos_number_only() ? convertTo<time_t>(r.Get(i, "seton")) : Anope::CurTime; + time_t expires = r.Get(i, "expires").is_pos_number_only() ? convertTo<time_t>(r.Get(i, "expires")) : Anope::CurTime; XLine *x = NULL; if (SNLine && r.Get(i, "type").equals_cs("SNLINE")) @@ -1145,7 +1143,7 @@ class DBMySQL : public Module void OnAccessAdd(ChannelInfo *ci, User *u, NickAlias *na, int level) { - this->RunQuery("INSERT DELAYED INTO `anope_cs_access` (level, display, channel, last_seen, creator) VALUES (" + stringify(level) + ", '" + this->Escape(na->nc->display) + "', '" + this->Escape(ci->name) + "', " + stringify(time(NULL)) + ", '" + this->Escape(u->nick) + "')"); + this->RunQuery("INSERT DELAYED INTO `anope_cs_access` (level, display, channel, last_seen, creator) VALUES (" + stringify(level) + ", '" + this->Escape(na->nc->display) + "', '" + this->Escape(ci->name) + "', " + stringify(Anope::CurTime) + ", '" + this->Escape(u->nick) + "')"); } void OnAccessDel(ChannelInfo *ci, User *u, NickCore *nc) @@ -1155,7 +1153,7 @@ class DBMySQL : public Module void OnAccessChange(ChannelInfo *ci, User *u, NickAlias *na, int level) { - this->RunQuery("INSERT DELAYED INTO `anope_cs_access` (level, display, channel, last_seen, creator) VALUES (" + stringify(level) + ", '" + this->Escape(na->nc->display) + "', '" + this->Escape(ci->name) + "', " + stringify(time(NULL)) + ", '" + this->Escape(u->nick) + "') ON DUPLICATE KEY UPDATE level=VALUES(level), display=VALUES(display), channel=VALUES(channel), last_seen=VALUES(last_seen), creator=VALUES(creator)"); + this->RunQuery("INSERT DELAYED INTO `anope_cs_access` (level, display, channel, last_seen, creator) VALUES (" + stringify(level) + ", '" + this->Escape(na->nc->display) + "', '" + this->Escape(ci->name) + "', " + stringify(Anope::CurTime) + ", '" + this->Escape(u->nick) + "') ON DUPLICATE KEY UPDATE level=VALUES(level), display=VALUES(display), channel=VALUES(channel), last_seen=VALUES(last_seen), creator=VALUES(creator)"); } void OnAccessClear(ChannelInfo *ci, User *u) diff --git a/modules/extra/hs_request.cpp b/modules/extra/hs_request.cpp index 9b1218113..edca02ade 100644 --- a/modules/extra/hs_request.cpp +++ b/modules/extra/hs_request.cpp @@ -84,7 +84,6 @@ class CommandHSRequest : public Command Anope::string rawhostmask = params[0]; Anope::string hostmask; NickAlias *na; - time_t now = time(NULL); Anope::string vIdent = myStrGetToken(rawhostmask, '@', 0); /* Get the first substring, @ as delimiter */ if (!vIdent.empty()) @@ -129,13 +128,13 @@ class CommandHSRequest : public Command if ((na = findnick(nick))) { - if ((HSRequestMemoOper || HSRequestMemoSetters) && Config->MSSendDelay > 0 && u && u->lastmemosend + Config->MSSendDelay > now) + if ((HSRequestMemoOper || HSRequestMemoSetters) && Config->MSSendDelay > 0 && u && u->lastmemosend + Config->MSSendDelay > Anope::CurTime) { me->NoticeLang(Config->s_HostServ, u, LNG_REQUEST_WAIT, Config->MSSendDelay); - u->lastmemosend = now; + u->lastmemosend = Anope::CurTime; return MOD_CONT; } - my_add_host_request(nick, vIdent, hostmask, u->nick, now); + my_add_host_request(nick, vIdent, hostmask, u->nick, Anope::CurTime); me->NoticeLang(Config->s_HostServ, u, LNG_REQUESTED); req_send_memos(u, vIdent, hostmask); diff --git a/modules/extra/m_dnsbl.cpp b/modules/extra/m_dnsbl.cpp index ac95c5e30..a72e8ac3b 100644 --- a/modules/extra/m_dnsbl.cpp +++ b/modules/extra/m_dnsbl.cpp @@ -32,7 +32,7 @@ class DNSBLResolver : public DNSRequest reason = reason.replace_all_ci("%i", user->ip.addr()); reason = reason.replace_all_ci("%h", user->host); - XLine *x = SGLine->Add(NULL, NULL, Anope::string("*@") + user->host, time(NULL) + this->blacklist.bantime, reason); + XLine *x = SGLine->Add(NULL, NULL, Anope::string("*@") + user->host, Anope::CurTime + this->blacklist.bantime, reason); if (x) { static Command command_akill("AKILL", 0); diff --git a/modules/protocol/bahamut.cpp b/modules/protocol/bahamut.cpp index 5707c642d..8e54de704 100644 --- a/modules/protocol/bahamut.cpp +++ b/modules/protocol/bahamut.cpp @@ -64,7 +64,7 @@ void bahamut_cmd_burst() */ void bahamut_cmd_svinfo() { - send_cmd("", "SVINFO 3 1 0 :%ld", static_cast<long>(time(NULL))); + send_cmd("", "SVINFO 3 1 0 :%ld", static_cast<long>(Anope::CurTime)); } /* PASS */ @@ -152,7 +152,7 @@ class BahamutIRCdProto : public IRCDProto /* this will likely fail so its only here for legacy */ send_cmd("", "SZLINE %s :%s", x->Mask.c_str(), x->Reason.c_str()); /* this is how we are supposed to deal with it */ - send_cmd("", "AKILL %s * %d %s %ld :%s", x->Mask.c_str(), 172800, x->By.c_str(), static_cast<long>(time(NULL)), x->Reason.c_str()); + send_cmd("", "AKILL %s * %d %s %ld :%s", x->Mask.c_str(), 172800, x->By.c_str(), static_cast<long>(Anope::CurTime), x->Reason.c_str()); } /* SVSNOOP */ @@ -207,10 +207,10 @@ class BahamutIRCdProto : public IRCDProto void SendAkill(const XLine *x) { // Calculate the time left before this would expire, capping it at 2 days - time_t timeleft = x->Expires - time(NULL); + time_t timeleft = x->Expires - Anope::CurTime; if (timeleft > 172800) timeleft = 172800; - send_cmd("", "AKILL %s %s %d %s %ld :%s", x->GetHost().c_str(), x->GetUser().c_str(), static_cast<int>(timeleft), x->By.c_str(), static_cast<long>(time(NULL)), x->Reason.c_str()); + send_cmd("", "AKILL %s %s %d %s %ld :%s", x->GetHost().c_str(), x->GetUser().c_str(), static_cast<int>(timeleft), x->By.c_str(), static_cast<long>(Anope::CurTime), x->Reason.c_str()); } /* diff --git a/modules/protocol/inspircd11.cpp b/modules/protocol/inspircd11.cpp index d5cacb6a6..4b92a694c 100644 --- a/modules/protocol/inspircd11.cpp +++ b/modules/protocol/inspircd11.cpp @@ -73,7 +73,7 @@ void inspircd_cmd_chghost(const Anope::string &nick, const Anope::string &vhost) int anope_event_idle(const Anope::string &source, int ac, const char **av) { if (ac == 1) - send_cmd(av[0], "IDLE %s %ld 0", source.c_str(), static_cast<long>(time(NULL))); + send_cmd(av[0], "IDLE %s %ld 0", source.c_str(), static_cast<long>(Anope::CurTime)); return MOD_CONT; } @@ -111,10 +111,10 @@ class InspIRCdProto : public IRCDProto void SendAkill(const XLine *x) { // Calculate the time left before this would expire, capping it at 2 days - time_t timeleft = x->Expires - time(NULL); + time_t timeleft = x->Expires - Anope::CurTime; if (timeleft > 172800) timeleft = 172800; - send_cmd(Config->ServerName, "ADDLINE G %s %s %ld %ld :%s", x->Mask.c_str(), x->By.c_str(), static_cast<long>(time(NULL)), static_cast<long>(timeleft), x->Reason.c_str()); + send_cmd(Config->ServerName, "ADDLINE G %s %s %ld %ld :%s", x->Mask.c_str(), x->By.c_str(), static_cast<long>(Anope::CurTime), static_cast<long>(timeleft), x->Reason.c_str()); } void SendSVSKillInternal(const BotInfo *source, const User *user, const Anope::string &buf) @@ -201,7 +201,7 @@ class InspIRCdProto : public IRCDProto /* SQLINE */ void SendSQLine(const XLine *x) { - send_cmd(Config->ServerName, "ADDLINE Q %s %s %ld 0 :%s", x->Mask.c_str(), Config->s_OperServ.c_str(), static_cast<long>(time(NULL)), x->Reason.c_str()); + send_cmd(Config->ServerName, "ADDLINE Q %s %s %ld 0 :%s", x->Mask.c_str(), Config->s_OperServ.c_str(), static_cast<long>(Anope::CurTime), x->Reason.c_str()); } /* SQUIT */ @@ -264,7 +264,7 @@ class InspIRCdProto : public IRCDProto /* SZLINE */ void SendSZLine(const XLine *x) { - send_cmd(Config->ServerName, "ADDLINE Z %s %s %ld 0 :%s", x->Mask.c_str(), x->By.c_str(), static_cast<long>(time(NULL)), x->Reason.c_str()); + send_cmd(Config->ServerName, "ADDLINE Z %s %s %ld 0 :%s", x->Mask.c_str(), x->By.c_str(), static_cast<long>(Anope::CurTime), x->Reason.c_str()); } void SendSVSJoin(const Anope::string &source, const Anope::string &nick, const Anope::string &chan, const Anope::string &) @@ -279,7 +279,7 @@ class InspIRCdProto : public IRCDProto void SendBOB() { - send_cmd("", "BURST %ld", time(NULL)); + send_cmd("", "BURST %ld", Anope::CurTime); } void SendEOB() @@ -516,7 +516,6 @@ int anope_event_away(const Anope::string &source, int ac, const char **av) int anope_event_topic(const Anope::string &source, int ac, const char **av) { Channel *c = findchan(av[0]); - time_t topic_time = time(NULL); if (!c) { @@ -524,7 +523,7 @@ int anope_event_topic(const Anope::string &source, int ac, const char **av) return MOD_CONT; } - if (check_topiclock(c, topic_time)) + if (check_topiclock(c, Anope::CurTime)) return MOD_CONT; c->topic.clear(); @@ -532,7 +531,7 @@ int anope_event_topic(const Anope::string &source, int ac, const char **av) c->topic = av[1]; c->topic_setter = source; - c->topic_time = topic_time; + c->topic_time = Anope::CurTime; record_topic(av[0]); diff --git a/modules/protocol/inspircd12.cpp b/modules/protocol/inspircd12.cpp index 4f2525a11..ffc696d94 100644 --- a/modules/protocol/inspircd12.cpp +++ b/modules/protocol/inspircd12.cpp @@ -76,7 +76,7 @@ int anope_event_idle(const Anope::string &source, int ac, const char **av) { BotInfo *bi = findbot(av[0]); - send_cmd(bi ? bi->GetUID() : av[0], "IDLE %s %ld %ld", source.c_str(), static_cast<long>(start_time), bi ? (static_cast<long>(time(NULL) - bi->lastmsg)) : 0); + send_cmd(bi ? bi->GetUID() : av[0], "IDLE %s %ld %ld", source.c_str(), static_cast<long>(start_time), bi ? (static_cast<long>(Anope::CurTime - bi->lastmsg)) : 0); return MOD_CONT; } @@ -114,10 +114,10 @@ class InspIRCdProto : public IRCDProto void SendAkill(const XLine *x) { // Calculate the time left before this would expire, capping it at 2 days - time_t timeleft = x->Expires - time(NULL); + time_t timeleft = x->Expires - Anope::CurTime; if (timeleft > 172800 || !x->Expires) timeleft = 172800; - send_cmd(OperServ->GetUID(), "ADDLINE G %s@%s %s %ld %ld :%s", x->GetUser().c_str(), x->GetHost().c_str(), x->By.c_str(), static_cast<long>(time(NULL)), static_cast<long>(timeleft), x->Reason.c_str()); + send_cmd(OperServ->GetUID(), "ADDLINE G %s@%s %s %ld %ld :%s", x->GetUser().c_str(), x->GetHost().c_str(), x->By.c_str(), static_cast<long>(Anope::CurTime), static_cast<long>(timeleft), x->Reason.c_str()); } void SendSVSKillInternal(const BotInfo *source, const User *user, const Anope::string &buf) @@ -191,7 +191,7 @@ class InspIRCdProto : public IRCDProto /* SQLINE */ void SendSQLine(const XLine *x) { - send_cmd(TS6SID, "ADDLINE Q %s %s %ld 0 :%s", x->Mask.c_str(), Config->s_OperServ.c_str(), static_cast<long>(time(NULL)), x->Reason.c_str()); + send_cmd(TS6SID, "ADDLINE Q %s %s %ld 0 :%s", x->Mask.c_str(), Config->s_OperServ.c_str(), static_cast<long>(Anope::CurTime), x->Reason.c_str()); } /* SQUIT */ @@ -248,7 +248,7 @@ class InspIRCdProto : public IRCDProto /* SZLINE */ void SendSZLine(const XLine *x) { - send_cmd(TS6SID, "ADDLINE Z %s %s %ld 0 :%s", x->Mask.c_str(), x->By.c_str(), static_cast<long>(time(NULL)), x->Reason.c_str()); + send_cmd(TS6SID, "ADDLINE Z %s %s %ld 0 :%s", x->Mask.c_str(), x->By.c_str(), static_cast<long>(Anope::CurTime), x->Reason.c_str()); } void SendSVSJoin(const Anope::string &source, const Anope::string &nick, const Anope::string &chan, const Anope::string &) @@ -274,7 +274,7 @@ class InspIRCdProto : public IRCDProto void SendBOB() { - send_cmd(TS6SID, "BURST %ld", time(NULL)); + send_cmd(TS6SID, "BURST %ld", Anope::CurTime); } void SendEOB() @@ -539,7 +539,7 @@ int anope_event_time(const Anope::string &source, int ac, const char **av) if (ac !=2) return MOD_CONT; - send_cmd(TS6SID, "TIME %s %s %ld", source.c_str(), av[1], static_cast<long>(time(NULL))); + send_cmd(TS6SID, "TIME %s %s %ld", source.c_str(), av[1], static_cast<long>(Anope::CurTime)); /* We handled it, don't pass it on to the core.. * The core doesn't understand our syntax anyways.. ~ Viper */ @@ -562,7 +562,6 @@ int anope_event_away(const Anope::string &source, int ac, const char **av) int anope_event_topic(const Anope::string &source, int ac, const char **av) { Channel *c = findchan(av[0]); - time_t topic_time = time(NULL); User *u = finduser(source); if (!c) @@ -571,7 +570,7 @@ int anope_event_topic(const Anope::string &source, int ac, const char **av) return MOD_CONT; } - if (check_topiclock(c, topic_time)) + if (check_topiclock(c, Anope::CurTime)) return MOD_CONT; c->topic.clear(); @@ -579,7 +578,7 @@ int anope_event_topic(const Anope::string &source, int ac, const char **av) c->topic = av[1]; c->topic_setter = u ? u->nick : source; - c->topic_time = topic_time; + c->topic_time = Anope::CurTime; record_topic(av[0]); diff --git a/modules/protocol/inspircd20.cpp b/modules/protocol/inspircd20.cpp index a9cc2e9bd..51784d071 100644 --- a/modules/protocol/inspircd20.cpp +++ b/modules/protocol/inspircd20.cpp @@ -74,7 +74,7 @@ int anope_event_idle(const Anope::string &source, int ac, const char **av) { BotInfo *bi = findbot(av[0]); - send_cmd(bi ? bi->GetUID() : av[0], "IDLE %s %ld %ld", source.c_str(), static_cast<long>(start_time), bi ? (static_cast<long>(time(NULL) - bi->lastmsg)) : 0); + send_cmd(bi ? bi->GetUID() : av[0], "IDLE %s %ld %ld", source.c_str(), static_cast<long>(start_time), bi ? (static_cast<long>(Anope::CurTime - bi->lastmsg)) : 0); return MOD_CONT; } @@ -112,10 +112,10 @@ class InspIRCdProto : public IRCDProto void SendAkill(const XLine *x) { // Calculate the time left before this would expire, capping it at 2 days - time_t timeleft = x->Expires - time(NULL); + time_t timeleft = x->Expires - Anope::CurTime; if (timeleft > 172800 || !x->Expires) timeleft = 172800; - send_cmd(OperServ->GetUID(), "ADDLINE G %s@%s %s %ld %ld :%s", x->GetUser().c_str(), x->GetHost().c_str(), x->By.c_str(), static_cast<long>(time(NULL)), static_cast<long>(timeleft), x->Reason.c_str()); + send_cmd(OperServ->GetUID(), "ADDLINE G %s@%s %s %ld %ld :%s", x->GetUser().c_str(), x->GetHost().c_str(), x->By.c_str(), static_cast<long>(Anope::CurTime), static_cast<long>(timeleft), x->Reason.c_str()); } void SendSVSKillInternal(const BotInfo *source, const User *user, const Anope::string &buf) @@ -189,7 +189,7 @@ class InspIRCdProto : public IRCDProto /* SQLINE */ void SendSQLine(const XLine *x) { - send_cmd(TS6SID, "ADDLINE Q %s %s %ld 0 :%s", x->Mask.c_str(), Config->s_OperServ.c_str(), static_cast<long>(time(NULL)), x->Reason.c_str()); + send_cmd(TS6SID, "ADDLINE Q %s %s %ld 0 :%s", x->Mask.c_str(), Config->s_OperServ.c_str(), static_cast<long>(Anope::CurTime), x->Reason.c_str()); } /* SQUIT */ @@ -249,7 +249,7 @@ class InspIRCdProto : public IRCDProto /* SZLINE */ void SendSZLine(const XLine *x) { - send_cmd(TS6SID, "ADDLINE Z %s %s %ld 0 :%s", x->Mask.c_str(), x->By.c_str(), static_cast<long>(time(NULL)), x->Reason.c_str()); + send_cmd(TS6SID, "ADDLINE Z %s %s %ld 0 :%s", x->Mask.c_str(), x->By.c_str(), static_cast<long>(Anope::CurTime), x->Reason.c_str()); } void SendSVSJoin(const Anope::string &source, const Anope::string &nick, const Anope::string &chan, const Anope::string &) @@ -275,7 +275,7 @@ class InspIRCdProto : public IRCDProto void SendBOB() { - send_cmd(TS6SID, "BURST %ld", time(NULL)); + send_cmd(TS6SID, "BURST %ld", Anope::CurTime); } void SendEOB() @@ -537,7 +537,7 @@ int anope_event_time(const Anope::string &source, int ac, const char **av) if (ac !=2) return MOD_CONT; - send_cmd(TS6SID, "TIME %s %s %ld", source.c_str(), av[1], static_cast<long>(time(NULL))); + send_cmd(TS6SID, "TIME %s %s %ld", source.c_str(), av[1], static_cast<long>(Anope::CurTime)); /* We handled it, don't pass it on to the core.. * The core doesn't understand our syntax anyways.. ~ Viper */ @@ -560,7 +560,6 @@ int anope_event_away(const Anope::string &source, int ac, const char **av) int anope_event_topic(const Anope::string &source, int ac, const char **av) { Channel *c = findchan(av[0]); - time_t topic_time = time(NULL); User *u = finduser(source); if (!c) @@ -569,7 +568,7 @@ int anope_event_topic(const Anope::string &source, int ac, const char **av) return MOD_CONT; } - if (check_topiclock(c, topic_time)) + if (check_topiclock(c, Anope::CurTime)) return MOD_CONT; c->topic.clear(); @@ -577,7 +576,7 @@ int anope_event_topic(const Anope::string &source, int ac, const char **av) c->topic = av[1]; c->topic_setter = u ? u->nick : source; - c->topic_time = topic_time; + c->topic_time = Anope::CurTime; record_topic(av[0]); diff --git a/modules/protocol/ratbox.cpp b/modules/protocol/ratbox.cpp index 2aa528f49..505d143fd 100644 --- a/modules/protocol/ratbox.cpp +++ b/modules/protocol/ratbox.cpp @@ -59,7 +59,7 @@ IRCDVar myIrcd[] = { */ void ratbox_cmd_svinfo() { - send_cmd("", "SVINFO 6 3 0 :%ld", static_cast<long>(time(NULL))); + send_cmd("", "SVINFO 6 3 0 :%ld", static_cast<long>(Anope::CurTime)); } void ratbox_cmd_svsinfo() @@ -147,7 +147,7 @@ class RatboxProto : public IRCDProto void SendAkill(const XLine *x) { BotInfo *bi = OperServ; - send_cmd(bi ? bi->GetUID() : Config->s_OperServ, "KLINE * %ld %s %s :%s", static_cast<long>(x->Expires - time(NULL)), x->GetUser().c_str(), x->GetHost().c_str(), x->Reason.c_str()); + send_cmd(bi ? bi->GetUID() : Config->s_OperServ, "KLINE * %ld %s %s :%s", static_cast<long>(x->Expires - Anope::CurTime), x->GetUser().c_str(), x->GetHost().c_str(), x->Reason.c_str()); } void SendSVSKillInternal(const BotInfo *source, const User *user, const Anope::string &buf) @@ -424,7 +424,6 @@ int anope_event_topic(const Anope::string &source, int ac, const char **av) else { Channel *c = findchan(av[0]); - time_t topic_time = time(NULL); if (!c) { @@ -432,7 +431,7 @@ int anope_event_topic(const Anope::string &source, int ac, const char **av) return MOD_CONT; } - if (check_topiclock(c, topic_time)) + if (check_topiclock(c, Anope::CurTime)) return MOD_CONT; c->topic.clear(); @@ -441,7 +440,7 @@ int anope_event_topic(const Anope::string &source, int ac, const char **av) u = finduser(source); c->topic_setter = u ? u->nick : source; - c->topic_time = topic_time; + c->topic_time = Anope::CurTime; record_topic(av[0]); diff --git a/modules/protocol/unreal32.cpp b/modules/protocol/unreal32.cpp index abb83adce..249da63b5 100644 --- a/modules/protocol/unreal32.cpp +++ b/modules/protocol/unreal32.cpp @@ -51,7 +51,7 @@ IRCDVar myIrcd[] = { void unreal_cmd_netinfo(int ac, const char **av) { - send_cmd("", "AO %ld %ld %d %s 0 0 0 :%s", static_cast<long>(maxusercnt), static_cast<long>(time(NULL)), Anope::string(av[2]).is_number_only() ? convertTo<int>(av[2]) : 0, av[3], av[7]); + send_cmd("", "AO %ld %ld %d %s 0 0 0 :%s", static_cast<long>(maxusercnt), static_cast<long>(Anope::CurTime), Anope::string(av[2]).is_number_only() ? convertTo<int>(av[2]) : 0, av[3], av[7]); } /* PROTOCTL */ @@ -129,10 +129,10 @@ class UnrealIRCdProto : public IRCDProto void SendAkill(const XLine *x) { // Calculate the time left before this would expire, capping it at 2 days - time_t timeleft = x->Expires - time(NULL); + time_t timeleft = x->Expires - Anope::CurTime; if (timeleft > 172800) timeleft = 172800; - send_cmd("", "BD + G %s %s %s %ld %ld :%s", x->GetUser().c_str(), x->GetHost().c_str(), x->By.c_str(), static_cast<long>(time(NULL) + timeleft), static_cast<long>(x->Created), x->Reason.c_str()); + send_cmd("", "BD + G %s %s %s %ld %ld :%s", x->GetUser().c_str(), x->GetHost().c_str(), x->By.c_str(), static_cast<long>(Anope::CurTime + timeleft), static_cast<long>(x->Created), x->Reason.c_str()); } void SendSVSKillInternal(const BotInfo *source, const User *user, const Anope::string &buf) @@ -249,7 +249,7 @@ class UnrealIRCdProto : public IRCDProto { if (!oldnick || newnick.empty()) return; - send_cmd(oldnick->nick, "& %s %ld", newnick.c_str(), static_cast<long>(time(NULL))); + send_cmd(oldnick->nick, "& %s %ld", newnick.c_str(), static_cast<long>(Anope::CurTime)); } /* Functions that use serval cmd functions */ @@ -272,7 +272,7 @@ class UnrealIRCdProto : public IRCDProto /* SVSHOLD - set */ void SendSVSHold(const Anope::string &nick) { - send_cmd("", "BD + Q H %s %s %ld %ld :Being held for registered user", nick.c_str(), Config->ServerName.c_str(), static_cast<long>(time(NULL) + Config->NSReleaseTimeout), static_cast<long>(time(NULL))); + send_cmd("", "BD + Q H %s %s %ld %ld :Being held for registered user", nick.c_str(), Config->ServerName.c_str(), static_cast<long>(Anope::CurTime + Config->NSReleaseTimeout), static_cast<long>(Anope::CurTime)); } /* SVSHOLD - release */ @@ -299,7 +299,7 @@ class UnrealIRCdProto : public IRCDProto /* SZLINE */ void SendSZLine(const XLine *x) { - send_cmd("", "BD + Z * %s %s %ld %ld :%s", x->Mask.c_str(), x->By.c_str(), static_cast<long>(time(NULL) + 172800), static_cast<long>(time(NULL)), x->Reason.c_str()); + send_cmd("", "BD + Z * %s %s %ld %ld :%s", x->Mask.c_str(), x->By.c_str(), static_cast<long>(Anope::CurTime + 172800), static_cast<long>(Anope::CurTime), x->Reason.c_str()); } /* SGLINE */ diff --git a/modules/socketengines/m_socketengine_epoll.cpp b/modules/socketengines/m_socketengine_epoll.cpp index 5edc40502..709a75804 100644 --- a/modules/socketengines/m_socketengine_epoll.cpp +++ b/modules/socketengines/m_socketengine_epoll.cpp @@ -119,6 +119,7 @@ class SocketEngineEPoll : public SocketEngineBase void Process() { int total = epoll_wait(EngineHandle, events, max - 1, Config->ReadTimeout * 1000); + Anope::CurTime = time(NULL); if (total == -1) { diff --git a/modules/socketengines/m_socketengine_select.cpp b/modules/socketengines/m_socketengine_select.cpp index b966820bd..13791d926 100644 --- a/modules/socketengines/m_socketengine_select.cpp +++ b/modules/socketengines/m_socketengine_select.cpp @@ -65,6 +65,7 @@ class SocketEngineSelect : public SocketEngineBase tval.tv_usec = 0; int sresult = select(MaxFD + 1, &rfdset, &wfdset, &efdset, &tval); + Anope::CurTime = time(NULL); if (sresult == -1) { diff --git a/src/actions.cpp b/src/actions.cpp index 92ecca132..4bb3563e5 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -21,15 +21,13 @@ */ bool bad_password(User *u) { - time_t now = time(NULL); - if (!u || !Config->BadPassLimit) return false; - if (Config->BadPassTimeout > 0 && u->invalid_pw_time > 0 && u->invalid_pw_time < now - Config->BadPassTimeout) + if (Config->BadPassTimeout > 0 && u->invalid_pw_time > 0 && u->invalid_pw_time < Anope::CurTime - Config->BadPassTimeout) u->invalid_pw_count = 0; ++u->invalid_pw_count; - u->invalid_pw_time = now; + u->invalid_pw_time = Anope::CurTime; if (u->invalid_pw_count >= Config->BadPassLimit) { kill_user("", u->nick, "Too many invalid passwords"); diff --git a/src/bots.cpp b/src/bots.cpp index 6b7e77377..be580c2a0 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -26,7 +26,7 @@ BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const A this->server = Me; this->chancount = 0; - this->lastmsg = this->created = time(NULL); + this->lastmsg = this->created = Anope::CurTime; this->SetFlag(BI_CORE); if (!Config->s_ChanServ.empty() && nnick.equals_ci(Config->s_ChanServ)) diff --git a/src/botserv.cpp b/src/botserv.cpp index c00b9c6fe..4cfd42e5b 100644 --- a/src/botserv.cpp +++ b/src/botserv.cpp @@ -266,15 +266,13 @@ void botchanmsgs(User *u, ChannelInfo *ci, const Anope::string &buf) /* Flood kicker */ if (ci->botflags.HasFlag(BS_KICK_FLOOD)) { - time_t now = time(NULL); - UserData *ud = get_user_data(ci->c, u); if (!ud) return; - if (now - ud->last_start > ci->floodsecs) + if (Anope::CurTime - ud->last_start > ci->floodsecs) { - ud->last_start = time(NULL); + ud->last_start = Anope::CurTime; ud->lines = 0; } @@ -390,10 +388,9 @@ static BanData *get_ban_data(Channel *c, User *u) return NULL; Anope::string mask = u->GetIdent() + "@" + u->GetDisplayedHost(); - time_t now = time(NULL); for (std::list<BanData *>::iterator it = c->bd.begin(), it_end = c->bd.end(); it != it_end; ++it) { - if (now - (*it)->last_use > Config->BSKeepData) + if (Anope::CurTime - (*it)->last_use > Config->BSKeepData) { delete *it; c->bd.erase(it); @@ -401,7 +398,7 @@ static BanData *get_ban_data(Channel *c, User *u) } if ((*it)->mask.equals_ci(mask)) { - (*it)->last_use = now; + (*it)->last_use = Anope::CurTime; return *it; } } @@ -409,7 +406,7 @@ static BanData *get_ban_data(Channel *c, User *u) /* If we fall here it is that we haven't found the record */ BanData *bd = new BanData(); bd->mask = mask; - bd->last_use = now; + bd->last_use = Anope::CurTime; for (int x = 0; x < TTB_SIZE; ++x) bd->ttb[x] = 0; @@ -435,15 +432,13 @@ static UserData *get_user_data(Channel *c, User *u) if (uc->user == u) { - time_t now = time(NULL); - /* Checks whether data is obsolete */ - if (now - uc->ud.last_use > Config->BSKeepData) + if (Anope::CurTime - uc->ud.last_use > Config->BSKeepData) { /* We should not free and realloc, but reset to 0 instead. */ uc->ud.Clear(); - uc->ud.last_use = now; + uc->ud.last_use = Anope::CurTime; } return &uc->ud; @@ -590,7 +585,7 @@ void bot_raw_mode(User *requester, ChannelInfo *ci, const Anope::string &mode, c if (!u || !ci->c->FindUser(u)) return; - snprintf(buf, BUFSIZE - 1, "%ld", static_cast<long>(time(NULL))); + snprintf(buf, BUFSIZE - 1, "%ld", static_cast<long>(Anope::CurTime)); if (ModeManager::FindUserModeByName(UMODE_PROTECTED) && u->IsProtected() && mode[0] == '-' && requester != u) { diff --git a/src/channels.cpp b/src/channels.cpp index 882dc887a..76db386e4 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -172,7 +172,7 @@ void Channel::JoinUser(User *user) if (this->FindUser(this->ci->bi) && this->ci->botflags.HasFlag(BS_GREET) && user->Account() && !user->Account()->greet.empty() && check_access(user, this->ci, CA_GREET) && user->server->IsSynced()) { ircdproto->SendPrivmsg(this->ci->bi, this->name, "[%s] %s", user->Account()->display.c_str(), user->Account()->greet.c_str()); - this->ci->bi->lastmsg = time(NULL); + this->ci->bi->lastmsg = Anope::CurTime; } } @@ -1114,7 +1114,6 @@ User *nc_on_chan(Channel *c, const NickCore *nc) void do_join(const Anope::string &source, int ac, const char **av) { User *user; - time_t ctime = time(NULL); user = finduser(source); if (!user) @@ -1146,7 +1145,7 @@ void do_join(const Anope::string &source, int ac, const char **av) /* Channel doesn't exist, create it */ if (!chan) - chan = new Channel(av[0], ctime); + chan = new Channel(av[0], Anope::CurTime); /* Join came with a TS */ if (ac == 2) @@ -1292,12 +1291,12 @@ void do_cmode(const Anope::string &source, int ac, const char **av) return; } - if (source.find('.') != Anope::string::npos && Anope::string(av[1]).find_first_of("bovahq") == Anope::string::npos) + if (source.find('.') != Anope::string::npos && Anope::string(av[1]).find_first_of("bovahq") == Anope::string::npos) // XXX { - if (time(NULL) != c->server_modetime) + if (Anope::CurTime != c->server_modetime) { c->server_modecount = 0; - c->server_modetime = time(NULL); + c->server_modetime = Anope::CurTime; } ++c->server_modecount; } diff --git a/src/chanserv.cpp b/src/chanserv.cpp index b6df9d8cd..c0ae4efd9 100644 --- a/src/chanserv.cpp +++ b/src/chanserv.cpp @@ -244,7 +244,6 @@ void cs_init() void check_modes(Channel *c) { - time_t t = time(NULL); ChannelInfo *ci; ChannelMode *cm; std::map<char, ChannelMode *>::iterator it, it_end; @@ -268,10 +267,10 @@ void check_modes(Channel *c) return; } - if (c->chanserv_modetime != t) + if (c->chanserv_modetime != Anope::CurTime) { c->chanserv_modecount = 0; - c->chanserv_modetime = t; + c->chanserv_modetime = Anope::CurTime; } c->chanserv_modecount++; @@ -462,7 +461,7 @@ void restore_topic(const Anope::string &chan) */ ci->last_topic.clear(); ci->last_topic_setter = whosends(ci)->nick; - ci->last_topic_time = time(NULL); + ci->last_topic_time = Anope::CurTime; return; } if (!ci->last_topic.empty()) @@ -522,7 +521,7 @@ int check_topiclock(Channel *c, time_t topic_time) /* Because older timestamps are rejected */ /* Some how the topic_time from do_topic is 0 set it to current + 1 */ if (!topic_time) - c->topic_time = time(NULL) + 1; + c->topic_time = Anope::CurTime + 1; else c->topic_time = topic_time + 1; } @@ -532,7 +531,7 @@ int check_topiclock(Channel *c, time_t topic_time) if (!ci->last_topic.empty()) c->topic_time = ci->last_topic_time; else - c->topic_time = time(NULL) + 1; + c->topic_time = Anope::CurTime + 1; } if (ircd->join2set && whosends(ci) == ChanServ) @@ -557,14 +556,12 @@ void expire_chans() if (!Config->CSExpire) return; - time_t now = time(NULL); - for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end; ) { ChannelInfo *ci = it->second; ++it; - if (!ci->c && now - ci->last_used >= Config->CSExpire && !ci->HasFlag(CI_FORBIDDEN) && !ci->HasFlag(CI_NO_EXPIRE) && !ci->HasFlag(CI_SUSPENDED)) + if (!ci->c && Anope::CurTime - ci->last_used >= Config->CSExpire && !ci->HasFlag(CI_FORBIDDEN) && !ci->HasFlag(CI_NO_EXPIRE) && !ci->HasFlag(CI_SUSPENDED)) { EventReturn MOD_RESULT; FOREACH_RESULT(I_OnPreChanExpire, OnPreChanExpire(ci)); @@ -678,7 +675,7 @@ int check_access(User *user, ChannelInfo *ci, int what) /* Resetting the last used time */ if (level > 0) - ci->last_used = time(NULL); + ci->last_used = Anope::CurTime; /* Superadmin always wins. Always. */ if (user->isSuperAdmin) @@ -794,7 +791,7 @@ void update_cs_lastseen(User *user, ChannelInfo *ci) if (IsFounder(user, ci) || user->IsIdentified() || (user->IsRecognized() && !ci->HasFlag(CI_SECURE))) if ((access = ci->GetAccess(user->Account()))) - access->last_seen = time(NULL); + access->last_seen = Anope::CurTime; } /*************************************************************************/ diff --git a/src/dns.cpp b/src/dns.cpp index 51cd14938..329c03c86 100644 --- a/src/dns.cpp +++ b/src/dns.cpp @@ -192,7 +192,7 @@ inline DNSRecord::DNSRecord() { this->type = DNS_QUERY_NONE; this->record_class = this->ttl = this->rdlength = 0; - this->created = time(NULL); + this->created = Anope::CurTime; } DNSSocket::DNSSocket(const Anope::string &nTargetHost, int nPort) : ClientSocket(nTargetHost, nPort, "", false, SOCK_DGRAM) @@ -471,7 +471,7 @@ bool DNSSocket::ProcessWrite() return cont; } -DNSManager::DNSManager() : Timer(3600, time(NULL), true) +DNSManager::DNSManager() : Timer(3600, Anope::CurTime, true) { this->sock = NULL; @@ -502,11 +502,10 @@ bool DNSManager::CheckCache(DNSRequest *request) { std::multimap<Anope::string, DNSRecord *>::iterator it_end = this->cache.upper_bound(request->address); - time_t now = time(NULL); for (; it != it_end; ++it) { DNSRecord *rec = it->second; - if (rec->created + rec->ttl >= now) + if (rec->created + rec->ttl >= Anope::CurTime) { request->OnLookupComplete(rec); } diff --git a/src/init.cpp b/src/init.cpp index df74aecab..0f6163dd4 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -22,7 +22,7 @@ extern void moduleAddIRCDMsgs(); void introduce_user(const Anope::string &user) { /* Watch out for infinite loops... */ - time_t now = time(NULL); + time_t now = Anope::CurTime; static time_t lasttime = now - 4; if (lasttime >= now - 3) throw FatalException("introduce_user loop detected"); @@ -427,7 +427,7 @@ void Init(int ac, char **av) /* Announce ourselves to the logfile. */ Log() << "Anope " << Anope::Version() << " (ircd protocol: " << ircd->name << ") starting up" << (debug || readonly ? " (options:" : "") << (debug ? " debug" : "") << (readonly ? " readonly" : "") << (debug || readonly ? ")" : ""); - start_time = time(NULL); + start_time = Anope::CurTime; /* Set signal handlers. Catch certain signals to let us do things or * panic as necessary, and ignore all others. diff --git a/src/logger.cpp b/src/logger.cpp index 673f7f9cb..15f69cfb6 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -76,7 +76,7 @@ static Anope::string GetTimeStamp() return tbuf; } -static Anope::string GetLogDate(time_t t = time(NULL)) +static Anope::string GetLogDate(time_t t = Anope::CurTime) { char timestamp[32]; @@ -88,7 +88,7 @@ static Anope::string GetLogDate(time_t t = time(NULL)) return timestamp; } -static inline Anope::string CreateLogName(const Anope::string &file, time_t t = time(NULL)) +static inline Anope::string CreateLogName(const Anope::string &file, time_t t = Anope::CurTime) { return "logs/" + file + "." + GetLogDate(t); } @@ -301,7 +301,7 @@ bool LogInfo::HasType(LogType type) void LogInfo::ProcessMessage(const Log *l) { - static time_t lastwarn = time(NULL); + static time_t lastwarn = Anope::CurTime; if (!l) throw CoreException("Bad values passed to LogInfo::ProcessMessages"); @@ -354,7 +354,7 @@ void LogInfo::ProcessMessage(const Log *l) if (this->LogAge) { - Anope::string oldlog = CreateLogName(target, time(NULL) - 86400 * this->LogAge); + Anope::string oldlog = CreateLogName(target, Anope::CurTime - 86400 * this->LogAge); if (IsFile(oldlog)) { DeleteFile(oldlog.c_str()); @@ -364,10 +364,9 @@ void LogInfo::ProcessMessage(const Log *l) } if (!log || !log->stream.is_open()) { - time_t now = time(NULL); - if (log && lastwarn + 300 > now) + if (log && lastwarn + 300 > Anope::CurTime) { - lastwarn = now; + lastwarn = Anope::CurTime; Log() << "Unable to open logfile " << log->GetName(); } delete log; @@ -382,10 +381,9 @@ void LogInfo::ProcessMessage(const Log *l) if (!log->stream.is_open()) { - time_t now = time(NULL); - if (lastwarn + 300 > now) + if (lastwarn + 300 > Anope::CurTime) { - lastwarn = now; + lastwarn = Anope::CurTime; Log() << "Unable to open logfile " << log->GetName(); delete log; log = NULL; diff --git a/src/mail.cpp b/src/mail.cpp index 666355b0a..55e99e406 100644 --- a/src/mail.cpp +++ b/src/mail.cpp @@ -35,17 +35,15 @@ bool Mail(User *u, NickRequest *nr, const Anope::string &service, const Anope::s if (!u || !nr || subject.empty() || service.empty() || message.empty()) return false; - time_t t = time(NULL); - if (!Config->UseMail) notice_lang(service, u, MAIL_DISABLED); - else if (t - u->lastmail < Config->MailDelay) - notice_lang(service, u, MAIL_DELAYED, Config->MailDelay - t - u->lastmail); + else if (Anope::CurTime - u->lastmail < Config->MailDelay) + notice_lang(service, u, MAIL_DELAYED, Config->MailDelay - Anope::CurTime - u->lastmail); else if (nr->email.empty()) notice_lang(service, u, MAIL_INVALID, nr->nick.c_str()); else { - u->lastmail = nr->lastmail = t; + u->lastmail = nr->lastmail = Anope::CurTime; threadEngine.Start(new MailThread(nr->nick, nr->email, subject, message)); return true; } @@ -58,17 +56,15 @@ bool Mail(User *u, NickCore *nc, const Anope::string &service, const Anope::stri if (!u || !nc || subject.empty() || service.empty() || message.empty()) return false; - time_t t = time(NULL); - if (!Config->UseMail) notice_lang(service, u, MAIL_DISABLED); - else if (t - u->lastmail < Config->MailDelay) - notice_lang(service, u, MAIL_DELAYED, Config->MailDelay - t - u->lastmail); + else if (Anope::CurTime - u->lastmail < Config->MailDelay) + notice_lang(service, u, MAIL_DELAYED, Config->MailDelay - Anope::CurTime - u->lastmail); else if (nc->email.empty()) notice_lang(service, u, MAIL_INVALID, nc->display.c_str()); else { - u->lastmail = nc->lastmail = t; + u->lastmail = nc->lastmail = Anope::CurTime; threadEngine.Start(new MailThread(nc->display, nc->email, subject, message)); return true; } @@ -81,7 +77,7 @@ bool Mail(NickCore *nc, const Anope::string &subject, const Anope::string &messa if (!Config->UseMail || !nc || nc->email.empty() || subject.empty() || message.empty()) return false; - nc->lastmail = time(NULL); + nc->lastmail = Anope::CurTime; threadEngine.Start(new MailThread(nc->display, nc->email, subject, message)); return true; diff --git a/src/main.cpp b/src/main.cpp index d325cdd06..b7fd536e9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -435,17 +435,15 @@ int main(int ac, char **av, char **envp) started = true; /* Set up timers */ - time_t last_check = time(NULL); - ExpireTimer expireTimer(Config->ExpireTimeout, last_check); - UpdateTimer updateTimer(Config->UpdateTimeout, last_check); + time_t last_check = Anope::CurTime; + ExpireTimer expireTimer(Config->ExpireTimeout, Anope::CurTime); + UpdateTimer updateTimer(Config->UpdateTimeout, Anope::CurTime); /*** Main loop. ***/ while (!quitting) { while (!quitting && UplinkSock) { - time_t t = time(NULL); - Log(LOG_DEBUG_2) << "Top of main loop"; if (!readonly && (save_data || shutting_down)) @@ -464,10 +462,10 @@ int main(int ac, char **av, char **envp) break; } - if (t - last_check >= Config->TimeoutCheck) + if (Anope::CurTime - last_check >= Config->TimeoutCheck) { - TimerManager::TickTimers(t); - last_check = t; + TimerManager::TickTimers(Anope::CurTime); + last_check = Anope::CurTime; } /* Process any modes that need to be (un)set */ diff --git a/src/memoserv.cpp b/src/memoserv.cpp index eec5ab7a3..471424970 100644 --- a/src/memoserv.cpp +++ b/src/memoserv.cpp @@ -170,7 +170,6 @@ void memo_send(User *u, const Anope::string &name, const Anope::string &text, in { bool ischan, isforbid; MemoInfo *mi; - time_t now = time(NULL); Anope::string source = u->Account()->display; int is_servoper = u->Account() && u->Account()->IsServicesOper(); @@ -199,9 +198,9 @@ void memo_send(User *u, const Anope::string &name, const Anope::string &text, in notice_lang(Config->s_MemoServ, u, ischan ? CHAN_X_NOT_REGISTERED : NICK_X_NOT_REGISTERED, name.c_str()); } } - else if (z != 2 && Config->MSSendDelay > 0 && u && u->lastmemosend + Config->MSSendDelay > now) + else if (z != 2 && Config->MSSendDelay > 0 && u && u->lastmemosend + Config->MSSendDelay > Anope::CurTime) { - u->lastmemosend = now; + u->lastmemosend = Anope::CurTime; if (!z) notice_lang(Config->s_MemoServ, u, MEMO_SEND_PLEASE_WAIT, Config->MSSendDelay); @@ -220,7 +219,7 @@ void memo_send(User *u, const Anope::string &name, const Anope::string &text, in } else { - u->lastmemosend = now; + u->lastmemosend = Anope::CurTime; Memo *m = new Memo(); mi->memos.push_back(m); m->sender = source; @@ -235,7 +234,7 @@ void memo_send(User *u, const Anope::string &name, const Anope::string &text, in } else m->number = 1; - m->time = time(NULL); + m->time = Anope::CurTime; m->text = text; m->SetFlag(MF_UNREAD); /* Set notify sent flag - DrStein */ diff --git a/src/messages.cpp b/src/messages.cpp index 84365ccea..cd5c9bf97 100644 --- a/src/messages.cpp +++ b/src/messages.cpp @@ -223,7 +223,7 @@ int m_stats(const Anope::string &source, int ac, const char **av) if (u && is_oper(u)) { ircdproto->SendNumeric(Config->ServerName, 211, source, "Server SendBuf SentBytes SentMsgs RecvBuf RecvBytes RecvMsgs ConnTime"); - ircdproto->SendNumeric(Config->ServerName, 211, source, "%s %d %d %d %d %d %d %ld", uplink_server->host.c_str(), UplinkSock->WriteBufferLen(), TotalWritten, -1, UplinkSock->ReadBufferLen(), TotalRead, -1, time(NULL) - start_time); + ircdproto->SendNumeric(Config->ServerName, 211, source, "%s %d %d %d %d %d %d %ld", uplink_server->host.c_str(), UplinkSock->WriteBufferLen(), TotalWritten, -1, UplinkSock->ReadBufferLen(), TotalRead, -1, Anope::CurTime - start_time); } ircdproto->SendNumeric(Config->ServerName, 219, source, "%c :End of /STATS report.", *av[0] ? *av[0] : '*'); @@ -253,7 +253,7 @@ int m_stats(const Anope::string &source, int ac, const char **av) case 'u': { - int uptime = time(NULL) - start_time; + time_t uptime = Anope::CurTime - start_time; ircdproto->SendNumeric(Config->ServerName, 242, source, ":Services up %d day%s, %02d:%02d:%02d", uptime / 86400, uptime / 86400 == 1 ? "" : "s", (uptime / 3600) % 24, (uptime / 60) % 60, uptime % 60); ircdproto->SendNumeric(Config->ServerName, 250, source, ":Current users: %d (%d ops); maximum %d", usercnt, opcnt, maxusercnt); ircdproto->SendNumeric(Config->ServerName, 219, source, "%c :End of /STATS report.", *av[0] ? *av[0] : '*'); @@ -288,7 +288,7 @@ int m_whois(const Anope::string &source, const Anope::string &who) ircdproto->SendNumeric(Config->ServerName, 311, source, "%s %s %s * :%s", bi->nick.c_str(), bi->GetIdent().c_str(), bi->host.c_str(), bi->realname.c_str()); ircdproto->SendNumeric(Config->ServerName, 307, source, "%s :is a registered nick", bi->nick.c_str()); ircdproto->SendNumeric(Config->ServerName, 312, source, "%s %s :%s", bi->nick.c_str(), Config->ServerName.c_str(), Config->ServerDesc.c_str()); - ircdproto->SendNumeric(Config->ServerName, 317, source, "%s %ld %ld :seconds idle, signon time", bi->nick.c_str(), time(NULL) - bi->lastmsg, start_time); + ircdproto->SendNumeric(Config->ServerName, 317, source, "%s %ld %ld :seconds idle, signon time", bi->nick.c_str(), Anope::CurTime - bi->lastmsg, start_time); ircdproto->SendNumeric(Config->ServerName, 318, source, "%s :End of /WHOIS list.", who.c_str()); } else if (!ircd->svshold && (u = finduser(who)) && u->server == Me) diff --git a/src/misc.cpp b/src/misc.cpp index d77ed4d91..225aac592 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -354,17 +354,15 @@ Anope::string duration(const NickCore *nc, time_t seconds) */ Anope::string expire_left(const NickCore *nc, time_t expires) { - time_t now = time(NULL); - char buf[256]; if (!expires) strlcpy(buf, getstring(nc, NO_EXPIRE), sizeof(buf)); - else if (expires <= now) + else if (expires <= Anope::CurTime) strlcpy(buf, getstring(nc, EXPIRES_SOON), sizeof(buf)); else { - time_t diff = expires - now + 59; + time_t diff = expires - Anope::CurTime + 59; if (diff >= 86400) { diff --git a/src/module.cpp b/src/module.cpp index 98eb9b4fd..148901180 100644 --- a/src/module.cpp +++ b/src/module.cpp @@ -23,7 +23,7 @@ Module::Module(const Anope::string &mname, const Anope::string &creator) if (FindModule(this->name)) throw CoreException("Module already exists!"); - this->created = time(NULL); + this->created = Anope::CurTime; this->SetVersion(Anope::Version()); diff --git a/src/nickserv.cpp b/src/nickserv.cpp index 4f3de5d61..58b481468 100644 --- a/src/nickserv.cpp +++ b/src/nickserv.cpp @@ -197,7 +197,7 @@ int validate_user(User *u) if (!na->nc->HasFlag(NI_SECURE) && u->IsRecognized()) { - na->last_seen = time(NULL); + na->last_seen = Anope::CurTime; Anope::string last_usermask = u->GetIdent() + "@" + u->GetDisplayedHost(); na->last_usermask = last_usermask; na->last_realname = u->realname; @@ -245,8 +245,6 @@ int validate_user(User *u) void expire_nicks() { - time_t now = time(NULL); - for (nickalias_map::const_iterator it = NickAliasList.begin(), it_end = NickAliasList.end(); it != it_end; ) { NickAlias *na = it->second; @@ -256,11 +254,11 @@ void expire_nicks() if (u && (na->nc->HasFlag(NI_SECURE) ? u->IsIdentified() : u->IsRecognized())) { Log(LOG_DEBUG_2) << "NickServ: updating last seen time for " << na->nick; - na->last_seen = now; + na->last_seen = Anope::CurTime; continue; } - if (Config->NSExpire && now - na->last_seen >= Config->NSExpire && !na->HasFlag(NS_FORBIDDEN) && !na->HasFlag(NS_NO_EXPIRE) && !na->nc->HasFlag(NI_SUSPENDED)) + if (Config->NSExpire && Anope::CurTime - na->last_seen >= Config->NSExpire && !na->HasFlag(NS_FORBIDDEN) && !na->HasFlag(NS_NO_EXPIRE) && !na->nc->HasFlag(NI_SUSPENDED)) { EventReturn MOD_RESULT; FOREACH_RESULT(I_OnPreNickExpire, OnPreNickExpire(na)); @@ -275,14 +273,12 @@ void expire_nicks() void expire_requests() { - time_t now = time(NULL); - for (nickrequest_map::const_iterator it = NickRequestList.begin(), it_end = NickRequestList.end(); it != it_end; ) { NickRequest *nr = it->second; ++it; - if (Config->NSRExpire && now - nr->requested >= Config->NSRExpire) + if (Config->NSRExpire && Anope::CurTime - nr->requested >= Config->NSRExpire) { Log() << "Request for nick " << nr->nick << " expiring"; delete nr; diff --git a/src/operserv.cpp b/src/operserv.cpp index 1a6f20eb5..2a752b43e 100644 --- a/src/operserv.cpp +++ b/src/operserv.cpp @@ -144,7 +144,7 @@ XLine::XLine(const Anope::string &mask, const Anope::string &reason) : Mask(mask { } -XLine::XLine(const Anope::string &mask, const Anope::string &by, const time_t expires, const Anope::string &reason) : Mask(mask), By(by), Created(time(NULL)), Expires(expires), Reason(reason) +XLine::XLine(const Anope::string &mask, const Anope::string &by, const time_t expires, const Anope::string &reason) : Mask(mask), By(by), Created(Anope::CurTime), Expires(expires), Reason(reason) { } @@ -405,13 +405,11 @@ XLine *XLineManager::HasEntry(const Anope::string &mask) */ XLine *XLineManager::Check(User *u) { - const time_t now = time(NULL); - for (unsigned i = this->XLines.size(); i > 0; --i) { XLine *x = this->XLines[i - 1]; - if (x->Expires && x->Expires < now) + if (x->Expires && x->Expires < Anope::CurTime) { OnExpire(x); delete x; diff --git a/src/process.cpp b/src/process.cpp index 8c5ff71fc..ba7679a52 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -60,21 +60,20 @@ void add_ignore(const Anope::string &nick, time_t delta) for (; ign != ign_end; ++ign) if (mask.equals_ci((*ign)->mask)) break; - time_t now = time(NULL); /* Found one.. */ if (ign != ign_end) { if (!delta) (*ign)->time = 0; - else if ((*ign)->time < now + delta) - (*ign)->time = now + delta; + else if ((*ign)->time < Anope::CurTime + delta) + (*ign)->time = Anope::CurTime + delta; } /* Create new entry.. */ else { IgnoreData *newign = new IgnoreData(); newign->mask = mask; - newign->time = delta ? now + delta : 0; + newign->time = delta ? Anope::CurTime + delta : 0; ignore.push_front(newign); Log(LOG_DEBUG) << "Added new ignore entry for " << mask; } @@ -133,9 +132,8 @@ IgnoreData *get_ignore(const Anope::string &nick) if (Anope::Match(tmp, (*ign)->mask)) break; } - time_t now = time(NULL); /* Check whether the entry has timed out */ - if (ign != ign_end && (*ign)->time && (*ign)->time <= now) + if (ign != ign_end && (*ign)->time && (*ign)->time <= Anope::CurTime) { Log(LOG_DEBUG) << "Expiring ignore entry " << (*ign)->mask; delete *ign; diff --git a/src/protocol.cpp b/src/protocol.cpp index 89730f1da..0e4449d21 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -234,7 +234,7 @@ void IRCDProto::SendSquit(const Anope::string &servname, const Anope::string &me void IRCDProto::SendChangeBotNick(const BotInfo *bi, const Anope::string &newnick) { - send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "NICK %s %ld", newnick.c_str(), static_cast<long>(time(NULL))); + send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "NICK %s %ld", newnick.c_str(), static_cast<long>(Anope::CurTime)); } void IRCDProto::SendForceNickChange(const User *u, const Anope::string &newnick, time_t when) diff --git a/src/regchannel.cpp b/src/regchannel.cpp index f22d3388f..e88065eb5 100644 --- a/src/regchannel.cpp +++ b/src/regchannel.cpp @@ -51,7 +51,7 @@ ChannelInfo::ChannelInfo(const Anope::string &chname) this->bantype = Config->CSDefBantype; this->memos.memomax = Config->MSMaxMemos; - this->last_used = this->time_registered = time(NULL); + this->last_used = this->time_registered = Anope::CurTime; this->ttb = new int16[2 * TTB_SIZE]; for (int i = 0; i < TTB_SIZE; ++i) @@ -578,7 +578,7 @@ bool ChannelInfo::CheckKick(User *user) if ((autokick->HasFlag(AK_ISNICK) && autokick->nc == nc) || (!autokick->HasFlag(AK_ISNICK) && match_usermask(autokick->mask, user))) { Log(LOG_DEBUG_2) << user->nick << " matched akick " << (autokick->HasFlag(AK_ISNICK) ? autokick->nc->display : autokick->mask); - autokick->last_used = time(NULL); + autokick->last_used = Anope::CurTime; if (autokick->HasFlag(AK_ISNICK)) get_idealban(this, user, mask); else diff --git a/src/servers.cpp b/src/servers.cpp index a5721083f..37518e01e 100644 --- a/src/servers.cpp +++ b/src/servers.cpp @@ -86,8 +86,6 @@ Server::~Server() if (Capab.HasFlag(CAPAB_NOQUIT) || Capab.HasFlag(CAPAB_QS)) { - time_t t = time(NULL); - for (user_map::const_iterator it = UserListByNick.begin(), it_end = UserListByNick.end(); it != it_end; ) { User *u = it->second; @@ -98,7 +96,7 @@ Server::~Server() NickAlias *na = findnick(u->nick); if (na && !na->HasFlag(NS_FORBIDDEN) && (!na->nc->HasFlag(NI_SUSPENDED)) && (u->IsRecognized() || u->IsIdentified())) { - na->last_seen = t; + na->last_seen = Anope::CurTime; na->last_quit = this->QReason; } diff --git a/src/sessions.cpp b/src/sessions.cpp index 8f1039fd8..dca3f7c63 100644 --- a/src/sessions.cpp +++ b/src/sessions.cpp @@ -145,7 +145,7 @@ void add_session(const Anope::string &nick, const Anope::string &host, const Ano if (Config->MaxSessionKill && session->hits >= Config->MaxSessionKill && SGLine) { Anope::string akillmask = "*@" + host; - XLine *x = new XLine(akillmask, Config->s_OperServ, time(NULL) + Config->SessionAutoKillExpiry, "Session limit exceeded"); + XLine *x = new XLine(akillmask, Config->s_OperServ, Anope::CurTime + Config->SessionAutoKillExpiry, "Session limit exceeded"); SGLine->AddXLine(x); ircdproto->SendGlobops(OperServ, "Added a temporary AKILL for \2%s\2 due to excessive connections", akillmask.c_str()); } @@ -215,14 +215,12 @@ void del_session(const Anope::string &host) void expire_exceptions() { - time_t now = time(NULL); - for (std::vector<Exception *>::iterator it = exceptions.begin(), it_end = exceptions.end(); it != it_end; ) { Exception *e = *it; std::vector<Exception *>::iterator curr_it = it++; - if (!e->expires || e->expires > now) + if (!e->expires || e->expires > Anope::CurTime) continue; if (Config->WallExceptionExpire) ircdproto->SendGlobops(OperServ, "Session limit exception for %s has expired.", e->mask.c_str()); @@ -290,7 +288,7 @@ int exception_add(User *u, const Anope::string &mask, int limit, const Anope::st exception->mask = mask; exception->limit = limit; exception->reason = reason; - exception->time = time(NULL); + exception->time = Anope::CurTime; exception->who = who; exception->expires = expires; diff --git a/src/sockets.cpp b/src/sockets.cpp index f58aa2498..4334bf873 100644 --- a/src/sockets.cpp +++ b/src/sockets.cpp @@ -109,6 +109,12 @@ bool sockaddrs::operator==(const sockaddrs &other) const return false; } +/** 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 sockaddrs::pton(int type, const Anope::string &address, int pport) { switch (type) @@ -132,6 +138,11 @@ void sockaddrs::pton(int type, const Anope::string &address, int pport) throw CoreException("Invalid socket type"); } +/** 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 sockaddrs::ntop(int type, const void *src) { switch (type) diff --git a/src/users.cpp b/src/users.cpp index 8c99575b7..e5fe7ee04 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -38,7 +38,7 @@ User::User(const Anope::string &snick, const Anope::string &sident, const Anope: nc = NULL; invalid_pw_count = invalid_pw_time = lastmemosend = lastnickreg = lastmail = 0; OnAccess = false; - timestamp = my_signon = time(NULL); + timestamp = my_signon = Anope::CurTime; this->nick = snick; this->ident = sident; @@ -57,7 +57,7 @@ User::User(const Anope::string &snick, const Anope::string &sident, const Anope: if (usercnt > maxusercnt) { maxusercnt = usercnt; - maxusertime = time(NULL); + maxusertime = Anope::CurTime; Log(this, "maxusers") << "connected - new maximum user count: " << maxusercnt; } } @@ -315,7 +315,7 @@ void User::Collide(NickAlias *na) } while (finduser(guestnick)); notice_lang(Config->s_NickServ, this, FORCENICKCHANGE_CHANGING, guestnick.c_str()); - ircdproto->SendForceNickChange(this, guestnick, time(NULL)); + ircdproto->SendForceNickChange(this, guestnick, Anope::CurTime); } else kill_user(Config->s_NickServ, this->nick, "Services nickname-enforcer kill"); @@ -665,7 +665,6 @@ User *do_nick(const Anope::string &source, const Anope::string &nick, const Anop user->server = serv; user->realname = realname; user->timestamp = ts; - user->my_signon = time(NULL); if (!vhost2.empty()) user->SetCloakedHost(vhost2); user->SetVIdent(username); @@ -726,11 +725,11 @@ User *do_nick(const Anope::string &source, const Anope::string &nick, const Anop else { /* Update this only if nicks aren't the same */ - user->my_signon = time(NULL); + user->my_signon = Anope::CurTime; NickAlias *old_na = findnick(user->nick); if (old_na && (old_na->nc == user->Account() || user->IsRecognized())) - old_na->last_seen = time(NULL); + old_na->last_seen = Anope::CurTime; Anope::string oldnick = user->nick; user->SetNewNick(nick); @@ -750,7 +749,7 @@ User *do_nick(const Anope::string &source, const Anope::string &nick, const Anop } else { - na->last_seen = time(NULL); + na->last_seen = Anope::CurTime; user->UpdateHost(); do_on_id(user); ircdproto->SetAutoIdentificationToken(user); @@ -807,7 +806,7 @@ void do_quit(const Anope::string &source, int ac, const char **av) NickAlias *na = findnick(user->nick); if (na && !na->HasFlag(NS_FORBIDDEN) && !na->nc->HasFlag(NI_SUSPENDED) && (user->IsRecognized() || user->IsIdentified(true))) { - na->last_seen = time(NULL); + na->last_seen = Anope::CurTime; na->last_quit = *av[0] ? av[0] : ""; } FOREACH_MOD(I_OnUserQuit, OnUserQuit(user, *av[0] ? av[0] : "")); @@ -835,7 +834,7 @@ void do_kill(const Anope::string &nick, const Anope::string &msg) NickAlias *na = findnick(user->nick); if (na && !na->HasFlag(NS_FORBIDDEN) && !na->nc->HasFlag(NI_SUSPENDED) && (user->IsRecognized() || user->IsIdentified(true))) { - na->last_seen = time(NULL); + na->last_seen = Anope::CurTime; na->last_quit = msg; } delete user; |