/** * Handle seen fantasy command. **/ int do_fantasy_seen(int argc, char **argv) { User *u; char *target = NULL; ChannelStats *cs; char *message = NULL; if (denora->debug) protocol_debug(NULL, argc, argv); if (argc >= 3 && stricmp(argv[0], "seen") == 0) { u = finduser(argv[1]); cs = find_cs(argv[2]); if (argc == 3) { if (cs->flags & CS_NOTICE) moduleNoticeLang(s_StatServ, u, SEEN_USAGE, ChanStatsTrigger); else moduleNoticeChanLang(s_StatServ, cs, SEEN_USAGE, ChanStatsTrigger); } else { target = myStrGetToken(argv[3], ' ', 0); message = do_seen(u, target); if (cs->flags & CS_NOTICE) notice(s_StatServ, u->nick, message); else denora_cmd_privmsg(s_StatServ, cs->name, message); } } return MOD_CONT; }
/** * Handle seen fantasy command. * @param argc Argument count * @param argv Argument list * @return MOD_CONT or MOD_STOP **/ int do_fantasy(int argc, char **argv) { User *u; char *chan; #ifdef USE_MYSQL MYSQL_RES *mysql_res; int i = 1; #endif ChannelStats *cs; if (argc < 3) { return MOD_CONT; } if (!denora->do_sql) { return MOD_CONT; } if (stricmp(argv[0], "top10") == 0) { u = finduser(argv[1]); chan = rdb_escape(argv[2]); cs = find_cs(argv[2]); rdb_query (QUERY_HIGH, "SELECT * FROM %s WHERE chan=\'%s\' AND type=0 ORDER BY letters DESC LIMIT 10;", UStatsTable, chan); free(chan); #ifdef USE_MYSQL mysql_res = mysql_store_result(mysql); if (mysql_num_rows(mysql_res) > 0) { if (cs->flags & CS_NOTICE) { notice_lang(s_StatServ, u, STATS_TOP10_CHANNEL, argv[2]); } else { denora_cmd_privmsg(s_StatServ, argv[2], getstring(NULL, STATS_TOP10_CHANNEL), argv[2]); } SET_SEGV_LOCATION(); while ((mysql_row = mysql_fetch_row(mysql_res)) != NULL) { if (cs->flags & CS_NOTICE) { notice_lang(s_StatServ, u, STATS_MESSAGE, i, mysql_row[0], mysql_row[3], mysql_row[4], mysql_row[5], mysql_row[7], mysql_row[6]); } else { denora_cmd_privmsg(s_StatServ, argv[2], getstring(NULL, STATS_MESSAGE), i, mysql_row[0], mysql_row[3], mysql_row[4], mysql_row[5], mysql_row[7], mysql_row[6]); } i++; } } SET_SEGV_LOCATION(); mysql_free_result(mysql_res); #endif } return MOD_CONT; }
/** * Connect to SQL Database * * @return void - no returend value * */ void db_connect(void) { Exclude *e, *next; ChannelStats *cs; int tablecount = 0; char *sqlchan; if (!denora->do_sql) { alog(LOG_ERROR, langstring(ALOG_FAILED_SQL_CONNECT), rdb_error_msg()); return; } SET_SEGV_LOCATION(); /* Checking for missing tables */ if (!rdb_check_table(ChanTable)) tablecount++; if (!rdb_check_table(IsOnTable)) tablecount++; if (!rdb_check_table(ServerTable)) tablecount++; if (!rdb_check_table(UserTable)) tablecount++; if (!rdb_check_table(GlineTable)) tablecount++; if (!rdb_check_table(ChanBansTable)) tablecount++; if (!rdb_check_table(CTCPTable)) tablecount++; if (!rdb_check_table(SpamTable)) tablecount++; if (!rdb_check_table(ChanExceptTable)) tablecount++; if (!rdb_check_table(ChanInviteTable)) tablecount++; if (!rdb_check_table(TLDTable)) tablecount++; if (!rdb_check_table(SglineTable)) tablecount++; if (!rdb_check_table(SqlineTable)) tablecount++; if (!rdb_check_table(MaxValueTable)) tablecount++; if (!rdb_check_table(AliasesTable)) tablecount++; if (!rdb_check_table(CStatsTable)) tablecount++; if (!rdb_check_table(UStatsTable)) tablecount++; if (!rdb_check_table(StatsTable)) tablecount++; if (!rdb_check_table(CurrentTable)) tablecount++; if (!rdb_check_table(ChanStatsTable)) tablecount++; if (!rdb_check_table(ServerStatsTable)) tablecount++; if (!rdb_check_table(ChanQuietTable)) tablecount++; if (!rdb_check_table(AdminTable)) tablecount++; if (tablecount) { alog(LOG_ERROR, "Denora is missing %d required sql tables, disabling sql. Run ./mydbgen to update your sql db.", tablecount); denora->do_sql = 0; return; } /* Cleaning up the database */ rdb_clear_table(ChanTable); rdb_clear_table(IsOnTable); rdb_clear_table(ServerTable); rdb_clear_table(UserTable); rdb_clear_table(GlineTable); rdb_clear_table(ChanBansTable); rdb_clear_table(CTCPTable); rdb_clear_table(SpamTable); rdb_clear_table(ChanExceptTable); rdb_clear_table(ChanInviteTable); rdb_clear_table(TLDTable); rdb_clear_table(SglineTable); rdb_clear_table(SqlineTable); e = first_exclude(); while (e) { next = next_exclude(); rdb_query(QUERY_LOW, "DELETE FROM %s WHERE uname=\'%s\'", UStatsTable, e->name); e = next; } rdb_query(QUERY_LOW, "DELETE FROM %s WHERE uname=\'%s\'", UStatsTable, s_StatServ); if (s_StatServ_alias) { rdb_query(QUERY_LOW, "DELETE FROM %s WHERE uname=\'%s\'", UStatsTable, s_StatServ_alias); } if (LogChannel) { if (!(cs = find_cs(LogChannel))) { if (cs) { del_cs(cs); } sqlchan = rdb_escape(LogChannel); save_cs_db(); rdb_query(QUERY_LOW, "DELETE FROM %s WHERE chan=\'%s\'", CStatsTable, sqlchan); rdb_query(QUERY_LOW, "DELETE FROM %s WHERE chan=\'%s\'", UStatsTable, sqlchan); free(sqlchan); } } if (!db_getcurrent_chans()) { rdb_query(QUERY_LOW, "INSERT INTO %s VALUES ('chans', 0, 0); ", CurrentTable); } SET_SEGV_LOCATION(); }
int chanstats_month(const char *name) { #ifdef USE_MYSQL MYSQL_RES *mysql_res; ChannelStats *cs; char *chan_; #endif time_t tbuf; if (!denora->do_sql) { return MOD_CONT; } if (!name) { return MOD_CONT; } SET_SEGV_LOCATION(); alog(LOG_NORMAL, langstr(ALOG_RESETTING_MONTHLY)); rdb_query (QUERY_LOW, "UPDATE %s SET letters=0, words=0, line=0, actions=0, smileys=0, " "kicks=0, modes=0, topics=0, wasted=0, " "time0=0, time1=0, time2=0, time3=0, time4=0, time5=0, time6=0, time7=0, " "time8=0, time9=0, time10=0, time11=0, time12=0, time13=0, time14=0, " "time15=0, time16=0, time17=0, time18=0, time19=0, time20=0, time21=0, " "time22=0, time23=0 WHERE type=3;", UStatsTable); rdb_query(QUERY_LOW, "UPDATE %s SET letters=0, words=0, line=0, actions=0, smileys=0, " "kicks=0, modes=0, topics=0, " "time0=0, time1=0, time2=0, time3=0, time4=0, time5=0, time6=0, time7=0, " "time8=0, time9=0, time10=0, time11=0, time12=0, time13=0, time14=0, " "time15=0, time16=0, time17=0, time18=0, time19=0, time20=0, time21=0, " "time22=0, time23=0 WHERE type=3;", CStatsTable); /* request 109 - auto-delete channel after not used for 1 month */ tbuf = (time(NULL) - ClearChanInActive); rdb_query (QUERY_HIGH, "SELECT chan FROM %s WHERE (lastspoke > 0) AND (lastspoke < %i);", CStatsTable, tbuf); #ifdef USE_MYSQL mysql_res = mysql_store_result(mysql); if (mysql_num_rows(mysql_res) > 0) { SET_SEGV_LOCATION(); while ((mysql_row = mysql_fetch_row(mysql_res)) != NULL) { if ((cs = find_cs(mysql_row[0]))) { alog(LOG_DEBUG, "chanstats monthly: channel %s is expired, statserv will leave this chan, all stats are deleted"); del_cs(cs); /* make statserv part the chan */ chan_ = rdb_escape(mysql_row[0]); rdb_query(QUERY_LOW, "DELETE FROM %s WHERE chan=\'%s\'", CStatsTable, chan_); rdb_query(QUERY_LOW, "DELETE FROM %s WHERE chan=\'%s\'", UStatsTable, chan_); free(chan_); if (LogChannel) { if (stricmp(LogChannel, mysql_row[0])) { denora_cmd_part(s_StatServ, mysql_row[0], getstring(NULL, STATS_CHANSTATS_PART), mysql_row[0]); } } } } save_cs_db(); } #endif return MOD_CONT; }
static int do_chanstats(User * u, int ac, char **av) { char *cmd1 = NULL; char *cmd2 = NULL; char *cmd3 = NULL; char *cmd4 = NULL; lnode_t *tn; ChannelStats *cs; Channel *c; int i; int x = 0; char *sqlchan; Uid *ud; char *modes; char nickbuf[BUFSIZE]; *nickbuf = '\0'; if (ac >= 1) { cmd1 = av[0]; } if (ac >= 2) { cmd2 = av[1]; } if (ac >= 3) { cmd3 = av[2]; } if (ac >= 4) { cmd4 = av[3]; } if (cmd1) { /* Since ChanStats does require SQL code... */ if (!denora->do_sql) { notice_lang(s_StatServ, u, SQL_DISABLED); return MOD_CONT; } if (!stricmp("ADD", cmd1)) { if (LargeNet) { notice_lang(s_StatServ, u, STAT_CHANSTATS_CHAN_LARGENET); return MOD_CONT; } if (!cmd2) { syntax_error(s_StatServ, u, "CHANSTATS", STAT_CHANSTATS_ADD_SYNTAX); return MOD_CONT; } if (BadChanName(cmd2)) { notice_lang(s_StatServ, u, STAT_CHANSTATS_NOT_VALID_CHAN); return MOD_CONT; } if (strlen(cmd2) > CHANMAX) { notice_lang(s_StatServ, u, STAT_CHANSTATS_NOT_VALID_CHAN); return MOD_CONT; } if (LogChannel) { if (!stricmp(cmd2, LogChannel)) { notice_lang(s_StatServ, u, STAT_CHANSTATS_LOGCHAN); return MOD_CONT; } } if (!(cs = find_cs(cmd2))) { cs = makecs(cmd2); save_cs_db(); sqlchan = rdb_escape(cmd2); if (CSDefFlag) { if (CSDefFlag == 1) { cs->flags |= CS_FANTASY; cs->flags &= ~CS_NOTICE; } else if (CSDefFlag == 2) { cs->flags |= CS_FANTASY; cs->flags |= CS_NOTICE; } } rdb_query(QUERY_LOW, "DELETE FROM %s WHERE chan=\'%s\'", CStatsTable, sqlchan); rdb_query(QUERY_LOW, "DELETE FROM %s WHERE chan=\'%s\'", UStatsTable, sqlchan); cs->timeadded = time(NULL); for (i = 0; i < 4; i++) { rdb_query (QUERY_LOW, "INSERT INTO %s SET chan=\'%s\', type=%i, timeadded=%ld;", CStatsTable, sqlchan, i, cs->timeadded); } notice_lang(s_StatServ, u, STAT_CHANSTATS_CHAN_ADDED, cmd2); ud = find_uid(s_StatServ); if (PartOnEmpty) { c = findchan(cmd2); if (c) { denora_cmd_join(s_StatServ, cs->name, time(NULL)); if (AutoOp && AutoMode) { modes = sstrdup(AutoMode); while (*modes) { switch (*modes) { case '+': break; case '-': break; default: ircsnprintf(nickbuf, BUFSIZE, "%s %s", nickbuf, ((ircd->p10 && ud) ? ud->uid : s_StatServ)); } (void) *modes++; } denora_cmd_mode(ServerName, cs->name, "%s%s", AutoMode, nickbuf); } } } else { denora_cmd_join(s_StatServ, cs->name, time(NULL)); if (AutoOp && AutoMode) { modes = sstrdup(AutoMode); while (*modes) { switch (*modes) { case '+': break; case '-': break; default: ircsnprintf(nickbuf, BUFSIZE, "%s %s", nickbuf, ((ircd->p10 && ud) ? ud->uid : s_StatServ)); } (void) *modes++; } denora_cmd_mode(ServerName, cs->name, "%s%s", AutoMode, nickbuf); } } free(sqlchan); } else { notice_lang(s_StatServ, u, STAT_CHANSTATS_CHAN_ALREADY, cmd2); } } else if (!stricmp("DEL", cmd1)) { if (!cmd2) { syntax_error(s_StatServ, u, "CHANSTATS", STAT_CHANSTATS_DEL_SYNTAX); return MOD_CONT; } sqlchan = rdb_escape(cmd2); if ((cs = find_cs(cmd2))) { del_cs(cs); save_cs_db(); rdb_query(QUERY_LOW, "DELETE FROM %s WHERE chan=\'%s\'", CStatsTable, sqlchan); rdb_query(QUERY_LOW, "DELETE FROM %s WHERE chan=\'%s\'", UStatsTable, sqlchan); notice_lang(s_StatServ, u, STAT_CHANSTATS_CHAN_DEL, cmd2); if (LogChannel) { if (stricmp(LogChannel, cmd2)) { denora_cmd_part(s_StatServ, cmd2, getstring(NULL, STATS_CHANSTATS_PART), cmd2); } } else { denora_cmd_part(s_StatServ, cmd2, getstring(NULL, STATS_CHANSTATS_PART), cmd2); } } else { notice_lang(s_StatServ, u, STAT_CHANSTATS_CHAN_NOTFOUND, cmd2); } free(sqlchan); } else if (!stricmp("LIST", cmd1)) { tn = list_first(CStatshead); while (tn != NULL) { cs = lnode_get(tn); notice(s_StatServ, u->nick, "%d %s", x, cs->name); x++; tn = list_next(CStatshead, tn); } if (!x) { notice_lang(s_StatServ, u, STATS_CHANSTATS_NOCHANNELS); } } else if (!stricmp("SUMUSER", cmd1)) { if (!cmd3) { syntax_error(s_StatServ, u, "CHANSTATS", STATS_CHANSTATS_SUMUSER_SYNTAX); return MOD_CONT; } sumuser(u, cmd2, cmd3); } else if (!stricmp("RENAME", cmd1)) { if (!cmd3) { syntax_error(s_StatServ, u, "CHANSTATS", STATS_CHANSTATS_RENAMEUSER_SYNTAX); return MOD_CONT; } renameuser(u, cmd2, cmd3); } else if (!stricmp("SET", cmd1)) { if (!cmd3) { syntax_error(s_StatServ, u, "CHANSTATS", STATS_CHANSTATS_SET_SYNTAX); return MOD_CONT; } if (!(cs = find_cs(cmd2))) { notice_lang(s_StatServ, u, STAT_CHANSTATS_CHAN_NOTFOUND, cmd2); return MOD_CONT; } if (!stricmp("FANTASY", cmd3)) { if (!cmd4) { syntax_error(s_StatServ, u, "CHANSTATS", STATS_CHANSTATS_SET_SYNTAX); return MOD_CONT; } if (!stricmp("ON", cmd4)) { cs->flags |= CS_FANTASY; cs->flags &= ~CS_NOTICE; notice_lang(s_StatServ, u, STATS_CHANSTATS_FANTASY_ON, cmd2); } else if (!stricmp("OFF", cmd4)) { cs->flags &= ~CS_FANTASY; cs->flags &= ~CS_NOTICE; notice_lang(s_StatServ, u, STATS_CHANSTATS_FANTASY_OFF, cmd2); } else if (!stricmp("NOTICE", cmd4)) { cs->flags |= CS_FANTASY; cs->flags |= CS_NOTICE; notice_lang(s_StatServ, u, STATS_CHANSTATS_FANTASY_NOTICE, cmd2); } else { syntax_error(s_StatServ, u, "CHANSTATS", STATS_CHANSTATS_SET_SYNTAX); } } /* fantasy */ } else { syntax_error(s_StatServ, u, "CHANSTATS", STAT_CHANSTATS_SYNTAX); } } else { syntax_error(s_StatServ, u, "CHANSTATS", STAT_CHANSTATS_SYNTAX); } return MOD_CONT; }