diff options
author | Adam- <Adam-@5417fbe8-f217-4b02-8779-1006273d7864> | 2010-03-28 07:57:05 +0000 |
---|---|---|
committer | Adam- <Adam-@5417fbe8-f217-4b02-8779-1006273d7864> | 2010-03-28 07:57:05 +0000 |
commit | f4bcf833ecb4c139544bf6de5fadabca56e016e9 (patch) | |
tree | 16beb2e9a5aa055aebb1e8391207fff7000b68f6 /src/modules/mysql/db_mysql_write.cpp | |
parent | aa90411f3ad2361db810a064906c2d8047a8ff92 (diff) |
Finish rest of BotServ SQL stuff
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2839 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src/modules/mysql/db_mysql_write.cpp')
-rw-r--r-- | src/modules/mysql/db_mysql_write.cpp | 89 |
1 files changed, 88 insertions, 1 deletions
diff --git a/src/modules/mysql/db_mysql_write.cpp b/src/modules/mysql/db_mysql_write.cpp index 2f2b69a41..b177a160f 100644 --- a/src/modules/mysql/db_mysql_write.cpp +++ b/src/modules/mysql/db_mysql_write.cpp @@ -160,6 +160,7 @@ static std::string GetBotServFlags(BotInfo *bi) static NickAlias *CurNick = NULL; static NickCore *CurCore = NULL; static ChannelInfo *CurChannel = NULL; +static BotInfo *CurBot = NULL; void Write(const std::string &data) { @@ -205,6 +206,16 @@ void WriteChannelMetadata(const std::string &key, const std::string &data) ExecuteQuery(query); } +void WriteBotMetadata(const std::string &key, const std::string &data) +{ + if (!CurBot) + throw CoreException("WriteBotMetadata without a bot to write"); + + mysqlpp::Query query(Me->Con); + query << "INSERT DELAYED INTO `anope_bs_info_metadata` (botname, name, value) VALUES(" << mysqlpp::quote << CurBot->nick << ", " << mysqlpp::quote << key << ", " << mysqlpp::quote << data << ")"; + ExecuteQuery(query); +} + static void SaveDatabases() { int i; @@ -383,13 +394,14 @@ class DBMySQLWrite : public DBMySQL /* BotServ */ I_OnBotCreate, I_OnBotChange, I_OnBotDelete, I_OnBotAssign, I_OnBotUnAssign, + I_OnBadWordAdd, I_OnBadWordDel, /* MemoServ */ I_OnMemoSend, I_OnMemoDel, /* OperServ */ I_OnOperServHelp, I_OnAddAkill, I_OnDelAkill, I_OnExceptionAdd, I_OnExceptionDel, I_OnAddSXLine, I_OnDelSXLine }; - ModuleManager::Attach(i, this, 35); + ModuleManager::Attach(i, this, 37); } void OnOperServHelp(User *u) @@ -433,6 +445,21 @@ class DBMySQLWrite : public DBMySQL FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteChannelMetadata, ci)); } } + + for (int i = 0; i < 256; ++i) + { + for (BotInfo *bi = botlists[i]; bi; bi = bi->next) + { + CurBot = bi; + FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteBotMetadata, bi)); + /* This is for the core bots, bots added by users are already handled by an event */ + query << "INSERT DELAYED INTO `anope_bs_core` (nick, user, host, rname, flags, created, chancount) VALUES("; + query << mysqlpp::quote << bi->nick << ", " << mysqlpp::quote << bi->user << ", " << mysqlpp::quote << bi->host; + query << ", " << mysqlpp::quote << bi->real << ", '" << GetBotServFlags(bi) << "', " << bi->created << ", "; + query << bi->chancount << ") ON DUPLICATE KEY UPDATE nick=VALUES(nick), user=VALUES(user), host=VALUES(host), rname=VALUES(rname), flags=VALUES(flags), created=VALUES(created), chancount=VALUES(created)"; + ExecuteQuery(query); + } + } FOREACH_MOD(I_OnDatabaseWrite, OnDatabaseWrite(Write)); @@ -569,6 +596,22 @@ class DBMySQLWrite : public DBMySQL } query << "UPDATE `anope_cs_info` SET `botflags` = '" << GetBotFlags(ci->botflags) << "' WHERE `name` = " << mysqlpp::quote << ci->name; ExecuteQuery(query); + + if (params[1] == "CAPS") + { + query << "UPDATE `anope_cs_info` SET `capsmin` = " << ci->capsmin << ", `capspercent` = " << ci->capspercent << " WHERE `name` = " << mysqlpp::quote << ci->name; + ExecuteQuery(query); + } + else if (params[1] == "FLOOD") + { + query << "UPDATE `anope_cs_info` SET `floodlines` = " << ci->floodlines << ", `floodsecs` = " << ci->floodsecs << " WHERE `name` = " << mysqlpp::quote << ci->name; + ExecuteQuery(query); + } + else if (params[1] == "REPEAT") + { + query << "UPDATE `anope_cs_info` SET `repeattimes` = " << ci->repeattimes << " WHERE `name` = " << mysqlpp::quote << ci->name; + ExecuteQuery(query); + } } } } @@ -831,6 +874,50 @@ class DBMySQLWrite : public DBMySQL return EVENT_CONTINUE; } + void OnBadWordAdd(ChannelInfo *ci, BadWord *bw) + { + mysqlpp::Query query(Me->Con); + query << "INSERT DELAYED INTO `anope_bs_badwords` (channel, word, type) VALUES(" << mysqlpp::quote << ci->name << ", " << mysqlpp::quote << bw->word << ", '"; + switch (bw->type) + { + case BW_SINGLE: + query << "SINGLE"; + break; + case BW_START: + query << "START"; + break; + case BW_END: + query << "END"; + break; + default: + query << "ANY"; + } + query << "') ON DUPLICATE KEY UPDATE channel=VALUES(channel), word=VALUES(word), type=VALUES(type)"; + ExecuteQuery(query); + } + + void OnBadWordDel(ChannelInfo *ci, BadWord *bw) + { + mysqlpp::Query query(Me->Con); + query << "DELETE FROM `anope_bs_badwords` WHERE `channel` = " << mysqlpp::quote << ci->name << " AND `word` = " << mysqlpp::quote << bw->word << " AND `type` = '"; + switch (bw->type) + { + case BW_SINGLE: + query << "SINGLE"; + break; + case BW_START: + query << "START"; + break; + case BW_END: + query << "END"; + break; + default: + query << "ANY"; + } + query << "'"; + ExecuteQuery(query); + } + void OnMemoSend(User *u, NickCore *nc, Memo *m) { mysqlpp::Query query(Me->Con); |