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