diff options
Diffstat (limited to 'src/modules/mysql/db_mysql_write.cpp')
-rw-r--r-- | src/modules/mysql/db_mysql_write.cpp | 134 |
1 files changed, 132 insertions, 2 deletions
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) |