datahandling.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364
  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 void incrstats(char *user, char *chan, int type, int value, int set)
  19. {
  20. globstats *gs, *gs2;
  21. locstats *ls, *ls2;
  22. int i, ii;
  23. if (type >= TOTAL_TYPES)
  24. return;
  25. if (!user) {
  26. debug0("Stats.mod: incrstats(..) Ups, user is NULL!");
  27. return;
  28. }
  29. if (!chan) {
  30. debug0("Stats.mod: incrstats(..) Ups, chan is NULL!");
  31. return;
  32. }
  33. for (gs = sdata; gs; gs = gs->next) {
  34. if (!strcasecmp(chan, gs->chan))
  35. break;
  36. }
  37. if (!gs) {
  38. gs2 = sdata;
  39. while (gs2 && gs2->next)
  40. gs2 = gs2->next;
  41. gs = nmalloc(sizeof(globstats));
  42. globstats_init(gs);
  43. gs->started = now;
  44. gs->chan = nmalloc(strlen(chan) + 1);
  45. strcpy(gs->chan, chan);
  46. if (gs2)
  47. gs2->next = gs;
  48. else
  49. sdata = gs;
  50. }
  51. for (ls = gs->local; ls; ls = ls->next) {
  52. if (!strcasecmp(ls->user, user))
  53. break;
  54. }
  55. if (type == T_GSTARTED) {
  56. gs->started = value;
  57. return;
  58. }
  59. if (type == T_PEAK) {
  60. gs->peak[set] = value;
  61. return;
  62. }
  63. if (!ls) {
  64. ls2 = gs->local;
  65. while (ls2 && ls2->next)
  66. ls2 = ls2->next;
  67. ls = nmalloc(sizeof(locstats));
  68. locstats_init(ls);
  69. ls->started = now;
  70. ls->user = nmalloc(strlen(user) + 1);
  71. strcpy(ls->user, user);
  72. if (ls2)
  73. ls2->next = ls;
  74. else
  75. gs->local = ls;
  76. for (i = 0; i < (TOTAL_TYPES + TOTAL_SPECIAL_TYPES); i++)
  77. ls->snext[S_TOTAL][i] = ls->snext[S_DAILY][i] = ls->snext[S_WEEKLY][i] = ls->snext[S_MONTHLY][i] = NULL;
  78. for (i = 0; i < 4; i++) {
  79. for (ii = 0; ii < (TOTAL_TYPES + TOTAL_SPECIAL_TYPES); ii++) {
  80. ls2 = gs->slocal[i][ii];
  81. while (ls2 && ls2->snext[i][ii])
  82. ls2 = ls2->snext[i][ii];
  83. if (ls2)
  84. ls2->snext[i][ii] = ls;
  85. else
  86. gs->slocal[i][ii] = ls;
  87. }
  88. }
  89. }
  90. if (type == T_LSTARTED)
  91. ls->started = value;
  92. else {
  93. if (set > 0)
  94. ls->values[set - 1][type] = value;
  95. else if (set < 0)
  96. ls->values[(set * (-1)) - 1][type] += value;
  97. else {
  98. ls->values[S_TOTAL][type] += value;
  99. ls->values[S_TODAY][type] += value;
  100. ls->values[S_WEEKLY][type] += value;
  101. ls->values[S_MONTHLY][type] += value;
  102. }
  103. }
  104. }
  105. static globstats *globstats_create(char *chan)
  106. {
  107. globstats *gs, *gs2;
  108. for (gs = sdata; gs; gs = gs->next) {
  109. if (!rfc_casecmp(chan, gs->chan))
  110. return gs;
  111. }
  112. gs2 = sdata;
  113. while (gs2 && gs2->next)
  114. gs2 = gs2->next;
  115. gs = nmalloc(sizeof(globstats));
  116. globstats_init(gs);
  117. gs->started = now;
  118. gs->chan = nmalloc(strlen(chan) + 1);
  119. strcpy(gs->chan, chan);
  120. if (gs2)
  121. gs2->next = gs;
  122. else
  123. sdata = gs;
  124. return gs;
  125. }
  126. static void nincrstats(locstats *ls, int type, int value)
  127. {
  128. ls->values[S_TOTAL][type] += value;
  129. ls->values[S_TODAY][type] += value;
  130. ls->values[S_WEEKLY][type] += value;
  131. ls->values[S_MONTHLY][type] += value;
  132. }
  133. /* initstats()
  134. * erzeugt einen Eintrag in den Statistiken eines Channels
  135. * für einen User.
  136. * FRAGE: _Muss_ ich den Rückgabewert irgendwo verwenden, oder
  137. * ist er nur optional? */
  138. static locstats *initstats(char *chan, char *user)
  139. {
  140. globstats *gs, *gs2;
  141. locstats *ls, *ls2;
  142. int i, ii;
  143. gs = sdata;
  144. while (gs) {
  145. if (!rfc_casecmp(gs->chan, chan))
  146. break;
  147. gs = gs->next;
  148. }
  149. if (!gs) {
  150. gs2 = sdata;
  151. while (gs2 && gs2->next)
  152. gs2 = gs2->next;
  153. gs = nmalloc(sizeof(globstats));
  154. globstats_init(gs);
  155. gs->started = now;
  156. gs->chan = nmalloc(strlen(chan) + 1);
  157. strcpy(gs->chan, chan);
  158. if (gs2)
  159. gs2->next = gs;
  160. else
  161. sdata = gs;
  162. }
  163. for (ls = gs->local; ls; ls = ls->next) {
  164. if (!rfc_casecmp(ls->user, user))
  165. return ls;
  166. }
  167. if (!ls) {
  168. ls2 = gs->local;
  169. while (ls2 && ls2->next)
  170. ls2 = ls2->next;
  171. ls = nmalloc(sizeof(locstats));
  172. locstats_init(ls);
  173. ls->started = now;
  174. ls->user = nmalloc(strlen(user) + 1);
  175. strcpy(ls->user, user);
  176. if (ls2)
  177. ls2->next = ls;
  178. else
  179. gs->local = ls;
  180. for (i = 0; i < (TOTAL_TYPES + TOTAL_SPECIAL_TYPES); i++)
  181. ls->snext[S_TOTAL][i] = ls->snext[S_DAILY][i] = ls->snext[S_WEEKLY][i] = ls->snext[S_MONTHLY][i] = NULL;
  182. for (i = 0; i < 4; i++) {
  183. for (ii = 0; ii < (TOTAL_TYPES + TOTAL_SPECIAL_TYPES); ii++) {
  184. ls2 = gs->slocal[i][ii];
  185. while (ls2 && ls2->snext[i][ii])
  186. ls2 = ls2->snext[i][ii];
  187. if (ls2)
  188. ls2->snext[i][ii] = ls;
  189. else
  190. gs->slocal[i][ii] = ls;
  191. }
  192. }
  193. }
  194. return ls;
  195. }
  196. static void locstats_init(locstats *ls)
  197. {
  198. int i;
  199. Assert(ls);
  200. ls->started = now;
  201. ls->next = NULL;
  202. ls->words = NULL;
  203. ls->tree = NULL;
  204. ls->quotes = NULL;
  205. ls->quotefr = 0;
  206. ls->flag = 0;
  207. for (i = 0; i < TOTAL_TYPES; i++) {
  208. ls->values[S_TOTAL][i] = 0;
  209. ls->values[S_TODAY][i] = 0;
  210. ls->values[S_WEEKLY][i] = 0;
  211. ls->values[S_MONTHLY][i] = 0;
  212. }
  213. ls->user = NULL;
  214. ls->u = NULL;
  215. ls->lastspoke = 0;
  216. for (i = 0; i < (TOTAL_TYPES + TOTAL_SPECIAL_TYPES); i++)
  217. ls->snext[S_TOTAL][i] = ls->snext[S_DAILY][i] = ls->snext[S_WEEKLY][i] = ls->snext[S_MONTHLY][i] = NULL;
  218. }
  219. static void globstats_init(globstats *gs)
  220. {
  221. int i;
  222. Assert(gs);
  223. gs->next = NULL;
  224. gs->chan = NULL;
  225. gs->started = now;
  226. gs->peak[S_TOTAL] = gs->peak[S_DAILY] = gs->peak[S_WEEKLY] = gs->peak[S_MONTHLY] = 0;
  227. for (i = 0; i < 24; i++) {
  228. gs->users[S_USERSUM][i] = 0;
  229. gs->users[S_USERCOUNTS][i] = -1;
  230. }
  231. for (i = 0; i < 24; i++)
  232. gs->activity[i] = 0;
  233. gs->local = NULL;
  234. for (i = 0; i < (TOTAL_TYPES + TOTAL_SPECIAL_TYPES); i++)
  235. gs->slocal[S_TOTAL][i] = gs->slocal[S_DAILY][i] = gs->slocal[S_WEEKLY][i] = gs->slocal[S_MONTHLY][i] = NULL;
  236. gs->words = NULL;
  237. gs->topics = NULL;
  238. gs->hosts = NULL;
  239. gs->urls = NULL;
  240. gs->log = gs->lastlog = NULL;
  241. gs->log_length = 0;
  242. gs->kicks = NULL;
  243. }
  244. static int getstats(char *user, char *chan, char *type, int today)
  245. {
  246. struct stats_global *gs = sdata;
  247. struct stats_local *ls;
  248. int itype;
  249. while (gs) {
  250. ls = gs->local;
  251. if (!strcasecmp(gs->chan, chan)) {
  252. while (ls) {
  253. if (!strcasecmp(ls->user, user)) {
  254. itype = typetoi(type);
  255. if (itype >= 0)
  256. return ls->values[today][itype];
  257. }
  258. ls = ls->next;
  259. }
  260. }
  261. gs = gs->next;
  262. }
  263. return 0;
  264. }
  265. static void countvocables(globstats *gs)
  266. {
  267. locstats *ls;
  268. wordstats *ws;
  269. for (ls = gs->local; ls; ls = ls->next) {
  270. ls->vocables = 0;
  271. for (ws = ls->words; ws; ws = ws->next)
  272. ls->vocables++;
  273. }
  274. }
  275. // typetoi(): returns the index of a stat-type
  276. static int typetoi(char *type)
  277. {
  278. if (!strcasecmp(type, "lstarted"))
  279. return T_LSTARTED;
  280. else if (!strcasecmp(type, "gstarted"))
  281. return T_GSTARTED;
  282. else if (!strcasecmp(type, "words"))
  283. return T_WORDS;
  284. else if (!strcasecmp(type, "letters"))
  285. return T_LETTERS;
  286. else if (!strcasecmp(type, "minutes"))
  287. return T_MINUTES;
  288. else if (!strcasecmp(type, "topics"))
  289. return T_TOPICS;
  290. else if (!strcasecmp(type, "lines"))
  291. return T_LINES;
  292. else if (!strcasecmp(type, "actions"))
  293. return T_ACTIONS;
  294. else if (!strcasecmp(type, "kicks"))
  295. return T_KICKS;
  296. else if (!strcasecmp(type, "modes"))
  297. return T_MODES;
  298. else if (!strcasecmp(type, "bans"))
  299. return T_BANS;
  300. else if (!strcasecmp(type, "nicks"))
  301. return T_NICKS;
  302. else if (!strcasecmp(type, "joins"))
  303. return T_JOINS;
  304. else if (!strcasecmp(type, "smileys"))
  305. return T_SMILEYS;
  306. else if (!strcasecmp(type, "questions"))
  307. return T_QUESTIONS;
  308. else if (!strcasecmp(type, "wpl"))
  309. return T_WPL;
  310. else if (!strcasecmp(type, "w/l"))
  311. return T_WPL;
  312. else if (!strcasecmp(type, "word"))
  313. return T_WORD;
  314. else if (!strcasecmp(type, "vocables"))
  315. return T_VOCABLES;
  316. else if (!strcasecmp(type, "started"))
  317. return T_LSTARTED;
  318. else if (!strcasecmp(type, "quote"))
  319. return T_QUOTE;
  320. else if (!strcasecmp(type, "idle"))
  321. return T_IDLE;
  322. else {
  323. debug1("Stats.mod: Unknown stat type: %s", type);
  324. return T_ERROR;
  325. }
  326. }
  327. /* itotype():
  328. * similar to typetoi(), but returns the string that describes
  329. * the given type
  330. */
  331. static char *itotype(int type)
  332. {
  333. switch (type) {
  334. case T_WORDS: return "words";
  335. case T_LETTERS: return "letters";
  336. case T_MINUTES: return "minutes";
  337. case T_TOPICS: return "topics";
  338. case T_LINES: return "lines";
  339. case T_ACTIONS: return "actions";
  340. case T_MODES: return "modes";
  341. case T_BANS: return "bans";
  342. case T_KICKS: return "kicks";
  343. case T_NICKS: return "nicks";
  344. case T_JOINS: return "joins";
  345. case T_SMILEYS: return "smileys";
  346. case T_QUESTIONS: return "questions";
  347. case T_WPL: return "w/l";
  348. case T_IDLE: return "idle";
  349. case T_VOCABLES: return "vocables";
  350. }
  351. return "!!!ERROR!!!";
  352. }
  353. static locstats *findlocstats(char *chan, char *user)
  354. {
  355. globstats *gl;
  356. locstats *ll;
  357. for (gl = sdata; gl; gl = gl->next) {
  358. if (!rfc_casecmp(gl->chan, chan))
  359. break;
  360. }
  361. if (!gl)
  362. return NULL;
  363. for (ll = gl->local; ll; ll = ll->next) {
  364. if (!rfc_casecmp(ll->user, user))
  365. return ll;
  366. }
  367. return NULL;
  368. }
  369. static globstats *findglobstats(char *chan)
  370. {
  371. globstats *gl;
  372. for (gl = sdata; gl; gl = gl->next) {
  373. if (!rfc_casecmp(gl->chan, chan))
  374. break;
  375. }
  376. return gl;
  377. }
  378. static void write_stats()
  379. {
  380. char s[125];
  381. FILE *f;
  382. struct stats_global *gs;
  383. struct stats_local *ls;
  384. struct stats_userlist *u;
  385. struct stats_hostlist *h;
  386. int i;
  387. Context;
  388. if (!statsfile[0])
  389. return;
  390. sprintf(s, "%s~new", statsfile);
  391. f = fopen(s, "w");
  392. chmod(s, statsfilemode);
  393. if (f == NULL) {
  394. putlog(LOG_MISC, "*", "ERROR writing stats file.");
  395. return;
  396. }
  397. fprintf(f, "@ # Statistics from %s.\n", botnetnick);
  398. fprintf(f, "@ filever 3\n");
  399. fprintf(f, "@ month %d\n", getmonth());
  400. for (gs = sdata; gs; gs = gs->next) {
  401. fprintf(f, "%s ! %d\n", gs->chan, (int) gs->started);
  402. fprintf(f, "%s @ %d\n", gs->chan, gs->peak[S_TOTAL]);
  403. fprintf(f, "@ peaks %s %d %d %d %d\n", gs->chan, gs->peak[S_TOTAL],
  404. gs->peak[S_DAILY], gs->peak[S_WEEKLY], gs->peak[S_MONTHLY]);
  405. for (ls = gs->local; ls; ls = ls->next) {
  406. fprintf(f, "%s %s %d", gs->chan, ls->user, (int) ls->started);
  407. for (i = 0; i < TOTAL_TYPES; i++)
  408. fprintf(f, " %ld", ls->values[S_TOTAL][i]);
  409. fprintf(f, "\n");
  410. fprintf(f, "@ lastspoke %d\n", (int) ls->lastspoke);
  411. fprintf(f, "@ daily %s %s", gs->chan, ls->user);
  412. for (i = 0; i < TOTAL_TYPES; i++)
  413. fprintf(f, " %ld", ls->values[S_DAILY][i]);
  414. fprintf(f, "\n");
  415. fprintf(f, "@ weekly %s %s", gs->chan, ls->user);
  416. for (i = 0; i < TOTAL_TYPES; i++)
  417. fprintf(f, " %ld", ls->values[S_WEEKLY][i]);
  418. fprintf(f, "\n");
  419. fprintf(f, "@ monthly %s %s", gs->chan, ls->user);
  420. for (i = 0; i < TOTAL_TYPES; i++)
  421. fprintf(f, " %ld", ls->values[S_MONTHLY][i]);
  422. fprintf(f, "\n");
  423. i = 0;
  424. }
  425. }
  426. for (u = suserlist; u; u = u->next) {
  427. fprintf(f, "@ user %s %d %lu %lu", u->user, u->flags, u->created, u->laston);
  428. for (h = u->hosts; h; h = h->next) {
  429. fprintf(f, " %s %lu %lu", h->mask, h->lastused, h->created);
  430. }
  431. fprintf(f, "\n");
  432. if (u->password || u->email || u->homepage || u->icqnr) {
  433. fprintf(f, "@ uxtra %s", u->user);
  434. if (u->email)
  435. fprintf(f, " e %s", u->email);
  436. if (u->homepage)
  437. fprintf(f, " h %s", u->homepage);
  438. if (u->icqnr)
  439. fprintf(f, " i %d", u->icqnr);
  440. if (u->password)
  441. fprintf(f, " p %s", u->password);
  442. fprintf(f, "\n");
  443. }
  444. }
  445. fclose(f);
  446. unlink(statsfile);
  447. movefile(s, statsfile);
  448. Context;
  449. return;
  450. }
  451. static void read_stats()
  452. {
  453. FILE *f;
  454. char buf[SAVESTATSLENGTH + 1];
  455. char *s, *chan, *user, *cmd, *host, *tmp;
  456. int i, version, range, month, list, addhosts, flags;
  457. struct stats_userlist *u;
  458. time_t lastused;
  459. locstats *ls;
  460. globstats *gs;
  461. time_t created, laston;
  462. Context;
  463. ls = NULL;
  464. gs = NULL;
  465. version = 0;
  466. month = 0;
  467. f = fopen(statsfile, "r");
  468. if (f == NULL) {
  469. putlog(LOG_MISC, "*", "ERROR reading stats file");
  470. return;
  471. }
  472. free_stats();
  473. while (!feof(f)) {
  474. buf[0] = 0;
  475. s = buf;
  476. fgets(s, SAVESTATSLENGTH - 1, f);
  477. s[SAVESTATSLENGTH - 1] = 0;
  478. if (buf[0] == 0)
  479. continue;
  480. if (s[strlen(s) - 1] == '\n')
  481. s[strlen(s) - 1] = 0;
  482. chan = newsplit(&s);
  483. if (!strcmp(chan, "@")) {
  484. cmd = newsplit(&s);
  485. if (!strcmp(cmd, "filever"))
  486. version = atoi(newsplit(&s));
  487. else if (!strcmp(cmd, "month"))
  488. month = atoi(newsplit(&s));
  489. else if (!strcmp(cmd, "peaks")) {
  490. chan = newsplit(&s);
  491. incrstats("*", chan, T_PEAK, atoi(newsplit(&s)), S_TOTAL);
  492. incrstats("*", chan, T_PEAK, atoi(newsplit(&s)), S_DAILY);
  493. incrstats("*", chan, T_PEAK, atoi(newsplit(&s)), S_WEEKLY);
  494. incrstats("*", chan, T_PEAK, atoi(newsplit(&s)), S_MONTHLY);
  495. } else if (!strcmp(cmd, "daily") || !strcmp(cmd, "weekly")
  496. || !strcmp(cmd, "monthly")) {
  497. if (!strcmp(cmd, "daily"))
  498. range = S_DAILY;
  499. else if (!strcmp(cmd, "weekly"))
  500. range = S_WEEKLY;
  501. else if (!strcmp(cmd, "monthly"))
  502. range = S_MONTHLY;
  503. else {
  504. debug2("Error while reading statsfile: range uninitialized! (%s %s)", cmd, s);
  505. continue;
  506. }
  507. if ((range == S_MONTHLY) && (month != lastmonth))
  508. continue;
  509. chan = newsplit(&s);
  510. user = newsplit(&s);
  511. // Check if pointers still point to the correct data and
  512. // update them, if not.
  513. if ((gs && strcmp(gs->chan, chan)) || !gs) {
  514. gs = findglobstats(chan);
  515. ls = findlocstats(chan, user);
  516. } else {
  517. if ((ls && strcmp(ls->user, user)) || !ls)
  518. ls = findlocstats(chan, user);
  519. }
  520. if (!ls)
  521. ls = initstats(chan, user);
  522. for (i = 0; i < TOTAL_TYPES; i++)
  523. ls->values[range][i] = atoi(newsplit(&s));
  524. } else if (!strcmp(cmd, "lastspoke")) {
  525. if (ls) {
  526. ls->lastspoke = atoi(newsplit(&s));
  527. } else {
  528. putlog(LOG_MISC, "*", "ERROR: Can't load lastspoke info. No locstats.");
  529. }
  530. } else if (!strcmp(cmd, "user")) {
  531. user = newsplit(&s);
  532. flags = 0;
  533. if (version < 2) {
  534. list = atoi(newsplit(&s));
  535. addhosts = atoi(newsplit(&s));
  536. if (list)
  537. flags |= S_LIST;
  538. if (addhosts)
  539. flags |= S_ADDHOSTS;
  540. } else
  541. flags = atoi(newsplit(&s));
  542. if (version >= 3) {
  543. created = atoi(newsplit(&s));
  544. laston = atoi(newsplit(&s));
  545. } else {
  546. created = get_creation_time_from_locstats(user);
  547. laston = get_laston_time_from_hosts(user);
  548. }
  549. u = addsuser(user, created, laston);
  550. u->flags = flags;
  551. while (s[0]) {
  552. host = newsplit(&s);
  553. lastused = (time_t) atoi(newsplit(&s));
  554. if (version >= 3)
  555. created = (time_t) atoi(newsplit(&s));
  556. else
  557. created = lastused;
  558. saddhost(u, host, lastused, created);
  559. }
  560. } else if (!strcmp(cmd, "uxtra")) {
  561. user = newsplit(&s);
  562. u = findsuser_by_name(user);
  563. while (u && s[0]) {
  564. tmp = newsplit(&s);
  565. if (!strcmp(tmp, "e"))
  566. setemail(u, newsplit(&s));
  567. else if (!strcmp(tmp, "h"))
  568. sethomepage(u, newsplit(&s));
  569. else if (!strcmp(tmp, "i"))
  570. u->icqnr = atoi(newsplit(&s));
  571. else if (!strcmp(tmp, "p"))
  572. setpassword(u, newsplit(&s));
  573. }
  574. }
  575. } else {
  576. // old style data
  577. // left-over from v1.0. I should change it, but I don't want
  578. // to break compatibility
  579. user = newsplit(&s);
  580. if (!strcmp(user, "!"))
  581. incrstats(user, chan, T_GSTARTED, atoi(newsplit(&s)), 1);
  582. else if (!strcmp(user, "@"))
  583. incrstats(user, chan, T_PEAK, atoi(newsplit(&s)), S_TOTAL);
  584. else {
  585. incrstats(user, chan, T_LSTARTED, atoi(newsplit(&s)), 1);
  586. // initstats also returns the current 'ls' if it also exists,
  587. // so better don't even use findlocstats() before to save
  588. // some CPU-time
  589. ls = initstats(chan, user);
  590. for (i = 0; i < TOTAL_TYPES; i++)
  591. ls->values[S_TOTAL][i] = atoi(newsplit(&s));
  592. }
  593. }
  594. }
  595. fclose(f);
  596. Context;
  597. return;
  598. }
  599. static void reset_tstats()
  600. {
  601. globstats *gs;
  602. locstats *ls;
  603. int i;
  604. Context;
  605. putlog(LOG_MISC, "*", "Stats.mod: Resetting today's statistics...");
  606. for (gs = sdata; gs; gs = gs->next) {
  607. gs->peak[S_TODAY] = 0;
  608. free_wordstats(gs->words);
  609. gs->words = NULL;
  610. free_topics(gs->topics);
  611. gs->topics = NULL;
  612. free_urls(gs->urls);
  613. gs->urls = NULL;
  614. free_hosts(gs->hosts);
  615. gs->hosts = NULL;
  616. free_kicks(gs->kicks);
  617. gs->kicks = NULL;
  618. for (ls = gs->local; ls; ls = ls->next) {
  619. free_wordstats(ls->words);
  620. ls->words = NULL;
  621. ls->tree = NULL;
  622. free_quotes(ls->quotes);
  623. ls->quotes = NULL;
  624. for (i = 0; i < TOTAL_TYPES; i++)
  625. ls->values[S_TODAY][i] = 0;
  626. }
  627. }
  628. Context;
  629. }
  630. static void reset_mwstats(int range)
  631. {
  632. globstats *gs;
  633. locstats *ls;
  634. int i;
  635. Context;
  636. putlog(LOG_MISC, "*", "Stats.mod: Resetting %s statistics...", (range == S_WEEKLY) ? "weekly" : "monthly");
  637. for (gs = sdata; gs; gs = gs->next) {
  638. gs->peak[range] = 0;
  639. for (ls = gs->local; ls; ls = ls->next) {
  640. for (i = 0; i < TOTAL_TYPES; i++)
  641. ls->values[range][i] = 0;
  642. }
  643. }
  644. Context;
  645. }
  646. static void resetlocstats(locstats *ls)
  647. {
  648. int i;
  649. if (!ls) {
  650. debug0("ERROR! resetlocstats called with NULL pointer!");
  651. return;
  652. }
  653. for (i = 0; i < TOTAL_TYPES; i++) {
  654. ls->values[S_TOTAL][i] = 0;
  655. ls->values[S_TODAY][i] = 0;
  656. ls->values[S_WEEKLY][i] = 0;
  657. ls->values[S_MONTHLY][i] = 0;
  658. }
  659. return;
  660. }
  661. static void calcwordstats(locstats *stats, char *text)
  662. {
  663. char *word;
  664. int i;
  665. Context;
  666. Assert(stats);
  667. if (!log_wordstats)
  668. return;
  669. for (i = 0; i < strlen(text); i++)
  670. if (strchr("!?.,\"<>&\\", text[i]))
  671. text[i] = ' ';
  672. while (text[0]) {
  673. word = newsplit(&text);
  674. strlower(word);
  675. incrwordstats(stats, word, 1, 0);
  676. }
  677. }
  678. // add another entry to the tree
  679. static void incrwordstats(locstats *ls, char *word, int value, int set)
  680. {
  681. wordstats *ne, *te, *le;
  682. wordstats *ll;
  683. int cmp;
  684. Context;
  685. if ((word[0] == ' ') || !word[0])
  686. return;
  687. if (min_word_length && (strlen(word) < min_word_length))
  688. return; /* only log words that are longer than min_word_length chars */
  689. if (!ls) {
  690. return;
  691. }
  692. // at first, check if it already exists and only needs to be updated
  693. te = ls->tree;
  694. le = NULL;
  695. while (te) {
  696. if (!(cmp = strcasecmp(te->word, word)))
  697. break;
  698. le = te;
  699. if (cmp < 0)
  700. te = te->left;
  701. else
  702. te = te->right;
  703. }
  704. if (!te) { // nothing to update, so let's append a new node
  705. ne = nmalloc(sizeof(struct stats_words));
  706. ne->word = nmalloc(strlen(word) + 1);
  707. strcpy(ne->word, word);
  708. ne->nr = 0;
  709. ne->left = ne->right = ne->next = NULL;
  710. if (!le) // no last entry -> new entry is going to be the crown
  711. ls->tree = ne;
  712. else {
  713. if (strcasecmp(le->word, word) < 0) // -1 -> left child
  714. le->left = ne;
  715. else // 1 -> right child
  716. le->right = ne;
  717. }
  718. // now let's add it also to the linked list (needed for sorting)
  719. ll = ls->words;
  720. while (ll && ll->next)
  721. ll = ll->next;
  722. if (ll)
  723. ll->next = ne;
  724. else
  725. ls->words = ne;
  726. te = ne;
  727. }
  728. // now let's set the value
  729. if (set)
  730. te->nr = value;
  731. else
  732. te->nr += value;
  733. }
  734. static void nincrwordstats(globstats *gs, char *word, int value)
  735. {
  736. wordstats *l, *ll;
  737. for (l = gs->words; l; l = l->next)
  738. if (!strcmp(word, l->word))
  739. break;
  740. if (!l) {
  741. l = gs->words;
  742. while (l && l->next)
  743. l = l->next;
  744. ll = nmalloc(sizeof(wordstats));
  745. ll->word = nmalloc(strlen(word) + 1);
  746. strcpy(ll->word, word);
  747. ll->nr = 0;
  748. ll->next = NULL;
  749. if (l)
  750. l->next = ll;
  751. else
  752. gs->words = ll;
  753. l = ll;
  754. }
  755. l->nr += value;
  756. }
  757. static time_t glob_lastglobwordstats;
  758. static void do_globwordstats(globstats *gs)
  759. {
  760. wordstats *l;
  761. locstats *ls;
  762. if (glob_lastglobwordstats == now)
  763. return; /* don't recalculate everything if we already did it in this second */
  764. debug0("calculating global wordstats");
  765. glob_lastglobwordstats = now;
  766. for (l = gs->words; l; l = l->next)
  767. l->nr = 0;
  768. for (ls = gs->local; ls; ls = ls->next)
  769. for (l = ls->words; l; l = l->next)
  770. nincrwordstats(gs, l->word, l->nr);
  771. sortwordstats(NULL, gs);
  772. }
  773. static void addquote(locstats *stats, char *quote)
  774. {
  775. quotestr *l, *nl;
  776. Assert(quote);
  777. if (!quote_freq)
  778. return;
  779. Assert(stats);
  780. stats->quotefr--;
  781. if (stats->quotefr > 0)
  782. return;
  783. stats->quotefr = quote_freq;
  784. l = stats->quotes;
  785. while (l && l->next)
  786. l = l->next;
  787. nl = nmalloc(sizeof(quotestr));
  788. nl->next = NULL;
  789. nl->quote = nmalloc(strlen(quote) + 1);
  790. strcpy(nl->quote, quote);
  791. if (l)
  792. l->next = nl;
  793. else
  794. stats->quotes = nl;
  795. }
  796. static void addtopic(char *channel, char *topic, char *by)
  797. {
  798. topicstr *e, *ne;
  799. globstats *gs;
  800. Context;
  801. gs = findglobstats(channel);
  802. if (!gs)
  803. return;
  804. for (e = gs->topics; e; e = e->next)
  805. if (!strcasecmp(topic, e->topic))
  806. return;
  807. e = gs->topics;
  808. while (e && e->next)
  809. e = e->next;
  810. ne = nmalloc(sizeof(topicstr));
  811. ne->topic = nmalloc(strlen(topic) + 1);
  812. strcpy(ne->topic, topic);
  813. ne->by = nmalloc(strlen(by) + 1);
  814. strcpy(ne->by, by);
  815. ne->when = now;
  816. ne->next = NULL;
  817. if (e)
  818. e->next = ne;
  819. else
  820. gs->topics = ne;
  821. }
  822. static void addhost(char *host, globstats *gs)
  823. {
  824. hoststr *e, *ne;
  825. char *s;
  826. if (!gs || !host)
  827. return;
  828. s = strchr(host, '@');
  829. if (s)
  830. host = s + 1;
  831. if (strcmp(host, "[IP]"))
  832. strlower(host);
  833. for (e = gs->hosts; e; e = e->next) {
  834. if (!strcmp(host, e->host)) {
  835. e->nr++;
  836. return;
  837. }
  838. }
  839. e = gs->hosts;
  840. while (e && e->next)
  841. e = e->next;
  842. ne = nmalloc(sizeof(hoststr));
  843. ne->host = nmalloc(strlen(host) + 1);
  844. strcpy(ne->host, host);
  845. ne->nr = 1;
  846. ne->next = NULL;
  847. if (e)
  848. e->next = ne;
  849. else
  850. gs->hosts = ne;
  851. return;
  852. }
  853. static void setword(globstats *gs, char *word)
  854. {
  855. locstats *l;
  856. wordstats *w;
  857. for (l = gs->local; l; l = l->next) {
  858. l->word = NULL;
  859. for (w = l->words; w; w = w->next) {
  860. if (!strcmp(w->word, word)) {
  861. l->word = w;
  862. break;
  863. }
  864. }
  865. }
  866. }
  867. static int track_stat_user(char *oldnick, char *newnick)
  868. {
  869. globstats *gs;
  870. locstats *ls;
  871. struct stats_userlist *u;
  872. int found = 0;
  873. Context;
  874. for (gs = sdata; gs; gs = gs->next) {
  875. for (ls = gs->local; ls; ls = ls->next) {
  876. if (!rfc_casecmp(oldnick, ls->user) && strcmp(newnick, ls->user)) {
  877. nfree(ls->user);
  878. ls->user = nmalloc(strlen(newnick) + 1);
  879. strcpy(ls->user, newnick);
  880. // ls->u should still be valid...
  881. found = 1;
  882. debug3("Transferred stats from %s to %s in %s", oldnick, newnick, gs->chan);
  883. }
  884. }
  885. }
  886. for (u = suserlist; u; u = u->next) {
  887. if (!rfc_casecmp(oldnick, u->user) && strcmp(newnick, u->user)) {
  888. nfree(u->user);
  889. u->user = nmalloc(strlen(newnick) + 1);
  890. strcpy(u->user, newnick);
  891. found = 1;
  892. debug2("Changed user name from %s to %s in my local database.", oldnick, newnick);
  893. }
  894. }
  895. if (found)
  896. return 1;
  897. return 0;
  898. }
  899. static void check_for_url(char *user, char *chan, char *text)
  900. {
  901. char *p, *url;
  902. char *tmp, *tmp2, *t;
  903. struct stats_url *e, *ne;
  904. globstats *gs;
  905. int weiter;
  906. if (log_urls < 1)
  907. return;
  908. gs = findglobstats(chan);
  909. if (!gs)
  910. return;
  911. url = p = tmp = tmp2 = t = NULL;
  912. if ((p = strstr(text, "http://")))
  913. url = newsplit(&p);
  914. else if ((p = strstr(text, "ftp://")))
  915. url = newsplit(&p);
  916. else if (strstr(text, "www.") || strstr(text, ".com") || strstr(text, "ftp.")) {
  917. tmp = nmalloc(strlen(text) + 1);
  918. strcpy(tmp, text);
  919. t = tmp;
  920. while (t[0]) {
  921. p = newsplit(&t);
  922. if (strstr(p, "www.") || strstr(p, ".com") || strstr(text, "ftp.")) {
  923. url = p;
  924. break;
  925. }
  926. }
  927. }
  928. if (!url)
  929. return;
  930. if (strchr(url, '@')) { /* probably an email address or something similar */
  931. if (tmp)
  932. nfree(tmp);
  933. return;
  934. }
  935. if (strncasecmp(url, "http://", 7) && strncasecmp(url, "ftp://", 6)) {
  936. if (!strncasecmp(url, "ftp.", 4)) {
  937. tmp2 = nmalloc(strlen(url) + 6 + 1);
  938. strcpy(tmp2, "ftp://");
  939. strcpy(tmp2 + 6, url);
  940. } else {
  941. tmp2 = nmalloc(strlen(url) + 7 + 1);
  942. strcpy(tmp2, "http://");
  943. strcpy(tmp2 + 7, url);
  944. }
  945. url = tmp2;
  946. }
  947. for (e = gs->urls; e; e = e->next) {
  948. if (!strcmp(e->url, url)) {
  949. nfree(e->by);
  950. e->by = nmalloc(strlen(user) + 1);
  951. strcpy(e->by, user);
  952. e->when = now;
  953. if (tmp)
  954. nfree(tmp);
  955. if (tmp2)
  956. nfree(tmp2);
  957. return;
  958. }
  959. }
  960. weiter = 1;
  961. for (p = url; (p != url) && weiter; p--) {
  962. if (strchr(".!?,#", p[0]))
  963. p[0] = 0;
  964. else
  965. weiter = 0;
  966. }
  967. for (e = gs->urls; e && e->next; e = e->next);
  968. ne = nmalloc(sizeof(struct stats_url));
  969. ne->url = nmalloc(strlen(url) + 1);
  970. strcpy(ne->url, url);
  971. ne->by = nmalloc(strlen(user) + 1);
  972. strcpy(ne->by, user);
  973. ne->when = now;
  974. ne->next = NULL;
  975. if (e)
  976. e->next = ne;
  977. else
  978. gs->urls = ne;
  979. if (tmp)
  980. nfree(tmp);
  981. if (tmp2)
  982. nfree(tmp2);
  983. debug2("Logged URL: \"%s\" mentioned by %s.", ne->url, ne->by);
  984. }
  985. static void add_chanlog(globstats *gs, char *nick, char *text, int type)
  986. {
  987. char ts[20];
  988. time_t tt, ttbuf;
  989. quotestr *newlog, *l;
  990. if (!gs || (kick_context < 1))
  991. return;
  992. Assert(nick);
  993. Assert(text);
  994. ttbuf = tt = now;
  995. strftime(ts, 19, "[%H:%M:%S]", localtime(&tt));
  996. newlog = nmalloc(sizeof(quotestr));
  997. newlog->next = NULL;
  998. if (type == SL_PRIVMSG) {
  999. newlog->quote = nmalloc(strlen(nick) + strlen(ts) + strlen(text) + 5);
  1000. sprintf(newlog->quote, "%s <%s> %s", ts, nick, text);
  1001. } else if (type == SL_KICK) {
  1002. newlog->quote = nmalloc(strlen(text) + strlen(ts) + 2);
  1003. sprintf(newlog->quote, "%s %s", ts, text);
  1004. } else if (type == SL_MODE) {
  1005. newlog->quote = nmalloc(strlen(ts) + strlen(text) + 2);
  1006. sprintf(newlog->quote, "%s %s", ts, text);
  1007. } else if (type == SL_NICK) {
  1008. newlog->quote = nmalloc(strlen(ts) + strlen(nick) + strlen(text) + 19);
  1009. sprintf(newlog->quote, "%s %s changed nick to %s", ts, nick, text);
  1010. } else if (type == SL_PART) {
  1011. newlog->quote = nmalloc(strlen(ts) + strlen(nick) + strlen(gs->chan) + 12);
  1012. sprintf(newlog->quote, "%s %s has left %s", ts, nick, gs->chan);
  1013. } else if (type == SL_JOIN) {
  1014. newlog->quote = nmalloc(strlen(ts) + strlen(nick) + strlen(gs->chan) + 14);
  1015. sprintf(newlog->quote, "%s %s has joined %s", ts, nick, gs->chan);
  1016. } else if (type == SL_QUIT) {
  1017. newlog->quote = nmalloc(strlen(ts) + strlen(nick) + strlen(text) + 18);
  1018. sprintf(newlog->quote, "%s %s has quit IRC (%s)", ts, nick, text);
  1019. } else {
  1020. debug1("Unknown log-type: %d !!!", type);
  1021. newlog->quote = nmalloc(1);
  1022. newlog->quote[0] = 0;
  1023. }
  1024. if (gs->lastlog)
  1025. gs->lastlog->next = newlog;
  1026. else
  1027. gs->log = newlog;
  1028. gs->lastlog = newlog;
  1029. gs->log_length++;
  1030. while ((gs->log_length > kick_context) && (gs->log_length > 0)) {
  1031. l = gs->log->next;
  1032. Assert(gs->log->quote);
  1033. nfree(gs->log->quote);
  1034. if (gs->lastlog == gs->log)
  1035. gs->lastlog = NULL;
  1036. nfree(gs->log);
  1037. gs->log = l;
  1038. gs->log_length--;
  1039. }
  1040. ctime(&ttbuf); /* workaround for a bug in older eggdrops */
  1041. }
  1042. static void save_kick(globstats *gs, char *kick)
  1043. {
  1044. struct stats_kick *k, *nk;
  1045. quotestr *log, *l, *nl;
  1046. Context;
  1047. if (!gs)
  1048. return;
  1049. for (k = gs->kicks; k && k->next; k = k->next);
  1050. nk = nmalloc(sizeof(struct stats_kick));
  1051. nk->next = NULL;
  1052. nk->log = NULL;
  1053. if (!gs->log || (kick_context < 1)) {
  1054. nl = nmalloc(sizeof(quotestr));
  1055. nl->quote = nmalloc(strlen(kick) + 1);
  1056. strcpy(nl->quote, kick);
  1057. nl->next = NULL;
  1058. nk->log = nl;
  1059. } else {
  1060. for (log = gs->log; log; log = log->next) {
  1061. nl = nmalloc(sizeof(quotestr));
  1062. nl->quote = nmalloc(strlen(log->quote) + 1);
  1063. strcpy(nl->quote, log->quote);
  1064. nl->next = NULL;
  1065. for (l = nk->log; l && l->next; l = l->next);
  1066. if (l)
  1067. l->next = nl;
  1068. else
  1069. nk->log = nl;
  1070. }
  1071. }
  1072. if (k)
  1073. k->next = nk;
  1074. else
  1075. gs->kicks = nk;
  1076. debug1("Logged kick in %s.", gs->chan);
  1077. }
  1078. static int getplace(globstats *gs, int today, int itype, char *user)
  1079. {
  1080. locstats *ls;
  1081. int place = 0;
  1082. // if itype is < 0, get the modified itype that we need for accessing the data
  1083. if (itype < 0)
  1084. itype = (TOTAL_TYPES - 1) + (itype * -1);
  1085. for (ls = gs->slocal[today][itype]; ls; ls = ls->snext[today][itype]) {
  1086. if (!listsuser(ls, gs->chan))
  1087. continue;
  1088. place++;
  1089. if (!rfc_casecmp(ls->user, user))
  1090. return place;
  1091. }
  1092. return 0;
  1093. }
  1094. static int countstatmembers(globstats *gs)
  1095. {
  1096. int members = 0;
  1097. locstats *ls;
  1098. Context;
  1099. for (ls = gs->local; ls; ls = ls->next) {
  1100. if (listsuser(ls, gs->chan))
  1101. members++;
  1102. }
  1103. return members;
  1104. }
  1105. static int countallstatmembers(globstats *gs)
  1106. {
  1107. int members = 0;
  1108. locstats *ls;
  1109. Context;
  1110. for (ls = gs->local; ls; ls = ls->next)
  1111. members++;
  1112. return members;
  1113. }
  1114. /* countactivestatmembers():
  1115. * counts all active members in a chan (and skips dead entries)
  1116. */
  1117. static int countactivestatmembers(globstats *gs, int listable, int today, int type, int min)
  1118. {
  1119. int members = 0;
  1120. locstats *ls;
  1121. Context;
  1122. for (ls = gs->local; ls; ls = ls->next) {
  1123. if (ls->values[today][type] < min)
  1124. continue;
  1125. if (listable && !listsuser(ls, gs->chan))
  1126. continue;
  1127. members++;
  1128. }
  1129. return members;
  1130. }
  1131. static int gettotal(globstats *gs, int type, int today)
  1132. {
  1133. int total = 0;
  1134. locstats *ls;
  1135. for (ls = gs->local;ls; ls = ls->next) {
  1136. if (!ls->u)
  1137. ls->u = findsuser_by_name(ls->user);
  1138. if (ls->u && !suser_list(ls->u))
  1139. continue;
  1140. total += ls->values[today][type];
  1141. }
  1142. return total;
  1143. }
  1144. static void free_stats()
  1145. {
  1146. struct stats_global *sl;
  1147. Context;
  1148. while (sdata) {
  1149. sl = sdata->next;
  1150. free_localstats(sdata->local);
  1151. free_wordstats(sdata->words);
  1152. free_topics(sdata->topics);
  1153. free_urls(sdata->urls);
  1154. free_quotes(sdata->log);
  1155. free_hosts(sdata->hosts);
  1156. free_kicks(sdata->kicks);
  1157. nfree(sdata->chan);
  1158. nfree(sdata);
  1159. sdata = sl;
  1160. }
  1161. sdata = NULL;
  1162. llist_free(&schanset);
  1163. // schans = NULL;
  1164. free_suserlist(suserlist);
  1165. suserlist = NULL;
  1166. slang_glob_free();
  1167. Context;
  1168. return;
  1169. }
  1170. static void free_localstats(struct stats_local *sl)
  1171. {
  1172. struct stats_local *sll;
  1173. Context;
  1174. while (sl) {
  1175. Context;
  1176. sll = sl->next;
  1177. free_wordstats(sl->words);
  1178. free_quotes(sl->quotes);
  1179. nfree(sl->user);
  1180. nfree(sl);
  1181. sl = sll;
  1182. Context;
  1183. }
  1184. Context;
  1185. return;
  1186. }
  1187. static void free_wordstats(wordstats *l)
  1188. {
  1189. wordstats *ll;
  1190. Context;
  1191. while (l) {
  1192. ll = l->next;
  1193. nfree(l->word);
  1194. nfree(l);
  1195. l = ll;
  1196. }
  1197. return;
  1198. }
  1199. static void free_quotes(quotestr *l)
  1200. {
  1201. quotestr *ll;
  1202. Context;
  1203. while (l) {
  1204. ll = l->next;
  1205. nfree(l->quote);
  1206. nfree(l);
  1207. l = ll;
  1208. }
  1209. return;
  1210. }
  1211. static void free_topics(topicstr *e)
  1212. {
  1213. topicstr *ee;
  1214. Context;
  1215. while (e) {
  1216. ee = e->next;
  1217. nfree(e->topic);
  1218. nfree(e->by);
  1219. nfree(e);
  1220. e = ee;
  1221. }
  1222. return;
  1223. }
  1224. static void free_urls(struct stats_url *e)
  1225. {
  1226. struct stats_url *ee;
  1227. Context;
  1228. while (e) {
  1229. ee = e->next;
  1230. nfree(e->url);
  1231. nfree(e->by);
  1232. nfree(e);
  1233. e = ee;
  1234. }
  1235. return;
  1236. }
  1237. static void free_kicks(struct stats_kick *e)
  1238. {
  1239. struct stats_kick *ee;
  1240. Context;
  1241. while (e) {
  1242. ee = e->next;
  1243. free_quotes(e->log);
  1244. nfree(e);
  1245. e = ee;
  1246. }
  1247. }
  1248. static void free_hosts(hoststr *e)
  1249. {
  1250. hoststr *ee;
  1251. Context;
  1252. while (e) {
  1253. ee = e->next;
  1254. nfree(e->host);
  1255. nfree(e);
  1256. e = ee;
  1257. }
  1258. return;
  1259. }
  1260. static int userdata_merge(char *sTo, char *sFrom)
  1261. {
  1262. globstats *gs;
  1263. locstats *ls;
  1264. int i, found = 0;
  1265. for (gs = sdata; gs; gs = gs->next) {
  1266. for (ls = gs->local; ls; ls = ls->next) {
  1267. if (!strcasecmp(ls->user, sFrom)) {
  1268. found = 1;
  1269. for (i = 0; i < TOTAL_TYPES; i++) {
  1270. incrstats(sTo, gs->chan, i, ls->values[S_TOTAL][i], (S_TOTAL + 1) * (-1));
  1271. incrstats(sTo, gs->chan, i, ls->values[S_DAILY][i], (S_DAILY + 1) * (-1));
  1272. incrstats(sTo, gs->chan, i, ls->values[S_WEEKLY][i], (S_WEEKLY + 1) * (-1));
  1273. incrstats(sTo, gs->chan, i, ls->values[S_MONTHLY][i], (S_MONTHLY + 1) * (-1));
  1274. }
  1275. if (getstats(sTo, "", "gstarted", 0) < getstats(sFrom, "", "gstarted", 0))
  1276. incrstats(sTo, "", T_LSTARTED, getstats(sFrom, "", "gstarted", 0), 1);
  1277. }
  1278. }
  1279. }
  1280. return found;
  1281. }