void db_removenick(char *nick, char *reason) { char *sqlreason; int nickid = db_getnick(nick); SET_SEGV_LOCATION(); if (!denora->do_sql) { return; } if (nickid == 0) { alog(LOG_DEBUG, "nickid 0"); return; } SET_SEGV_LOCATION(); db_removefromchans(nickid); if (UserCacheTime) { sqlreason = rdb_escape(reason); rdb_query(QUERY_LOW, "UPDATE %s SET online=\'N\', lastquit=NOW(), lastquitmsg=\'%s\', servid=0 WHERE nickid=%d", UserTable, sqlreason, nickid); if (sqlreason) { free(sqlreason); } } else { rdb_query(QUERY_LOW, "DELETE FROM %s WHERE nickid=%d", UserTable, nickid); } SET_SEGV_LOCATION(); }
void db_checkemptychan(int chanid) { #ifdef USE_MYSQL MYSQL_RES *mysql_res; #endif SET_SEGV_LOCATION(); if (!denora->do_sql) { return; } rdb_query(QUERY_HIGH, "SELECT chanid FROM %s WHERE chanid=%d", IsOnTable, chanid); #ifdef USE_MYSQL mysql_res = mysql_store_result(mysql); if (mysql_res) { SET_SEGV_LOCATION(); if (!mysql_num_rows(mysql_res)) { rdb_query(QUERY_LOW, "DELETE FROM %s WHERE chanid=%d", ChanTable, chanid); } SET_SEGV_LOCATION(); mysql_free_result(mysql_res); } #endif }
/** * Handle MOTD messages * * @param source is the nick of the person whom requested * * @return always returns MOD_CONT */ int m_motd(char *source) { FILE *f; char buf[BUFSIZE]; *buf = '\0'; SET_SEGV_LOCATION(); if (!source) { return MOD_CONT; } denora_cmd_375(source); if (!MOTDFilename) { denora_cmd_422(source); } else { if ((f = FileOpen(MOTDFilename, FILE_READ)) != NULL) { SET_SEGV_LOCATION(); while (fgets(buf, BUFSIZE - 1, f)) { buf[strlen(buf) - 1] = 0; denora_cmd_372(source, buf); } fclose(f); } else { denora_cmd_422(source); } } SET_SEGV_LOCATION(); denora_cmd_376(source); return MOD_CONT; }
int db_getservfromnick(char *nick) { int res = 0; #ifdef USE_MYSQL MYSQL_RES *mysql_res; #endif if (!denora->do_sql) { return -1; } SET_SEGV_LOCATION(); rdb_query(QUERY_HIGH, "SELECT servid FROM %s WHERE nick=\'%s\'", UserTable, nick); #ifdef USE_MYSQL mysql_res = mysql_store_result(mysql); if (mysql_res) { if (mysql_num_rows(mysql_res)) { mysql_row = mysql_fetch_row(mysql_res); res = strtol(mysql_row[0], NULL, 10); } else { alog(LOG_NONEXISTANT, "nickname not found ! %s", nick); } SET_SEGV_LOCATION(); mysql_free_result(mysql_res); } #endif return res; }
void ConnectServ(User * u, char *buf) { char *cmd, *buf2; char *str; buf2 = sstrdup(buf); cmd = myStrGetToken(buf, ' ', 0); str = myStrGetTokenRemainder(buf, ' ', 1); SET_SEGV_LOCATION(); if (!cmd) { free(buf2); return; } else if (stricmp(cmd, "\1PING") == 0) { denora_cmd_ctcp(s_StatServ, u->nick, "PING %s", str); } else { SET_SEGV_LOCATION(); mod_run_cmd(s_StatServ, u, STATSERV, cmd, str); } free(cmd); if (str) { free(str); } free(buf2); }
int db_getcurrent_chans(void) { int retcode = 0; #ifdef USE_MYSQL MYSQL_RES *mysql_res; #endif if (!denora->do_sql) { return 0; } SET_SEGV_LOCATION(); rdb_query(QUERY_HIGH, "SELECT COUNT(*) FROM %s WHERE type=\'chans\'", CurrentTable); SET_SEGV_LOCATION(); #ifdef USE_MYSQL mysql_res = mysql_store_result(mysql); if (mysql_res) { if (mysql_num_rows(mysql_res)) { retcode = atoi(*mysql_fetch_row(mysql_res)); } else { retcode = -1; } SET_SEGV_LOCATION(); mysql_free_result(mysql_res); } #endif return retcode; }
char *db_getchannel_byid(int chanid) { char *res = NULL; #ifdef USE_MYSQL MYSQL_RES *mysql_res; MYSQL_ROW row; #endif if (!denora->do_sql) { return NULL; } SET_SEGV_LOCATION(); rdb_query(QUERY_HIGH, "SELECT channel FROM %s WHERE chanid=%d", ChanTable, chanid); #ifdef USE_MYSQL mysql_res = mysql_store_result(mysql); if (mysql_res) { if (!mysql_num_rows(mysql_res)) { alog(LOG_NONEXISTANT, "channel not found ! %d", chanid); } else { row = mysql_fetch_row(mysql_res); res = rdb_escape(row[0]); } SET_SEGV_LOCATION(); mysql_free_result(mysql_res); } #endif return res; }
/* -1 if server not found, servid else */ int db_checkserver_online(char *serv) { int servid = 0; Server *s; #ifdef USE_MYSQL MYSQL_RES *mysql_res; #endif s = server_find(serv); if (s && s->sqlid) { return s->sqlid; } SET_SEGV_LOCATION(); if (!denora->do_sql) { return -1; } rdb_query(QUERY_HIGH, "SELECT servid FROM %s WHERE server=\'%s\' and online=\'Y\'", ServerTable, serv); #ifdef USE_MYSQL mysql_res = mysql_store_result(mysql); if (mysql_res) { SET_SEGV_LOCATION(); mysql_free_result(mysql_res); return 1; } #endif return servid; }
/* check if servs > servs_max */ void do_checkservsmax() { int diff1 = 0; SET_SEGV_LOCATION(); if (stats->servers > stats->servers_max) { stats->servers_max = stats->servers; stats->servers_max_time = time(NULL); diff1 = 1; } if (!stats->servers_max_time) { stats->servers_max_time = time(NULL); diff1 = 1; } SET_SEGV_LOCATION(); if (stats->servers > stats->daily_servers) { stats->daily_servers++; stats->daily_servers_time = time(NULL); } if (denora->do_sql) { rdb_query(QUERY_LOW, "UPDATE %s SET val=%d, time=%ld WHERE type='servers'", CurrentTable, stats->servers, time(NULL)); if (diff1) { rdb_query (QUERY_LOW, "UPDATE %s SET val=%d, time=FROM_UNIXTIME(%ld) WHERE type='servers'", MaxValueTable, stats->servers_max, (long int) stats->servers_max_time); } } }
/* chan should be db_escape'd before call */ int db_getchannel_users(char *chan) { int res = 0; #ifdef USE_MYSQL MYSQL_RES *mysql_res; #endif SET_SEGV_LOCATION(); strtolwr(chan); if (!denora->do_sql) { return -1; } SET_SEGV_LOCATION(); rdb_query(QUERY_HIGH, "SELECT currentusers FROM %s WHERE channel=\'%s\'", ChanTable, chan); #ifdef USE_MYSQL mysql_res = mysql_store_result(mysql); SET_SEGV_LOCATION(); if (mysql_res) { if (mysql_num_rows(mysql_res)) { res = strtol(*mysql_fetch_row(mysql_res), NULL, 10); } else { alog(LOG_DEBUG, "debug: unable to find the requested channel %s", chan); } SET_SEGV_LOCATION(); mysql_free_result(mysql_res); } #endif return res; }
int db_getlusers(int type) { int retcode = 0; #ifdef USE_MYSQL MYSQL_RES *mysql_res; #endif if (!denora->do_sql) { return 0; } SET_SEGV_LOCATION(); switch (type) { case LUSERS_USERS: rdb_query(QUERY_HIGH, "SELECT COUNT(*) FROM %s WHERE mode_li=\'N\'", UserTable); break; case LUSERS_USERSINV: rdb_query(QUERY_HIGH, "SELECT COUNT(*) FROM %s WHERE mode_li=\'Y\'", UserTable); break; case LUSERS_OPERS: rdb_query(QUERY_HIGH, "SELECT COUNT(*) FROM %s WHERE mode_lo=\'Y\'", UserTable); break; case LUSERS_CHAN: rdb_query(QUERY_HIGH, "SELECT COUNT(*) FROM %s", ChanTable); break; case LUSERS_SERV: rdb_query(QUERY_HIGH, "SELECT COUNT(*) FROM %s", ServerTable); break; case LUSERS_USERSGLOB: rdb_query(QUERY_HIGH, "SELECT COUNT(*) FROM %s", UserTable); break; case LUSERS_USERSMAX: rdb_query(QUERY_HIGH, "SELECT val FROM %s WHERE type='users'", MaxValueTable); break; } SET_SEGV_LOCATION(); #ifdef USE_MYSQL mysql_res = mysql_store_result(mysql); if (mysql_res) { if (mysql_num_rows(mysql_res)) { retcode = atoi(*mysql_fetch_row(mysql_res)); } else { retcode = -1; } SET_SEGV_LOCATION(); mysql_free_result(mysql_res); } #endif return retcode; }
int chans_hourly(const char *name) { static struct tm mytime; time_t ts; int year; int month; #ifdef USE_MYSQL MYSQL_RES *mysql_res; #endif ts = time(NULL); #ifdef _WIN32 localtime_s(&mytime, &ts); #else mytime = *localtime(&ts); #endif year = 1900 + mytime.tm_year; month = 1 + mytime.tm_mon; if (name) { alog(LOG_DEBUG, "Executing for %s", name); } if (!denora->do_sql) { return MOD_CONT; } rdb_query(QUERY_HIGH, "SELECT id FROM %s WHERE day=%d and month=%d and year=%d", ChanStatsTable, mytime.tm_mday, month, year); #ifdef USE_MYSQL mysql_res = mysql_store_result(mysql); if (mysql_res) { if (mysql_num_rows(mysql_res) > 0) { rdb_query (QUERY_LOW, "UPDATE %s SET time_%d=%d WHERE day=%d and month=%d and year=%d", ChanStatsTable, mytime.tm_hour, stats->chans, mytime.tm_mday, month, year); } else { rdb_query (QUERY_LOW, "INSERT INTO %s (day, month, year, time_%d) VALUES (%d, %d, %d, %d)", ChanStatsTable, mytime.tm_hour, mytime.tm_mday, month, year, stats->chans); } mysql_free_result(mysql_res); } SET_SEGV_LOCATION(); #endif SET_SEGV_LOCATION(); return MOD_CONT; }
/* chan is created if not exists */ int db_getchancreate(char *chan) { int res = -1; Channel *c; char *channel; #ifdef USE_MYSQL MYSQL_RES *mysql_res; #endif SET_SEGV_LOCATION(); strtolwr(chan); c = findchan(chan); if (c) { if (c->sqlid) { return c->sqlid; } else { channel = sstrdup(c->sqlchan); } } else { channel = rdb_escape(chan); } if (!denora->do_sql) { return -1; } strtolwr(channel); rdb_query(QUERY_HIGH, "SELECT chanid FROM %s WHERE channel=\'%s\'", ChanTable, channel); #ifdef USE_MYSQL mysql_res = mysql_store_result(mysql); if (mysql_res) { if (mysql_num_rows(mysql_res)) res = atoi(*mysql_fetch_row(mysql_res)); mysql_free_result(mysql_res); } #endif SET_SEGV_LOCATION(); if (res == -1) { rdb_query(QUERY_HIGH, "INSERT INTO %s (channel) VALUES (\'%s\')", ChanTable, channel); res = rdb_insertid(); } SET_SEGV_LOCATION(); if (c && res) { c->sqlid = res; } free(channel); return res; }
int ns_cmd_modlist( const CmdParams* cmdparams ) { SET_SEGV_LOCATION(); ProcessModuleList( ReportModuleInfo, (void *)cmdparams->source ); irc_prefmsg( ns_botptr, cmdparams->source, __( "End of Module List", cmdparams->source ) ); return 0; }
/** * example command * Just sends "Hello World!" to the services channel */ static int template_hello_world( const CmdParams *cmdparams ) { SET_SEGV_LOCATION(); irc_chanalert( template_bot, "%s says \"Hello World!\"", cmdparams->source->name ); return NS_SUCCESS; }
/** * Export ctcp struct to xml file * * @param file is the name that will be used * @return void - no returend value * */ void xml_export_ctcp(char *file) { FILE *ptr; CTCPVerStats *c; lnode_t *tn; ptr = new_xml(file); SET_SEGV_LOCATION(); if (ptr) { xml_write_header(ptr); xml_write_block_top(ptr, "ctcp"); tn = list_first(CTCPhead); while (tn) { c = lnode_get(tn); xml_write_block_top(ptr, "client"); xml_write_tag(ptr, "version", c->version); xml_write_tag_int(ptr, "current", c->count); xml_write_tag_int(ptr, "overall", c->overall); xml_write_block_bottom(ptr, "client"); tn = list_next(CTCPhead, tn); } xml_write_block_bottom(ptr, "ctcp"); xml_write_footer(ptr); } }
/** * This will delete all module data used in any struct by module m. * @param m The module to clear all data for **/ void moduleDelAllDataMod(Module * m) { boolean freeme = false; int i; User *user; SET_SEGV_LOCATION(); if (!mod_current_module_name) { mod_current_module_name = sstrdup(m->name); freeme = true; } for (i = 0; i < 1024; i++) { /* Remove the users */ for (user = userlist[i]; user; user = user->next) { moduleDelAllData(&user->moduleData); } } if (freeme) { free(mod_current_module_name); mod_current_module_name = NULL; } }
/* check if chans > chans_max */ void do_checkchansmax() { int diff1 = 0; if (stats->chans > stats->chans_max) { stats->chans_max = stats->chans; stats->chans_max_time = time(NULL); diff1 = 1; } if (!stats->chans_max_time) { stats->chans_max_time = time(NULL); diff1 = 1; } SET_SEGV_LOCATION(); if (stats->chans > stats->daily_chans) { stats->daily_chans++; stats->daily_chans_time = time(NULL); } rdb_query(QUERY_LOW, "UPDATE %s SET val=%d, time=%ld WHERE type='chans'", CurrentTable, stats->chans, time(NULL)); if (diff1) { rdb_query (QUERY_LOW, "UPDATE %s SET val=%d, time=FROM_UNIXTIME(%ld) WHERE type='channels'", MaxValueTable, stats->chans_max, (long int) stats->chans_max_time); } }
int ns_cmd_unload( const CmdParams *cmdparams ) { SET_SEGV_LOCATION(); if( unload_module( cmdparams->av[0], cmdparams->source ) > 0 ) irc_chanalert( ns_botptr, _( "%s unloaded module %s" ), cmdparams->source->name, cmdparams->av[0] ); return NS_SUCCESS; }
int do_newnick(int ac, char **av) { User *u; SET_SEGV_LOCATION(); if (!ConnectServConnected) { return 1; } u = user_find(av[0]); if (!u) { return MOD_CONT; } if (!stricmp(u->nick, s_ConnectServ)) { return MOD_CONT; } /* Print Connection Notice */ if (SignOnMessage) { if (!UseColorfulMessages) { alog(LOG_NORMAL, "\2SIGNON\2 %s (%s@%s - %s) has signed on at %s", u->nick, u->username, u->host, u->realname, u->server->name); } else { alog(LOG_NORMAL, "\2\0034SIGNED ON\2 user: \2%s\2 (%s@%s - %s) at: \2%s\2\003", u->nick, u->username, u->host, u->realname, u->server->name); } } return MOD_CONT; }
/** * Returns the value from a key/value pair set. * This allows module coders to retrive any data they have previuosly stored in any given struct * @param md The module data for the struct to be used * @param key The key to find the data for * @return the value paired to the given key will be returned, or NULL **/ char *moduleGetData(ModuleData ** md, char *key) { char *mod_name = sstrdup(mod_current_module_name); ModuleData *modcurrent = *md; SET_SEGV_LOCATION(); alog(LOG_DEBUG, "debug: moduleGetData %p : key %s", (void *) md, key); alog(LOG_DEBUG, "debug: Current Module %s", mod_name); if (mod_current_module_name == NULL) { alog(LOG_DEBUG, "moduleGetData() called with mod_current_module_name being NULL"); if (denora->debug) { do_backtrace(0); } } while (modcurrent) { if ((stricmp(modcurrent->moduleName, mod_name) == 0) && (stricmp(modcurrent->key, key) == 0)) { free(mod_name); return sstrdup(modcurrent->value); } modcurrent = modcurrent->next; } free(mod_name); return NULL; }
int chanstats_daily(const char *name) { if (!denora->do_sql) { return MOD_CONT; } if (!name) { return MOD_CONT; } SET_SEGV_LOCATION(); alog(LOG_NORMAL, langstr(ALOG_RESET_DAILY)); 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=1;", 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=1;", CStatsTable); return MOD_CONT; }
void html_top10client_title(FILE * ptr) { SET_SEGV_LOCATION(); if (ptr) { fprintf(ptr, "%s", langstring(HTML_TOP10_CLIENT_TITLE)); } }
/** * Handle AWAY messages * * @param source is the nick of the person whom is now away * @param msg is the text of the away message * * @return always returns MOD_CONT */ int m_away(char *source, char *msg) { User *u; if (!source) { return MOD_CONT; } u = user_find(source); if (!u) { return MOD_CONT; } SET_SEGV_LOCATION(); if (msg) { stats->away++; u->isaway = 1; u->awaymsg = sstrdup(msg); } else { stats->away--; u->isaway = 0; u->awaymsg = NULL; } if (denora->do_sql) { rdb_query (QUERY_LOW, "UPDATE %s SET away=\'%s\', awaymsg=\'%s\' WHERE nickid=%d", UserTable, (u->isaway ? (char *) "Y" : (char *) "N"), rdb_escape(u->awaymsg), db_getnick(u->sqlnick)); } return MOD_CONT; }
/* * Echo nick changes */ int cs_user_nick(int ac, char **av) { User *u; SET_SEGV_LOCATION(); if (!ConnectServConnected) { return MOD_CONT; } u = user_find(av[1]); if (!u) { return MOD_CONT; } if (!stricmp(u->nick, s_ConnectServ)) { return MOD_CONT; } if (NickChangeMessage) { if (!UseColorfulMessages) { alog(LOG_NORMAL, "\2NICK\2 %s (%s@%s) changed their nick to %s", av[0], u->username, u->host, av[1]); } else { alog(LOG_NORMAL, "\2\0037Nick Change\2 user: \2%s\2 (%s@%s) Changed their nick to \2%s\2\003", av[0], u->username, u->host, av[1]); } } return 1; }
/** * Process numeric 372 messages * * @param source is the server that sent the message * @param ac is the array count * @param av is the array * * @return return is always MOD_CONT * */ int denora_event_372(char *source, int ac, char **av) { Server *s; char buf[NET_BUFSIZE]; SET_SEGV_LOCATION(); if (denora->protocoldebug) { protocol_debug(source, ac, av); } s = server_find(source); if (!s) { return MOD_CONT; } if (ac >= 2) { if (s->motd) { ircsnprintf(buf, NET_BUFSIZE - 1, "%s\n\r%s", s->motd, av[1]); free(s->motd); s->motd = sstrdup(buf); } else { s->motd = sstrdup(av[1]); } } return MOD_CONT; }
int chanstats_weekly(const char *name) { if (!denora->do_sql) { return MOD_CONT; } if (!name) { return MOD_CONT; } SET_SEGV_LOCATION(); alog(LOG_NORMAL, langstr(ALOG_RESETTING_WEEKLY)); 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=2;", 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=2;", CStatsTable); rdb_query(QUERY_LOW, "DELETE %s.*,%s.* FROM %s,%s WHERE %s.uname = %s.uname AND %s.lastspoke < %i AND %s.ignore = 'N';", UStatsTable, AliasesTable, UStatsTable, AliasesTable, UStatsTable, AliasesTable, UStatsTable, (time(NULL) - ClearInActive), AliasesTable); return MOD_CONT; }
/** * Export tld struct to xml file * * @param file is the name that will be used * @return void - no returend value * */ void xml_export_tld(char *file) { FILE *ptr; TLD *t; lnode_t *tn; ptr = new_xml(file); SET_SEGV_LOCATION(); if (ptr) { xml_write_header(ptr); xml_write_block_top(ptr, "tld"); list_sort(Thead, sortusers); tn = list_first(Thead); while (tn) { t = lnode_get(tn); denora_cmd_pong(ServerName, ServerName); xml_write_block_top(ptr, "domain"); xml_write_tag(ptr, "countrycode", t->countrycode); xml_write_tag(ptr, "country", t->country); xml_write_tag_int(ptr, "current", t->count); xml_write_tag_int(ptr, "overall", t->overall); xml_write_block_bottom(ptr, "domain"); tn = list_next(Thead, tn); } xml_write_block_bottom(ptr, "tld"); xml_write_footer(ptr); } }
static int cmd_level( const CmdParams *cmdparams ) { SET_SEGV_LOCATION(); if( cmdparams->ac < 1 ) { /* Force recalc user level */ cmdparams->source->user->ulevel = -1; irc_prefmsg( ns_botptr, cmdparams->source, __( "Your level is %d", cmdparams->source ), UserLevel( cmdparams->source ) ); } else { Client * otheruser; otheruser = FindUser( cmdparams->av[0] ); if( otheruser == NULL ) { irc_prefmsg( ns_botptr, cmdparams->source, __( "User %s not found", cmdparams->source ), cmdparams->av[0] ); return NS_FAILURE; } /* Force recalc user level */ otheruser->user->ulevel = -1; irc_prefmsg( ns_botptr, cmdparams->source, __( "User level for %s is %d", cmdparams->source ), otheruser->name, UserLevel( otheruser ) ); } return NS_SUCCESS; }
/** * \fn bool ModuleHandler::DeleteModule(Module *m) * \brief Delete the Module from Module lists and unload it from navn completely * \param Module the Module to be removed */ bool ModuleHandler::DeleteModule(Module *m) { SET_SEGV_LOCATION(); if(!m || !m->handle) return false; void *handle = m->handle; Flux::string filepath = m->filepath; dlerror(); void (*df)(Module *) = function_cast<void ( *)(Module *)>(dlsym(m->handle, "ModunInit")); const char *err = dlerror(); if(!df && err && *err) { Log(LOG_WARN) << "No destroy function found for " << m->name << ", chancing delete..."; delete m; /* we just have to chance they haven't overwrote the delete operator then... */ } else df(m); /* Let the Module delete it self, just in case */ if(handle) if(dlclose(handle)) Log() << "[" << m->name << ".so] " << dlerror(); if(!filepath.empty()) Delete(filepath.c_str()); return true; }