| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465 |
- /*
- * Copyright (C) 2000,2001 Florian Sander
- *
- * 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.
- */
- static int inactivechan(char *chan)
- {
- #ifndef NO_EGG
- struct chanset_t *ch;
- ch = findchan_by_dname(chan);
- if (!ch)
- return 0;
- if (ch->status & CHAN_INACTIVE)
- return 1;
- #endif
- return 0;
- }
- static int nostats(char *chan)
- {
- #if EGG_IS_MIN_VER(10503)
- if (ngetudef("nostats", chan))
- return 1;
- #endif
- return 0;
- }
- static int sensor_pubm(char *nick, char *uhost, char *hand, char *chan, char *rest)
- {
- int i, hour;
- char buf[511];
- struct stats_member *m;
- globstats *gs;
- if (nostats(chan))
- return 0;
- strncpy(buf, rest, 510);
- buf[510] = 0;
- rest = buf;
- gs = findglobstats(chan);
- if (!gs) {
- debug1("No stats structure for channel '%s'.", chan);
- return 0;
- }
- hour = gethour();
- gs->activity[hour]++;
- add_chanlog(gs, nick, rest, SL_PRIVMSG);
- m = getschanmember(nick, chan);
- if (!m) {
- check_for_url(nick, chan, rest);
- return 0;
- }
- // increase spoken lines (needed for autoadd)
- // if there's no link to the stats, call initstats() which either
- // returns an existing stats struct, or initializes a new one
- m->spoken_lines++;
- if (!m->user) {
- check_for_url(nick, chan, rest);
- return 0;
- }
- check_for_url(m->user->user, chan, rest);
- if (!m->stats)
- m->stats = initstats(chan, m->user->user);
- m->stats->lastspoke = now;
- nincrstats(m->stats, T_WORDS, countwords(rest));
- nincrstats(m->stats, T_LETTERS, strlen(rest));
- nincrstats(m->stats, T_LINES, 1);
- i = countsmileys(rest);
- if (i)
- nincrstats(m->stats, T_SMILEYS, i);
- i = countquestions(rest);
- if (i)
- nincrstats(m->stats, T_QUESTIONS, i);
- addquote(hand, gs, rest, m->stats);
- calcwordstats(hand, gs, rest, m->stats);
- return 0;
- }
- static void sensor_minutely()
- {
- struct stats_chanset *ch;
- struct stats_memberlist *mm;
- Context;
- for (chan = schan_getfirst(); chan; chan = schan_getnext()) {
- }
-
- for (ch = schans; ch; ch = ch->next) {
- if (nostats(ch->chan))
- continue;
- for (mm = ch->members; mm; mm = mm->next) {
- if (mm->user) {
- if (!mm->stats)
- mm->stats = initstats(ch->chan, mm->user->user);
- // now let's use a generic flag to check if we already increased this
- // user's minutes (if he's a clone, for example)
- // (thanks to Zev for this idea)
- if (mm->stats->flag)
- continue;
- nincrstats(mm->stats, T_MINUTES, 1);
- mm->stats->flag = 1;
- } else {
- stats_autosadd(mm, ch);
- }
- }
- // now reset the flag
- for (mm = ch->members; mm; mm = mm->next)
- if (mm->stats)
- mm->stats->flag = 0;
- }
- }
- static void sensor_countusers()
- {
- struct chanset_t *chan;
- struct stats_chanset *ch;
- struct stats_memberlist *mm;
- globstats *gs;
- int hour, nr;
- for (chan = chanset; chan; chan = chan->next) {
- if (chan->channel.members < 1)
- continue;
- nr = 0;
- #if EGG_IS_MIN_VER(10500)
- if (nostats(chan->name))
- continue;
- gs = findglobstats(chan->dname);
- #else
- if (nostats(chan->name))
- continue;
- gs = findglobstats(chan->name);
- #endif
- if (!gs)
- continue;
- #if EGG_IS_MIN_VER(10500)
- ch = findschan(chan->dname);
- #else
- ch = findschan(chan->name);
- #endif
- if (!ch)
- continue;
- for (mm = ch->members; mm; mm = mm->next) {
- if (mm->user && !suser_list(mm->user))
- continue;
- nr++;
- }
- hour = gethour();
- if (hour != lasthour) {
- gs->users[S_USERSUM][hour] = nr;
- gs->users[S_USERCOUNTS][hour] = 1;
- lasthour = hour;
- } else {
- gs->users[S_USERSUM][hour] += nr;
- if (gs->users[S_USERCOUNTS][hour] < 0)
- gs->users[S_USERCOUNTS][hour] = 1;
- else
- gs->users[S_USERCOUNTS][hour]++;
- }
- }
- }
- static void sensor_peak(char *channel)
- {
- struct chanset_t *chan;
- memberlist *m;
- struct stats_chanset *ch;
- struct stats_memberlist *mm;
- globstats *gs;
- int users = 0;
- if (nostats(channel))
- return;
- gs = findglobstats(channel);
- if (!gs)
- return;
- #ifndef OLDBOT
- chan = findchan_by_dname(channel);
- #else
- chan = findchan(channel);
- #endif
- if (!chan)
- return;
- if (use_userfile) {
- if (chan->channel.members > 0) {
- for (m = chan->channel.member; m; m = m->next) {
- if (!m->nick[0])
- continue;
- if (m->user) {
- if (matchattr(m->user, nopeak, channel))
- continue;
- }
- users++;
- }
- }
- } else {
- #if EGG_IS_MIN_VER(10500)
- ch = findschan(chan->dname);
- #else
- ch = findschan(chan->name);
- #endif
- if (!ch)
- return;
- for (mm = ch->members; mm; mm = mm->next) {
- if (mm->user && !suser_list(mm->user))
- continue;
- users++;
- }
- }
- if (users > gs->peak[S_TOTAL]) {
- gs->peak[S_TOTAL] = users;
- putlog(LOG_MISC, "*", "New user peak in %s: %d.", channel, users);
- }
- if (users > gs->peak[S_TODAY])
- gs->peak[S_TODAY] = users;
- if (users > gs->peak[S_WEEKLY])
- gs->peak[S_WEEKLY] = users;
- if (users > gs->peak[S_MONTHLY])
- gs->peak[S_MONTHLY] = users;
- }
- static int sensor_topc(char *nick, char *uhost, char *hand, char *chan, char *topic)
- {
- struct stats_memberlist *m;
- Context;
- if (nostats(chan))
- return 0;
- if (!use_userfile) {
- m = nick2suser(nick, chan);
- if (!m)
- return 0;
- if (!m->user)
- return 0;
- if (!m->stats)
- m->stats = initstats(chan, m->user->user);
- nincrstats(m->stats, T_TOPICS, 1);
- } else if (hand[0] != '*')
- incrstats(hand, chan, T_TOPICS, 1, 0);
- addtopic(chan, topic, nick);
- return 0;
- }
- static int sensor_action(char *nick, char *uhost, char *hand, char *chan, char *key, char *rest)
- {
- char *pbuf;
- struct stats_memberlist *m;
- if (!strchr(CHANMETA, chan[0]))
- return 0;
- if (nostats(chan))
- return 0;
- if (!use_userfile) {
- m = nick2suser(nick, chan);
- if (!m)
- return 0;
- if (!m->user)
- return 0;
- if (!m->stats)
- m->stats = initstats(chan, m->user->user);
- nincrstats(m->stats, T_ACTIONS, 1);
- } else if (hand[0] != '*')
- incrstats(hand, chan, T_ACTIONS, 1, 0);
- pbuf = nmalloc(strlen(nick) + strlen(rest) + 2);
- sprintf(pbuf, "%s %s", nick, rest);
- sensor_pubm(nick, uhost, hand, chan, pbuf);
- nfree(pbuf);
- return 0;
- }
- static int sensor_kick(char *nick, char *uhost, char *hand, char *chan, char *victim, char *reason)
- {
- struct stats_memberlist *m;
- char *buf;
- globstats *gs;
- if (nostats(chan))
- return 0;
- gs = findglobstats(chan);
- buf = nmalloc(strlen(victim) + strlen(nick) + strlen(reason) + 23);
- sprintf(buf, "*** %s was kicked by %s (%s)", victim, nick, reason);
- add_chanlog(gs, nick, buf, SL_KICK);
- save_kick(gs, buf);
- nfree(buf);
- skillmember(chan, victim);
- if (!use_userfile) {
- m = nick2suser(nick, chan);
- if (!m)
- return 0;
- if (!m->user)
- return 0;
- if (!m->stats)
- m->stats = initstats(chan, m->user->user);
- nincrstats(m->stats, T_KICKS, 1);
- } else if (hand[0] != '*')
- incrstats(hand, chan, T_KICKS, 1, 0);
- return 0;
- }
- static int sensor_mode(char *nick, char *uhost, char *hand, char *chan, char *mode, char *victim)
- {
- struct stats_memberlist *m;
- char *buf;
- if (nostats(chan))
- return 0;
- buf = nmalloc(strlen(nick) + strlen(mode) + strlen(victim) + 13);
- sprintf(buf, "%s sets mode %s %s", nick, mode, victim);
- add_chanlog(findglobstats(chan), nick, buf, SL_MODE);
- nfree(buf);
- if (!use_userfile) {
- m = nick2suser(nick, chan);
- if (!m)
- return 0;
- if (!m->user)
- return 0;
- if (!m->stats)
- m->stats = initstats(chan, m->user->user);
- nincrstats(m->stats, T_MODES, 1);
- if ((mode[1] == 'b') && (mode[0] == '+'))
- nincrstats(m->stats, T_BANS, 1);
- } else if (hand[0] != '*') {
- incrstats(hand, chan, T_MODES, 1, 0);
- if ((mode[1] == 'b') && (mode[0] == '+'))
- incrstats(hand, chan, T_BANS, 1, 0);
- }
- return 0;
- }
- static int sensor_nick(char *nick, char *uhost, char *hand, char *chan, char *newnick)
- {
- struct stats_memberlist *m;
- if (nostats(chan))
- return 0;
- add_chanlog(findglobstats(chan), nick, newnick, SL_NICK);
- strackmember(chan, nick, newnick);
- if (!use_userfile) {
- m = nick2suser(newnick, chan);
- if (!m)
- return 0;
- if (!m->user)
- return 0;
- if (!m->stats)
- m->stats = initstats(chan, m->user->user);
- nincrstats(m->stats, T_NICKS, 1);
- } else if (hand[0] != '*')
- incrstats(hand, chan, T_NICKS, 1, 0);
- return 0;
- }
- static int sensor_join(char *nick, char *uhost, char *hand, char *chan)
- {
- struct stats_memberlist *m;
- if (nostats(chan))
- return 0;
- add_chanlog(findglobstats(chan), nick, NULL, SL_JOIN);
- if (match_my_nick(nick))
- free_one_chan(chan);
- else
- saddmember(nick, uhost, hand, chan);
- sensor_peak(chan);
- if (!use_userfile) {
- m = nick2suser(nick, chan);
- if (!m)
- return 0;
- if (!m->user)
- return 0;
- if (!m->stats)
- m->stats = initstats(chan, m->user->user);
- nincrstats(m->stats, T_JOINS, 1);
- } else if (hand[0] != '*')
- incrstats(hand, chan, T_JOINS, 1, 0);
- addhost(uhost, findglobstats(chan));
- return 0;
- }
- static int sensor_part(char *nick, char *uhost, char *hand, char *chan)
- {
- if (nostats(chan))
- return 0;
- add_chanlog(findglobstats(chan), nick, NULL, SL_PART);
- skillmember(chan, nick);
- return 0;
- }
- static int sensor_sign(char *nick, char *uhost, char *hand, char *chan, char *reason)
- {
- if (nostats(chan))
- return 0;
- add_chanlog(findglobstats(chan), nick, reason, SL_QUIT);
- skillmember(chan, nick);
- return 0;
- }
- static cmd_t stats_pubm[] =
- {
- {"*", "", (Function) sensor_pubm, "stat"},
- {0, 0, 0, 0}
- };
- static cmd_t stats_topc[] =
- {
- {"*", "", (Function) sensor_topc, "stat"},
- {0, 0, 0, 0}
- };
- static cmd_t stats_ctcp[] =
- {
- {"ACTION", "", (Function) sensor_action, "stat"},
- {0, 0, 0, 0}
- };
- static cmd_t stats_kick[] =
- {
- {"*", "", (Function) sensor_kick, "stat"},
- {0, 0, 0, 0}
- };
- static cmd_t stats_mode[] =
- {
- {"*", "", (Function) sensor_mode, "stat"},
- {0, 0, 0, 0}
- };
- static cmd_t stats_nick[] =
- {
- {"*", "", (Function) sensor_nick, "stat"},
- {0, 0, 0, 0}
- };
- static cmd_t stats_join[] =
- {
- {"*", "", (Function) sensor_join, "stat"},
- {0, 0, 0, 0}
- };
- static cmd_t stats_part[] =
- {
- {"*", "", (Function) sensor_part, "stat"},
- {0, 0, 0, 0}
- };
- static cmd_t stats_sign[] =
- {
- {"*", "", (Function) sensor_sign, "stat"},
- {0, 0, 0, 0}
- };
|