This repository has been archived on 2025-02-12. You can view files and clone it, but cannot push or open issues or pull requests.
NeoStats/timer.c

92 lines
2.1 KiB
C
Raw Permalink Normal View History

/* NeoStats - IRC Statistical Services
2004-01-14 11:36:37 +00:00
** Copyright (c) 1999-2004 Adam Rutter, Justin Hammond
** http://www.neostats.net/
**
** Portions Copyright (c) 2000-2001 ^Enigma^
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
** USA
**
** NeoStats CVS Identification
** $Id$
2000-02-03 23:45:51 +00:00
*/
2000-02-03 23:45:51 +00:00
#include "stats.h"
#include "dl.h"
2003-04-11 09:26:31 +00:00
#include "log.h"
#include "conf.h"
#include "server.h"
2000-02-03 23:45:51 +00:00
static int midnight = 0;
2004-02-03 21:38:06 +00:00
#ifdef GOTSVSTIME
static int lastservertimesync = 0;
#endif
2000-02-03 23:45:51 +00:00
2003-10-14 15:29:41 +00:00
static int is_midnight (void);
static void TimerMidnight (void);
2003-07-30 13:58:22 +00:00
void
2003-10-14 15:29:41 +00:00
CheckTimers (void)
2000-02-03 23:45:51 +00:00
{
run_mod_timers();
2003-09-18 12:21:32 +00:00
SET_SEGV_LOCATION();
if (me.now - ping.last_sent > me.pingtime) {
PingServers ();
flush_keeper();
ping.last_sent = me.now;
#ifdef DEBUG
verify_hashes();
#endif
/* flush log files */
2003-07-30 13:58:22 +00:00
fflush (NULL);
2000-02-03 23:45:51 +00:00
}
2004-02-03 21:38:06 +00:00
#ifdef GOTSVSTIME
2004-02-03 21:54:11 +00:00
if (me.synced && me.setservertimes) {
2004-02-03 21:38:06 +00:00
if((me.now - lastservertimesync) > me.setservertimes) {
2004-02-03 21:54:11 +00:00
/* The above check does not need to be exact, but
setting times ought to be so reset me.now */
me.now = time(NULL);
2004-02-03 21:38:06 +00:00
ssvstime_cmd (me.now);
lastservertimesync = me.now;
}
}
#endif
2003-07-30 13:58:22 +00:00
if (is_midnight () == 1 && midnight == 0) {
TimerMidnight ();
2000-02-03 23:45:51 +00:00
midnight = 1;
} else {
2003-07-30 13:58:22 +00:00
if (midnight == 1 && is_midnight () == 0)
2000-02-03 23:45:51 +00:00
midnight = 0;
}
2000-02-03 23:45:51 +00:00
}
static void
2003-10-14 15:29:41 +00:00
TimerMidnight (void)
2000-02-03 23:45:51 +00:00
{
nlog (LOG_DEBUG1, LOG_CORE, "Its midnight!!! -> %s", sctime (me.now));
reset_logs ();
2000-02-03 23:45:51 +00:00
}
2003-10-14 15:29:41 +00:00
static int
is_midnight (void)
2000-02-03 23:45:51 +00:00
{
struct tm *ltm = localtime (&me.now);
2000-02-03 23:45:51 +00:00
2004-01-12 00:29:53 +00:00
if (ltm->tm_hour == 0 && ltm->tm_min == 0)
2000-02-03 23:45:51 +00:00
return 1;
return 0;
2000-02-03 23:45:51 +00:00
}