templates_stats_commands.c 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483
  1. /*
  2. * Copyright (C) 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 float glob_r, glob_g, glob_b, glob_rstep, glob_gstep, glob_bstep;
  19. #define CF_TOP -1
  20. #define CF_TOPICS -2
  21. #define CF_MISCFACTS -3
  22. #define CF_USERS -4
  23. #define CF_ONCHAN -5
  24. /* template_init_colorfade()
  25. * see template_add_cmd_init_colorfade for description
  26. */
  27. static void template_init_colorfade(int idx, struct template_content *htpc)
  28. {
  29. int wert, steps;
  30. float r2, b2, g2;
  31. memberlist *m;
  32. struct chanset_t *chan;
  33. topicstr *topic;
  34. int ret;
  35. // find out how many steps the color fade will have
  36. steps = htpc->intpar1;
  37. // if it has 0 steps, then the number of steps wasn't specified as parameter,
  38. // so we'll just use the number of results
  39. if (steps == CF_TOP)
  40. steps = webnr;
  41. else if (steps == CF_MISCFACTS) {
  42. steps = 0;
  43. for (ret = selectfirstfact(); ret; ret = selectnextfact())
  44. steps++;
  45. } else if ((steps == CF_USERS) && glob_globstats)
  46. steps = countallstatmembers(glob_globstats);
  47. else if ((steps == CF_ONCHAN) && glob_globstats) {
  48. steps = 0;
  49. chan = findchan_by_dname(glob_globstats->chan);
  50. if (chan)
  51. for (m = chan->channel.member; m && m->nick[0]; m = m->next)
  52. steps++;
  53. } else if ((steps == CF_TOPICS) && glob_globstats) {
  54. steps = 0;
  55. for (topic = glob_globstats->topics; topic; topic = topic->next)
  56. steps++;
  57. } else if (steps < 1)
  58. steps = 1;
  59. // split our r/g/b values of the starting color (stored in intpar1)
  60. wert = htpc->floatpar1;
  61. glob_b = wert & 0xff; glob_g = (wert & 0xff00) >> 8; glob_r = (wert & 0xff0000) >> 16;
  62. // now do the same with the target color (intpar2)
  63. wert = htpc->floatpar2;
  64. b2 = wert & 0xff; g2 = (wert & 0xff00) >> 8; r2 = (wert & 0xff0000) >> 16;
  65. // finally, determine the "length" of a step between colors
  66. glob_rstep = (r2 - glob_r) / steps;
  67. glob_gstep = (g2 - glob_g) / steps;
  68. glob_bstep = (b2 - glob_b) / steps;
  69. // all global variables are now initialized and can be used.
  70. }
  71. /* template_add_cmd_init_colorfade():
  72. * Parameters: <startcolor> <endcolor> [steps]
  73. * initialiazes a color-fade from <startcolor> to <endcolor>
  74. * in [steps] steps. (if steps isn't defined, numresults is used)
  75. */
  76. static void template_add_cmd_init_colorfade(struct template_content *h_tpc,
  77. struct llist_2string *params,
  78. char *included_text)
  79. {
  80. char *startcolor, *endcolor, *steps;
  81. float istartcolor, iendcolor, isteps;
  82. Context;
  83. startcolor = endcolor = steps = "";
  84. for (; params; params = params->next) {
  85. if (!strcasecmp(params->s1, "startcolor"))
  86. startcolor = params->s2;
  87. else if (!strcasecmp(params->s1, "endcolor"))
  88. endcolor = params->s2;
  89. else if (!strcasecmp(params->s1, "steps"))
  90. steps = params->s2;
  91. else
  92. putlog(LOG_MISC, "*", "ERROR parsing templates: Unknown parameter '%s' "
  93. "for command init_color_fade.", params->s1);
  94. }
  95. istartcolor = strtol(startcolor, NULL, 0);
  96. iendcolor = strtol(endcolor, NULL, 0);
  97. if (!istartcolor)
  98. istartcolor = table_color;
  99. if (!iendcolor)
  100. iendcolor = fade_table_to;
  101. if (!strcasecmp(steps, "toplist"))
  102. isteps = CF_TOP;
  103. else if (!strcasecmp(steps, "topics"))
  104. isteps = CF_TOPICS;
  105. else if (!strcasecmp(steps, "miscfacts"))
  106. isteps = CF_MISCFACTS;
  107. else if (!strcasecmp(steps, "users"))
  108. isteps = CF_USERS;
  109. else if (!strcasecmp(steps, "onchan"))
  110. isteps = CF_ONCHAN;
  111. else
  112. isteps = strtol(steps, NULL, 0);
  113. // now write a pointer to the executing command and all parameters into our
  114. // content structure
  115. h_tpc->command = template_init_colorfade;
  116. h_tpc->floatpar1 = istartcolor;
  117. h_tpc->floatpar2 = iendcolor;
  118. h_tpc->intpar1 = isteps;
  119. }
  120. /* template_send_fcolor():
  121. * outputs the current color-code
  122. */
  123. static void template_send_fcolor(int idx, struct template_content *htpc)
  124. {
  125. dprintf(idx, "#%02x%02x%02x", (int) glob_r, (int) glob_g, (int) glob_b);
  126. }
  127. /* template_fade_color():
  128. * fades the color one step further
  129. */
  130. static void template_fade_color(int idx, struct template_content *htpc)
  131. {
  132. glob_r += glob_rstep;
  133. glob_g += glob_gstep;
  134. glob_b += glob_bstep;
  135. }
  136. /* <?chanlist ...?>
  137. * outputs the list of channels
  138. */
  139. static void template_send_chanlist(int idx, struct template_content *h_tpc)
  140. {
  141. globstats *gs;
  142. Context;
  143. for (gs = sdata; gs; gs = gs->next) {
  144. if (!egg_chan_active(gs->chan))
  145. continue;
  146. /* if (!list_secret_chans && secretchan(gs->chan))
  147. continue; */
  148. /* if (inactivechan(gs->chan))
  149. continue;
  150. */
  151. glob_globstats = gs;
  152. debug0("lang für skins nicht vergessen!");
  153. templates_content_send(h_tpc->subcontent, idx);
  154. }
  155. }
  156. /* <?chan?>
  157. * outputs the current chan
  158. */
  159. static void template_send_chan(int idx, struct template_content *tpc)
  160. {
  161. char *chan;
  162. if (glob_globstats) {
  163. if (tpc->floatpar1 && glob_globstats->chan[0] == '#')
  164. chan = glob_globstats->chan + 1;
  165. else
  166. chan = glob_globstats->chan;
  167. dprintf(idx, "%s", tpc->intpar1 ? encode_url(chan) : chan);
  168. }
  169. }
  170. /* <?encoded_chan?>
  171. * outputs the current channel, but in an encoded form, so that
  172. * it can be used in URLs
  173. */
  174. /*
  175. static void template_send_encoded_chan(int idx, struct template_content *tpc)
  176. {
  177. if (glob_globstats) {
  178. if (glob_globstats->chan[0] == '#')
  179. dprintf(idx, "%s", encode_url(glob_globstats->chan + 1));
  180. else
  181. dprintf(idx, "%s", encode_url(glob_globstats->chan));
  182. }
  183. }
  184. */
  185. /* <?topnr?>
  186. * outputs how many users get listed in the topX
  187. */
  188. static void template_send_topnr(int idx, struct template_content *tpc)
  189. {
  190. dprintf(idx, "%d", webnr);
  191. }
  192. /* <?current_topic?>
  193. * outputs the topic of the current chan (if there is any)
  194. */
  195. static void template_send_current_topic(int idx, struct template_content *tpc)
  196. {
  197. struct chanset_t *chan;
  198. if (glob_globstats) {
  199. chan = findchan_by_dname(glob_globstats->chan);
  200. if (chan && chan->channel.topic)
  201. dprintf(idx, "%s", text2html(chan->channel.topic));
  202. }
  203. }
  204. /* <?if_total ...?>
  205. * <?if_daily ...?>
  206. * <?if_weekly ...?>
  207. * <?if_monthly ...?>
  208. * outputs its subcontent if the current timerange is
  209. * TOTAL/DAILY/WEEKLY/MONTHLY
  210. */
  211. static void template_send_if_total(int idx, struct template_content *h_tpc)
  212. {
  213. if (glob_timerange == S_TOTAL)
  214. templates_content_send(h_tpc->subcontent, idx);
  215. }
  216. static void template_send_if_daily(int idx, struct template_content *h_tpc)
  217. {
  218. if (glob_timerange == S_DAILY)
  219. templates_content_send(h_tpc->subcontent, idx);
  220. }
  221. static void template_send_if_weekly(int idx, struct template_content *h_tpc)
  222. {
  223. if (glob_timerange == S_WEEKLY)
  224. templates_content_send(h_tpc->subcontent, idx);
  225. }
  226. static void template_send_if_monthly(int idx, struct template_content *h_tpc)
  227. {
  228. if (glob_timerange == S_MONTHLY)
  229. templates_content_send(h_tpc->subcontent, idx);
  230. }
  231. /* <?topstats ...?>
  232. * sends the list of stats which should be shown in the topX
  233. */
  234. static void template_send_topstats(int idx, struct template_content *h_tpc)
  235. {
  236. char buf[512], *pbuf;
  237. Context;
  238. strncpy(buf, webstats, sizeof(buf));
  239. pbuf = buf;
  240. while (pbuf[0]) {
  241. glob_toptype = newsplit(&pbuf);
  242. templates_content_send(h_tpc->subcontent, idx);
  243. }
  244. }
  245. /* <?toplist ...?>
  246. * sends the top X users
  247. */
  248. static void template_send_toplist(int idx, struct template_content *h_tpc)
  249. {
  250. locstats *ls;
  251. int sort;
  252. Context;
  253. Assert((glob_timerange >= 0) && (glob_timerange <= 3));
  254. if (glob_sorting == T_ERROR) {
  255. dprintf(idx, "<H1>ERROR! Invalid sorting!</H1>");
  256. return;
  257. }
  258. if (glob_sorting < 0)
  259. sort = (glob_sorting * -1) + (TOTAL_TYPES - 1);
  260. else
  261. sort = glob_sorting;
  262. debug0("überprüfen, ob toplist rekursions-fähig ist");
  263. glob_place = 0;
  264. for (ls = glob_globstats->slocal[glob_timerange][sort]; ls; ls = ls->snext[glob_timerange][sort]) {
  265. if (glob_place > glob_top_end)
  266. break;
  267. // skip users who shouldn't be listed (.schattr user -list)
  268. if (!listsuser(ls, glob_globstats->chan))
  269. continue;
  270. // break if the value is 0, because we probably reached the end
  271. // of the sorted list (who want's to see the stats of 1000 users who
  272. // don't have any stats in the sorted value?)
  273. if ((glob_sorting >= 0) && !ls->values[glob_timerange][glob_sorting])
  274. break;
  275. glob_place++;
  276. if (glob_place < glob_top_start)
  277. continue;
  278. glob_locstats = ls;
  279. if (!ls->u)
  280. ls->u = findsuser_by_name(ls->user);
  281. glob_user = ls->u;
  282. templates_content_send(h_tpc->subcontent, idx);
  283. }
  284. }
  285. static void template_send_type(int idx, struct template_content *h_tpc)
  286. {
  287. if (h_tpc->intpar1)
  288. dprintf(idx, "%s", getslangtype(glob_toptype));
  289. else
  290. dprintf(idx, "%s", glob_toptype);
  291. }
  292. static void template_add_cmd_type(struct template_content *h_tpc,
  293. struct llist_2string *params,
  294. char *included_text)
  295. {
  296. Context;
  297. for (; params; params = params->next)
  298. if (!strcasecmp(params->s1, "slang") && !strcasecmp(params->s2, "yes"))
  299. h_tpc->intpar1 = 1;
  300. }
  301. static void template_send_place(int idx, struct template_content *h_tpc)
  302. {
  303. dprintf(idx, "%d", glob_place);
  304. }
  305. static void template_add_cmd_chan_user(struct template_content *h_tpc,
  306. struct llist_2string *params,
  307. char *included_text)
  308. {
  309. Context;
  310. for (; params; params = params->next)
  311. if (!strcasecmp(params->s1, "encode") && !strcasecmp(params->s2, "yes"))
  312. h_tpc->intpar1 = 1;
  313. else if (!strcasecmp(params->s1, "short") && !strcasecmp(params->s2, "yes"))
  314. h_tpc->floatpar1 = 1.0;
  315. }
  316. static void template_send_user(int idx, struct template_content *h_tpc)
  317. {
  318. if (glob_locstats)
  319. dprintf(idx, "%s", h_tpc->intpar1 ? encode_url(glob_locstats->user) : glob_locstats->user);
  320. else if (glob_user)
  321. dprintf(idx, "%s", h_tpc->intpar1 ? encode_url(glob_user->user) : glob_user->user);
  322. }
  323. static void template_send_value(int idx, struct template_content *h_tpc)
  324. {
  325. int i;
  326. if (!glob_locstats || (glob_timerange == T_ERROR) || !glob_toptype) {
  327. if (!glob_locstats)
  328. debug0("no locstats");
  329. if (!glob_timerange == T_ERROR)
  330. debug0("no timerange");
  331. if (!glob_toptype)
  332. debug0("no toptype");
  333. return;
  334. }
  335. i = typetoi(glob_toptype);
  336. if (i == T_MINUTES)
  337. dprintf(idx, "%s", stats_duration(glob_locstats->values[glob_timerange][i] * 60, 2));
  338. else if (i >= 0)
  339. dprintf(idx, "%d", glob_locstats->values[glob_timerange][i]);
  340. else if (i == T_WPL) {
  341. if (glob_locstats->values[glob_timerange][T_LINES])
  342. dprintf(idx, "%.2f",
  343. ((float) glob_locstats->values[glob_timerange][T_WORDS])
  344. / ((float) glob_locstats->values[glob_timerange][T_LINES]));
  345. } else if (i == T_IDLE) {
  346. if (glob_locstats->values[glob_timerange][T_LINES])
  347. dprintf(idx, "%.2f",
  348. ((float) glob_locstats->values[glob_timerange][T_MINUTES])
  349. / ((float) glob_locstats->values[glob_timerange][T_LINES]));
  350. } else
  351. debug1("invalid type: %s", glob_toptype);
  352. }
  353. static void template_send_channel_load(int idx, struct template_content *h_tpc)
  354. {
  355. float umax, uonep, aonep, f;
  356. int i, amax;
  357. Context;
  358. if (!glob_globstats)
  359. return;
  360. umax = 0.0;
  361. amax = 0;
  362. for (i = 0; i < 24; i++) {
  363. if (glob_globstats->users[S_USERCOUNTS][i] > 0)
  364. if ((((float) glob_globstats->users[S_USERSUM][i]) / ((float) glob_globstats->users[S_USERCOUNTS][i])) > umax)
  365. umax = ((float) glob_globstats->users[S_USERSUM][i]) / ((float) glob_globstats->users[S_USERCOUNTS][i]);
  366. if (glob_globstats->activity[i] > amax)
  367. amax = glob_globstats->activity[i];
  368. }
  369. uonep = umax / 100.0;
  370. aonep = amax / 100.0;
  371. for (i = 0; i < 24; i++) {
  372. glob_cl_timerange = i;
  373. glob_activity = glob_globstats->activity[i];
  374. if (glob_globstats->users[S_USERCOUNTS][i] > 0) {
  375. f = ((float) glob_globstats->users[S_USERSUM][i]) / ((float) glob_globstats->users[S_USERCOUNTS][i]);
  376. glob_au_users = f;
  377. glob_au_percent = (int) (f / uonep);
  378. } else {
  379. glob_au_users = -1.0;
  380. glob_au_percent = -1;
  381. }
  382. if (glob_activity >= 0)
  383. glob_activity_percent = (int) (glob_globstats->activity[i] / aonep);
  384. else
  385. glob_activity_percent = 0;
  386. templates_content_send(h_tpc->subcontent, idx);
  387. }
  388. }
  389. static void template_send_au_users(int idx, struct template_content *h_tpc)
  390. {
  391. if (glob_au_percent >= 0)
  392. dprintf(idx, "%.1f", glob_au_users);
  393. }
  394. static void template_send_if_cl_logged(int idx, struct template_content *h_tpc)
  395. {
  396. if (glob_au_percent != -1)
  397. templates_content_send(h_tpc->subcontent, idx);
  398. }
  399. static void template_send_au_value(int idx, struct template_content *h_tpc)
  400. {
  401. if (!h_tpc->intpar1)
  402. return;
  403. dprintf(idx, "%d", (int) (((float) (glob_au_percent / 100.0)) * ((float) h_tpc->intpar1)));
  404. }
  405. static void template_add_cmd_au_value(struct template_content *h_tpc,
  406. struct llist_2string *params,
  407. char *included_text)
  408. {
  409. int max = 100;
  410. for (; params; params = params->next) {
  411. if (!strcasecmp(params->s1, "max"))
  412. max = atoi(params->s2);
  413. }
  414. if (!max)
  415. max = 100;
  416. h_tpc->intpar1 = max;
  417. }
  418. static void template_send_activity_value(int idx, struct template_content *h_tpc)
  419. {
  420. if (!h_tpc->intpar1)
  421. return;
  422. dprintf(idx, "%d", (int) (((float) (glob_activity_percent / 100.0)) * ((float) h_tpc->intpar1)));
  423. }
  424. static void template_send_activity(int idx, struct template_content *h_tpc)
  425. {
  426. dprintf(idx, "%d", glob_activity);
  427. }
  428. static void template_send_if_urls(int idx, struct template_content *h_tpc)
  429. {
  430. if (log_urls)
  431. if (glob_globstats)
  432. if (glob_globstats->urls)
  433. templates_content_send(h_tpc->subcontent, idx);
  434. }
  435. static void template_send_random_urls(int idx, struct template_content *h_tpc)
  436. {
  437. int urls, nr, i;
  438. unsigned long x;
  439. if (!glob_globstats || !log_urls)
  440. return;
  441. urls = 0;
  442. for (glob_url = glob_globstats->urls; glob_url; glob_url = glob_url->next) {
  443. urls++;
  444. glob_url->shown = 0;
  445. }
  446. if (!urls)
  447. return;
  448. Assert(glob_globstats->urls);
  449. if (urls > log_urls)
  450. nr = log_urls;
  451. else
  452. nr = urls;
  453. while (nr > 0) {
  454. x = random() % nr;
  455. i = 0;
  456. for (glob_url = glob_globstats->urls; glob_url; glob_url = glob_url->next) {
  457. if (glob_url->shown)
  458. continue;
  459. if (i == x) {
  460. glob_url->shown = 1;
  461. templates_content_send(h_tpc->subcontent, idx);
  462. urls--;
  463. }
  464. i++;
  465. }
  466. nr--;
  467. }
  468. }
  469. static void template_send_url(int idx, struct template_content *h_tpc)
  470. {
  471. if (glob_url)
  472. dprintf(idx, "%s", glob_url->url);
  473. }
  474. static void template_send_if_hosts(int idx, struct template_content *h_tpc)
  475. {
  476. if (glob_globstats)
  477. if (glob_globstats->hosts)
  478. templates_content_send(h_tpc->subcontent, idx);
  479. }
  480. static void template_send_hosts(int idx, struct template_content *h_tpc)
  481. {
  482. globstats *tlds, *isps;
  483. hoststr *h;
  484. char *host;
  485. char *s;
  486. int i;
  487. if (!glob_globstats)
  488. return;
  489. if (!glob_globstats->hosts)
  490. return;
  491. tlds = nmalloc(sizeof(globstats));
  492. tlds->hosts = NULL;
  493. isps = nmalloc(sizeof(globstats));
  494. isps->hosts = NULL;
  495. for (h = glob_globstats->hosts; h; h = h->next) {
  496. Assert(h->host);
  497. // skip IPv6 hosts
  498. if (strchr(h->host, ':'))
  499. continue;
  500. host = strrchr(h->host, '.') + 1;
  501. // skip other unusable hosts
  502. if (!((host - 1) && host)) {
  503. debug1("[stats.mod] Skipping host-stats for '%s'.", h->host);
  504. continue;
  505. }
  506. if (!atoi(host) && (host[0] != '0')) {
  507. addhost(host, tlds);
  508. host = h->host;
  509. while ((s = strchr(host, '.')) && strchr(s + 1, '.'))
  510. host = s + 1;
  511. addhost(host, isps);
  512. } else {
  513. addhost("[IP]", tlds);
  514. addhost("[IP]", isps);
  515. }
  516. }
  517. sorthosts(isps);
  518. sorthosts(tlds);
  519. i = 0;
  520. glob_isp = isps->hosts;
  521. glob_tld = tlds->hosts;
  522. while ((i <= 5) && (glob_isp || glob_tld)) {
  523. i++;
  524. templates_content_send(h_tpc->subcontent, idx);
  525. if (glob_isp)
  526. glob_isp = glob_isp->next;
  527. if (glob_tld)
  528. glob_tld = glob_tld->next;
  529. }
  530. free_hosts(isps->hosts);
  531. free_hosts(tlds->hosts);
  532. nfree(isps);
  533. nfree(tlds);
  534. }
  535. static void template_send_isp(int idx, struct template_content *h_tpc)
  536. {
  537. if (glob_isp)
  538. dprintf(idx, "%s", glob_isp->host);
  539. }
  540. static void template_send_ispnr(int idx, struct template_content *h_tpc)
  541. {
  542. if (glob_isp)
  543. dprintf(idx, "%d", glob_isp->nr);
  544. }
  545. static void template_send_tld(int idx, struct template_content *h_tpc)
  546. {
  547. if (glob_tld)
  548. dprintf(idx, "%s", glob_tld->host);
  549. }
  550. static void template_send_tldnr(int idx, struct template_content *h_tpc)
  551. {
  552. if (glob_tld)
  553. dprintf(idx, "%d", glob_tld->nr);
  554. }
  555. static void template_send_if_kicks(int idx, struct template_content *h_tpc)
  556. {
  557. if (glob_globstats)
  558. if (glob_globstats->kicks)
  559. templates_content_send(h_tpc->subcontent, idx);
  560. }
  561. static void template_send_random_kicks(int idx, struct template_content *h_tpc)
  562. {
  563. int nr, i, kicks;
  564. struct stats_kick *kick;
  565. unsigned long x;
  566. if (!glob_globstats)
  567. return;
  568. if (!glob_globstats->kicks)
  569. return;
  570. nr = 0;
  571. for (kick = glob_globstats->kicks; kick; kick = kick->next) {
  572. nr++;
  573. kick->shown = 0;
  574. }
  575. if (nr > display_kicks)
  576. kicks = display_kicks;
  577. else
  578. kicks = nr;
  579. while (kicks > 0) {
  580. x = random() % nr;
  581. i = 0;
  582. for (glob_kick = glob_globstats->kicks; glob_kick; glob_kick = glob_kick->next) {
  583. if (glob_kick->shown)
  584. continue;
  585. if (i == x) {
  586. glob_kick->shown = 1;
  587. templates_content_send(h_tpc->subcontent, idx);
  588. break;
  589. }
  590. i++;
  591. }
  592. nr--;
  593. kicks--;
  594. }
  595. }
  596. /* <?kick_contexts ..?>
  597. * sends the last few loglines before a kick occured.
  598. * the log of the actual kick is _not_ sent with this command
  599. */
  600. static void template_send_kick_contexts(int idx, struct template_content *h_tpc)
  601. {
  602. if (!glob_kick)
  603. return;
  604. for (glob_kick_context = glob_kick->log; glob_kick_context && glob_kick_context->next; glob_kick_context = glob_kick_context->next)
  605. templates_content_send(h_tpc->subcontent, idx);
  606. }
  607. static void template_send_kick_context(int idx, struct template_content *h_tpc)
  608. {
  609. if (glob_kick_context)
  610. dprintf(idx, "%s", text2html(glob_kick_context->quote));
  611. }
  612. static void template_send_kick(int idx, struct template_content *h_tpc)
  613. {
  614. struct stats_quote *k;
  615. if (!glob_kick)
  616. return;
  617. for (k = glob_kick->log; k && k->next; k = k->next);
  618. dprintf(idx, "%s", text2html(k->quote));
  619. }
  620. static void template_send_if_topics(int idx, struct template_content *h_tpc)
  621. {
  622. if (glob_globstats)
  623. if (glob_globstats->topics)
  624. templates_content_send(h_tpc->subcontent, idx);
  625. }
  626. static void template_send_topiclist(int idx, struct template_content *h_tpc)
  627. {
  628. if (glob_globstats)
  629. for (glob_topic = glob_globstats->topics; glob_topic; glob_topic = glob_topic->next)
  630. templates_content_send(h_tpc->subcontent, idx);
  631. }
  632. static void template_send_topic(int idx, struct template_content *h_tpc)
  633. {
  634. if (glob_topic)
  635. dprintf(idx, "%s", text2html(glob_topic->topic));
  636. }
  637. static void template_send_topic_set_by(int idx, struct template_content *h_tpc)
  638. {
  639. if (glob_topic)
  640. dprintf(idx, "%s", glob_topic->by);
  641. }
  642. static void template_send_topic_set_when(int idx, struct template_content *h_tpc)
  643. {
  644. char ts[21];
  645. if (glob_topic) {
  646. strftime(ts, 20, "%H:%M", localtime(&glob_topic->when));
  647. dprintf(idx, "%s", ts);
  648. }
  649. }
  650. static void template_send_if_chan_topwords(int idx, struct template_content *h_tpc)
  651. {
  652. locstats *ls;
  653. if (glob_globstats) {
  654. for (ls = glob_globstats->local; ls; ls = ls->next) {
  655. if (ls->words) {
  656. templates_content_send(h_tpc->subcontent, idx);
  657. return;
  658. }
  659. }
  660. }
  661. }
  662. static void template_send_chan_topwords(int idx, struct template_content *h_tpc)
  663. {
  664. if (!glob_globstats)
  665. return;
  666. do_globwordstats(glob_globstats);
  667. glob_wordplace = 0;
  668. for (glob_wordstats = glob_globstats->words;
  669. glob_wordstats && (glob_wordplace < 10);
  670. glob_wordstats = glob_wordstats->next) {
  671. glob_wordplace++;
  672. templates_content_send(h_tpc->subcontent, idx);
  673. }
  674. }
  675. static void template_send_if_user_topwords(int idx, struct template_content *h_tpc)
  676. {
  677. if (glob_locstats)
  678. if (glob_locstats->words)
  679. templates_content_send(h_tpc->subcontent, idx);
  680. }
  681. static void template_send_user_topwords(int idx, struct template_content *h_tpc)
  682. {
  683. if (!glob_locstats)
  684. return;
  685. sortwordstats(glob_locstats, NULL);
  686. glob_wordplace = 0;
  687. for (glob_wordstats = glob_locstats->words;
  688. glob_wordstats && (glob_wordplace < 10);
  689. glob_wordstats = glob_wordstats->next) {
  690. glob_wordplace++;
  691. templates_content_send(h_tpc->subcontent, idx);
  692. }
  693. }
  694. static void template_send_wordplace(int idx, struct template_content *h_tpc)
  695. {
  696. dprintf(idx, "%d", glob_wordplace);
  697. }
  698. static void template_send_word(int idx, struct template_content *h_tpc)
  699. {
  700. if (glob_wordstats)
  701. dprintf(idx, "%s", text2html(glob_wordstats->word));
  702. }
  703. static void template_send_wordnr(int idx, struct template_content *h_tpc)
  704. {
  705. if (glob_wordstats)
  706. dprintf(idx, "%d", glob_wordstats->nr);
  707. }
  708. static void template_send_miscfacts(int idx, struct template_content *h_tpc)
  709. {
  710. /* struct slang_lang *l;
  711. int itype, pitype;
  712. locstats *ls;
  713. if (!glob_globstats)
  714. return;
  715. // at first, find the current language
  716. for (l = slangs; l; l = l->next) {
  717. if ((!l->lang && !slgloblang) || (l->lang && slgloblang && !strcasecmp(l->lang, slgloblang))) {
  718. // now cycle through all fact-types
  719. for (glob_fact = l->bignumbers; glob_fact; glob_fact = glob_fact->next) {
  720. itype = typetoi(glob_fact->type);
  721. if (itype < 0)
  722. pitype = (itype * -1) + (TOTAL_TYPES - 1);
  723. else
  724. pitype = itype;
  725. sortstats(glob_globstats, itype, S_DAILY);
  726. ls = glob_globstats->slocal[S_DAILY][pitype];
  727. if (!ls)
  728. continue;
  729. else if ((itype >= 0) && !ls->values[S_DAILY][itype])
  730. continue;
  731. else if ((itype == T_WPL) && (!ls->values[S_DAILY][T_WORDS] || !ls->values[S_DAILY][T_LINES]))
  732. continue;
  733. else if ((itype == T_IDLE) && (!ls->values[S_DAILY][T_MINUTES] || !ls->values[S_DAILY][T_LINES]))
  734. continue;
  735. else if ((itype == T_VOCABLES) && !ls->vocables)
  736. continue;
  737. templates_content_send(h_tpc->subcontent, idx);
  738. }
  739. }
  740. }*/
  741. int ret;
  742. for (ret = selectfirstfact(); ret; ret = selectnextfact())
  743. templates_content_send(h_tpc->subcontent, idx);
  744. }
  745. static void template_send_fact(int idx, struct template_content *h_tpc)
  746. {
  747. /* unsigned long x;
  748. int itype, pitype, iplace;
  749. locstats *ls;
  750. struct slang_texts *txt;
  751. struct slang_bnplaces *place;
  752. if (!glob_fact || !glob_globstats)
  753. return;
  754. itype = typetoi(glob_fact->type);
  755. sortstats(glob_globstats, itype, S_DAILY);
  756. // now find the desired place
  757. for (place = glob_fact->places; place; place = place->next)
  758. if (place->place == h_tpc->intpar1)
  759. break;
  760. if (!place)
  761. return;
  762. if (itype < 0)
  763. pitype = (itype * -1) + (TOTAL_TYPES - 1);
  764. else
  765. pitype = itype;
  766. ls = glob_globstats->slocal[S_DAILY][pitype];
  767. // now find the user who who is on the specified place
  768. iplace = 1;
  769. while (ls && (iplace < place->place)) {
  770. iplace++;
  771. ls = ls->snext[S_DAILY][pitype];
  772. }
  773. // just don't output anything if there's no useful data
  774. if (!ls)
  775. return;
  776. else if ((itype >= 0) && !ls->values[S_DAILY][itype])
  777. return;
  778. else if ((itype == T_WPL) && (!ls->values[S_DAILY][T_WORDS] || !ls->values[S_DAILY][T_LINES]))
  779. return;
  780. else if ((itype == T_IDLE) && (!ls->values[S_DAILY][T_MINUTES] || !ls->values[S_DAILY][T_LINES]))
  781. return;
  782. else if ((itype == T_VOCABLES) && !ls->vocables)
  783. return;
  784. slgloblocstats = ls;
  785. slglobtype = glob_fact->type;
  786. x = random() % place->entries;
  787. txt = place->texts;
  788. while (txt) {
  789. if (!x)
  790. dprintf(idx, "%s\n", dynamicslang(txt->text));
  791. x--;
  792. txt = txt->next;
  793. }
  794. */
  795. int place;
  796. char *fact;
  797. place = h_tpc->intpar1;
  798. if (!place)
  799. return;
  800. fact = getfact(place);
  801. if (fact)
  802. dprintf(idx, "%s", fact);
  803. }
  804. /* template_add_cmd_fact():
  805. * Parameters: <place>
  806. */
  807. static void template_add_cmd_fact(struct template_content *h_tpc,
  808. struct llist_2string *params,
  809. char *included_text)
  810. {
  811. int place;
  812. Context;
  813. place = 0;
  814. for (; params; params = params->next) {
  815. if (!strcasecmp(params->s1, "place"))
  816. place = atoi(params->s2);
  817. }
  818. if (!place) {
  819. putlog(LOG_MISC, "*", "Error parsing template: Invalid parameter for \"<?fact <place>?>\"!");
  820. place = 1;
  821. }
  822. h_tpc->command = template_send_fact;
  823. h_tpc->intpar1 = place;
  824. }
  825. static void template_send_userlist(int idx, struct template_content *h_tpc)
  826. {
  827. if (!glob_globstats)
  828. return;
  829. sort_stats_alphabetically(glob_globstats);
  830. for (glob_locstats = glob_globstats->local; glob_locstats; glob_locstats = glob_locstats->next)
  831. templates_content_send(h_tpc->subcontent, idx);
  832. }
  833. static void template_send_timeranges(int idx, struct template_content *h_tpc)
  834. {
  835. for (glob_timerange = 0; glob_timerange <= 3; glob_timerange++)
  836. templates_content_send(h_tpc->subcontent, idx);
  837. }
  838. static void template_send_timerange(int idx, struct template_content *h_tpc)
  839. {
  840. dprintf(idx, "%s", RANGESTR_LONG(glob_timerange));
  841. }
  842. static void template_send_tplace(int idx, struct template_content *h_tpc)
  843. {
  844. locstats *ls;
  845. int place = 0;
  846. if (!glob_globstats || !glob_locstats)
  847. return;
  848. sortstats(glob_globstats, T_WORDS, glob_timerange);
  849. for (ls = glob_globstats->slocal[glob_timerange][T_WORDS]; ls; ls = ls->snext[glob_timerange][T_WORDS]) {
  850. if (!listsuser(ls, glob_globstats->chan))
  851. continue;
  852. place++;
  853. if (ls == glob_locstats)
  854. break;
  855. }
  856. if (ls)
  857. dprintf(idx, "%d", place);
  858. else
  859. dprintf(idx, "-");
  860. }
  861. static void template_send_if_quote(int idx, struct template_content *h_tpc)
  862. {
  863. if (glob_locstats)
  864. if (glob_locstats->quotes)
  865. templates_content_send(h_tpc->subcontent, idx);
  866. }
  867. static void template_send_random_quote(int idx, struct template_content *h_tpc)
  868. {
  869. int nr, i;
  870. quotestr *qs;
  871. unsigned long x;
  872. if (!glob_locstats)
  873. return;
  874. if (!glob_locstats->quotes)
  875. return;
  876. nr = 0;
  877. for (qs = glob_locstats->quotes; qs; qs = qs->next)
  878. nr++;
  879. x = random() % nr;
  880. i = 0;
  881. qs = glob_locstats->quotes;
  882. while (qs) {
  883. if (i == x) {
  884. dprintf(idx, "%s", text2html(qs->quote));
  885. return;
  886. }
  887. qs = qs->next;
  888. i++;
  889. }
  890. }
  891. static void template_send_onchanlist(int idx, struct template_content *h_tpc)
  892. {
  893. struct stats_member *m;
  894. struct stats_chan *chan;
  895. if (!show_usersonchan || !glob_globstats)
  896. return;
  897. chan = schan_find(glob_globstats->chan);
  898. if (!chan)
  899. return;
  900. for (m = schan_members_getfirst(&chan->members); m ; m = schan_members_getnext(&chan->members)) {
  901. glob_statsmember = m;
  902. glob_user = m->user;
  903. if (m->stats)
  904. glob_locstats = m->stats;
  905. else
  906. glob_locstats = NULL;
  907. templates_content_send(h_tpc->subcontent, idx);
  908. }
  909. }
  910. static void template_send_usermode(int idx, struct template_content *h_tpc)
  911. {
  912. if (glob_statsmember && glob_statsmember->eggmember) {
  913. #ifndef NO_EGG
  914. if (chan_hasop(glob_statsmember->eggmember))
  915. dprintf(idx, "@");
  916. if (chan_hasvoice(glob_statsmember->eggmember))
  917. dprintf(idx, "+");
  918. #endif
  919. }
  920. }
  921. static void template_send_if_user(int idx, struct template_content *h_tpc)
  922. {
  923. if (glob_locstats)
  924. templates_content_send(h_tpc->subcontent, idx);
  925. }
  926. static void template_send_if_nouser(int idx, struct template_content *h_tpc)
  927. {
  928. if (!glob_locstats)
  929. templates_content_send(h_tpc->subcontent, idx);
  930. }
  931. static void template_send_idletime(int idx, struct template_content *h_tpc)
  932. {
  933. if (!glob_statsmember)
  934. return;
  935. #ifndef NO_EGG
  936. if (glob_statsmember->eggmember && chan_issplit(glob_statsmember->eggmember))
  937. return;
  938. #endif
  939. dprintf(idx, "%s", stats_duration(now - glob_statsmember->last, 2));
  940. }
  941. static void template_send_if_netsplitted(int idx, struct template_content *h_tpc)
  942. {
  943. #ifndef NO_EGG
  944. if (!glob_statsmember || !glob_statsmember->eggmember)
  945. return;
  946. if (chan_issplit(glob_statsmember->eggmember))
  947. templates_content_send(h_tpc->subcontent, idx);
  948. #endif
  949. }
  950. static void template_send_nick(int idx, struct template_content *h_tpc)
  951. {
  952. if (glob_statsmember)
  953. dprintf(idx, "%s", glob_statsmember->nick);
  954. }
  955. static void template_send_graphstats(int idx, struct template_content *h_tpc)
  956. {
  957. char buf[512], *pbuf;
  958. locstats ls;
  959. Context;
  960. if (!glob_globstats || (glob_timerange == T_ERROR))
  961. return;
  962. locstats_init(&ls);
  963. strncpy(buf, graphstats, sizeof(buf));
  964. pbuf = buf;
  965. while (pbuf[0]) {
  966. glob_toptype = newsplit(&pbuf);
  967. glob_sorting = slangtypetoi(glob_toptype);
  968. if (glob_sorting < 0)
  969. continue;
  970. sortstats(glob_globstats, glob_sorting, glob_timerange);
  971. glob_graph_total = gettotal(glob_globstats, glob_sorting, glob_timerange);
  972. ls.values[glob_timerange][glob_sorting] = glob_graph_total;
  973. glob_locstats = &ls;
  974. templates_content_send(h_tpc->subcontent, idx);
  975. }
  976. }
  977. static void template_send_graphs(int idx, struct template_content *h_tpc)
  978. {
  979. float percent, wpercent, onep;
  980. locstats *ls;
  981. int max;
  982. if (!glob_globstats || (glob_sorting == T_ERROR) ||
  983. (glob_timerange == T_ERROR) || (glob_sorting < 0))
  984. return;
  985. max = 0;
  986. for (ls = glob_globstats->slocal[glob_timerange][glob_sorting];
  987. ls;
  988. ls = ls->snext[glob_timerange][glob_sorting]) {
  989. if (listsuser(ls, glob_globstats->chan)) {
  990. max = ls->values[glob_timerange][glob_sorting];
  991. break;
  992. }
  993. }
  994. if (!glob_graph_total || !max)
  995. return;
  996. onep = (float) glob_graph_total / 100.0;
  997. glob_place = 0;
  998. for (ls = glob_globstats->slocal[glob_timerange][glob_sorting];
  999. ls;
  1000. ls = ls->snext[glob_timerange][glob_sorting]) {
  1001. if (!listsuser(ls, glob_globstats->chan))
  1002. continue;
  1003. if (!ls->values[glob_timerange][glob_sorting])
  1004. break;
  1005. glob_place++;
  1006. if (glob_place > graphnr)
  1007. break;
  1008. percent = (float) ls->values[glob_timerange][glob_sorting] / onep;
  1009. wpercent = (float) ls->values[glob_timerange][glob_sorting] / ((float) max / 100.0);
  1010. glob_graph_percent = percent;
  1011. glob_graph_width_percent = wpercent;
  1012. glob_locstats = ls;
  1013. templates_content_send(h_tpc->subcontent, idx);
  1014. }
  1015. }
  1016. /* static void template_send_graph_filled_percent(int idx, struct template_content *h_tpc)
  1017. *{
  1018. * dprintf(idx, "%d%%", (int) (glob_graph_width_percent * 0.8));
  1019. *}
  1020. */
  1021. static void template_send_graph_percent(int idx, struct template_content *h_tpc)
  1022. {
  1023. if (!h_tpc->intpar1)
  1024. dprintf(idx, "%.2f", glob_graph_percent);
  1025. else
  1026. dprintf(idx, "%d", (int) (((float) (glob_graph_width_percent / 100.0)) * ((float) h_tpc->intpar1)));
  1027. }
  1028. static void template_add_cmd_graph_percent(struct template_content *h_tpc,
  1029. struct llist_2string *params,
  1030. char *included_text)
  1031. {
  1032. int max = 100, stretch = 0;
  1033. for (; params; params = params->next) {
  1034. if (!strcasecmp(params->s1, "max"))
  1035. max = atoi(params->s2);
  1036. if (!strcasecmp(params->s1, "stretch") && !strcasecmp(params->s2, "true"))
  1037. stretch = 1;
  1038. }
  1039. if (!max)
  1040. max = 100;
  1041. if (stretch)
  1042. h_tpc->intpar1 = max;
  1043. else
  1044. h_tpc->intpar1 = 0;
  1045. }
  1046. /*static void template_send_graph_label_percent(int idx, struct template_content *h_tpc)
  1047. *{
  1048. * dprintf(idx, "%d%%", 100 - ((int) (glob_graph_width_percent * 0.8)));
  1049. *}
  1050. *
  1051. *static void template_send_graph_exact_percent(int idx, struct template_content *h_tpc)
  1052. *{
  1053. * dprintf(idx, "%.02f%%", glob_graph_percent);
  1054. *}
  1055. */
  1056. static void template_send_password(int idx, struct template_content *h_tpc)
  1057. {
  1058. if (glob_user && glob_user->password)
  1059. dprintf(idx, "%s", glob_user->password);
  1060. }
  1061. static void template_send_email(int idx, struct template_content *h_tpc)
  1062. {
  1063. if (glob_user && glob_user->email)
  1064. dprintf(idx, "%s", glob_user->email);
  1065. }
  1066. static void template_send_homepage(int idx, struct template_content *h_tpc)
  1067. {
  1068. if (glob_user && glob_user->homepage)
  1069. dprintf(idx, "%s", glob_user->homepage);
  1070. }
  1071. static void template_send_icqnr(int idx, struct template_content *h_tpc)
  1072. {
  1073. if (glob_user && glob_user->icqnr)
  1074. dprintf(idx, "%d", glob_user->icqnr);
  1075. }
  1076. static void template_send_if_icqnr(int idx, struct template_content *h_tpc)
  1077. {
  1078. if (!glob_user) {
  1079. debug0("WARNING: No globuser (if_icqnr)");
  1080. return;
  1081. }
  1082. if (glob_user->icqnr)
  1083. templates_content_send(h_tpc->subcontent, idx);
  1084. }
  1085. static void template_send_if_email(int idx, struct template_content *h_tpc)
  1086. {
  1087. if (!glob_user) {
  1088. debug0("WARNING: No globuser (if_email)");
  1089. return;
  1090. }
  1091. if (glob_user->email)
  1092. templates_content_send(h_tpc->subcontent, idx);
  1093. }
  1094. static void template_send_if_homepage(int idx, struct template_content *h_tpc)
  1095. {
  1096. if (!glob_user) {
  1097. debug0("WARNING: No globuser (if_homepage)");
  1098. return;
  1099. }
  1100. if (glob_user->homepage)
  1101. templates_content_send(h_tpc->subcontent, idx);
  1102. }
  1103. static void template_send_if_listuser(int idx, struct template_content *h_tpc)
  1104. {
  1105. if (!glob_user) {
  1106. debug0("WARNING: No globuser (if_listuser)");
  1107. return;
  1108. }
  1109. if (suser_list(glob_user))
  1110. templates_content_send(h_tpc->subcontent, idx);
  1111. }
  1112. static void template_send_if_addhosts(int idx, struct template_content *h_tpc)
  1113. {
  1114. if (!glob_user) {
  1115. debug0("WARNING: No globuser (if_addhosts)");
  1116. return;
  1117. }
  1118. if (suser_addhosts(glob_user))
  1119. templates_content_send(h_tpc->subcontent, idx);
  1120. }
  1121. static void template_send_if_not_listuser(int idx, struct template_content *h_tpc)
  1122. {
  1123. if (!glob_user) {
  1124. debug0("WARNING: No globuser (if_listuser)");
  1125. return;
  1126. }
  1127. if (!suser_list(glob_user))
  1128. templates_content_send(h_tpc->subcontent, idx);
  1129. }
  1130. static void template_send_if_not_addhosts(int idx, struct template_content *h_tpc)
  1131. {
  1132. if (!glob_user) {
  1133. debug0("WARNING: No globuser (if_addhosts)");
  1134. return;
  1135. }
  1136. if (!suser_addhosts(glob_user))
  1137. templates_content_send(h_tpc->subcontent, idx);
  1138. }
  1139. static void template_send_if_nostats(int idx, struct template_content *h_tpc)
  1140. {
  1141. if (glob_user && suser_nostats(glob_user))
  1142. templates_content_send(h_tpc->subcontent, idx);
  1143. }
  1144. static void template_send_if_not_nostats(int idx, struct template_content *h_tpc)
  1145. {
  1146. if (glob_user && !suser_nostats(glob_user))
  1147. templates_content_send(h_tpc->subcontent, idx);
  1148. }
  1149. static void template_send_login_error(int idx, struct template_content *h_tpc)
  1150. {
  1151. if (h_tpc->intpar1)
  1152. dprintf(idx, "%s", getslang(h_tpc->intpar1 + glob_loginerror));
  1153. }
  1154. static void template_add_cmd_login_error(struct template_content *h_tpc,
  1155. struct llist_2string *params,
  1156. char *included_text)
  1157. {
  1158. char *s_baseid;
  1159. s_baseid = llist_2string_get_s2(params, "baseid");
  1160. if (s_baseid)
  1161. h_tpc->intpar1 = atoi(s_baseid);
  1162. }
  1163. static void template_send_binary_url(int idx, struct template_content *h_tpc)
  1164. {
  1165. dprintf(idx, "%s", binary_url);
  1166. }
  1167. static void template_send_if_binary(int idx, struct template_content *h_tpc)
  1168. {
  1169. if (binary_url[0])
  1170. templates_content_send(h_tpc->subcontent, idx);
  1171. }
  1172. static void template_send_if_nobinary(int idx, struct template_content *h_tpc)
  1173. {
  1174. if (!binary_url[0])
  1175. templates_content_send(h_tpc->subcontent, idx);
  1176. }
  1177. static void template_send_memberage(int idx, struct template_content *h_tpc)
  1178. {
  1179. int max, age, maxage;
  1180. float onep, percent;
  1181. if (glob_locstats && !h_tpc->intpar1)
  1182. dprintf(idx, "%s", stats_duration(now - glob_locstats->started, 3));
  1183. else if (glob_locstats && glob_globstats) {
  1184. max = h_tpc->intpar1;
  1185. maxage = (int) h_tpc->floatpar1 * 60 * 60 * 24;
  1186. if ((now - glob_globstats->started) < maxage)
  1187. maxage = (now - glob_globstats->started);
  1188. age = now - glob_locstats->started;
  1189. onep = (float) maxage / (float) max;
  1190. percent = (float) age / onep;
  1191. dprintf(idx, "%d", (int) percent);
  1192. }
  1193. }
  1194. static void template_add_cmd_memberage(struct template_content *h_tpc,
  1195. struct llist_2string *params,
  1196. char *included_text)
  1197. {
  1198. int relative = 0, max = 100, maxage = 0;
  1199. for (; params; params = params->next) {
  1200. if (!strcasecmp(params->s1, "max"))
  1201. max = atoi(params->s2);
  1202. if (!strcasecmp(params->s1, "relative") &&
  1203. (!strcasecmp(params->s2, "true") || !strcasecmp(params->s2, "yes")))
  1204. relative = 1;
  1205. if (!strcasecmp(params->s1, "maxage"))
  1206. maxage = atoi(params->s2);
  1207. }
  1208. if (!max)
  1209. max = 100;
  1210. if (relative)
  1211. h_tpc->intpar1 = max;
  1212. else
  1213. h_tpc->intpar1 = 0;
  1214. h_tpc->floatpar1 = (float) maxage;
  1215. }
  1216. static void template_send_types(int idx, struct template_content *h_tpc)
  1217. {
  1218. char *buffer, *buf, *oldtype;
  1219. oldtype = glob_toptype; /* backup glob_toptype and pray that we don't
  1220. the old value during the cycle */
  1221. buffer = nmalloc(strlen(TYPES) + 1);
  1222. strcpy(buffer, TYPES);
  1223. buf = buffer;
  1224. for (glob_toptype = newsplit(&buf); glob_toptype[0];
  1225. glob_toptype = newsplit(&buf))
  1226. templates_content_send(h_tpc->subcontent, idx);
  1227. nfree(buffer);
  1228. buffer = nmalloc(strlen(SPECIAL_TYPES) + 1);
  1229. strcpy(buffer, SPECIAL_TYPES);
  1230. buf = buffer;
  1231. for (glob_toptype = newsplit(&buf); glob_toptype[0];
  1232. glob_toptype = newsplit(&buf))
  1233. templates_content_send(h_tpc->subcontent, idx);
  1234. nfree(buffer);
  1235. glob_toptype = oldtype;
  1236. }
  1237. static void template_send_sorting(int idx, struct template_content *h_tpc)
  1238. {
  1239. if (glob_sorting != T_ERROR)
  1240. dprintf(idx, "%s", itotype(glob_sorting));
  1241. }
  1242. static void template_send_userage(int idx, struct template_content *h_tpc)
  1243. {
  1244. if (glob_user)
  1245. dprintf(idx, "%s", stats_duration((now - glob_user->created), 3));
  1246. }
  1247. static void template_send_timetolive(int idx, struct template_content *h_tpc)
  1248. {
  1249. if (glob_user)
  1250. dprintf(idx, "%s", stats_duration(TIMETOLIVE(glob_user), 2));
  1251. }
  1252. struct template_commands stats_template_commands[] =
  1253. {
  1254. {"init_colorfade", template_init_colorfade, template_add_cmd_init_colorfade},
  1255. {"fcolor", template_send_fcolor, NULL},
  1256. {"fade_color", template_fade_color, NULL},
  1257. {"chanlist", template_send_chanlist, template_add_subcontent},
  1258. {"chan", template_send_chan, template_add_cmd_chan_user},
  1259. // {"encoded_chan", template_send_encoded_chan, NULL},
  1260. {"current_topic", template_send_current_topic, NULL},
  1261. {"topnr", template_send_topnr, NULL},
  1262. {"if_total", template_send_if_total, template_add_subcontent},
  1263. {"if_daily", template_send_if_daily, template_add_subcontent},
  1264. {"if_weekly", template_send_if_weekly, template_add_subcontent},
  1265. {"if_monthly", template_send_if_monthly, template_add_subcontent},
  1266. {"topstats", template_send_topstats, template_add_subcontent},
  1267. {"toplist", template_send_toplist, template_add_subcontent},
  1268. {"type", template_send_type, template_add_cmd_type},
  1269. {"types", template_send_types, template_add_subcontent},
  1270. {"place", template_send_place, NULL},
  1271. {"user", template_send_user, template_add_cmd_chan_user},
  1272. {"value", template_send_value, NULL},
  1273. {"if_urls", template_send_if_urls, template_add_subcontent},
  1274. {"random_urls", template_send_random_urls, template_add_subcontent},
  1275. {"url", template_send_url, NULL},
  1276. {"if_hosts", template_send_if_hosts, template_add_subcontent},
  1277. {"hosts", template_send_hosts, template_add_subcontent},
  1278. {"isp", template_send_isp, NULL},
  1279. {"ispnr", template_send_ispnr, NULL},
  1280. {"tld", template_send_tld, NULL},
  1281. {"tldnr", template_send_tldnr, NULL},
  1282. {"if_kicks", template_send_if_kicks, template_add_subcontent},
  1283. {"random_kicks", template_send_random_kicks, template_add_subcontent},
  1284. {"kick_contexts", template_send_kick_contexts, template_add_subcontent},
  1285. {"kick_context", template_send_kick_context, NULL},
  1286. {"kick", template_send_kick, NULL},
  1287. {"if_topics", template_send_if_topics, template_add_subcontent},
  1288. {"topiclist", template_send_topiclist, template_add_subcontent},
  1289. {"topic", template_send_topic, NULL},
  1290. {"topic_set_by", template_send_topic_set_by, NULL},
  1291. {"topic_set_when", template_send_topic_set_when, NULL},
  1292. {"if_chan_topwords", template_send_if_chan_topwords, template_add_subcontent},
  1293. {"chan_topwords", template_send_chan_topwords, template_add_subcontent},
  1294. {"if_user_topwords", template_send_if_user_topwords, template_add_subcontent},
  1295. {"user_topwords", template_send_user_topwords, template_add_subcontent},
  1296. {"wordplace", template_send_wordplace, NULL},
  1297. {"word", template_send_word, NULL},
  1298. {"wordnr", template_send_wordnr, NULL},
  1299. {"userlist", template_send_userlist, template_add_subcontent},
  1300. {"timeranges", template_send_timeranges, template_add_subcontent},
  1301. {"timerange", template_send_timerange, NULL},
  1302. {"tplace", template_send_tplace, NULL},
  1303. {"if_quote", template_send_if_quote, template_add_subcontent},
  1304. {"random_quote", template_send_random_quote, NULL},
  1305. {"onchanlist", template_send_onchanlist, template_add_subcontent},
  1306. {"usermode", template_send_usermode, NULL},
  1307. {"if_user", template_send_if_user, template_add_subcontent},
  1308. {"if_nouser", template_send_if_nouser, template_add_subcontent},
  1309. {"idletime", template_send_idletime, NULL},
  1310. {"if_netsplitted", template_send_if_netsplitted, template_add_subcontent},
  1311. {"nick", template_send_nick, NULL},
  1312. {"graphstats", template_send_graphstats, template_add_subcontent},
  1313. {"graphs", template_send_graphs, template_add_subcontent},
  1314. {"graph_percent", template_send_graph_percent, template_add_cmd_graph_percent},
  1315. {"password", template_send_password, NULL},
  1316. {"email", template_send_email, NULL},
  1317. {"homepage", template_send_homepage, NULL},
  1318. {"icqnr", template_send_icqnr, NULL},
  1319. {"if_icqnr", template_send_if_icqnr, template_add_subcontent},
  1320. {"if_homepage", template_send_if_homepage, template_add_subcontent},
  1321. {"if_email", template_send_if_email, template_add_subcontent},
  1322. {"if_listuser", template_send_if_listuser, template_add_subcontent},
  1323. {"if_addhosts", template_send_if_addhosts, template_add_subcontent},
  1324. {"if_not_listuser", template_send_if_not_listuser, template_add_subcontent},
  1325. {"if_not_addhosts", template_send_if_not_addhosts, template_add_subcontent},
  1326. {"if_nostats", template_send_if_nostats, template_add_subcontent},
  1327. {"if_not_nostats", template_send_if_not_nostats, template_add_subcontent},
  1328. {"login_error", template_send_login_error, template_add_cmd_login_error},
  1329. {"if_binary", template_send_if_binary, template_add_subcontent},
  1330. {"if_nobinary", template_send_if_nobinary, template_add_subcontent},
  1331. {"binary_url", template_send_binary_url, NULL},
  1332. {"miscfacts", template_send_miscfacts, template_add_subcontent},
  1333. {"fact", template_send_fact, template_add_cmd_fact},
  1334. {"activity_value", template_send_activity_value, template_add_cmd_au_value},
  1335. {"channel_load", template_send_channel_load, template_add_subcontent},
  1336. {"au_users", template_send_au_users, NULL},
  1337. {"activity", template_send_activity, NULL},
  1338. {"au_value", template_send_au_value, template_add_cmd_au_value},
  1339. {"if_cl_logged", template_send_if_cl_logged, template_add_subcontent},
  1340. {"memberage", template_send_memberage, template_add_cmd_memberage},
  1341. {"sorting", template_send_sorting, NULL},
  1342. {"userage", template_send_userage, NULL},
  1343. {"timetolive", template_send_timetolive, NULL},
  1344. {0, 0, 0},
  1345. };