user.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 stats_checkhand(char *oldnick, char *newnick)
  19. {
  20. Context;
  21. if (findsuser_by_name(newnick)) {
  22. putlog(LOG_MISC, "*", "Stats.mod: %s changed handle to %s which already "
  23. "existed in the database. The datasets have been merged.",
  24. oldnick, newnick);
  25. if (!user_merge(newnick, oldnick))
  26. putlog(LOG_MISC, "*", ".. failed!");
  27. } else {
  28. if (track_stat_user(oldnick, newnick))
  29. putlog(LOG_MISC, "*", "Stats.mod: Transferred stats from %s to %s",
  30. oldnick, newnick);
  31. else
  32. putlog(LOG_MISC, "*", "Stats.mod: Transfer from %s to %s failed!", oldnick, newnick);
  33. }
  34. Context;
  35. return 1;
  36. }
  37. static cmd_t stats_nkch[] = {
  38. {"*", "", (Function) stats_checkhand, "stat:nkch"},
  39. {0, 0, 0, 0}
  40. };
  41. static void deloldstatusers()
  42. {
  43. struct userrec *u;
  44. struct stats_userlist *su, *lsu;
  45. struct stats_hostlist *h, *lh;
  46. if (expire_base < 1)
  47. return;
  48. su = suserlist;
  49. lsu = NULL;
  50. while (su) {
  51. h = su->hosts;
  52. lh = NULL;
  53. while (h) {
  54. if ((now - h->lastused) > TIMETOLIVE(h)) {
  55. putlog(LOG_MISC, "*",
  56. "Stats.Mod: %s didn't use the hostmask %s during the last %d days. Removing from hostlist...",
  57. su->user, h->mask, ((now - h->lastused) / 86400));
  58. nfree(h->mask);
  59. if (lh)
  60. lh->next = h->next;
  61. else
  62. su->hosts = h->next;
  63. nfree(h);
  64. if (lh)
  65. h = lh->next;
  66. else
  67. h = su->hosts;
  68. } else {
  69. lh = h;
  70. h = h->next;
  71. }
  72. }
  73. if (!su->hosts && (TIMETOLIVE(su) < (now - su->laston))) {
  74. u = get_user_by_handle(userlist, su->user);
  75. if (u) {
  76. lsu = su;
  77. su = su->next;
  78. continue;
  79. }
  80. putlog(LOG_MISC, "*",
  81. "Stats.Mod: %s wasn't online since %d days. "
  82. "Deleting stat user...", su->user,
  83. (now - su->laston) / 86400);
  84. nfree(su->user);
  85. if (lsu)
  86. lsu->next = su->next;
  87. else
  88. suserlist = su->next;
  89. weed_userlink_from_chanset(su);
  90. weed_userlink_from_locstats(su);
  91. nfree(su);
  92. if (lsu)
  93. su = lsu->next;
  94. else
  95. su = suserlist;
  96. } else {
  97. lsu = su;
  98. su = su->next;
  99. }
  100. }
  101. }
  102. static void purgestats()
  103. {
  104. globstats *gs, *gs2;
  105. locstats *ls, *ls2;
  106. locstats *sl, *sl2;
  107. int i, ii, kill;
  108. struct stats_userlist *u;
  109. struct userrec *u2;
  110. struct stats_chan *chan;
  111. Context;
  112. gs = sdata;
  113. gs2 = NULL;
  114. while (gs) {
  115. chan = schan_find(gs->chan);
  116. if (chan && gs->local) {
  117. ls = gs->local;
  118. ls2 = NULL;
  119. while (ls) {
  120. kill = 1;
  121. u2 = get_user_by_handle(userlist, ls->user);
  122. u = findsuser_by_name(ls->user);
  123. if (u2 || u) {
  124. for (i = 0; i < TOTAL_TYPES; i++) {
  125. if (ls->values[S_TOTAL][i] != 0) {
  126. kill = 0;
  127. break;
  128. }
  129. }
  130. if (!kill) {
  131. if (strcmp(ls->user, u->user)) {
  132. debug2
  133. ("Stats.mod: Transferred stats from %s to %s",
  134. ls->user, u->user);
  135. nfree(ls->user);
  136. ls->user = nmalloc(strlen(u->user) + 1);
  137. strcpy(ls->user, u->user);
  138. }
  139. }
  140. }
  141. if (kill) {
  142. putlog(LOG_MISC, "*",
  143. "Stats.mod: Deleting stats for %s in %s(empty data or no such user)",
  144. ls->user, gs->chan);
  145. for (i = 0; i < 4; i++) {
  146. for (ii = 0; ii < (TOTAL_TYPES + TOTAL_SPECIAL_TYPES);
  147. ii++) {
  148. sl = gs->slocal[i][ii];
  149. sl2 = NULL;
  150. while (sl) {
  151. if (!rfc_casecmp(sl->user, ls->user))
  152. break;
  153. sl2 = sl;
  154. sl = sl->snext[i][ii];
  155. }
  156. if (sl) {
  157. if (sl2)
  158. sl2->snext[i][ii] = sl->snext[i][ii];
  159. else
  160. gs->slocal[i][ii] = sl->snext[i][ii];
  161. } else
  162. putlog(LOG_MISC, "*",
  163. "WARNING!!! %s not found in sorted list ([%d][%d])! Corrupted data?",
  164. ls->user, i, ii);
  165. }
  166. }
  167. if (ls2)
  168. ls2->next = ls->next;
  169. else
  170. gs->local = ls->next;
  171. nfree(ls->user);
  172. free_wordstats(ls->words);
  173. free_quotes(ls->quotes);
  174. weed_statlink_from_chanset(ls);
  175. nfree(ls);
  176. if (ls2)
  177. ls = ls2->next;
  178. else
  179. ls = gs->local;
  180. } else {
  181. ls2 = ls;
  182. ls = ls->next;
  183. }
  184. }
  185. gs2 = gs;
  186. gs = gs->next;
  187. } else {
  188. putlog(LOG_MISC, "*",
  189. "Stats.mod: Deleting stats for %s. (no such channel)", gs->chan);
  190. if (gs2)
  191. gs2->next = gs->next;
  192. else
  193. sdata = gs->next;
  194. free_localstats(gs->local);
  195. free_wordstats(gs->words);
  196. free_topics(gs->topics);
  197. free_urls(gs->urls);
  198. free_quotes(gs->log);
  199. free_hosts(gs->hosts);
  200. free_kicks(gs->kicks);
  201. nfree(gs->chan);
  202. nfree(gs);
  203. if (gs2)
  204. gs = gs2->next;
  205. else
  206. gs = sdata;
  207. }
  208. }
  209. Context;
  210. }