1
0
mirror of https://github.com/anope/anope.git synced 2026-07-06 14:53:13 +02:00

Finish rest of BotServ SQL stuff

git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2839 5417fbe8-f217-4b02-8779-1006273d7864
This commit is contained in:
Adam-
2010-03-28 07:57:05 +00:00
parent aa90411f3a
commit f4bcf833ec
5 changed files with 207 additions and 6 deletions
+72 -2
View File
@@ -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
+88 -1
View File
@@ -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);