diff options
author | Adam- <Adam-@5417fbe8-f217-4b02-8779-1006273d7864> | 2010-03-20 04:59:38 +0000 |
---|---|---|
committer | Adam- <Adam-@5417fbe8-f217-4b02-8779-1006273d7864> | 2010-03-20 04:59:38 +0000 |
commit | 51351aac2b7e993de3610c406af1218d32a2811f (patch) | |
tree | 452919cf896b89063894d5ff4af7a7e676d54c00 /src/modules | |
parent | ba4c7d813808cad3dd79bfb58025b61506482252 (diff) |
Added in support for OperServ and MemoServ into SQL
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2822 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/mysql/db_mysql.h | 13 | ||||
-rw-r--r-- | src/modules/mysql/db_mysql_read.cpp | 102 | ||||
-rw-r--r-- | src/modules/mysql/db_mysql_write.cpp | 134 |
3 files changed, 247 insertions, 2 deletions
diff --git a/src/modules/mysql/db_mysql.h b/src/modules/mysql/db_mysql.h index b617b7dd5..aeb365563 100644 --- a/src/modules/mysql/db_mysql.h +++ b/src/modules/mysql/db_mysql.h @@ -149,6 +149,19 @@ BotServFlagInfo BotServFlags[] = { {"", static_cast<BotFlag>(-1)} }; +struct MemoFlagInfo +{ + std::string Name; + MemoFlag Flag; +}; + +MemoFlagInfo MemoFlags[] = { + {"UNREAD", MF_UNREAD}, + {"RECEIPT", MF_RECEIPT}, + {"NOTIFYS", MF_NOTIFYS}, + {"", static_cast<MemoFlag>(-1)} +}; + #define MYSQLPP_MYSQL_HEADERS_BURIED #include <mysql++/mysql++.h> diff --git a/src/modules/mysql/db_mysql_read.cpp b/src/modules/mysql/db_mysql_read.cpp index f9330270c..36c48b4eb 100644 --- a/src/modules/mysql/db_mysql_read.cpp +++ b/src/modules/mysql/db_mysql_read.cpp @@ -486,6 +486,108 @@ static void LoadDatabase() } } } + + query << "SELECT * FROM `anope_ms_info`"; + qres = StoreQuery(query); + + if (qres) + { + for (size_t i = 0; i < qres.num_rows(); ++i) + { + MemoInfo *mi = NULL; + if (qres[i]["serv"] == "NICK") + { + NickCore *nc = findcore(qres[i]["receiver"].c_str()); + if (nc) + mi = &nc->memos; + } + else if (qres[i]["serv"] == "CHAN") + { + ChannelInfo *ci = cs_findchan(SQLAssign(qres[i]["receiver"])); + if (ci) + mi = &ci->memos; + } + if (mi) + { + Memo *m = new Memo(); + mi->memos.push_back(m); + m->sender = SQLAssign(qres[i]["sender"]); + if (mi->memos.size() > 1) + { + m->number = mi->memos[mi->memos.size() - 2]->number + 1; + if (m->number < 1) + { + for (unsigned j = 0; j < mi->memos.size(); ++j) + mi->memos[j]->number = j + 1; + } + } + else + { + m->number = 1; + } + m->time = atol(qres[i]["time"].c_str()); + m->text = sstrdup(qres[i]["text"].c_str()); + + if (!qres[i]["flags"].empty()) + { + spacesepstream sep(SQLAssign(qres[i]["flags"])); + std::string buf; + while (sep.GetToken(buf)) + { + for (unsigned j = 0; MemoFlags[j].Flag != -1; ++j) + { + if (MemoFlags[j].Name == buf) + { + m->SetFlag(MemoFlags[j].Flag); + } + } + } + } + } + } + } + + query << "SELECT * FROM `anope_os_akills`"; + qres = StoreQuery(query); + + if (qres) + { + for (size_t i = 0; i < qres.size(); ++i) + { + Akill *ak = new Akill; + ak->user = sstrdup(qres[i]["user"].c_str()); + ak->host = sstrdup(qres[i]["host"].c_str()); + ak->by = sstrdup(qres[i]["xby"].c_str()); + ak->reason = sstrdup(qres[i]["reason"].c_str()); + ak->seton = atol(qres[i]["seton"].c_str()); + ak->expires = atol(qres[i]["expire"].c_str()); + slist_add(&akills, ak); + } + } + + query << "SELECT * FROM `anope_os_sxlines`"; + qres = StoreQuery(query); + + if (qres) + { + for (size_t i = 0; i < qres.size(); ++i) + { + SXLine *sx = new SXLine; + sx->mask = sstrdup(qres[i]["mask"].c_str()); + sx->by = sstrdup(qres[i]["xby"].c_str()); + sx->reason = sstrdup(qres[i]["reason"].c_str()); + sx->seton = atol(qres[i]["seton"].c_str()); + sx->expires = atol(qres[i]["expires"].c_str()); + if (qres[i]["type"] == "SGLINE") + slist_add(&sglines, sx); + else if (qres[i]["type"] == "SQLINE") + slist_add(&sqlines, sx); + else if (qres[i]["type"] == "SZLINE") + slist_add(&szlines, sx); + else + delete sx; + } + } } class DBMySQLRead : public DBMySQL diff --git a/src/modules/mysql/db_mysql_write.cpp b/src/modules/mysql/db_mysql_write.cpp index 746b46260..c66486f15 100644 --- a/src/modules/mysql/db_mysql_write.cpp +++ b/src/modules/mysql/db_mysql_write.cpp @@ -56,6 +56,24 @@ static std::string BuildFlagsList(NickCore *nc) return ret; } +static std::string BuildFlagsList(Memo *m) +{ + std::string ret; + + for (int i = 0; MemoFlags[i].Flag != -1; ++i) + { + if (m->HasFlag(MemoFlags[i].Flag)) + { + ret += " " + MemoFlags[i].Name; + } + } + + if (!ret.empty()) + ret.erase(ret.begin()); + + return ret; +} + static std::string MakeMLock(ChannelInfo *ci, bool status) { std::string ret; @@ -365,10 +383,13 @@ class DBMySQLWrite : public DBMySQL /* BotServ */ I_OnBotCreate, I_OnBotChange, I_OnBotDelete, I_OnBotAssign, I_OnBotUnAssign, + /* MemoServ */ + I_OnMemoSend, I_OnMemoDel, /* OperServ */ - I_OnOperServHelp + I_OnOperServHelp, I_OnAddAkill, I_OnDelAkill, I_OnExceptionAdd, I_OnExceptionDel, + I_OnAddSXLine, I_OnDelSXLine }; - ModuleManager::Attach(i, this, 27); + ModuleManager::Attach(i, this, 35); } void OnOperServHelp(User *u) @@ -378,6 +399,12 @@ class DBMySQLWrite : public DBMySQL EventReturn OnSaveDatabase() { + mysqlpp::Query query(Me->Con); + + query << "INSERT DELAYED INTO `anope_os_core` (maxusercnt, maxusertime, akills_count, sglines_count, sqlines_count, szlines_count) VALUES("; + query << maxusercnt << ", " << maxusertime << ", " << akills.count << ", " << sqlines.count << ", " << sglines.count << ", " << szlines.count << ")"; + ExecuteQuery(query); + for (int i = 0; i < 1024; ++i) { for (NickCore *nc = nclists[i]; nc; nc = nc->next) @@ -553,6 +580,8 @@ class DBMySQLWrite : public DBMySQL ExecuteQuery(query); query << "DELETE FROM `anope_ns_core` WHERE `display` = " << mysqlpp::quote << nc->display; ExecuteQuery(query); + query << "DELETE FROM `anope_ms_core` WHERE `receiver` = " << mysqlpp::quote << nc->display; + ExecuteQuery(query); } void OnNickForbidden(NickAlias *na) @@ -623,6 +652,8 @@ class DBMySQLWrite : public DBMySQL ExecuteQuery(query); query << "UPDATE `anope_cs_info` SET `successor` = " << mysqlpp::quote << newdisplay << " WHERE `successor` = " << mysqlpp::quote << nc->display; ExecuteQuery(query); + query << "UDATEE `anope_ms_info` SET `receiver` = " << mysqlpp::quote << newdisplay << " WHERE `receiver` = " << mysqlpp::quote << nc->display; + ExecuteQuery(query); } void OnNickSuspend(NickAlias *na) @@ -750,6 +781,105 @@ class DBMySQLWrite : public DBMySQL ExecuteQuery(query); return EVENT_CONTINUE; } + + void OnMemoSend(User *u, NickCore *nc, Memo *m) + { + mysqlpp::Query query(Me->Con); + query << "INSERT DELAYED INTO `anope_ms_info` (receiver, number, flags, time, sender, text, serv) VALUES("; + query << mysqlpp::quote << nc->display << ", " << m->number << ", '" << BuildFlagsList(m) << "', " << m->time << ", "; + query << mysqlpp::quote << u->nick << ", " << mysqlpp::quote << m->text << ", 'NICK')"; + ExecuteQuery(query); + } + + void OnMemoSend(User *u, ChannelInfo *ci, Memo *m) + { + mysqlpp::Query query(Me->Con); + query << "INSERT DELAYED INTO `anope_ms_info` (receiver, number, flags, time, sender, text, serv) VALUES("; + query << mysqlpp::quote << ci->name << ", " << m->number << ", '" << BuildFlagsList(m) << "', " << m->time << ", "; + query << mysqlpp::quote << u->nick << ", " << mysqlpp::quote << m->text << ", 'CHAN')"; + ExecuteQuery(query); + } + + void OnMemoDel(NickCore *nc, MemoInfo *mi, int number) + { + mysqlpp::Query query(Me->Con); + if (number) + query << "DELETE FROM `anope_ms_info` WHERE `receiver` = " << mysqlpp::quote << nc->display << " AND `number` = " << number; + else + query << "DELETE FROM `anope_ms_info` WHERE `receiver` = " << mysqlpp::quote << nc->display; + ExecuteQuery(query); + } + + void OnMemoDel(ChannelInfo *ci, MemoInfo *mi, int number) + { + mysqlpp::Query query(Me->Con); + if (number) + query << "DELETE FROM `anope_ms_info` WHERE `receiver` = " << mysqlpp::quote << ci->name << " AND `number` = " << number; + else + query << "DELETE FROM `anope_ms_info` WHERE `receiver` = " << mysqlpp::quote << ci->name; + ExecuteQuery(query); + } + + EventReturn OnAddAkill(User *u, Akill *ak) + { + mysqlpp::Query query(Me->Con); + query << "INSERT DELAYED INTO `anope_os_akills` (user, host, xby, reason, seton, expire) VALUES("; + query << mysqlpp::quote << ak->user << ", " << mysqlpp::quote << ak->host << ", " << mysqlpp::quote << ak->by; + query << ", " << mysqlpp::quote << ak->reason << ", " << ak->seton << ", " << ak->expires << ")"; + ExecuteQuery(query); + return EVENT_CONTINUE; + } + + void OnDelAkill(User *u, Akill *ak) + { + mysqlpp::Query query(Me->Con); + if (ak) + query << "DELETE FROM `anope_os_akills` WHERE `host` = " << mysqlpp::quote << ak->host; + else + query << "TRUNCATE TABLE `anope_os_akills`"; + ExecuteQuery(query); + } + + EventReturn OnExceptionAdd(User *u, Exception *ex) + { + mysqlpp::Query query(Me->Con); + query << "INSERT DELAYED INTO `anope_os_exceptions` (mask, limit, who, reason, time, expires) VALUES("; + query << mysqlpp::quote << ex->mask << ", " << ex->limit << ", " << mysqlpp::quote << ex->who << ", "; + query << mysqlpp::quote << ex->reason << ", " << ex->time << ", " << ex->expires << ")"; + ExecuteQuery(query); + return EVENT_CONTINUE; + } + + void OnExceptionDel(User *u, Exception *ex) + { + mysqlpp::Query query(Me->Con); + query << "DELETE FROM `anope_os_exceptions` WHERE `mask` = " << mysqlpp::quote << ex->mask; + ExecuteQuery(query); + } + + EventReturn OnAddSXLine(User *u, SXLine *sx, SXLineType Type) + { + mysqlpp::Query query(Me->Con); + query << "INSERT DELAYED INTO `anope_os_sxlines` (type, mask, xby, reason, seton, expire) VALUES('"; + query << (Type == SX_SGLINE ? "SGLINE" : (Type == SX_SQLINE ? "SQLINE" : "SZLINE")) << "', "; + query << mysqlpp::quote << sx->mask << ", " << mysqlpp::quote << sx->by << ", " << mysqlpp::quote << sx->reason; + query << ", " << sx->seton << ", " << sx->expires << ")"; + ExecuteQuery(query); + return EVENT_CONTINUE; + } + + void OnDelSXLine(User *u, SXLine *sx, SXLineType Type) + { + mysqlpp::Query query(Me->Con); + if (sx) + { + query << "DELETE FROM `anope_os_sxlines` WHERE `mask` = " << mysqlpp::quote << sx->mask << " AND `type` = '"; + query << (Type == SX_SGLINE ? "SGLINE" : (Type == SX_SQLINE ? "SQLINE" : "SZLINE")) << "'"; + } + else + query << "DELETE FROM `anope_os_sxlines` WHERE `type` = '" << (Type == SX_SGLINE ? "SGLINE" : (Type == SX_SQLINE ? "SQLINE" : "SZLINE")) << "'"; + ExecuteQuery(query); + } }; MODULE_INIT(DBMySQLWrite) |