4
0

stats.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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. #define SAVESTATSLENGTH 5000
  19. #define MAXSLANGLENGTH 2000
  20. #define TYPES "words letters started minutes topics lines actions modes bans kicks nicks joins smileys questions"
  21. #define T_GSTARTED -1
  22. #define T_LSTARTED -2
  23. #define T_PEAK -3
  24. #define T_WPL -4
  25. #define T_WORD -5
  26. #define T_VOCABLES -6
  27. #define T_QUOTE -7
  28. #define T_IDLE -8
  29. #define T_ERROR -999
  30. #define T_WORDS 0
  31. #define T_LETTERS 1
  32. #define T_MINUTES 2
  33. #define T_TOPICS 3
  34. #define T_LINES 4
  35. #define T_ACTIONS 5
  36. #define T_MODES 6
  37. #define T_BANS 7
  38. #define T_KICKS 8
  39. #define T_NICKS 9
  40. #define T_JOINS 10
  41. #define T_SMILEYS 11
  42. #define T_QUESTIONS 12
  43. #define TOTAL_TYPES 13
  44. #define TOTAL_SPECIAL_TYPES 8
  45. #define S_TOTAL 0
  46. #define S_TODAY 1
  47. #define S_DAILY 1
  48. #define S_WEEKLY 2
  49. #define S_MONTHLY 3
  50. #define RANGESTR today ? ((today == S_DAILY) ? SLDAILY : ((today == S_WEEKLY) ? SLWEEKLY : SLMONTHLY)) : SLTOTAL
  51. #define RANGESTR_LONG today ? ((today == S_DAILY) ? SLLTODAY : ((today == S_WEEKLY) ? SLLWEEKLY : SLLMONTHLY)) : SLLTOTAL
  52. #define ISLINK(x) x ? "" : "!"
  53. #define ISTEXT(x, y) x ? y : " "
  54. #define S_USERSUM 0
  55. #define S_USERCOUNTS 1
  56. #define SL_PRIVMSG 0
  57. #define SL_KICK 1
  58. #define SL_MODE 2
  59. #define SL_NICK 3
  60. #define SL_PART 4
  61. #define SL_QUIT 5
  62. #define SL_JOIN 6
  63. typedef struct stats_hosts {
  64. struct stats_hosts *next;
  65. char *host;
  66. int nr;
  67. } hoststr;
  68. typedef struct stats_words {
  69. struct stats_words *next;
  70. struct stats_words *left;
  71. struct stats_words *right;
  72. char *word;
  73. int nr;
  74. } wordstats;
  75. typedef struct stats_quote {
  76. struct stats_quote *next;
  77. char *quote;
  78. } quotestr;
  79. typedef struct stats_topic {
  80. struct stats_topic *next;
  81. char *topic;
  82. char *by;
  83. time_t when;
  84. } topicstr;
  85. struct stats_url {
  86. struct stats_url *next;
  87. char *url;
  88. char *by;
  89. int shown;
  90. time_t when;
  91. };
  92. struct stats_kick {
  93. struct stats_kick *next;
  94. quotestr *log;
  95. int shown;
  96. };
  97. typedef struct stats_local {
  98. struct stats_local *next;
  99. struct stats_local *snext[4][TOTAL_TYPES + TOTAL_SPECIAL_TYPES];
  100. char *user;
  101. struct stats_userlist *u;
  102. time_t started;
  103. long int values[4][TOTAL_TYPES];
  104. wordstats *words;
  105. wordstats *tree;
  106. wordstats *word;
  107. int vocables;
  108. quotestr *quotes;
  109. int quotefr;
  110. int flag;
  111. } locstats;
  112. typedef struct stats_global {
  113. struct stats_global *next;
  114. char *chan;
  115. time_t started;
  116. int peak[4];
  117. int users[2][24];
  118. struct stats_local *local;
  119. struct stats_local *slocal[4][TOTAL_TYPES + TOTAL_SPECIAL_TYPES];
  120. wordstats *words;
  121. topicstr *topics;
  122. hoststr *hosts;
  123. struct stats_url *urls;
  124. quotestr *log;
  125. quotestr *lastlog;
  126. int log_length;
  127. struct stats_kick *kicks;
  128. } globstats;
  129. struct stats_clientinfo {
  130. int traffic;
  131. int code;
  132. char *browser;
  133. char *referer;
  134. char *cmd;
  135. };
  136. #define stats_info_access(i) ((struct stats_clientinfo *) dcc[(i)].u.other)
  137. static void sortstats(struct stats_global *, int, int);
  138. static void countvocables(globstats *);
  139. static int localstats_expmem(struct stats_local *);
  140. static int wordstats_expmem(wordstats *);
  141. static void free_stats();
  142. static void free_localstats(struct stats_local *);
  143. static void free_wordstats(wordstats *);
  144. static void reset_tstats();
  145. static void free_urls(struct stats_url *);
  146. static void tell_top(char *, char *, char *, char *, int, int, int);
  147. static void tell_place(char *, char *, char *, char *, char *, int);
  148. static void tell_stat(char *, char *, char *, char *, char *, int);
  149. static int typetoi(char *);
  150. static int slangtypetoi(char *);
  151. static void incrstats(char *, char *, int, int, int);
  152. static int getstats(char *, char *, char *, int);
  153. static locstats *findlocstats(char *, char *);
  154. static globstats *findglobstats(char *);
  155. static int countwords(char *);
  156. static void write_stats();
  157. static void read_stats();
  158. static int countsmileys(char *);
  159. static int countstatmembers(globstats *);
  160. static int gettotal(globstats *, int, int);
  161. static void stats_autoadd(memberlist *, char *);
  162. static int matchattr(struct userrec *, char *, char *);
  163. static void deloldstatusers();
  164. static void purgestats();
  165. static void sensor_minutely();
  166. static int validchan(char *);
  167. static void start_listen_livestats(int);
  168. static void stop_listen_livestats();
  169. static void display_livestats_accept(int, char *);
  170. static void timeout_livestats(int);
  171. #ifndef OLDBOT
  172. static void outdone_livestats(int);
  173. #endif
  174. static void timeout_listen_livestats(int);
  175. static void livestats_accept(int, char *, int);
  176. static void eof_livestats(int);
  177. static void display_livestats(int, char *);
  178. static void livestats_activity(int, char *, int);
  179. static void send_livestats(int, char *);
  180. static char *splitpath(char **);
  181. static void sort_stats_alphabetically(globstats *);
  182. static void sensor_peak(char *);
  183. static int stat_flood();
  184. static void resetlocstats(locstats *);
  185. static int expmem_livestats(void *);
  186. static void kill_livestats(int, void *);
  187. static void out_livestats(int, char *, void *);
  188. static void calcwordstats(char *, globstats *, char *, locstats *ls);
  189. static void incrwordstats(locstats *, char *, int, int);
  190. static void strlower(char *);
  191. static void sortwordstats(locstats *, globstats *);
  192. static void filt(char *);
  193. static char *filt2(char *);
  194. static char *filtbrackets(char *);
  195. static void tell_wordstats(char *, char *, char *, char *, char *);
  196. static void tell_topwords(char *, char *, char *, char *);
  197. static void nincrwordstats(globstats *, char *, int);
  198. static void addquote(char *, globstats *, char *, locstats *);
  199. static void free_quotes(quotestr *);
  200. static int quotes_expmem(quotestr *);
  201. static void do_globwordstats(globstats *);
  202. static int topics_expmem(topicstr *);
  203. static int urls_expmem(struct stats_url *);
  204. static int hosts_expmem(hoststr *);
  205. static void free_topics(topicstr *);
  206. static void free_hosts(hoststr *);
  207. static void addtopic(char *, char *, char *);
  208. static void do_graphs(int, int, globstats *, char *);
  209. static void do_toptalkers(int, int, globstats *, char *, char *);
  210. static void do_miscstats(int, char *);
  211. static int countquestions(char *);
  212. static int inactivechan(char *);
  213. static int gethour();
  214. static int getmonth();
  215. static void sensor_countusers();
  216. static void reset_mwstats(int);
  217. static int secretchan(char *);
  218. static int nostats(char *);
  219. static void sorthosts(struct stats_global *);
  220. static void addhost(char *, globstats *);
  221. static void tell_top_word(char *, char *, char *, char *, int, int, globstats *);
  222. static int quietstats(char *);
  223. static int track_stat_user(char *, char *);
  224. static void check_for_url(char *, char *, char *);
  225. static void free_kicks(struct stats_kick *);
  226. static int kicks_expmem(struct stats_kick *);
  227. #if EGG_IS_MIN_VER(10500)
  228. static void write_new_webstats();
  229. void stats_setsock(int, int);
  230. #endif
  231. static char *stats_duration(int);
  232. static int livestats_flood();
  233. static void display_users_on_chan(int, char *, struct chanset_t *);
  234. /* eggdrop-userfile-independent user management */
  235. struct stats_hostlist {
  236. struct stats_hostlist *next;
  237. char *mask;
  238. time_t lastused;
  239. };
  240. struct stats_userlist {
  241. struct stats_userlist *next;
  242. char *user;
  243. int list;
  244. int addhosts;
  245. struct stats_hostlist *hosts;
  246. char *email;
  247. char *homepage;
  248. };
  249. struct stats_memberlist {
  250. struct stats_memberlist *next;
  251. char *nick;
  252. char *uhost;
  253. time_t joined;
  254. struct stats_userlist *user;
  255. locstats *stats;
  256. };
  257. struct stats_chanset {
  258. struct stats_chanset *next;
  259. char *chan;
  260. struct stats_memberlist *members;
  261. };
  262. static int suserlist_expmem(struct stats_userlist *);
  263. static int hostlist_expmem(struct stats_hostlist *);
  264. static int chanlist_expmem(struct stats_chanset *);
  265. static int memberlist_expmem(struct stats_memberlist *);
  266. static void free_suserlist(struct stats_userlist *);
  267. static void free_hostlist(struct stats_hostlist *);
  268. static void free_chanlist(struct stats_chanset *);
  269. static void free_memberlist(struct stats_memberlist *);
  270. static void free_one_chan(char *);
  271. static struct stats_memberlist *nick2suser(char *, char *);
  272. static struct stats_chanset *findschan(char *);
  273. static struct stats_chanset *initchan(char *);
  274. static void saddmember(char *, char *, char *, char *);
  275. static void strackmember(char *, char *, char *);
  276. static void skillmember(char *, char *);
  277. static struct stats_userlist *findsuser(char *);
  278. static struct stats_userlist *findsuser_by_name(char *);
  279. static struct stats_userlist *addsuser(char *, int, int);
  280. static void delsuser(char *user);
  281. static void saddhost(struct stats_userlist *, char *, time_t);
  282. static int sdelhost(struct stats_userlist *, char *);
  283. static void stats_autosadd(struct stats_memberlist *, struct stats_chanset *);
  284. static void nincrstats(locstats *, int, int);
  285. static locstats *initstats(char *, char *);
  286. static int listsuser(locstats *, char *);
  287. static int countsusers();
  288. static int counthosts();
  289. static void weed_userlink_from_chanset(struct stats_userlist *);
  290. static void weed_statlink_from_chanset(locstats *);
  291. static void weed_userlink_from_locstats(struct stats_userlist *);
  292. static int countmembers(struct stats_memberlist *);
  293. static void check_desynch();
  294. static void update_schannel_members();
  295. static void dump_suser(int, struct stats_userlist *);
  296. static void setemail(struct stats_userlist *, char *);
  297. static void sethomepage(struct stats_userlist *, char *);
  298. static void long_dprintf(int, char *);
  299. /* language system */
  300. struct slang_texts {
  301. struct slang_texts *next;
  302. char *text;
  303. int dynamic;
  304. };
  305. struct slang_ids {
  306. struct slang_ids *next;
  307. int id;
  308. int entries;
  309. struct slang_texts *texts;
  310. };
  311. struct slang_types {
  312. struct slang_types *next;
  313. char *type;
  314. int entries;
  315. struct slang_texts *texts;
  316. };
  317. struct slang_lang {
  318. struct slang_lang *next;
  319. char *lang;
  320. struct slang_ids *ids;
  321. struct slang_types *types;
  322. struct slang_bntypes *bignumbers;
  323. char *durs[10];
  324. };
  325. struct slang_chan {
  326. struct slang_chan *next;
  327. char *chan;
  328. char *lang;
  329. };
  330. struct slang_bnplaces {
  331. struct slang_bnplaces *next;
  332. int place;
  333. int entries;
  334. struct slang_texts *texts;
  335. };
  336. struct slang_bntypes {
  337. struct slang_bntypes *next;
  338. char *type;
  339. struct slang_bnplaces *places;
  340. };
  341. static int slang_expmem();
  342. static void free_slang();
  343. static int loadslang(char *, char *);
  344. static void addslangitem(struct slang_lang *, int, char *);
  345. static void addslangtype(struct slang_lang *, char *);
  346. static void addslangbn(struct slang_lang *, char *);
  347. static char *getslang(int idnr);
  348. static char *getslangtype(char *);
  349. static char *dynamicslang(char *);
  350. static int isdynamicslang(char *);
  351. static char *dynamicslang(char *);
  352. static char *chanlang(char *);
  353. static void setchanlang(char *, char *);
  354. static void setslglobs(char *, int, int, time_t);
  355. static void setslnick(char *);
  356. static char *getdur(int);
  357. static void sortstats_wpl(struct stats_global *, int);
  358. static void sortstats_vocables(struct stats_global *, int);
  359. static void sortstats_word(struct stats_global *, int);
  360. static void sortstats_idle(struct stats_global *, int);
  361. static void maskstricthost(const char *, char *);