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 | |
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')
-rw-r--r-- | src/modules/mysql/db_mysql_read.cpp | 74 | ||||
-rw-r--r-- | src/modules/mysql/db_mysql_write.cpp | 89 | ||||
-rw-r--r-- | src/regchannel.cpp | 4 |
3 files changed, 164 insertions, 3 deletions
diff --git a/src/modules/mysql/db_mysql_read.cpp b/src/modules/mysql/db_mysql_read.cpp index 36c48b4eb..2cbcd669c 100644 --- a/src/modules/mysql/db_mysql_read.cpp +++ b/src/modules/mysql/db_mysql_read.cpp @@ -202,6 +202,33 @@ static void LoadDatabase() } } + query << "SELECT * FROM `anope_bs_info_metadata`"; + qres = StoreQuery(query); + + if (qres) + { + for (size_t i = 0; i < qres.num_rows(); ++i) + { + BotInfo *bi = findbot(SQLAssign(qres[i]["botname"])); + if (!bi) + { + Alog() << "MySQL: BotInfo metadata for nonexistant bot " << qres[i]["botname"]; + continue; + } + + try + { + EventReturn MOD_RESULT; + std::vector<std::string> Params = MakeVector(SQLAssign(qres[i]["value"])); + FOREACH_RESULT(I_OnDatabaseReadMetadata, OnDatabaseReadMetadata(bi, SQLAssign(qres[i]["name"]), Params)); + } + catch (const char *err) + { + Alog() << "[db_mysql_read]: " << err; + } + } + } + query << "SELECT * FROM `anope_cs_info`"; qres = StoreQuery(query); @@ -336,7 +363,7 @@ static void LoadDatabase() if (!qres[i]["capspercent"].empty()) ci->capspercent = atoi(qres[i]["capspercent"].c_str()); if (!qres[i]["floodlines"].empty()) - ci->floodlines = atoi(qres[i]["capspercent"].c_str()); + ci->floodlines = atoi(qres[i]["floodlines"].c_str()); if (!qres[i]["floodsecs"].empty()) ci->floodsecs = atoi(qres[i]["floodsecs"].c_str()); if (!qres[i]["repeattimes"].empty()) @@ -344,6 +371,49 @@ static void LoadDatabase() } } + query << "SELECT * FROM `anope_cs_ttb"; + qres = StoreQuery(query); + + if (qres) + { + for (size_t i = 0; i < qres.num_rows(); ++i) + { + ChannelInfo *ci = cs_findchan(SQLAssign(qres[i]["channel"])); + if (!ci) + { + Alog() << "MySQL: Channel ttb for nonexistant channel " << qres[i]["channel"]; + continue; + } + + ci->ttb[atoi(qres[i]["ttb_id"].c_str())] = atoi(qres[i]["value"].c_str()); + } + } + + query << "SELECT * FROM `anope_bs_badwords`"; + qres = StoreQuery(query); + + if (qres) + { + for (size_t i = 0; i < qres.num_rows(); ++i) + { + ChannelInfo *ci = cs_findchan(SQLAssign(qres[i]["channel"])); + if (!ci) + { + Alog() << "MySQL: Channel badwords entry for nonexistant channel " << qres[i]["channel"]; + continue; + } + + BadWordType BWTYPE = BW_ANY; + if (qres[i]["type"] == "SINGLE") + BWTYPE = BW_SINGLE; + else if (qres[i]["type"] == "START") + BWTYPE = BW_START; + else if (qres[i]["type"] == "END") + BWTYPE = BW_END; + ci->AddBadWord(SQLAssign(qres[i]["word"]), BWTYPE); + } + } + query << "SELECT * FROM `anope_cs_access`"; qres = StoreQuery(query); @@ -395,7 +465,7 @@ static void LoadDatabase() ChannelInfo *ci = cs_findchan(SQLAssign(qres[i]["channel"])); if (!ci) { - Alog() << "MySQL: Channel level entry for nonexistant channel " << qres[i]["channel"]; + Alog() << "MySQL: Channel metadata for nonexistant channel " << qres[i]["channel"]; continue; } try 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); diff --git a/src/regchannel.cpp b/src/regchannel.cpp index 706746422..1f4542948 100644 --- a/src/regchannel.cpp +++ b/src/regchannel.cpp @@ -350,6 +350,9 @@ BadWord *ChannelInfo::AddBadWord(const std::string &word, BadWordType type) bw->type = type; badwords.push_back(bw); + + FOREACH_MOD(I_OnBadWordAdd, OnBadWordAdd(this, bw)); + return bw; } @@ -382,6 +385,7 @@ void ChannelInfo::EraseBadWord(BadWord *badword) if (it != badwords.end()) { + FOREACH_MOD(I_OnBadWordDel, OnBadWordDel(this, *it)); delete *it; badwords.erase(it); } |