sensors_old.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. /*
  2. * Copyright (C) 2000,2001 Florian Sander
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. static int inactivechan(char *chan)
  19. {
  20. #ifndef NO_EGG
  21. struct chanset_t *ch;
  22. ch = findchan_by_dname(chan);
  23. if (!ch)
  24. return 0;
  25. if (ch->status & CHAN_INACTIVE)
  26. return 1;
  27. #endif
  28. return 0;
  29. }
  30. static int nostats(char *chan)
  31. {
  32. #if EGG_IS_MIN_VER(10503)
  33. if (ngetudef("nostats", chan))
  34. return 1;
  35. #endif
  36. return 0;
  37. }
  38. static int sensor_pubm(char *nick, char *uhost, char *hand, char *chan, char *rest)
  39. {
  40. int i, hour;
  41. char buf[511];
  42. struct stats_member *m;
  43. globstats *gs;
  44. if (nostats(chan))
  45. return 0;
  46. strncpy(buf, rest, 510);
  47. buf[510] = 0;
  48. rest = buf;
  49. gs = findglobstats(chan);
  50. if (!gs) {
  51. debug1("No stats structure for channel '%s'.", chan);
  52. return 0;
  53. }
  54. hour = gethour();
  55. gs->activity[hour]++;
  56. add_chanlog(gs, nick, rest, SL_PRIVMSG);
  57. m = getschanmember(nick, chan);
  58. if (!m) {
  59. check_for_url(nick, chan, rest);
  60. return 0;
  61. }
  62. // increase spoken lines (needed for autoadd)
  63. // if there's no link to the stats, call initstats() which either
  64. // returns an existing stats struct, or initializes a new one
  65. m->spoken_lines++;
  66. if (!m->user) {
  67. check_for_url(nick, chan, rest);
  68. return 0;
  69. }
  70. check_for_url(m->user->user, chan, rest);
  71. if (!m->stats)
  72. m->stats = initstats(chan, m->user->user);
  73. m->stats->lastspoke = now;
  74. nincrstats(m->stats, T_WORDS, countwords(rest));
  75. nincrstats(m->stats, T_LETTERS, strlen(rest));
  76. nincrstats(m->stats, T_LINES, 1);
  77. i = countsmileys(rest);
  78. if (i)
  79. nincrstats(m->stats, T_SMILEYS, i);
  80. i = countquestions(rest);
  81. if (i)
  82. nincrstats(m->stats, T_QUESTIONS, i);
  83. addquote(hand, gs, rest, m->stats);
  84. calcwordstats(hand, gs, rest, m->stats);
  85. return 0;
  86. }
  87. static void sensor_minutely()
  88. {
  89. struct stats_chanset *ch;
  90. struct stats_memberlist *mm;
  91. Context;
  92. for (chan = schan_getfirst(); chan; chan = schan_getnext()) {
  93. }
  94. for (ch = schans; ch; ch = ch->next) {
  95. if (nostats(ch->chan))
  96. continue;
  97. for (mm = ch->members; mm; mm = mm->next) {
  98. if (mm->user) {
  99. if (!mm->stats)
  100. mm->stats = initstats(ch->chan, mm->user->user);
  101. // now let's use a generic flag to check if we already increased this
  102. // user's minutes (if he's a clone, for example)
  103. // (thanks to Zev for this idea)
  104. if (mm->stats->flag)
  105. continue;
  106. nincrstats(mm->stats, T_MINUTES, 1);
  107. mm->stats->flag = 1;
  108. } else {
  109. stats_autosadd(mm, ch);
  110. }
  111. }
  112. // now reset the flag
  113. for (mm = ch->members; mm; mm = mm->next)
  114. if (mm->stats)
  115. mm->stats->flag = 0;
  116. }
  117. }
  118. static void sensor_countusers()
  119. {
  120. struct chanset_t *chan;
  121. struct stats_chanset *ch;
  122. struct stats_memberlist *mm;
  123. globstats *gs;
  124. int hour, nr;
  125. for (chan = chanset; chan; chan = chan->next) {
  126. if (chan->channel.members < 1)
  127. continue;
  128. nr = 0;
  129. #if EGG_IS_MIN_VER(10500)
  130. if (nostats(chan->name))
  131. continue;
  132. gs = findglobstats(chan->dname);
  133. #else
  134. if (nostats(chan->name))
  135. continue;
  136. gs = findglobstats(chan->name);
  137. #endif
  138. if (!gs)
  139. continue;
  140. #if EGG_IS_MIN_VER(10500)
  141. ch = findschan(chan->dname);
  142. #else
  143. ch = findschan(chan->name);
  144. #endif
  145. if (!ch)
  146. continue;
  147. for (mm = ch->members; mm; mm = mm->next) {
  148. if (mm->user && !suser_list(mm->user))
  149. continue;
  150. nr++;
  151. }
  152. hour = gethour();
  153. if (hour != lasthour) {
  154. gs->users[S_USERSUM][hour] = nr;
  155. gs->users[S_USERCOUNTS][hour] = 1;
  156. lasthour = hour;
  157. } else {
  158. gs->users[S_USERSUM][hour] += nr;
  159. if (gs->users[S_USERCOUNTS][hour] < 0)
  160. gs->users[S_USERCOUNTS][hour] = 1;
  161. else
  162. gs->users[S_USERCOUNTS][hour]++;
  163. }
  164. }
  165. }
  166. static void sensor_peak(char *channel)
  167. {
  168. struct chanset_t *chan;
  169. memberlist *m;
  170. struct stats_chanset *ch;
  171. struct stats_memberlist *mm;
  172. globstats *gs;
  173. int users = 0;
  174. if (nostats(channel))
  175. return;
  176. gs = findglobstats(channel);
  177. if (!gs)
  178. return;
  179. #ifndef OLDBOT
  180. chan = findchan_by_dname(channel);
  181. #else
  182. chan = findchan(channel);
  183. #endif
  184. if (!chan)
  185. return;
  186. if (use_userfile) {
  187. if (chan->channel.members > 0) {
  188. for (m = chan->channel.member; m; m = m->next) {
  189. if (!m->nick[0])
  190. continue;
  191. if (m->user) {
  192. if (matchattr(m->user, nopeak, channel))
  193. continue;
  194. }
  195. users++;
  196. }
  197. }
  198. } else {
  199. #if EGG_IS_MIN_VER(10500)
  200. ch = findschan(chan->dname);
  201. #else
  202. ch = findschan(chan->name);
  203. #endif
  204. if (!ch)
  205. return;
  206. for (mm = ch->members; mm; mm = mm->next) {
  207. if (mm->user && !suser_list(mm->user))
  208. continue;
  209. users++;
  210. }
  211. }
  212. if (users > gs->peak[S_TOTAL]) {
  213. gs->peak[S_TOTAL] = users;
  214. putlog(LOG_MISC, "*", "New user peak in %s: %d.", channel, users);
  215. }
  216. if (users > gs->peak[S_TODAY])
  217. gs->peak[S_TODAY] = users;
  218. if (users > gs->peak[S_WEEKLY])
  219. gs->peak[S_WEEKLY] = users;
  220. if (users > gs->peak[S_MONTHLY])
  221. gs->peak[S_MONTHLY] = users;
  222. }
  223. static int sensor_topc(char *nick, char *uhost, char *hand, char *chan, char *topic)
  224. {
  225. struct stats_memberlist *m;
  226. Context;
  227. if (nostats(chan))
  228. return 0;
  229. if (!use_userfile) {
  230. m = nick2suser(nick, chan);
  231. if (!m)
  232. return 0;
  233. if (!m->user)
  234. return 0;
  235. if (!m->stats)
  236. m->stats = initstats(chan, m->user->user);
  237. nincrstats(m->stats, T_TOPICS, 1);
  238. } else if (hand[0] != '*')
  239. incrstats(hand, chan, T_TOPICS, 1, 0);
  240. addtopic(chan, topic, nick);
  241. return 0;
  242. }
  243. static int sensor_action(char *nick, char *uhost, char *hand, char *chan, char *key, char *rest)
  244. {
  245. char *pbuf;
  246. struct stats_memberlist *m;
  247. if (!strchr(CHANMETA, chan[0]))
  248. return 0;
  249. if (nostats(chan))
  250. return 0;
  251. if (!use_userfile) {
  252. m = nick2suser(nick, chan);
  253. if (!m)
  254. return 0;
  255. if (!m->user)
  256. return 0;
  257. if (!m->stats)
  258. m->stats = initstats(chan, m->user->user);
  259. nincrstats(m->stats, T_ACTIONS, 1);
  260. } else if (hand[0] != '*')
  261. incrstats(hand, chan, T_ACTIONS, 1, 0);
  262. pbuf = nmalloc(strlen(nick) + strlen(rest) + 2);
  263. sprintf(pbuf, "%s %s", nick, rest);
  264. sensor_pubm(nick, uhost, hand, chan, pbuf);
  265. nfree(pbuf);
  266. return 0;
  267. }
  268. static int sensor_kick(char *nick, char *uhost, char *hand, char *chan, char *victim, char *reason)
  269. {
  270. struct stats_memberlist *m;
  271. char *buf;
  272. globstats *gs;
  273. if (nostats(chan))
  274. return 0;
  275. gs = findglobstats(chan);
  276. buf = nmalloc(strlen(victim) + strlen(nick) + strlen(reason) + 23);
  277. sprintf(buf, "*** %s was kicked by %s (%s)", victim, nick, reason);
  278. add_chanlog(gs, nick, buf, SL_KICK);
  279. save_kick(gs, buf);
  280. nfree(buf);
  281. skillmember(chan, victim);
  282. if (!use_userfile) {
  283. m = nick2suser(nick, chan);
  284. if (!m)
  285. return 0;
  286. if (!m->user)
  287. return 0;
  288. if (!m->stats)
  289. m->stats = initstats(chan, m->user->user);
  290. nincrstats(m->stats, T_KICKS, 1);
  291. } else if (hand[0] != '*')
  292. incrstats(hand, chan, T_KICKS, 1, 0);
  293. return 0;
  294. }
  295. static int sensor_mode(char *nick, char *uhost, char *hand, char *chan, char *mode, char *victim)
  296. {
  297. struct stats_memberlist *m;
  298. char *buf;
  299. if (nostats(chan))
  300. return 0;
  301. buf = nmalloc(strlen(nick) + strlen(mode) + strlen(victim) + 13);
  302. sprintf(buf, "%s sets mode %s %s", nick, mode, victim);
  303. add_chanlog(findglobstats(chan), nick, buf, SL_MODE);
  304. nfree(buf);
  305. if (!use_userfile) {
  306. m = nick2suser(nick, chan);
  307. if (!m)
  308. return 0;
  309. if (!m->user)
  310. return 0;
  311. if (!m->stats)
  312. m->stats = initstats(chan, m->user->user);
  313. nincrstats(m->stats, T_MODES, 1);
  314. if ((mode[1] == 'b') && (mode[0] == '+'))
  315. nincrstats(m->stats, T_BANS, 1);
  316. } else if (hand[0] != '*') {
  317. incrstats(hand, chan, T_MODES, 1, 0);
  318. if ((mode[1] == 'b') && (mode[0] == '+'))
  319. incrstats(hand, chan, T_BANS, 1, 0);
  320. }
  321. return 0;
  322. }
  323. static int sensor_nick(char *nick, char *uhost, char *hand, char *chan, char *newnick)
  324. {
  325. struct stats_memberlist *m;
  326. if (nostats(chan))
  327. return 0;
  328. add_chanlog(findglobstats(chan), nick, newnick, SL_NICK);
  329. strackmember(chan, nick, newnick);
  330. if (!use_userfile) {
  331. m = nick2suser(newnick, chan);
  332. if (!m)
  333. return 0;
  334. if (!m->user)
  335. return 0;
  336. if (!m->stats)
  337. m->stats = initstats(chan, m->user->user);
  338. nincrstats(m->stats, T_NICKS, 1);
  339. } else if (hand[0] != '*')
  340. incrstats(hand, chan, T_NICKS, 1, 0);
  341. return 0;
  342. }
  343. static int sensor_join(char *nick, char *uhost, char *hand, char *chan)
  344. {
  345. struct stats_memberlist *m;
  346. if (nostats(chan))
  347. return 0;
  348. add_chanlog(findglobstats(chan), nick, NULL, SL_JOIN);
  349. if (match_my_nick(nick))
  350. free_one_chan(chan);
  351. else
  352. saddmember(nick, uhost, hand, chan);
  353. sensor_peak(chan);
  354. if (!use_userfile) {
  355. m = nick2suser(nick, chan);
  356. if (!m)
  357. return 0;
  358. if (!m->user)
  359. return 0;
  360. if (!m->stats)
  361. m->stats = initstats(chan, m->user->user);
  362. nincrstats(m->stats, T_JOINS, 1);
  363. } else if (hand[0] != '*')
  364. incrstats(hand, chan, T_JOINS, 1, 0);
  365. addhost(uhost, findglobstats(chan));
  366. return 0;
  367. }
  368. static int sensor_part(char *nick, char *uhost, char *hand, char *chan)
  369. {
  370. if (nostats(chan))
  371. return 0;
  372. add_chanlog(findglobstats(chan), nick, NULL, SL_PART);
  373. skillmember(chan, nick);
  374. return 0;
  375. }
  376. static int sensor_sign(char *nick, char *uhost, char *hand, char *chan, char *reason)
  377. {
  378. if (nostats(chan))
  379. return 0;
  380. add_chanlog(findglobstats(chan), nick, reason, SL_QUIT);
  381. skillmember(chan, nick);
  382. return 0;
  383. }
  384. static cmd_t stats_pubm[] =
  385. {
  386. {"*", "", (Function) sensor_pubm, "stat"},
  387. {0, 0, 0, 0}
  388. };
  389. static cmd_t stats_topc[] =
  390. {
  391. {"*", "", (Function) sensor_topc, "stat"},
  392. {0, 0, 0, 0}
  393. };
  394. static cmd_t stats_ctcp[] =
  395. {
  396. {"ACTION", "", (Function) sensor_action, "stat"},
  397. {0, 0, 0, 0}
  398. };
  399. static cmd_t stats_kick[] =
  400. {
  401. {"*", "", (Function) sensor_kick, "stat"},
  402. {0, 0, 0, 0}
  403. };
  404. static cmd_t stats_mode[] =
  405. {
  406. {"*", "", (Function) sensor_mode, "stat"},
  407. {0, 0, 0, 0}
  408. };
  409. static cmd_t stats_nick[] =
  410. {
  411. {"*", "", (Function) sensor_nick, "stat"},
  412. {0, 0, 0, 0}
  413. };
  414. static cmd_t stats_join[] =
  415. {
  416. {"*", "", (Function) sensor_join, "stat"},
  417. {0, 0, 0, 0}
  418. };
  419. static cmd_t stats_part[] =
  420. {
  421. {"*", "", (Function) sensor_part, "stat"},
  422. {0, 0, 0, 0}
  423. };
  424. static cmd_t stats_sign[] =
  425. {
  426. {"*", "", (Function) sensor_sign, "stat"},
  427. {0, 0, 0, 0}
  428. };