diff options
| author | keeper keeper@31f1291d-b8d6-0310-a050-a5561fc1590b <keeper keeper@31f1291d-b8d6-0310-a050-a5561fc1590b@5417fbe8-f217-4b02-8779-1006273d7864> | 2004-08-01 02:27:43 +0000 |
|---|---|---|
| committer | keeper keeper@31f1291d-b8d6-0310-a050-a5561fc1590b <keeper keeper@31f1291d-b8d6-0310-a050-a5561fc1590b@5417fbe8-f217-4b02-8779-1006273d7864> | 2004-08-01 02:27:43 +0000 |
| commit | a090c812cf88617ad825485791f7f38764db6ae8 (patch) | |
| tree | 6876ce6d4b05c036e1417e6c149827899804b703 /src | |
| parent | e5e4057f22edb81b3783f7fd092d2addbfdf1d0a (diff) | |
BUILD : 1.7.4 (294) BUGS : NOTES : First import. Current status: anope_bs_core finished for new phase1, anope_cs_access working for cs access add.
git-svn-id: svn://svn.anope.org/anope/trunk@294 31f1291d-b8d6-0310-a050-a5561fc1590b
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@183 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src')
| -rw-r--r-- | src/botserv.c | 31 | ||||
| -rw-r--r-- | src/chanserv.c | 50 | ||||
| -rw-r--r-- | src/config.c | 2 | ||||
| -rw-r--r-- | src/hostserv.c | 33 | ||||
| -rw-r--r-- | src/init.c | 34 | ||||
| -rw-r--r-- | src/main.c | 36 | ||||
| -rw-r--r-- | src/mysql.c | 1755 | ||||
| -rw-r--r-- | src/news.c | 19 | ||||
| -rw-r--r-- | src/nickserv.c | 112 | ||||
| -rw-r--r-- | src/operserv.c | 13 | ||||
| -rw-r--r-- | src/rdb.c | 452 | ||||
| -rw-r--r-- | src/sessions.c | 19 |
12 files changed, 232 insertions, 2324 deletions
diff --git a/src/botserv.c b/src/botserv.c index 4b5ce1561..15f09e5c8 100644 --- a/src/botserv.c +++ b/src/botserv.c @@ -722,28 +722,6 @@ void save_bs_dbase(void) /*************************************************************************/ -void save_bs_rdb_dbase(void) -{ -#ifdef USE_RDB - int i; - BotInfo *bi; - - if (!rdb_open()) - return; - - rdb_clear_table("anope_bs_core"); - - for (i = 0; i < 256; i++) { - for (bi = botlists[i]; bi; bi = bi->next) { - rdb_save_bs_core(bi); - } - } - rdb_close(); -#endif -} - -/*************************************************************************/ - /* Inserts a bot in the bot list. I can't be much explicit mh? */ static void insert_bot(BotInfo * bi) @@ -800,6 +778,7 @@ static void change_bot_nick(BotInfo * bi, char *newnick) static int delbot(BotInfo * bi) { cs_remove_bot(bi); + rdb_bs_del_bot(bi); if (bi->next) bi->next->prev = bi->prev; @@ -847,6 +826,7 @@ static void unassign(User * u, ChannelInfo * ci) u->nick); } ci->bi->chancount--; + rdb_bs_change_bot_chancount(ci->bi); ci->bi = NULL; } @@ -1391,6 +1371,8 @@ static int do_bot(User * u) bi->real = sstrdup(real); bi->created = time(NULL); bi->chancount = 0; + + rdb_bs_add_bot(bi); /* We check whether user with this nick is online, and kill it if so */ EnforceQlinedNick(nick, s_BotServ); @@ -1517,6 +1499,8 @@ static int do_bot(User * u) /* We check whether user with this nick is online, and kill it if so */ EnforceQlinedNick(nick, s_BotServ); } + + rdb_bs_change_bot(bi, nick, user, host ,real); if (strcmp(nick, bi->nick)) change_bot_nick(bi, nick); @@ -1653,6 +1637,7 @@ static int do_assign(User * u) unassign(u, ci); ci->bi = bi; bi->chancount++; + rdb_bs_change_bot_chancount(bi); if (ci->c && ci->c->usercount >= BSMinUsers) { bot_join(ci); } @@ -1921,9 +1906,11 @@ static int do_set(User * u) if ((bi = findbot(chan))) { if (!stricmp(value, "ON")) { bi->flags |= BI_PRIVATE; + rdb_bs_change_bot_flags(bi); notice_lang(s_BotServ, u, BOT_SET_PRIVATE_ON, bi->nick); } else if (!stricmp(value, "OFF")) { bi->flags &= ~BI_PRIVATE; + rdb_bs_change_bot_flags(bi); notice_lang(s_BotServ, u, BOT_SET_PRIVATE_OFF, bi->nick); } else { syntax_error(s_BotServ, u, "SET PRIVATE", diff --git a/src/chanserv.c b/src/chanserv.c index 06236c547..eabfd643b 100644 --- a/src/chanserv.c +++ b/src/chanserv.c @@ -1288,35 +1288,6 @@ void save_cs_dbase(void) /*************************************************************************/ -void save_cs_rdb_dbase(void) -{ -#ifdef USE_RDB - int i; - ChannelInfo *ci; - - if (!rdb_open()) - return; - - rdb_tag_table("anope_cs_info"); - rdb_scrub_table("anope_ms_info", "serv='CHAN'"); - rdb_clear_table("anope_cs_access"); - rdb_clear_table("anope_cs_levels"); - rdb_clear_table("anope_cs_akicks"); - rdb_clear_table("anope_cs_badwords"); - - for (i = 0; i < 256; i++) { - for (ci = chanlists[i]; ci; ci = ci->next) { - rdb_save_cs_info(ci); - } /* for (chanlists[i]) */ - } /* for (i) */ - - rdb_scrub_table("anope_cs_info", "active='0'"); - rdb_close(); -#endif -} - -/*************************************************************************/ - /* Check the current modes on a channel; if they conflict with a mode lock, * fix them. */ @@ -1951,12 +1922,6 @@ void cs_remove_nick(const NickCore * nc) ci->founder = nc2; ci->successor = NULL; nc2->channelcount++; -#ifdef USE_RDB - if (rdb_open()) { - rdb_cs_set_founder(ci->name, nc2->display); - rdb_close(); - } -#endif } } else { alog("%s: Deleting channel %s owned by deleted nick %s", s_ChanServ, ci->name, nc->display); @@ -2001,12 +1966,6 @@ void cs_remove_nick(const NickCore * nc) } } } -#ifdef USE_RDB - if (rdb_open()) { - rdb_cs_deluser(nc->display); - rdb_close(); - } -#endif } /*************************************************************************/ @@ -2135,12 +2094,6 @@ int delchan(ChannelInfo * ci) } ci->c->ci = NULL; } -#ifdef USE_RDB - if (rdb_open()) { - rdb_cs_delchan(ci); - rdb_close(); - } -#endif if (ci->next) ci->next->prev = ci->prev; if (ci->prev) @@ -3888,6 +3841,7 @@ static int access_del(User * u, ChanAccess * access, int *perm, int uacc) (*perm)++; return 0; } + rdb_cs_del_access(access); access->nc = NULL; access->in_use = 0; return 1; @@ -4023,6 +3977,7 @@ static int do_access(User * u) return MOD_CONT; } access->level = level; + rdb_cs_add_access(ci, access); alog("%s: %s!%s@%s (level %d) set access level %d to %s (group %s) on channel %s", s_ChanServ, u->nick, u->username, GetHost(u), ulev, access->level, na->nick, nc->display, ci->name); notice_lang(s_ChanServ, u, CHAN_ACCESS_LEVEL_CHANGED, access->nc->display, chan, level); @@ -4052,6 +4007,7 @@ static int do_access(User * u) access->in_use = 1; access->level = level; access->last_seen = 0; + rdb_cs_add_access(ci, access); alog("%s: %s!%s@%s (level %d) set access level %d to %s (group %s) on channel %s", s_ChanServ, u->nick, u->username, GetHost(u), ulev, access->level, na->nick, nc->display, ci->name); notice_lang(s_ChanServ, u, CHAN_ACCESS_ADDED, nc->display, diff --git a/src/config.c b/src/config.c index e2d09f9e3..004f5ac49 100644 --- a/src/config.c +++ b/src/config.c @@ -297,7 +297,6 @@ char *MysqlSecure; char *MysqlSock; int MysqlRetries = 0; int MysqlRetryGap = 0; -int UseRDB = 0; int DefConLevel; int DefCon1; @@ -492,7 +491,6 @@ Directive directives[] = { {"MysqlSock", {{PARAM_STRING, PARAM_RELOAD, &MysqlSock}}}, {"MysqlRetries", {{PARAM_POSINT, PARAM_RELOAD, &MysqlRetries}}}, {"MysqlRetryGap", {{PARAM_POSINT, PARAM_RELOAD, &MysqlRetryGap}}}, - {"UseRDB", {{PARAM_SET, PARAM_RELOAD, &UseRDB}}}, {"ModuleAutoload", {{PARAM_STRING, PARAM_RELOAD, &Modules}}}, {"ModuleDelayedAutoload", {{PARAM_STRING, PARAM_RELOAD, &ModulesDelayed}}}, diff --git a/src/hostserv.c b/src/hostserv.c index 7c2945683..d47ae32db 100644 --- a/src/hostserv.c +++ b/src/hostserv.c @@ -443,25 +443,11 @@ int listOut(User * u) /*************************************************************************/ void delHostCore(char *nick) { -#ifdef USE_RDB - static char clause[128]; -#endif HostCore *tmp; boolean found = false; tmp = findHostCore(head, nick, &found); if (found) { head = deleteHostCore(head, tmp); - -#ifdef USE_RDB - /* Reflect this change in the database right away. */ - if (rdb_open()) { - - snprintf(clause, sizeof(clause), "nick='%s'", nick); - rdb_scrub_table("anope_hs_core", clause); - rdb_close(); - } -#endif - } } @@ -623,25 +609,6 @@ void save_hs_dbase(void) #undef SAFE -void save_hs_rdb_dbase(void) -{ -#ifdef USE_RDB - HostCore *current; - - if (!rdb_open()) - return; - - rdb_clear_table("anope_hs_core"); - - current = head; - while (current != NULL) { - rdb_save_hs_core(current); - current = current->next; - } - rdb_close(); -#endif -} - /*************************************************************************/ /* End of Load/Save Functions */ /*************************************************************************/ diff --git a/src/init.c b/src/init.c index c6daf5918..e8e13d862 100644 --- a/src/init.c +++ b/src/init.c @@ -607,6 +607,11 @@ int init(int ac, char **av) lang_init(); if (debug) alog("debug: Loaded languages"); + + /* Initialize remote database support */ + rdb_init(); + if (debug) + alog("debug: Loaded remote databases"); /* Initialize subservices */ ns_init(); @@ -617,10 +622,6 @@ int init(int ac, char **av) hostserv_init(); helpserv_init(); -#ifdef USE_RDB - rdb_init(); -#endif - /* Initialize proxy detection */ #ifdef USE_THREADS if (ProxyDetect && !proxy_init()) { @@ -643,12 +644,6 @@ int init(int ac, char **av) #endif /* Load up databases */ -#ifdef USE_RDB - if (UseRDB) - rdb_load_dbases(); - /* Need a better way to handle this -dane */ - if (!UseRDB) { -#endif if (!skeleton) { load_ns_dbase(); if (debug) @@ -682,25 +677,8 @@ int init(int ac, char **av) if (debug) alog("debug: Loaded PreNick database (9/9)"); } -#ifdef USE_RDB - } -#endif alog("Databases loaded"); - - /* Save the databases back to file/mysql to reflect any changes */ -#ifdef USE_RDB - if (!UseRDB) { /* Only save if we are not using remote databases - * to avoid floods. As a side effects our nice - * FFF databases won't get overwritten if the - * mysql db is broken (empty etc.) */ -#endif - alog("Info: Reflecting database records."); - save_databases(); -#ifdef USE_RDB - } else { - alog("Info: Not reflecting database records."); - } -#endif + save_databases(); /* Make myself known to myself in the serverlist */ me_server = new_server(NULL, ServerName, ServerDesc, SERVER_ISME); diff --git a/src/main.c b/src/main.c index cb9c3a009..3af7dc73c 100644 --- a/src/main.c +++ b/src/main.c @@ -48,7 +48,6 @@ int is44 = 0; /* -is44 */ #endif #ifdef USE_RDB -int do_mysql = 0; /* use mysql ? */ #endif /* Set to 1 if we are to quit */ @@ -154,40 +153,6 @@ void save_databases(void) save_news(); waiting = -18; save_exceptions(); - -#ifdef USE_RDB - if (do_mysql) { - if (debug) - alog("debug: Saving RDB databases"); - waiting = -10; - if (!skeleton) { - waiting = -11; - save_ns_rdb_dbase(); - waiting = -12; - save_cs_rdb_dbase(); - if (PreNickDBName) { - save_ns_req_rdb_dbase(); - waiting = -13; - } - /* Temporary fix to avoid unwanted timeouts... */ - send_cmd(ServerName, "PONG %s", ServerName); - if (s_BotServ) { - waiting = -14; - save_bs_rdb_dbase(); - } - if (s_HostServ) { - waiting = -15; - save_hs_rdb_dbase(); - } - waiting = -16; - save_os_rdb_dbase(); - waiting = -17; - save_rdb_news(); - waiting = -18; - save_rdb_exceptions(); - } - } -#endif } /*************************************************************************/ @@ -232,6 +197,7 @@ void do_restart_services(void) static void services_shutdown(void) { + rdb_end(); if (!quitmsg) quitmsg = "Terminating, reason unknown"; alog("%s", quitmsg); diff --git a/src/mysql.c b/src/mysql.c index 1b83502c2..3c4541ee3 100644 --- a/src/mysql.c +++ b/src/mysql.c @@ -15,1624 +15,231 @@ /*************************************************************************/ -/* Database Global Variables */ -MYSQL *mysql; /* MySQL Handler */ -MYSQL_RES *mysql_res; /* MySQL Result */ -MYSQL_FIELD *mysql_fields; /* MySQL Fields */ -MYSQL_ROW mysql_row; /* MySQL Row */ +#ifdef USE_MYSQL -/*************************************************************************/ - -void db_mysql_error(int severity, char *msg) -{ - static char buf[512]; - - if (mysql_error(mysql)) { - snprintf(buf, sizeof(buf), "MySQL %s %s: %s", msg, - severity == MYSQL_WARNING ? "warning" : "error", - mysql_error(mysql)); - } else { - snprintf(buf, sizeof(buf), "MySQL %s %s", msg, - severity == MYSQL_WARNING ? "warning" : "error"); - } - - log_perror(buf); - - if (severity == MYSQL_ERROR) { - log_perror("MySQL FATAL error... aborting."); - exit(0); - } - -} +MYSQL *mysql; +MYSQL_RES *mysql_res; +MYSQL_ROW mysql_row; +int do_mysql = 0; -/*************************************************************************/ - -int db_mysql_init() +void db_mysql_init(void) { + if (!MysqlPort) MysqlPort = 3306; - /* If the host is not defined, assume we don't want MySQL */ - if (!MysqlHost) { + if (!MysqlHost && !MysqlSock) { + alog("MySQL is disabled."); do_mysql = 0; - alog("MySQL has been disabled."); - } else { - do_mysql = 1; - alog("MySQL has been enabled."); + return; } - - /* The following configuration options are required. - * If missing disable MySQL to avoid any problems. - */ - - if (!MysqlName || !MysqlUser) { + if (!MysqlUser || !MysqlPass) { + alog("Missing required config directives for MySQL."); do_mysql = 0; - alog("MySQL Error: Set all required configuration options."); + return; } - if (!db_mysql_open()) - do_mysql = 0; - - return 1; -} - -/*************************************************************************/ - -int db_mysql_open() -{ - /* If MySQL is disabled, return 0 */ - if (!do_mysql) - return 0; - mysql = mysql_init(NULL); - if (mysql == NULL) - db_mysql_error(MYSQL_WARNING, "Unable to create mysql object"); - - if (!MysqlPort) - MysqlPort = 3306; - - if (MysqlSock) { - if ((!mysql_real_connect - (mysql, MysqlHost, MysqlUser, MysqlPass, MysqlName, MysqlPort, - MysqlSock, 0))) { - log_perror("Cant connect to MySQL: %s\n", mysql_error(mysql)); - return 0; - } - } else { - if ((!mysql_real_connect - (mysql, MysqlHost, MysqlUser, MysqlPass, MysqlName, MysqlPort, - NULL, 0))) { - log_perror("Cant connect to MySQL: %s\n", mysql_error(mysql)); - return 0; - } + if ((!mysql_real_connect(mysql, MysqlHost, MysqlUser, MysqlPass, MysqlName, MysqlPort, MysqlSock ? MysqlSock : NULL, 0))) { + alog("Unable to connect to MySQL database:"); + alog(mysql_error(mysql)); + do_mysql = 0; + return; } - - return 1; - + + alog("MySQL enabled."); + do_mysql = 1; } -/*************************************************************************/ - -int db_mysql_query(char *sql) +void db_mysql_end(void) { - int result, lcv; - char *s; - - if (!do_mysql) { - return -1; - } - - if (debug) { - s = db_mysql_quote(sql); - alog(s); - free(s); - + if (do_mysql) { + mysql_close(mysql); + alog("MySQL connection closed."); } - - result = mysql_query(mysql, sql); - - if (result) { - switch (mysql_errno(mysql)) { - case CR_SERVER_GONE_ERROR: - case CR_SERVER_LOST: - - for (lcv = 0; lcv < MysqlRetries; lcv++) { - if (db_mysql_open()) { - result = mysql_query(mysql, sql); - return (result); - } - sleep(MysqlRetryGap); - } - - /* If we get here, we could not connect. */ - log_perror("Unable to reconnect to database: %s\n", - mysql_error(mysql)); - db_mysql_error(MYSQL_ERROR, "connect"); - - /* Never reached. */ - break; - - default: - /* Unhandled error. */ - return (result); - } - } - - return (0); - } -/*************************************************************************/ - char *db_mysql_quote(char *sql) { - int slen; char *quoted; - - - if (!sql) { - return sstrdup(""); - } - - slen = strlen(sql); - quoted = malloc((1 + (slen * 2)) * sizeof(char)); - - mysql_real_escape_string(mysql, quoted, sql, slen); + int len; + + if (!do_mysql || !sql) return sstrdup(""); + + len = strlen(sql); + quoted = malloc((2*len + 1) * sizeof(char)); + mysql_real_escape_string(mysql, quoted, sql, len); return quoted; - -} - -/*************************************************************************/ - -/* I don't like using res here, maybe we can pass it as a param? */ -int db_mysql_close() -{ - if (mysql_res) - mysql_free_result(mysql_res); - mysql_close(mysql); - return 1; -} - -/*************************************************************************/ - -/* - * NickServ Specific Secion - */ - -/*************************************************************************/ -void db_mysql_save_ns_req(NickRequest * nr) -{ - char *qnick, *qpasscode, *qpassword, *qemail; - char sqlcmd[MAX_SQL_BUF]; - - qnick = db_mysql_quote(nr->nick); - qpasscode = db_mysql_quote(nr->passcode); - qpassword = db_mysql_quote(nr->password); - qemail = db_mysql_quote(nr->email); - - snprintf(sqlcmd, MAX_SQL_BUF, - "REPLACE anope_ns_request (nick,passcode,password,email,requested,active)" - " VALUES ('%s','%s','%s','%s','%d','1')", - qnick, qpasscode, qpassword, qemail, (int) nr->requested); - if (db_mysql_query(sqlcmd)) { - log_perror("Can't create sql query: %s", sqlcmd); - db_mysql_error(MYSQL_WARNING, "query"); - } - free(qnick); - free(qpasscode); - free(qpassword); - free(qemail); -} - -char *db_mysql_secure(char *pass) -{ - - char epass[BUFSIZE]; - - /* Initialize the buffer. Bug #86 */ - memset(epass, '\0', BUFSIZE); - -#ifdef USE_ENCRYPTION - /* If we use the builtin encryption don't double encrypt! */ - snprintf(epass, sizeof(epass), "'%s'", pass); -#else - - if (!pass) { - snprintf(epass, sizeof(epass), "''"); - } else if ((!MysqlSecure) || (strcmp(MysqlSecure, "") == 0)) { - snprintf(epass, sizeof(epass), "'%s'", pass); - } else if (strcmp(MysqlSecure, "des") == 0) { - snprintf(epass, sizeof(epass), "ENCRYPT('%s')", pass); - } else if (strcmp(MysqlSecure, "md5") == 0) { - snprintf(epass, sizeof(epass), "MD5('%s')", pass); - } else if (strcmp(MysqlSecure, "sha") == 0) { - snprintf(epass, sizeof(epass), "SHA('%s')", pass); - } else { - snprintf(epass, sizeof(epass), "ENCODE('%s','%s')", pass, - MysqlSecure); - } - -#endif - - return sstrdup(epass); - -} - -/*************************************************************************/ -void db_mysql_save_ns_core(NickCore * nc) -{ - char sqlcmd[MAX_SQL_BUF]; - int j; - char **access; - Memo *memos; - char *cnick, *cpass, *epass, *cemail, *cgreet, *curl, *caccess, - *msender, *mtext; - - cnick = db_mysql_quote(nc->display); - cpass = db_mysql_quote(nc->pass); - cemail = db_mysql_quote(nc->email); - cgreet = db_mysql_quote(nc->greet); - curl = db_mysql_quote(nc->url); - - epass = db_mysql_secure(cpass); - free(cpass); - - /* Let's take care of the core itself */ - /* Update the existing records */ - snprintf(sqlcmd, MAX_SQL_BUF, - "UPDATE anope_ns_core SET pass=%s,email='%s',greet='%s',icq='%d',url='%s',flags='%d'," - "language='%d',accesscount='%d',memocount='%d',memomax='%d',channelcount='%d'" - ",channelmax='%d',active='1' WHERE display='%s'", - epass, cemail, cgreet, nc->icq, curl, nc->flags, - nc->language, nc->accesscount, nc->memos.memocount, - nc->memos.memomax, nc->channelcount, nc->channelmax, cnick); - if (db_mysql_query(sqlcmd)) { - log_perror("Can't create sql query: %s", sqlcmd); - db_mysql_error(MYSQL_WARNING, "query"); - } - - /* need to write a wrapper for mysql_affected_rows */ - /* Our previous UPDATE affected no rows, therefore this is a new record */ - if ((int) mysql_affected_rows(mysql) <= 0) { - - /* Let's take care of the core itself */ - snprintf(sqlcmd, MAX_SQL_BUF, - "INSERT DELAYED INTO anope_ns_core (display,pass,email,greet,icq,url,flags," - "language,accesscount,memocount,memomax,channelcount,channelmax,active)" - " VALUES ('%s',%s,'%s','%s','%d','%s','%d','%d','%d','%d','%d','%d','%d','1')", - cnick, epass, cemail, cgreet, nc->icq, curl, nc->flags, - nc->language, nc->accesscount, nc->memos.memocount, - nc->memos.memomax, nc->channelcount, nc->channelmax); - if (db_mysql_query(sqlcmd)) { - log_perror("Can't create sql query: %s", sqlcmd); - db_mysql_error(MYSQL_WARNING, "query"); - } - } - - /* Now let's do the access */ - for (j = 0, access = nc->access; j < nc->accesscount; j++, access++) { - caccess = db_mysql_quote(*access); - snprintf(sqlcmd, MAX_SQL_BUF, - "INSERT DELAYED INTO anope_ns_access (display,access) VALUES ('%s','%s')", - cnick, caccess); - if (db_mysql_query(sqlcmd)) { - log_perror("Can't create sql query: %s", sqlcmd); - db_mysql_error(MYSQL_WARNING, "query"); - } - free(caccess); - } - - /* And... memos */ - memos = nc->memos.memos; - for (j = 0; j < nc->memos.memocount; j++, memos++) { - msender = db_mysql_quote(memos->sender); - mtext = db_mysql_quote(memos->text); - snprintf(sqlcmd, MAX_SQL_BUF, - "INSERT DELAYED INTO anope_ms_info (receiver,number,flags,time,sender,text,serv)" - " VALUES ('%s','%d','%d','%d','%s','%s','NICK')", - cnick, memos->number, memos->flags, - (int) memos->time, msender, mtext); - if (db_mysql_query(sqlcmd)) { - log_perror("Can't create sql query: %s", sqlcmd); - db_mysql_error(MYSQL_WARNING, "query"); - } - free(msender); - free(mtext); - } - - free(cnick); - free(epass); - free(cemail); - free(cgreet); - free(curl); -} - - -/*************************************************************************/ -void db_mysql_save_ns_alias(NickAlias * na) -{ - char sqlcmd[MAX_SQL_BUF]; - char *nnick, *nlmask, *nlrname, *nlquit, *nncnick; - nnick = db_mysql_quote(na->nick); - nlmask = db_mysql_quote(na->last_usermask); - nlrname = db_mysql_quote(na->last_realname); - nlquit = db_mysql_quote(na->last_quit); - nncnick = db_mysql_quote(na->nc->display); - snprintf(sqlcmd, MAX_SQL_BUF, - "UPDATE anope_ns_alias SET last_usermask='%s',last_realname='%s',last_quit='%s',time_registered='%d',last_seen='%d',status='%d',display='%s',active='1' WHERE nick='%s'", - nlmask, nlrname, nlquit, (int) na->time_registered, - (int) na->last_seen, (int) na->status, nncnick, nnick); - if (db_mysql_query(sqlcmd)) { - log_perror("Can't create sql query: %s", sqlcmd); - db_mysql_error(MYSQL_WARNING, "query"); - } - /* Our previous UPDATE affected no rows, therefore this is a new record */ - if ((int) mysql_affected_rows(mysql) <= 0) { - snprintf(sqlcmd, MAX_SQL_BUF, - "INSERT INTO anope_ns_alias (nick,last_usermask,last_realname,last_quit,time_registered,last_seen,status,display,active) VALUES ('%s','%s','%s','%s','%d','%d','%d','%s','1')", - nnick, nlmask, nlrname, nlquit, (int) na->time_registered, - (int) na->last_seen, (int) na->status, nncnick); - if (db_mysql_query(sqlcmd)) { - log_perror("Can't create sql query: %s", sqlcmd); - db_mysql_error(MYSQL_WARNING, "query"); - } - } - - free(nnick); - free(nlmask); - free(nlrname); - free(nlquit); - free(nncnick); - - return; -} - -/*************************************************************************/ - -/* - * ChanServ Specific Secion - */ - -/*************************************************************************/ -void db_mysql_save_cs_info(ChannelInfo * ci) -{ - char sqlcmd[MAX_SQL_BUF]; - int j, position; - Memo *memos; - char *ciname, *cifoundernick, *cisuccessornick, *cifounderpass, - *cidesc, *ciurl, *ciemail, *cilasttopic, *cilasttopicsetter, - *ciforbidby, *ciforbidreason, *cimlock_key, *cimlock_flood, - *cimlock_redirect, *cientrymsg, *cibotnick, *msender, *mtext, - *ciaccessdisp, *ciakickdisp, *ciakickreason, *ciakickcreator, - *cbadwords, *efounderpass; - - ciname = db_mysql_quote(ci->name); - cifoundernick = - ci->founder ? db_mysql_quote(ci->founder->display) : ""; - cisuccessornick = - ci->successor ? db_mysql_quote(ci->successor->display) : ""; - cifounderpass = db_mysql_quote(ci->founderpass); - cidesc = db_mysql_quote(ci->desc); - ciurl = db_mysql_quote(ci->url); - ciemail = db_mysql_quote(ci->email); - cilasttopic = db_mysql_quote(ci->last_topic); - cilasttopicsetter = db_mysql_quote(ci->last_topic_setter); - ciforbidby = db_mysql_quote(ci->forbidby); - ciforbidreason = db_mysql_quote(ci->forbidreason); - cimlock_key = db_mysql_quote(ci->mlock_key); -#ifdef HAS_FMODE - cimlock_flood = db_mysql_quote(ci->mlock_flood); -#else - cimlock_flood = NULL; -#endif -#ifdef HAS_LMODE - cimlock_redirect = db_mysql_quote(ci->mlock_redirect); -#else - cimlock_redirect = NULL; -#endif - cientrymsg = db_mysql_quote(ci->entry_message); - cibotnick = ci->bi ? db_mysql_quote(ci->bi->nick) : ""; - - efounderpass = db_mysql_secure(cifounderpass); - free(cifounderpass); - - /* Let's take care of the core itself */ - snprintf(sqlcmd, MAX_SQL_BUF, - "UPDATE anope_cs_info SET founder='%s',successor='%s',founderpass=%s," - "descr='%s',url='%s',email='%s',time_registered='%d',last_used='%d'," - "last_topic='%s',last_topic_setter='%s',last_topic_time='%d',flags='%d'," - "forbidby='%s',forbidreason='%s',bantype='%d',accesscount='%d'," - "akickcount='%d',mlock_on='%d',mlock_off='%d',mlock_limit='%d'," - "mlock_key='%s',mlock_flood='%s',mlock_redirect='%s',entry_message='%s'," - "memomax='%d',botnick='%s',botflags='%d',ttb='%d',bwcount='%d'," - "capsmin='%d',capspercent='%d',floodlines='%d',floodsecs='%d'," - "repeattimes='%d',active='1' WHERE name='%s'", - cifoundernick, - cisuccessornick, - efounderpass, cidesc, ciurl, ciemail, - (int) ci->time_registered, (int) ci->last_used, - cilasttopic, cilasttopicsetter, - (int) ci->last_topic_time, (int) ci->flags, - ciforbidby, ciforbidreason, (int) ci->bantype, - (int) ci->accesscount, (int) ci->akickcount, - (int) ci->mlock_on, (int) ci->mlock_off, - (int) ci->mlock_limit, cimlock_key, -#ifdef HAS_FMODE - cimlock_flood, -#else - "", -#endif -#ifdef HAS_LMODE - cimlock_redirect, -#else - "", -#endif - cientrymsg, - (int) ci->memos.memomax, - cibotnick, - (int) ci->botflags, - (int) ci->ttb, - (int) ci->bwcount, - (int) ci->capsmin, - (int) ci->capspercent, - (int) ci->floodlines, - (int) ci->floodsecs, (int) ci->repeattimes, ciname); - if (db_mysql_query(sqlcmd)) { - log_perror("Can't create sql query: %s", sqlcmd); - db_mysql_error(MYSQL_WARNING, "query"); - } - - /* Our previous UPDATE affected no rows, therefore this is a new record */ - if ((int) mysql_affected_rows(mysql) <= 0) { - snprintf(sqlcmd, MAX_SQL_BUF, - "INSERT DELAYED INTO anope_cs_info (name,founder,successor,founderpass," - "descr,url,email,time_registered,last_used,last_topic,last_topic_setter" - ",last_topic_time,flags,forbidby,forbidreason,bantype,accesscount,akickcount" - ",mlock_on,mlock_off,mlock_limit,mlock_key,mlock_flood,mlock_redirect," - "entry_message,botnick,botflags,bwcount,capsmin,capspercent,floodlines," - "floodsecs,repeattimes,active) VALUES ('%s','%s','%s',%s,'%s','%s','%s'" - ",'%d','%d','%s','%s','%d','%d','%s','%s','%d','%d','%d','%d','%d','%d'," - "'%s','%s','%s','%s','%s','%d','%d','%d','%d','%d','%d','%d','1')", - ciname, - cifoundernick, - cisuccessornick, - efounderpass, cidesc, ciurl, ciemail, - (int) ci->time_registered, (int) ci->last_used, - cilasttopic, cilasttopicsetter, - (int) ci->last_topic_time, (int) ci->flags, - ciforbidby, ciforbidreason, (int) ci->bantype, - (int) ci->accesscount, (int) ci->akickcount, - (int) ci->mlock_on, (int) ci->mlock_off, - (int) ci->mlock_limit, cimlock_key, -#ifdef HAS_FMODE - cimlock_flood, -#else - "", -#endif -#ifdef HAS_LMODE - cimlock_redirect, -#else - "", -#endif - cientrymsg, - cibotnick, - (int) ci->botflags, - (int) ci->bwcount, - (int) ci->capsmin, - (int) ci->capspercent, - (int) ci->floodlines, - (int) ci->floodsecs, (int) ci->repeattimes); - if (db_mysql_query(sqlcmd)) { - log_perror("Can't create sql query: %s", sqlcmd); - db_mysql_error(MYSQL_WARNING, "query"); - } - } - - /* Memos */ - memos = ci->memos.memos; - for (j = 0; j < ci->memos.memocount; j++, memos++) { - msender = db_mysql_quote(memos->sender); - mtext = db_mysql_quote(memos->text); - snprintf(sqlcmd, MAX_SQL_BUF, - "INSERT DELAYED INTO anope_ms_info (receiver,number,flags,time,sender,text,serv)" - " VALUES ('%s','%d','%d','%d','%s','%s','CHAN')", - ciname, memos->number, memos->flags, - (int) memos->time, msender, mtext); - if (db_mysql_query(sqlcmd)) { - log_perror("Can't create sql query: %s", sqlcmd); - db_mysql_error(MYSQL_WARNING, "query"); - } - free(msender); - free(mtext); - } - - /* Access */ - for (j = 0; j < ci->accesscount; j++) { - if (ci->access[j].in_use) { - ciaccessdisp = db_mysql_quote(ci->access[j].nc->display); |
