4
0

stats.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. /*
  2. * Statistics module for eggdrop 1.4+
  3. * by G`Quann
  4. */
  5. /*
  6. * stats.c - this is never gonna work... (Oct 99)
  7. */
  8. /*
  9. * oops... seems that it works :) (Dec 99)
  10. */
  11. /*
  12. * Copyright (C) 2000,2001 Florian Sander
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License
  16. * as published by the Free Software Foundation; either version 2
  17. * of the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  27. */
  28. #define MAKING_STATS
  29. #define MODULE_NAME "stats"
  30. #define MODULE_VERSION "1.4.0 dev21"
  31. #ifndef NO_EGG
  32. #include "../module.h"
  33. #include "../irc.mod/irc.h"
  34. #include "../server.mod/server.h"
  35. #include "../channels.mod/channels.h"
  36. #else
  37. #include "compat/noegg.h"
  38. #include "compat/noegg.c"
  39. #endif
  40. #include <stdlib.h>
  41. #include <sys/stat.h>
  42. #include <time.h> /* for time_t */
  43. #include <ctype.h>
  44. #include <sys/types.h>
  45. #include <fcntl.h>
  46. #undef global
  47. #ifndef NO_EGG
  48. static Function *global = NULL, *irc_funcs = NULL, *server_funcs = NULL, *channels_funcs = NULL;
  49. #endif
  50. #ifndef EGG_IS_MIN_VER
  51. #define EGG_IS_MIN_VER(ver) ((ver) <= 10400)
  52. #endif
  53. #if !EGG_IS_MIN_VER(10500)
  54. #define OLDBOT 1
  55. #endif
  56. #ifndef Context
  57. #define Context context
  58. #endif
  59. #ifndef findchan_by_dname
  60. #define findchan_by_dname findchan
  61. #endif
  62. #ifndef my_htonl
  63. #define my_htonl htonl
  64. #endif
  65. // #include "stats.h"
  66. #ifndef NO_MEM_DEBUG
  67. #ifndef DYNAMIC_MEM_DEBUG
  68. #include "core/dynamic_mem_debug.c"
  69. #endif
  70. #endif
  71. /* static struct slang_lang *slangs = NULL;
  72. static struct slang_chan *slangchans = NULL;
  73. */
  74. #include "egg_chancontrol.h"
  75. #include "core/core.c"
  76. #include "settings.c"
  77. #include "misc.c"
  78. #include "pubcmds.h"
  79. #include "pubcmds.c"
  80. #include "msgcmds.c"
  81. #include "dcccmds.h"
  82. #include "dcccmds.c"
  83. #include "tclstats.c"
  84. #include "egg_chancontrol.c"
  85. #include "egg_bindings.c"
  86. static int stats_save_temp = 1;
  87. static int stats_expmem()
  88. {
  89. return 0;
  90. }
  91. /* a report on the module status */
  92. static void stats_report(int idx, int details)
  93. {
  94. // int memtotal, memusers, memchans, memtemplates, memslang, memdata;
  95. int users, hosts;
  96. Context;
  97. users = countsusers();
  98. hosts = counthosts();
  99. if (!details)
  100. dprintf(idx, " Stats-userbase contains %d users and %d hosts\n", users, hosts);
  101. else {
  102. /* memtotal = stats_expmem();
  103. memdata = stats_globstats_expmem(sdata);
  104. memusers = suserlist_expmem(suserlist);
  105. memchans = llist_expmem(&schanset);
  106. memtemplates = expmem_templates();
  107. memslang = slang_glob_expmem() + slang_expmem(coreslangs) +
  108. slang_chanlang_expmem(chanlangs);
  109. dprintf(idx, " Stats-userbase contains %d users and %d hosts using "
  110. "%d bytes.\n", users, hosts, memusers);
  111. dprintf(idx, " Statistic data itself using %d bytes.\n", memdata);
  112. dprintf(idx, " Channels and channel members using %d bytes.\n", memchans);
  113. dprintf(idx, " Templates using %d bytes.\n", memtemplates);
  114. dprintf(idx, " Total memory usage: %d bytes.\n", memtotal); */
  115. }
  116. }
  117. static void stats_minutely ()
  118. {
  119. eggbnd_minutely();
  120. if (stats_save_temp >= stats_save_time) {
  121. write_stats();
  122. stats_save_temp = 1;
  123. } else
  124. stats_save_temp++;
  125. }
  126. static void stats_daily ()
  127. {
  128. Context;
  129. deloldstatusers();
  130. purgestats();
  131. reset_tstats();
  132. if (lastmonth != getmonth()) {
  133. reset_mwstats(S_MONTHLY);
  134. lastmonth = getmonth();
  135. }
  136. if (ismonday())
  137. reset_mwstats(S_WEEKLY);
  138. update_schannel_members();
  139. Context;
  140. }
  141. static tcl_ints my_tcl_ints[] =
  142. {
  143. {"save-stats", &stats_save_time, 0},
  144. {"webnr", &webnr, 0},
  145. {"topnr", &webnr, 0},
  146. {"graphnr", &graphnr, 0},
  147. {"autoadd", &autoadd, 0},
  148. {"write-today", &write_today, 0},
  149. {"stats-file-mode", &statsfilemode, 0},
  150. {"livestats-timeout", &livestats_timeout, 0},
  151. {"offset", &offset, 0},
  152. {"topwords-limit", &topwords_limit, 0},
  153. {"quote-frequency", &quote_freq, 0},
  154. {"log-wordstats", &log_wordstats, 0},
  155. {"min-word-length", &min_word_length, 0},
  156. {"table-color", &table_color, 0},
  157. {"fade-table-to", &fade_table_to, 0},
  158. {"table-border", &table_border, 0},
  159. {"display-urls", &log_urls, 0},
  160. {"kick-context", &kick_context, 0},
  161. {"display-kicks", &display_kicks, 0},
  162. {"display-average-users", &display_average_users, 0},
  163. {"show-userlist", &show_userlist, 0},
  164. {"show-usersonchan", &show_usersonchan, 0},
  165. {"list-secret-chans", &list_secret_chans, 0},
  166. {"autoadd-min-lines", &autoadd_min_lines, 0},
  167. {"min-lines", &min_lines, 0},
  168. {"expire-base", &expire_base, 0},
  169. {"expire-factor", &expire_factor, 0},
  170. {"greet-new-users", &greet_new_users, 0},
  171. {0, 0, 0}
  172. };
  173. static tcl_strings my_tcl_strings[] =
  174. {
  175. {"statsfile", statsfile, 121, 0},
  176. {"webstats", webstats, 510, 0},
  177. {"topstats", webstats, 510, 0},
  178. {"webdir", webdir, 256, 0},
  179. {"smileys", smileys, 128, 0},
  180. {"smilies", smileys, 128, 0},
  181. {"graphstats", graphstats, 510, 0},
  182. {"graphgif", graphgif, 128, 0},
  183. {"graphcolor", graphcolor, 20, 0},
  184. {"anti-autoadd-flags", badflags, 20, 0},
  185. {"anti-stats-flag", nostatsflags, 20, 0},
  186. {"anti-peak-flag", nopeak, 20, 0},
  187. {"network", network, 40, 0},
  188. {"livestats-loglevel", httpd_loglevel, 20, 0},
  189. {"livestats-log", httpd_log, 121, 0},
  190. {"stat-reply", stat_reply, 128, 0},
  191. {"livestats-ignore-msg", httpd_ignore_msg, 255, 0},
  192. {"livestats-ip", httpd_ip, 20, 0},
  193. {"default-slang", default_slang, 20, 0},
  194. {"default-skin", default_skin, 20, 0},
  195. {"binary-url", binary_url, 120, 0},
  196. {0, 0, 0, 0}
  197. };
  198. static tcl_coups my_tcl_coups[] =
  199. {
  200. {"max-stat-cmds", &maxstat_thr, &maxstat_time},
  201. {"max-livestats-access", &maxlivestats_thr, &maxlivestats_time},
  202. {0, 0, 0},
  203. };
  204. static char *stats_close()
  205. {
  206. Context;
  207. stats_core_unload();
  208. unload_httpd();
  209. unload_templates();
  210. write_stats();
  211. free_stats();
  212. free_global_vars();
  213. slang_chanlang_free(chanlangs);
  214. if (stats_pubcmd_reply)
  215. nfree(stats_pubcmd_reply);
  216. rem_builtins(H_dcc, mydcc);
  217. rem_builtins(H_pubm, stats_pubm);
  218. rem_builtins(H_pub, stats_pub);
  219. rem_builtins(H_msg, stats_msg);
  220. rem_builtins(H_topc, stats_topc);
  221. rem_builtins(H_ctcp, stats_ctcp);
  222. rem_builtins(H_kick, stats_kick);
  223. rem_builtins(H_mode, stats_mode);
  224. rem_builtins(H_nick, stats_nick);
  225. rem_builtins(H_join, stats_join);
  226. rem_builtins(H_nkch, stats_nkch);
  227. rem_builtins(H_sign, stats_sign);
  228. rem_builtins(H_part, stats_part);
  229. rem_tcl_ints(my_tcl_ints);
  230. rem_tcl_coups(my_tcl_coups);
  231. rem_tcl_strings(my_tcl_strings);
  232. rem_tcl_commands(mytcls);
  233. rem_help_reference("stats.help");
  234. del_hook(HOOK_MINUTELY, (Function) stats_minutely);
  235. del_hook(HOOK_DAILY, (Function) stats_daily);
  236. module_undepend(MODULE_NAME);
  237. #ifndef NO_MEM_DEBUG
  238. dmd_unload();
  239. #endif
  240. return NULL;
  241. }
  242. char *stats_start();
  243. static Function stats_table[] =
  244. {
  245. (Function) stats_start,
  246. (Function) stats_close,
  247. (Function) stats_expmem,
  248. (Function) stats_report,
  249. };
  250. char *stats_start(Function * global_funcs)
  251. {
  252. global = global_funcs;
  253. Context;
  254. #ifndef NO_MEM_DEBUG
  255. dmd_init();
  256. #endif
  257. stats_core_init();
  258. // schans = NULL;
  259. suserlist = NULL;
  260. // slangs = NULL;
  261. // slangchans = NULL;
  262. stats_pubcmd_reply = NULL;
  263. chanlangs = NULL;
  264. slang_glob_init();
  265. Context;
  266. module_register(MODULE_NAME, stats_table, 1, 4);
  267. if (!(irc_funcs = module_depend(MODULE_NAME, "irc", 1, 0)))
  268. return "You need the irc module to use the stats module.";
  269. if (!(server_funcs = module_depend(MODULE_NAME, "server", 1, 0)))
  270. return "You need the server module to use the stats module.";
  271. if (!(channels_funcs = module_depend(MODULE_NAME, "channels", 1, 0)))
  272. return "You need the channels module to use the stats module.";
  273. if (!module_depend(MODULE_NAME, "eggdrop", 107, 0)) {
  274. if (!module_depend(MODULE_NAME, "eggdrop", 106, 0)) {
  275. if (!module_depend(MODULE_NAME, "eggdrop", 105, 0)) {
  276. if (!module_depend(MODULE_NAME, "eggdrop", 104, 0)) {
  277. module_undepend(MODULE_NAME);
  278. return "Sorry, stats.mod doesn't work with this eggdrop version.";
  279. }
  280. }
  281. }
  282. }
  283. #ifndef OLDBOT
  284. livestats_timeout = 10;
  285. #else
  286. livestats_timeout = 1;
  287. #endif
  288. add_builtins(H_dcc, mydcc);
  289. add_builtins(H_pubm, stats_pubm);
  290. add_builtins(H_pub, stats_pub);
  291. add_builtins(H_msg, stats_msg);
  292. add_builtins(H_topc, stats_topc);
  293. add_builtins(H_ctcp, stats_ctcp);
  294. add_builtins(H_kick, stats_kick);
  295. add_builtins(H_mode, stats_mode);
  296. add_builtins(H_nick, stats_nick);
  297. add_builtins(H_join, stats_join);
  298. add_builtins(H_nkch, stats_nkch);
  299. add_builtins(H_sign, stats_sign);
  300. add_builtins(H_part, stats_part);
  301. add_tcl_ints(my_tcl_ints);
  302. add_tcl_coups(my_tcl_coups);
  303. add_tcl_strings(my_tcl_strings);
  304. add_tcl_commands(mytcls);
  305. add_hook(HOOK_MINUTELY, (Function) stats_minutely);
  306. add_hook(HOOK_DAILY, (Function) stats_daily);
  307. add_help_reference("stats.help");
  308. lastmonth = getmonth();
  309. read_stats();
  310. #if EGG_IS_MIN_VER(10503)
  311. initudef(1, "nopubstats", 1);
  312. initudef(1, "quietstats", 1);
  313. initudef(1, "nostats", 1);
  314. #endif
  315. init_httpd();
  316. init_templates();
  317. init_global_vars();
  318. glob_tpl_cmd_list = templates_commands_list_add(glob_tpl_cmd_list, stats_template_commands);
  319. glob_tpl_cmd_list = templates_commands_list_add(glob_tpl_cmd_list, template_httpd_commands);
  320. glob_slang_cmd_list = slang_commands_list_add(glob_slang_cmd_list, slang_text_stats_command_table);
  321. putlog(LOG_MISC, "*", "Stats.mod v%s loaded.", MODULE_VERSION);
  322. return NULL;
  323. }