diff options
Diffstat (limited to 'modules/extra/mysql')
-rw-r--r-- | modules/extra/mysql/db_mysql.h | 212 | ||||
-rw-r--r-- | modules/extra/mysql/db_mysql_execute.cpp | 159 | ||||
-rw-r--r-- | modules/extra/mysql/db_mysql_read.cpp | 618 | ||||
-rw-r--r-- | modules/extra/mysql/db_mysql_write.cpp | 1040 |
4 files changed, 0 insertions, 2029 deletions
diff --git a/modules/extra/mysql/db_mysql.h b/modules/extra/mysql/db_mysql.h deleted file mode 100644 index 011c2647d..000000000 --- a/modules/extra/mysql/db_mysql.h +++ /dev/null @@ -1,212 +0,0 @@ -#ifndef DB_MYSQL_H -#define DB_MYSQL_H - -#include "module.h" - -struct NickAliasFlagInfo -{ - std::string Name; - NickNameFlag Flag; -}; - -NickAliasFlagInfo NickAliasFlags[] = { - {"FORBIDDEN", NS_FORBIDDEN}, - {"NOEXPIRE", NS_NO_EXPIRE}, - {"", static_cast<NickNameFlag>(-1)} -}; - -struct NickCoreFlagInfo -{ - std::string Name; - NickCoreFlag Flag; -}; - -NickCoreFlagInfo NickCoreFlags[] = { - {"KILLPROTECT", NI_KILLPROTECT}, - {"SECURE", NI_SECURE}, - {"MSG", NI_MSG}, - {"MEMO_HARDMAX", NI_MEMO_HARDMAX}, - {"MEMO_SIGNON", NI_MEMO_SIGNON}, - {"MEMO_RECEIVE", NI_MEMO_RECEIVE}, - {"PRIVATE", NI_PRIVATE}, - {"HIDE_EMAIL", NI_HIDE_EMAIL}, - {"HIDE_MASK", NI_HIDE_MASK}, - {"HIDE_QUIT", NI_HIDE_QUIT}, - {"KILL_QUICK", NI_KILL_QUICK}, - {"KILL_IMMED", NI_KILL_IMMED}, - {"MEMO_MAIL", NI_MEMO_MAIL}, - {"HIDE_STATUS", NI_HIDE_STATUS}, - {"SUSPENDED", NI_SUSPENDED}, - {"AUTOOP", NI_AUTOOP}, - {"FORBIDDEN", NI_FORBIDDEN}, - {"", static_cast<NickCoreFlag>(-1)} -}; - -struct BotFlagInfo -{ - std::string Name; - BotServFlag Flag; -}; - -BotFlagInfo BotFlags[] = { - {"DONTKICKOPS", BS_DONTKICKOPS}, - {"DONTKICKVOICES", BS_DONTKICKVOICES}, - {"FANTASY", BS_FANTASY}, - {"SYMBIOSIS", BS_SYMBIOSIS}, - {"GREET", BS_GREET}, - {"NOBOT", BS_NOBOT}, - {"KICK_BOLDS", BS_KICK_BOLDS}, - {"KICK_COLORS", BS_KICK_COLORS}, - {"KICK_REVERSES", BS_KICK_REVERSES}, - {"KICK_UNDERLINES", BS_KICK_UNDERLINES}, - {"KICK_BADWORDS", BS_KICK_BADWORDS}, - {"KICK_CAPS", BS_KICK_CAPS}, - {"KICK_FLOOD", BS_KICK_FLOOD}, - {"KICK_REPEAT", BS_KICK_REPEAT}, - {"KICK_ITALICS", BS_KICK_ITALICS}, - {"", static_cast<BotServFlag>(-1)} -}; - -struct ChannelFlagInfo -{ - std::string Name; - ChannelInfoFlag Flag; -}; - -ChannelFlagInfo ChannelFlags[] = { - {"KEEPTOPIC", CI_KEEPTOPIC}, - {"SECUREOPS", CI_SECUREOPS}, - {"PRIVATE", CI_PRIVATE}, - {"TOPICLOCK", CI_TOPICLOCK}, - {"RESTRICTED", CI_RESTRICTED}, - {"PEACE", CI_PEACE}, - {"SECURE", CI_SECURE}, - {"FORBIDDEN", CI_FORBIDDEN}, - {"NO_EXPIRE", CI_NO_EXPIRE}, - {"MEMO_HARDMAX", CI_MEMO_HARDMAX}, - {"OPNOTICE", CI_OPNOTICE}, - {"SECUREFOUNDER", CI_SECUREFOUNDER}, - {"SIGNKICK", CI_SIGNKICK}, - {"SIGNKICK_LEVEL", CI_SIGNKICK_LEVEL}, - {"XOP", CI_XOP}, - {"SUSPENDED", CI_SUSPENDED}, - {"PERSIST", CI_PERSIST}, - {"", static_cast<ChannelInfoFlag>(-1)} -}; - -struct BotServFlagInfo -{ - std::string Name; - BotFlag Flag; -}; - -BotServFlagInfo BotServFlags[] = { - {"PRIVATE", BI_PRIVATE}, - {"", 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> - -inline std::string SQLAssign(const mysqlpp::String &s) { return s.c_str(); } - -class DBMySQL; -static DBMySQL *me; - -bool ExecuteQuery(mysqlpp::Query &query) -{ - Alog(LOG_DEBUG) << "MySQL: " << query.str(); - - if (!query.execute()) - { - Alog() << "MySQL: error executing query: " << query.error(); - return false; - } - - return true; -} - -mysqlpp::StoreQueryResult StoreQuery(mysqlpp::Query &query) -{ - Alog(LOG_DEBUG) << "MySQL: " << query.str(); - - mysqlpp::StoreQueryResult result = query.store(); - if (!result) - Alog() << "MySQL: error executing query: " << query.error(); - return result; -} - -class DBMySQL : public Module -{ - private: - bool LoadConfig() - { - ConfigReader config; - - Database = config.ReadValue("mysql", "database", "anope", 0); - Server = config.ReadValue("mysql", "server", "127.0.0.1", 0); - SQLUser = config.ReadValue("mysql", "username", "anope", 0); - Password = config.ReadValue("mysql", "password", "", 0); - Port = config.ReadInteger("mysql", "port", "3306", 0, true); - Delay = config.ReadInteger("mysql", "updatedelay", "60", 0, true); - - return !Password.empty(); - } - - public: - mysqlpp::Connection *Con; - mysqlpp::NoExceptions *Ne; - - std::string Database; - std::string Server; - std::string SQLUser; - std::string Password; - unsigned int Port; - unsigned int Delay; - - DBMySQL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) - { - me = this; - - this->SetAuthor("Anope"); - this->SetType(DATABASE); - - if (!LoadConfig()) - throw ModuleException(Anope::string("Couldn't load config")); - - Con = new mysqlpp::Connection(false); - Ne = new mysqlpp::NoExceptions(Con); - if (!Con->connect(Database.c_str(), Server.c_str(), SQLUser.c_str(), Password.c_str(), Port)) - { - std::string Error = "MySQL: Error connecting to SQL server: "; - Error += Con->error(); - delete Con; - throw ModuleException(Anope::string(Error)); - } - - mysqlpp::Query query(Con); - query << "SET NAMES 'utf8'"; - ExecuteQuery(query); - } - - virtual ~DBMySQL() - { - delete Ne; - delete Con; - } -}; - -#endif // DB_MYSQL_H diff --git a/modules/extra/mysql/db_mysql_execute.cpp b/modules/extra/mysql/db_mysql_execute.cpp deleted file mode 100644 index 079e88147..000000000 --- a/modules/extra/mysql/db_mysql_execute.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/* RequiredLibraries: mysqlpp */ - -#include "db_mysql.h" - -class FakeNickCore : public NickCore -{ - public: - FakeNickCore() : NickCore("-SQLUser") - { - NickCoreList.erase(this->display); - } - - ~FakeNickCore() - { - NickCoreList[this->display] = this; - Users.clear(); - } - - bool IsServicesOper() const { return true; } - bool HasCommand(const std::string &) const { return true; } - bool HasPriv(const std::string &) const { return true; } -} SQLCore; - -class FakeUser : public User -{ - public: - FakeUser() : User("-SQLUser", "") - { - this->SetIdent("SQL"); - this->host = sstrdup(Config.ServerName); - this->realname = sstrdup("Fake SQL User"); - this->hostip = sstrdup("255.255.255.255"); - this->vhost = NULL; - this->server = Me; - - UserListByNick.erase("-SQLUser"); - --usercnt; - } - - ~FakeUser() - { - UserListByNick["-SQLUser"] = this; - ++usercnt; - - nc = NULL; - } - - void SetNewNick(const std::string &newnick) { this->nick = newnick; } - - void SendMessage(const std::string &, const char *, ...) { } - void SendMessage(const std::string &, const std::string &) { } - - NickCore *Account() const { return nc; } - const bool IsIdentified(bool) const { return nc ? true : false; } - const bool IsRecognized(bool) const { return true; } -} SQLUser; - -class SQLTimer : public Timer -{ - public: - SQLTimer() : Timer(me->Delay, time(NULL), true) - { - mysqlpp::Query query(me->Con); - query << "TRUNCATE TABLE `anope_commands`"; - ExecuteQuery(query); - } - - void Tick(time_t) - { - mysqlpp::Query query(me->Con); - mysqlpp::StoreQueryResult qres; - - query << "SELECT * FROM `anope_commands`"; - qres = StoreQuery(query); - - if (qres && qres.num_rows()) - { - for (size_t i = 0, end = qres.num_rows(); i < end; ++i) - { - User *u; - NickAlias *na = NULL; - bool logout = false; - - /* If they want -SQLUser to execute the command, use it */ - if (qres[i]["nick"] == "-SQLUser") - { - u = &SQLUser; - u->SetNewNick("-SQLUser"); - u->Login(&SQLCore); - logout = true; - } - else - { - /* See if the nick they want to execute the command is registered */ - na = findnick(SQLAssign(qres[i]["nick"])); - if (na) - { - /* If it is and someone is online using that nick, use them */ - if (!na->nc->Users.empty()) - u = na->nc->Users.front(); - /* Make a fake nick and use that logged in as the nick we want to use */ - else - { - u = &SQLUser; - u->SetNewNick(SQLAssign(qres[i]["nick"])); - u->Login(na->nc); - logout = true; - } - } - else - { - /* Check if someone is online using the nick now */ - u = finduser(SQLAssign(qres[i]["nick"])); - /* If they arent make a fake user, and use them */ - if (!u) - { - u = &SQLUser; - u->SetNewNick(SQLAssign(qres[i]["nick"])); - u->Logout(); - logout = true; - } - } - } - - BotInfo *bi = findbot(SQLAssign(qres[i]["service"])); - if (!bi) - { - Alog() << "Warning: SQL command for unknown service " << qres[i]["service"]; - continue; - } - - mod_run_cmd(bi, u, qres[i]["command"].c_str()); - - if (logout) - u->Logout(); - } - - query << "TRUNCATE TABLE `anope_commands`"; - ExecuteQuery(query); - } - } -}; - -class DBMySQLExecute : public DBMySQL -{ - SQLTimer *_SQLTimer; - public: - DBMySQLExecute(const Anope::string &modname, const Anope::string &creator) : DBMySQL(modname, creator) - { - _SQLTimer = new SQLTimer(); - } - - ~DBMySQLExecute() - { - delete _SQLTimer; - } -}; - -MODULE_INIT(DBMySQLExecute) diff --git a/modules/extra/mysql/db_mysql_read.cpp b/modules/extra/mysql/db_mysql_read.cpp deleted file mode 100644 index ff608b700..000000000 --- a/modules/extra/mysql/db_mysql_read.cpp +++ /dev/null @@ -1,618 +0,0 @@ -/* RequiredLibraries: mysqlpp */ - -#include "db_mysql.h" - -static std::vector<std::string> MakeVector(std::string buf) -{ - std::string s; - spacesepstream sep(buf); - std::vector<std::string> params; - - while (sep.GetToken(s)) - { - if (s[0] == ':') - { - s.erase(s.begin()); - if (!s.empty() && !sep.StreamEnd()) - params.push_back(s + " " + sep.GetRemaining()); - else if (!s.empty()) - params.push_back(s); - } - else - params.push_back(s); - } - - return params; -} - -static void LoadDatabase() -{ - mysqlpp::Query query(me->Con); - mysqlpp::StoreQueryResult qres; - - query << "SELECT * FROM `anope_ns_core`"; - qres = StoreQuery(query); - - if (qres) - for (size_t i = 0, end = qres.num_rows(); i < end; ++i) - { - NickCore *nc = new NickCore(SQLAssign(qres[i]["display"])); - nc->pass = SQLAssign(qres[i]["pass"]); - if (qres[i]["email"].size()) - nc->email = sstrdup(qres[i]["email"].c_str()); - if (qres[i]["greet"].size()) - nc->greet = sstrdup(qres[i]["greet"].c_str()); - if (qres[i]["icq"].size()) - nc->icq = atol(qres[i]["icq"].c_str()); - if (qres[i]["url"].size()) - nc->url = sstrdup(qres[i]["url"].c_str()); - - spacesepstream sep(SQLAssign(qres[i]["flags"])); - std::string buf; - while (sep.GetToken(buf)) - for (int j = 0; NickCoreFlags[j].Flag != -1; ++j) - if (NickCoreFlags[j].Name == buf) - nc->SetFlag(NickCoreFlags[j].Flag); - - nc->language = atoi(qres[i]["language"].c_str()); - nc->channelcount = atoi(qres[i]["channelcount"].c_str()); - nc->memos.memomax = atoi(qres[i]["memomax"].c_str()); - } - - query << "SELECT * FROM `anope_ns_access`"; - qres = StoreQuery(query); - - if (qres) - for (size_t i = 0, end = qres.num_rows(); i < end; ++i) - { - NickCore *nc = findcore(qres[i]["display"].c_str()); - if (!nc) - { - Alog() << "MySQL: Got NickCore access entry for nonexistant core " << qres[i]["display"]; - continue; - } - - nc->AddAccess(SQLAssign(qres[i]["access"])); - } - - query << "SELECT * FROM `anope_ns_core_metadata`"; - qres = StoreQuery(query); - - if (qres) - for (size_t i = 0, end = qres.num_rows(); i < end; ++i) - { - NickCore *nc = findcore(qres[i]["display"].c_str()); - if (!nc) - { - Alog() << "MySQL: Got NickCore access entry for nonexistant core " << qres[i]["display"]; - continue; - } - EventReturn MOD_RESULT; - std::vector<std::string> Params = MakeVector(SQLAssign(qres[i]["value"])); - FOREACH_RESULT(I_OnDatabaseReadMetadata, OnDatabaseReadMetadata(nc, SQLAssign(qres[i]["name"]), Params)); - } - - query << "SELECT * FROM `anope_ns_alias`"; - qres = StoreQuery(query); - - if (qres) - for (size_t i = 0, end = qres.num_rows(); i < end; ++i) - { - NickCore *nc = findcore(qres[i]["display"].c_str()); - if (!nc) - { - Alog() << "MySQL: Got NickAlias for nick " << qres[i]["nick"] << " with nonexistant core " << qres[i]["display"]; - continue; - } - - NickAlias *na = new NickAlias(SQLAssign(qres[i]["nick"]), nc); - na->last_quit = sstrdup(qres[i]["last_quit"].c_str()); - na->last_realname = sstrdup(qres[i]["last_realname"].c_str()); - na->last_usermask = sstrdup(qres[i]["last_usermask"].c_str()); - na->time_registered = atol(qres[i]["time_registered"].c_str()); - na->last_seen = atol(qres[i]["last_seen"].c_str()); - - spacesepstream sep(SQLAssign(qres[i]["flags"])); - std::string buf; - while (sep.GetToken(buf)) - for (int j = 0; NickAliasFlags[j].Flag != -1; ++j) - if (NickAliasFlags[j].Name == buf) - na->SetFlag(NickAliasFlags[j].Flag); - } - - query << "SELECT * FROM `anope_ns_alias_metadata`"; - qres = StoreQuery(query); - - if (qres) - for (size_t i = 0, end = qres.num_rows(); i < end; ++i) - { - NickAlias *na = findnick(SQLAssign(qres[i]["nick"])); - if (!na) - { - Alog() << "MySQL: Got metadata for nonexistant nick " << qres[i]["nick"]; - continue; - } - EventReturn MOD_RESULT; - std::vector<std::string> Params = MakeVector(SQLAssign(qres[i]["value"])); - FOREACH_RESULT(I_OnDatabaseReadMetadata, OnDatabaseReadMetadata(na, SQLAssign(qres[i]["name"]), Params)); - } - - query << "SELECT * FROM `anope_bs_core`"; - qres = StoreQuery(query); - - if (qres) - for (size_t i = 0, end = qres.num_rows(); i < end; ++i) - { - BotInfo *bi = findbot(SQLAssign(qres[i]["nick"])); - if (!bi) - bi = new BotInfo(SQLAssign(qres[i]["nick"])); - bi->user = SQLAssign(qres[i]["user"]); - bi->host = SQLAssign(qres[i]["host"]); - bi->real = SQLAssign(qres[i]["rname"]); - - if (qres[i]["flags"].size()) - { - spacesepstream sep(SQLAssign(qres[i]["flags"])); - std::string buf; - while (sep.GetToken(buf)) - for (unsigned j = 0; BotServFlags[j].Flag != -1; ++j) - if (buf == BotServFlags[j].Name) - { - bi->SetFlag(BotServFlags[j].Flag); - break; - } - } - bi->created = atol(qres[i]["created"]); - bi->chancount = atol(qres[i]["chancount"]); - } - - query << "SELECT * FROM `anope_bs_info_metadata`"; - qres = StoreQuery(query); - - if (qres) - for (size_t i = 0, end = qres.num_rows(); i < end; ++i) - { - BotInfo *bi = findbot(SQLAssign(qres[i]["botname"])); - if (!bi) - { - Alog() << "MySQL: BotInfo metadata for nonexistant bot " << qres[i]["botname"]; - continue; - } - - EventReturn MOD_RESULT; - std::vector<std::string> Params = MakeVector(SQLAssign(qres[i]["value"])); - FOREACH_RESULT(I_OnDatabaseReadMetadata, OnDatabaseReadMetadata(bi, SQLAssign(qres[i]["name"]), Params)); - } - - query << "SELECT * FROM `anope_cs_info`"; - qres = StoreQuery(query); - - if (qres) - for (size_t i = 0, end = qres.num_rows(); i < end; ++i) - { - NickCore *nc; - if (qres[i]["founder"].size()) - { - nc = findcore(qres[i]["founder"].c_str()); - if (!nc) - { - Alog() << "MySQL: Channel " << qres[i]["name"] << " with nonexistant founder " << qres[i]["founder"]; - continue; - } - } - - ChannelInfo *ci = new ChannelInfo(SQLAssign(qres[i]["name"])); - ci->founder = nc; - if (qres[i]["successor"].size()) - ci->successor = findcore(qres[i]["successor"].c_str()); - ci->desc = sstrdup(qres[i]["descr"].c_str()); - if (qres[i]["url"].size()) - ci->url = sstrdup(qres[i]["url"].c_str()); - if (qres[i]["email"].size()) - ci->email = sstrdup(qres[i]["email"].c_str()); - ci->time_registered = atol(qres[i]["time_registered"]); - ci->last_used = atol(qres[i]["last_used"]); - if (qres[i]["last_topic"].size()) - ci->last_topic = sstrdup(qres[i]["last_topic"].c_str()); - if (qres[i]["last_topic_setter"].size()) - ci->last_topic_setter = SQLAssign(qres[i]["last_topic_setter"]); - if (qres[i]["last_topic_time"].size()) - ci->last_topic_time = atol(qres[i]["last_topic_time"].c_str()); - if (qres[i]["flags"].size()) - { - std::string buf; - spacesepstream sep(SQLAssign(qres[i]["flags"])); - while (sep.GetToken(buf)) - for (int j = 0; ChannelFlags[j].Flag != -1; ++j) - if (buf == ChannelFlags[j].Name) - { - ci->SetFlag(ChannelFlags[j].Flag); - break; - } - } - if (qres[i]["forbidby"].size()) - ci->forbidby = sstrdup(qres[i]["forbidby"].c_str()); - if (qres[i]["forbidreason"].size()) - ci->forbidreason = sstrdup(qres[i]["forbidreason"].c_str()); - ci->bantype = atoi(qres[i]["bantype"].c_str()); - if (qres[i]["mlock_on"].size()) - { - std::vector<Anope::string> modes; - std::string buf; - - spacesepstream sep(SQLAssign(qres[i]["mlock_on"])); - while (sep.GetToken(buf)) - modes.push_back(Anope::string(buf)); - - ci->Extend("db_mlock_modes_on", new ExtensibleItemRegular<std::vector<Anope::string> >(modes)); - } - if (qres[i]["mlock_off"].size()) - { - std::vector<Anope::string> modes; - std::string buf; - - spacesepstream sep(SQLAssign(qres[i]["mlock_off"])); - while (sep.GetToken(buf)) - modes.push_back(Anope::string(buf)); - - ci->Extend("db_mlock_modes_off", new ExtensibleItemRegular<std::vector<Anope::string> >(modes)); - } - if (qres[i]["mlock_params"].size()) - { - std::vector<std::pair<Anope::string, Anope::string> > mlp; - std::string buf, buf2; - - spacesepstream sep(SQLAssign(qres[i]["mlock_params"])); - - while (sep.GetToken(buf) && sep.GetToken(buf2)) - mlp.push_back(std::make_pair(Anope::string(buf), Anope::string(buf2))); - - ci->Extend("db_mlp", new ExtensibleItemRegular<std::vector<std::pair<Anope::string, Anope::string> > >(mlp)); - } - if (qres[i]["entry_message"].size()) - ci->entry_message = sstrdup(qres[i]["entry_message"].c_str()); - ci->memos.memomax = atoi(qres[i]["memomax"].c_str()); - if (qres[i]["botnick"].size()) - ci->bi = findbot(SQLAssign(qres[i]["botnick"])); - if (ci->bi) - { - if (qres[i]["botflags"].size()) - { - std::string buf; - spacesepstream sep(SQLAssign(qres[i]["botflags"])); - while (sep.GetToken(buf)) - for (int j = 0; BotFlags[j].Flag != -1; ++j) - if (buf == BotFlags[j].Name) - { - ci->botflags.SetFlag(BotFlags[j].Flag); - break; - } - } - } - if (qres[i]["capsmin"].size()) - ci->capsmin = atoi(qres[i]["capsmin"].c_str()); - if (qres[i]["capspercent"].size()) - ci->capspercent = atoi(qres[i]["capspercent"].c_str()); - if (qres[i]["floodlines"].size()) - ci->floodlines = atoi(qres[i]["floodlines"].c_str()); - if (qres[i]["floodsecs"].size()) - ci->floodsecs = atoi(qres[i]["floodsecs"].c_str()); - if (qres[i]["repeattimes"].size()) - ci->repeattimes = atoi(qres[i]["repeattimes"].c_str()); - } - - query << "SELECT * FROM `anope_cs_ttb"; - qres = StoreQuery(query); - - if (qres) - for (size_t i = 0, end = qres.num_rows(); i < end; ++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, end = qres.num_rows(); i < end; ++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); - - if (qres) - for (size_t i = 0, end = qres.num_rows(); i < end; ++i) - { - ChannelInfo *ci = cs_findchan(SQLAssign(qres[i]["channel"])); - if (!ci) - { - Alog() << "MySQL: Channel access entry for nonexistant channel " << qres[i]["channel"]; - continue; - } - NickCore *nc = findcore(qres[i]["display"]); - if (!nc) - { - Alog() << "MySQL: Channel access entry for " << ci->name << " with nonexistant nick " << qres[i]["display"]; - continue; - } - - ci->AddAccess(nc, atoi(qres[i]["level"]), SQLAssign(qres[i]["creator"]), atol(qres[i]["last_seen"])); - } - - query << "SELECT * FROM `anope_cs_akick`"; - qres = StoreQuery(query); - - if (qres) - for (size_t i = 0, end = qres.num_rows(); i < end; ++i) - { - ChannelInfo *ci = cs_findchan(SQLAssign(qres[i]["channel"])); - if (!ci) - { - Alog() << "MySQL: Channel akick entry for nonexistant channel " << qres[i]["channel"]; - continue; - } - NickCore *nc = NULL; - spacesepstream sep(qres[i]["flags"]); - std::string flag, mask; - bool stuck = false; - while (sep.GetToken(flag)) - if (flag == "ISNICK") - nc = findcore(qres[i]["mask"]); - else if (flag == "STUCK") - stuck = true; - AutoKick *ak; - if (nc) - ak = ci->AddAkick(SQLAssign(qres[i]["creator"]), nc, SQLAssign(qres[i]["reason"]), atol(qres[i]["created"].c_str()), atol(qres[i]["last_used"].c_str())); - else - ak = ci->AddAkick(SQLAssign(qres[i]["creator"]), SQLAssign(qres[i]["mask"]), SQLAssign(qres[i]["reason"]), atol(qres[i]["created"].c_str()), atol(qres[i]["last_used"].c_str())); - if (stuck) - ak->SetFlag(AK_STUCK); - if (nc) - ak->SetFlag(AK_ISNICK); - } - - query << "SELECT * FROM `anope_cs_levels`"; - qres = StoreQuery(query); - - if (qres) - for (size_t i = 0, end = qres.num_rows(); i < end; ++i) - { - ChannelInfo *ci = cs_findchan(SQLAssign(qres[i]["channel"])); - if (!ci) - { - Alog() << "MySQL: Channel level entry for nonexistant channel " << qres[i]["channel"]; - continue; - } - ci->levels[atoi(qres[i]["position"])] = atoi(qres[i]["level"]); - } - - query << "SELECT * FROM `anope_cs_info_metadata`"; - qres = StoreQuery(query); - - if (qres) - for (size_t i = 0, end = qres.num_rows(); i < end; ++i) - { - ChannelInfo *ci = cs_findchan(SQLAssign(qres[i]["channel"])); - if (!ci) - { - Alog() << "MySQL: Channel metadata for nonexistant channel " << qres[i]["channel"]; - continue; - } - - EventReturn MOD_RESULT; - std::vector<std::string> Params = MakeVector(SQLAssign(qres[i]["value"])); - FOREACH_RESULT(I_OnDatabaseReadMetadata, OnDatabaseReadMetadata(ci, SQLAssign(qres[i]["name"]), Params)); - } - - query << "SELECT * FROM `anope_ns_request`"; - qres = StoreQuery(query); - - if (qres) - for (size_t i = 0, end = qres.num_rows(); i < end; ++i) - { - NickRequest *nr = new NickRequest(qres[i]["nick"].c_str()); - nr->passcode = SQLAssign(qres[i]["passcode"]); - nr->password = SQLAssign(qres[i]["password"]); - nr->email = sstrdup(qres[i]["email"].c_str()); - nr->requested = atol(qres[i]["requested"].c_str()); - } - - EventReturn MOD_RESULT; - query << "SELECT * FROM `anope_extra`"; - qres = StoreQuery(query); - - if (qres) - for (size_t i = 0, end = qres.num_rows(); i < end; ++i) - { - std::vector<std::string> params = MakeVector(SQLAssign(qres[i]["data"])); - FOREACH_RESULT(I_OnDatabaseRead, OnDatabaseRead(params)); - } - - query << "SELECT * FROM `anope_ns_core_metadata`"; - qres = StoreQuery(query); - - if (qres) - for (size_t i = 0, end = qres.num_rows(); i < end; ++i) - { - NickCore *nc = findcore(qres[i]["nick"].c_str()); - if (nc) - { - std::vector<std::string> params = MakeVector(SQLAssign(qres[i]["value"])); - FOREACH_RESULT(I_OnDatabaseReadMetadata, OnDatabaseReadMetadata(nc, SQLAssign(qres[i]["name"]), params)); - } - } - - query << "SELECT * FROM `anope_ns_alias_metadata`"; - qres = StoreQuery(query); - - if (qres) - for (size_t i = 0, end = qres.num_rows(); i < end; ++i) - { - NickAlias *na = findnick(SQLAssign(qres[i]["nick"])); - if (na) - { - std::vector<std::string> params = MakeVector(SQLAssign(qres[i]["value"])); - FOREACH_RESULT(I_OnDatabaseReadMetadata, OnDatabaseReadMetadata(na, SQLAssign(qres[i]["name"]), params)); - } - } - - query << "SELECT * FROM `anope_cs_info_metadata`"; - qres = StoreQuery(query); - - if (qres) - for (size_t i = 0, end = qres.num_rows(); i < end; ++i) - { - ChannelInfo *ci = cs_findchan(SQLAssign(qres[i]["channel"])); - if (ci) - { - std::vector<std::string> params = MakeVector(SQLAssign(qres[i]["value"])); - FOREACH_RESULT(I_OnDatabaseReadMetadata, OnDatabaseReadMetadata(ci, SQLAssign(qres[i]["name"]), params)); - } - } - - query << "SELECT * FROM `anope_ms_info`"; - qres = StoreQuery(query); - - if (qres) - for (size_t i = 0, end = qres.num_rows(); i < end; ++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"].size()) - { - 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 && SGLine) - for (size_t i = 0, end = qres.num_rows(); i < end; ++i) - { - ci::string user = qres[i]["user"].c_str(); - ci::string host = qres[i]["host"].c_str(); - ci::string by = qres[i]["xby"].c_str(); - std::string reason = SQLAssign(qres[i]["reason"]); - time_t seton = atol(qres[i]["seton"].c_str()); - time_t expires = atol(qres[i]["expire"].c_str()); - - XLine *x = SGLine->Add(NULL, NULL, user + "@" + host, expires, reason); - if (x) - { - x->By = by; - x->Created = seton; - } - } - - query << "SELECT * FROM `anope_os_xlines`"; - qres = StoreQuery(query); - - if (qres) - for (size_t i = 0, end = qres.num_rows(); i < end; ++i) - { - ci::string mask = qres[i]["mask"].c_str(); - ci::string by = qres[i]["xby"].c_str(); - std::string reason = SQLAssign(qres[i]["reason"]); - time_t seton = atol(qres[i]["seton"].c_str()); - time_t expires = atol(qres[i]["expires"].c_str()); - - XLine *x = NULL; - if (qres[i]["type"] == "SNLINE" && SNLine) - x = SNLine->Add(NULL, NULL, mask, expires, reason); - else if (qres[i]["type"] == "SQLINE" && SQLine) - x = SQLine->Add(NULL, NULL, mask, expires, reason); - else if (qres[i]["type"] == "SZLINE" && SZLine) - x = SZLine->Add(NULL, NULL,mask, expires, reason); - if (x) - { - x->By = by; - x->Created = seton; - } - } -} - -class DBMySQLRead : public DBMySQL -{ - public: - DBMySQLRead(const Anope::string &modname, const Anope::string &creator) : DBMySQL(modname, creator) - { - Implementation i[] = { I_OnLoadDatabase }; - ModuleManager::Attach(i, this, 1); - } - - ~DBMySQLRead() - { - } - - EventReturn OnLoadDatabase() - { - LoadDatabase(); - - /* No need to ever reload this again, although this should never be triggered again */ - ModuleManager::Detach(I_OnLoadDatabase, this); - - return EVENT_STOP; - } -}; - -MODULE_INIT(DBMySQLRead) diff --git a/modules/extra/mysql/db_mysql_write.cpp b/modules/extra/mysql/db_mysql_write.cpp deleted file mode 100644 index 5d2ef2a78..000000000 --- a/modules/extra/mysql/db_mysql_write.cpp +++ /dev/null @@ -1,1040 +0,0 @@ -/* RequiredLibraries: mysqlpp */ - -#include "db_mysql.h" - -static std::string BuildFlagsList(ChannelInfo *ci) -{ - std::string ret; - - for (int i = 0; ChannelFlags[i].Flag != -1; ++i) - if (ci->HasFlag(ChannelFlags[i].Flag)) - ret += " " + ChannelFlags[i].Name; - - if (!ret.empty()) - ret.erase(ret.begin()); - - return ret; -} - -static std::string BuildFlagsList(NickAlias *na) -{ - std::string ret; - - for (int i = 0; NickAliasFlags[i].Flag != -1; ++i) - if (na->HasFlag(NickAliasFlags[i].Flag)) - ret += " " + NickAliasFlags[i].Name; - - if (!ret.empty()) - ret.erase(ret.begin()); - - return ret; -} - -static std::string BuildFlagsList(NickCore *nc) -{ - std::string ret; - - for (int i = 0; NickCoreFlags[i].Flag != -1; ++i) - if (nc->HasFlag(NickCoreFlags[i].Flag)) - ret += " " + NickCoreFlags[i].Name; - - if (!ret.empty()) - ret.erase(ret.begin()); - - 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; - - for (std::list<Mode *>::iterator it = ModeManager::Modes.begin(), it_end = ModeManager::Modes.end(); it != it_end; ++it) - { - if ((*it)->Class == MC_CHANNEL) - { - ChannelMode *cm = debug_cast<ChannelMode *>(*it); - - if (ci->HasMLock(cm->Name, status)) - ret += " " + cm->NameAsString; - } - } - - if (!ret.empty()) - ret.erase(ret.begin()); - - return ret; -} - -static inline std::string GetMLockOn(ChannelInfo *ci) -{ - return MakeMLock(ci, true); -} - -static inline std::string GetMLockOff(ChannelInfo *ci) -{ - return MakeMLock(ci, false); -} - -static std::string GetMLockParams(ChannelInfo *ci) -{ - std::string ret; - - for (std::list<Mode *>::iterator it = ModeManager::Modes.begin(), it_end = ModeManager::Modes.end(); it != it_end; ++it) - { - if ((*it)->Class == MC_CHANNEL) - { - ChannelMode *cm = debug_cast<ChannelMode *>(*it); - - std::string param; - if (ci->GetParam(cm->Name, param)) - ret += " " + cm->NameAsString + " " + param; - } - } - - if (!ret.empty()) - ret.erase(ret.begin()); - - return ret; -} - -static std::string GetBotFlags(Flags<BotServFlag>& Flags) -{ - std::string buf; - - for (int i = 0; BotFlags[i].Flag != -1; ++i) - if (Flags.HasFlag(BotFlags[i].Flag)) - buf += " " + BotFlags[i].Name; - - if (!buf.empty()) - buf.erase(buf.begin()); - - return buf; -} - -static std::string GetBotServFlags(BotInfo *bi) -{ - std::string buf; - - for (int i = 0; BotServFlags[i].Flag != -1; ++i) - if (bi->HasFlag(BotServFlags[i].Flag)) - buf += " " + BotServFlags[i].Name; - - if (!buf.empty()) - buf.erase(buf.begin());; - - return buf; -} - -static NickAlias *CurNick = NULL; -static NickCore *CurCore = NULL; -static ChannelInfo *CurChannel = NULL; -static BotInfo *CurBot = NULL; - -void Write(const std::string &data) -{ - mysqlpp::Query query(me->Con); - query << "INSERT DELAYED INTO `anope_extra` (data) VALUES(" << mysqlpp::quote << data << ")"; - ExecuteQuery(query); -} - -void WriteMetadata(const std::string &key, const std::string &data) -{ - mysqlpp::Query query(me->Con); - query << "INSERT DELAYED INTO `anope_metadata` (name, value) VALUES(" << mysqlpp::quote << key << ", " << mysqlpp::quote << data << ")"; - ExecuteQuery(query); -} - -void WriteNickMetadata(const std::string &key, const std::string &data) -{ - if (!CurNick) - throw CoreException(Anope::string("WriteNickMetadata without a nick to write")); - - mysqlpp::Query query(me->Con); - query << "INSERT DELAYED INTO `anope_ns_alias_metadata` (nick, name, value) VALUES(" << mysqlpp::quote << CurNick->nick << ", " << mysqlpp::quote << key << ", " << mysqlpp::quote << data << ")"; - ExecuteQuery(query); -} - -void WriteCoreMetadata(const std::string &key, const std::string &data) -{ - if (!CurCore) - throw CoreException(Anope::string("WritCoreMetadata without a core to write")); - - mysqlpp::Query query(me->Con); - query << "INSERT DELAYED INTO `anope_ns_core_metadata` (nick, name, value) VALUES(" << mysqlpp::quote << CurCore->display << ", " << mysqlpp::quote << key << ", " << mysqlpp::quote << data << ")"; - ExecuteQuery(query); -} - -void WriteChannelMetadata(const std::string &key, const std::string &data) -{ - if (!CurChannel) - throw CoreException(Anope::string("WriteChannelMetadata without a channel to write")); - - mysqlpp::Query query(me->Con); - query << "INSERT DELAYED INTO `anope_cs_info_metadata` (channel, name, value) VALUES(" << mysqlpp::quote << CurChannel->name << ", " << mysqlpp::quote << key << ", " << mysqlpp::quote << data << ")"; - ExecuteQuery(query); -} - -void WriteBotMetadata(const std::string &key, const std::string &data) -{ - if (!CurBot) - throw CoreException(Anope::string("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() -{ - mysqlpp::Query query(me->Con); - - query << "TRUNCATE TABLE `anope_ns_alias`"; - ExecuteQuery(query); - - for (nickalias_map::const_iterator it = NickAliasList.begin(), it_end = NickAliasList.end(); it != it_end; ++it) - me->OnNickRegister(it->second); - - query << "TRUNCATE TABLE `anope_ns_core`"; - ExecuteQuery(query); - query << "TRUNCATE TABLE `anope_ms_info`"; - ExecuteQuery(query); - - for (nickcore_map::const_iterator nit = NickCoreList.begin(), nit_end = NickCoreList.end(); nit != nit_end; ++nit) - { - NickCore *nc = nit->second; - - for (std::vector<std::string>::iterator it = nc->access.begin(), it_end = nc->access.end(); it != it_end; ++it) - { - query << "INSERT DELAYED INTO `anope_ns_access` (display, access) VALUES(" << mysqlpp::quote << nc->display << ", " << mysqlpp::quote << *it << ")"; - ExecuteQuery(query); - } - - for (unsigned j = 0, end = nc->memos.memos.size(); j < end; ++j) - { - Memo *m = nc->memos.memos[j]; - - me->OnMemoSend(NULL, nc, m); - } - } - - - query << "TRUNCATE TABLE `anope_bs_core`"; - ExecuteQuery(query); - - for (botinfo_map::const_iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end; ++it) - me->OnBotCreate(it->second); - - query << "TRUNCATE TABLE `anope_cs_info`"; - ExecuteQuery(query); - query << "TRUNCATE TABLE `anope_bs_badwords`"; - ExecuteQuery(query); - query << "TRUNCATE TABLE `anope_cs_access`"; - ExecuteQuery(query); - query << "TRUNCATE TABLE `anope_cs_akick`"; - ExecuteQuery(query); - query << "TRUNCATE TABLE `anope_cs_levels`"; - ExecuteQuery(query); - - for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end; ++it) - { - ChannelInfo *ci = it->second; - - me->OnChanRegistered(ci); - - for (unsigned j = 0, end = ci->GetBadWordCount(); j < end; ++j) - { - BadWord *bw = ci->GetBadWord(j); - - me->OnBadWordAdd(ci, bw); - } - - for (unsigned j = 0, end = ci->GetAccessCount(); j < end; ++j) - { - ChanAccess *access = ci->GetAccess(j); - - query << "INSERT DELAYED INTO `anope_cs_access` (level, display, channel, last_seen, creator) VALUES('" << access->level << "', " << mysqlpp::quote << access->nc->display << ", " << mysqlpp::quote << ci->name << ", " << access->last_seen << ", " << mysqlpp::quote << access->creator << ") ON DUPLICATE KEY UPDATE level=VALUES(level), last_seen=VALUES(last_seen), creator=VALUES(creator)"; - ExecuteQuery(query); - } - - for (unsigned j = 0, end = ci->GetAkickCount(); j < end; ++j) - { - AutoKick *ak = ci->GetAkick(j); - - me->OnAkickAdd(NULL, ci, ak); - } - - for (int k = 0; k < CA_SIZE; ++k) - { - query << "INSERT DELAYED INTO `anope_cs_levels` (channel, position, level) VALUES(" << mysqlpp::quote << ci->name << ", '" << k << "', '" << ci->levels[k] << "') ON DUPLICATE KEY UPDATE position=VALUES(position), level=VALUES(level)"; - ExecuteQuery(query); - } - - for (unsigned j = 0, end = ci->memos.memos.size(); j < end; ++j) - { - Memo *m = ci->memos.memos[j]; - - me->OnMemoSend(NULL, ci, m); - } - } - - query << "TRUNCATE TABLE `anope_ns_request`"; - ExecuteQuery(query); - - for (nickrequest_map::const_iterator it = NickRequestList.begin(), it_end = NickRequestList.end(); it != it_end; ++it) - me->OnMakeNickRequest(it->second); - - if (SGLine) - for (unsigned i = 0, end = SGLine->GetCount(); i < end; ++i) - me->OnAddAkill(NULL, SGLine->GetEntry(i)); - - if (SZLine) - for (unsigned i = 0, end = SZLine->GetCount(); i < end; ++i) - me->OnAddXLine(NULL, SZLine->GetEntry(i), X_SZLINE); - - if (SQLine) - for (unsigned i = 0, end = SQLine->GetCount(); i < end; ++i) - me->OnAddXLine(NULL, SQLine->GetEntry(i), X_SQLINE); - - if (SNLine) - for (unsigned i = 0, end = SNLine->GetCount(); i < end; ++i) - me->OnAddXLine(NULL, SNLine->GetEntry(i), X_SNLINE); - - for (int i = 0; i < nexceptions; ++i) - { - Exception *ex = &exceptions[i]; - - me->OnExceptionAdd(NULL, ex); - } -} - -class CommandSyncSQL : public Command -{ - public: - CommandSyncSQL(const ci::string &cname) : Command(cname, 0, 0, "operserv/sqlsync") - { - } - - CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) - { - notice_lang(Config.s_OperServ, u, OPER_SYNC_UPDATING); - SaveDatabases(); - notice_lang(Config.s_OperServ, u, OPER_SYNC_UPDATED); - return MOD_CONT; - } - - bool OnHelp(User *u, const Anope::string &subcommand) - { - notice_help(Config.s_OperServ, u, OPER_HELP_SYNC); - return true; - } - - void OnServHelp(User *u) - { - notice_lang(Config.s_OperServ, u, OPER_HELP_CMD_SQLSYNC); - } -}; - -class DBMySQLWrite : public DBMySQL -{ - public: - DBMySQLWrite(const Anope::string &modname, const Anope::string &creator) : DBMySQL(modname, creator) - { - me = this; - - ModuleManager::Attach(I_OnServerConnect, this); - - this->AddCommand(OperServ, new CommandSyncSQL("SQLSYNC")); - - if (uplink_server) - OnServerConnect(); - } - - ~DBMySQLWrite() - { - } - - void OnServerConnect() - { - Implementation i[] = { - /* Misc */ - I_OnSaveDatabase, I_OnPostCommand, - /* NickServ */ - I_OnNickAddAccess, I_OnNickEraseAccess, I_OnNickClearAccess, - I_OnDelCore, I_OnNickForbidden, I_OnNickGroup, I_OnMakeNickRequest, - I_OnDelNickRequest, I_OnNickRegister, I_OnChangeCoreDisplay, - I_OnNickSuspended, - /* ChanServ */ - I_OnAccessAdd, I_OnAccessDel, I_OnAccessChange, I_OnAccessClear, I_OnLevelChange, - I_OnChanForbidden, I_OnDelChan, I_OnChanRegistered, I_OnChanSuspend, - I_OnAkickAdd, I_OnAkickDel, - /* BotServ */ - I_OnBotCreate, I_OnBotChange, I_OnBotDelete, - I_OnBotAssign, I_OnBotUnAssign, - I_OnBadWordAdd, I_OnBadWordDel, - /* MemoServ */ - I_OnMemoSend, I_OnMemoDel, - /* OperServ */ - I_OnAddAkill, I_OnDelAkill, I_OnExceptionAdd, I_OnExceptionDel, - I_OnAddXLine, I_OnDelXLine - }; - ModuleManager::Attach(i, this, 39); - } - - EventReturn OnSaveDatabase() - { - mysqlpp::Query query(me->Con); - - query << "TRUNCATE TABLE `anope_os_core`"; - ExecuteQuery(query); - query << "INSERT DELAYED INTO `anope_os_core` (maxusercnt, maxusertime, akills_count, sglines_count, sqlines_count, szlines_count) VALUES("; - query << maxusercnt << ", " << maxusertime << ", " << (SGLine ? SGLine->GetCount() : 0) << ", " << (SQLine ? SQLine->GetCount() : 0) << ", " << (SNLine ? SNLine->GetCount() : 0) << ", " << (SZLine ? SZLine->GetCount() : 0) << ")"; - ExecuteQuery(query); - - for (nickcore_map::const_iterator it = NickCoreList.begin(), it_end = NickCoreList.end(); it != end; ++it) - { - CurCore = it->second; - FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteCoreMetadata, CurCore)); - } - - for (nickalias_map::const_iterator it = NickAliasList.begin(), it_end = NickAliasList.end(); it != it_end; ++it) - { - CurNick = it->second; - FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteNickMetadata, CurNick)); - } - - for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChanelList.end(); it != it_end; ++it) - { - CurChannel = it->second; - FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteChannelMetadata, CurChannel)); - } - - for (botinfo_map::const_iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end; ++it) - { - CurBot = it->second; - FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteBotMetadata, CurBot)); - - /* 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 << CurBot->nick << ", " << mysqlpp::quote << CurBot->user << ", " << mysqlpp::quote << CurBot->host; - query << ", " << mysqlpp::quote << CurBot->real << ", '" << GetBotServFlags(CurBot) << "', " << CurBot->created << ", "; - query << CurBot->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)); - - return EVENT_CONTINUE; - } - - void OnPostCommand(User *u, const std::string &service, const ci::string &command, const std::vector<ci::string> ¶ms) - { - mysqlpp::Query query(me->Con); - - if (service == Config.s_NickServ) - { - if (u->Account() && ((command == "SET" && !params.empty()) || (command == "SASET" && u->Account()->HasCommand("nickserv/saset") && params.size() > 1))) - { - ci::string cmd = (command == "SET" ? params[0] : params[1]); - NickCore *nc = (command == "SET" ? u->Account() : findcore(params[0])); - if (!nc) - return; - if (cmd == "PASSWORD" && params.size() > 1) - { - query << "UPDATE `anope_ns_core` SET `pass` = " << mysqlpp::quote << nc->pass << " WHERE `display` = " << mysqlpp::quote << nc->display; - ExecuteQuery(query); - } - else if (cmd == "LANGUAGE" && params.size() > 1) - { - query << "UPDATE `anope_ns_core` SET `language` = " << nc->language << " WHERE `display` = " << mysqlpp::quote << nc->display; - ExecuteQuery(query); - } - else if (cmd == "URL") - { - query << "UPDATE `anope_ns_core` SET `url` = " << mysqlpp::quote << (nc->url ? nc->url : "") << " WHERE `display` = " << mysqlpp::quote << nc->display; - ExecuteQuery(query); - } - else if (cmd == "EMAIL") - { - query << "UPDATE `anope_ns_core` SET `email` = " << mysqlpp::quote << (nc->email ? nc->email : "") << " WHERE `display` = " << mysqlpp::quote << nc->display; - ExecuteQuery(query); - } - else if (cmd == "ICQ") - { - query << "UPDATE `anope_ns_core` SET `icq` = " << (nc->icq ? nc->icq : 0) << " WHERE `display` = " << mysqlpp::quote << nc->display; - ExecuteQuery(query); - } - else if (cmd == "GREET") - { - query << "UPDATE `anope_ns_core` SET `greet` = " << mysqlpp::quote << (nc->greet ? nc->greet : "") << " WHERE `display` = " << mysqlpp::quote << nc->display; - ExecuteQuery(query); - } - else if (cmd == "KILL" || cmd == "SECURE" || cmd == "PRIVATE" || cmd == "MSG" || cmd == "HIDE" || cmd == "AUTOOP") - { - query << "UPDATE `anope_ns_core` SET `flags` = '" << BuildFlagsList(nc) << "' WHERE `display` = " << mysqlpp::quote << nc->display; - ExecuteQuery(query); - } - } - } - else if (service == Config.s_ChanServ) - { - if (command == "SET" && u->Account() && params.size() > 1) - { - ChannelInfo *ci = cs_findchan(params[0]); - if (!ci) - return; - if (!u->Account()->HasPriv("chanserv/set") && check_access(u, ci, CA_SET)) - return; - if (params[1] == "FOUNDER" && ci->founder) - { - query << "UPDATE `anope_cs_info` SET `founder` = " << mysqlpp::quote << ci->founder->display << " WHERE `name` = " << mysqlpp::quote << ci->name; - ExecuteQuery(query); - } - else if (params[1] == "SUCCESSOR") - { - query << "UPDATE `anope_cs_info` SET `successor` = " << mysqlpp::quote << (ci->successor ? ci->successor->display : "") << " WHERE `name` = " << mysqlpp::quote << ci->name; - ExecuteQuery(query); - } - else if (params[1] == "DESC") - { - query << "UPDATE `anope_cs_info` SET `descr` = " << mysqlpp::quote << ci->desc << " WHERE `name` = " << mysqlpp::quote << ci->name; - ExecuteQuery(query); - } - else if (params[1] == "URL") - { - query << "UPDATE `anope_cs_info` SET `url` = " << mysqlpp::quote << (ci->url ? ci->url : "") << " WHERE `name` = " << mysqlpp::quote << ci->name; - ExecuteQuery(query); - } - else if (params[1] == "EMAIL") - { - query << "UPDATE `anope_cs_info` SET `email` = " << mysqlpp::quote << (ci->email ? ci->email : "") << " WHERE `name` = " << mysqlpp::quote << ci->name; - ExecuteQuery(query); - } - else if (params[1] == "ENTRYMSG") - { - query << "UPDATE `anope_cs_info` SET `entry_message` = " << mysqlpp::quote << (ci->entry_message ? ci->entry_message : "") << " WHERE `name` = " << mysqlpp::quote << ci->name; - ExecuteQuery(query); - } - else if (params[1] == "MLOCK") - { - query << "UPDATE `anope_cs_info` SET `mlock_on` = '" << GetMLockOn(ci) << "' WHERE `name` = " << mysqlpp::quote << ci->name; - ExecuteQuery(query); - query << "UPDATE `anope_cs_info` SET `mlock_off` = '" << GetMLockOff(ci) << "' WHERE `name` = " << mysqlpp::quote << ci->name; - ExecuteQuery(query); - query << "UPDATE `anope_cs_info` SET `mlock_params` = '" << GetMLockParams(ci) << "' WHERE `name` = " << mysqlpp::quote << ci->name; - ExecuteQuery(query); - } - else if (params[1] == "BANTYPE") - { - query << "UPDATE `anope_cs_info` SET `bantype` = " << ci->bantype << " WHERE `name` = " << mysqlpp::quote << ci->name; - ExecuteQuery(query); - } - else if (params[1] == "KEEPTOPIC" || params[1] == "TOPICLOCK" || params[1] == "PRIVATE" || params[1] == "SECUREOPS" || params[1] == "SECUREFOUNDER" || params[1] == "RESTRICTED" || params[1] == "SECURE" || params[1] == "SIGNKICK" || params[1] == "OPNOTICE" || params[1] == "XOP" || params[1] == "PEACE" || params[1] == "PERSIST" || params[1] == "NOEXPIRE") - { - query << "UPDATE `anope_cs_info` SET `flags` = '" << BuildFlagsList(ci) << "' WHERE `name` = " << mysqlpp::quote << ci->name; - ExecuteQuery(query); - } - } - } - else if (Config.s_BotServ && service == Config.s_BotServ) - { - if (command == "KICK" && params.size() > 2) - { - ChannelInfo *ci = cs_findchan(params[0]); - if (!ci) - return; - if (!check_access(u, ci, CA_SET) && !u->Account()->HasPriv("botserv/administration")) - return; - if (params[1] == "BADWORDS" || params[1] == "BOLDS" || params[1] == "CAPS" || params[1] == "COLORS" || params[1] == "FLOOD" || params[1] == "REPEAT" || params[1] == "REVERSES" || params[1] == "UNDERLINES") - { - if (params[2] == "ON" || params[2] == "OFF") - { - for (int i = 0; i < TTB_SIZE; ++i) - { - query << "INSERT DELAYED INTO `anope_cs_ttb` (channel, ttb_id, value) VALUES(" << mysqlpp::quote << ci->name << ", " << i << ", " << ci->ttb[i] << ") ON DUPLICATE KEY UPDATE channel=VALUES(channel), ttb_id=VALUES(ttb_id), value=VALUES(value)"; - ExecuteQuery(query); - } - 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); - } - } - } - } - else if (command == "SET" && params.size() > 2) - { - ChannelInfo *ci = cs_findchan(params[0]); - if (ci && !check_access(u, ci, CA_SET) && !u->Account()->HasPriv("botserv/administration")) - return; - BotInfo *bi = NULL; - if (!ci) - bi = findbot(params[0]); - if (bi && params[1] == "PRIVATE" && u->Account()->HasPriv("botserv/set/private")) - { - query << "UPDATE `anope_bs_core` SET `flags` = '" << GetBotServFlags(bi) << "' WHERE `nick` = " << mysqlpp::quote << bi->nick; - ExecuteQuery(query); - } - else if (!ci) - return; - else if (params[1] == "DONTKICKOPS" || params[1] == "DONTKICKVOICES" || params[1] == "FANTASY" || params[1] == "GREET" || params[1] == "SYMBIOSIS" || params[1] == "NOBOT") - { - query << "UPDATE `anope_cs_info` SET `botflags` = '" << GetBotFlags(ci->botflags) << "' WHERE `name` = " << mysqlpp::quote << ci->name; - ExecuteQuery(query); - } - } - } - } - - void OnNickAddAccess(NickCore *nc, const Anope::string &entry) - { - mysqlpp::Query query(me->Con); - query << "INSERT DELAYED INTO `anope_ns_access` (display, access) VALUES(" << mysqlpp::quote << nc->display << ", " << mysqlpp::quote << entry << ")"; - ExecuteQuery(query); - } - - void OnNickEraseAccess(NickCore *nc, const Anope::string &entry) - { - mysqlpp::Query query(me->Con); - query << "DELETE FROM `anope_ns_access` WHERE `display` = " << mysqlpp::quote << nc->display << " AND `access` = " << mysqlpp::quote << entry; - ExecuteQuery(query); - } - - void OnNickClearAccess(NickCore *nc) - { - mysqlpp::Query query(me->Con); - query << "DELETE FROM `anope_ns_access` WHERE `display` = " << mysqlpp::quote << nc->display; - ExecuteQuery(query); - } - - void OnDelCore(NickCore *nc) - { - mysqlpp::Query query(me->Con); - query << "DELETE FROM `anope_cs_access` WHERE `display` = " << mysqlpp::quote << nc->display; - ExecuteQuery(query); - query << "DELETE FROM `anope_cs_akick` WHERE `mask` = " << mysqlpp::quote << nc->display; - ExecuteQuery(query); - query << "DELETE FROM `anope_ns_access` WHERE `display` = " << mysqlpp::quote << nc->display; - ExecuteQuery(query); - query << "DELETE FROM `anope_ns_alias` WHERE `display` = " << mysqlpp::quote << nc->display; - ExecuteQuery(query); - query << "DELETE FROM `anope_ns_core` WHERE `display` = " << mysqlpp::quote << nc->display; - ExecuteQuery(query); - query << "DELETE FROM `anope_ms_info` WHERE `receiver` = " << mysqlpp::quote << nc->display; - ExecuteQuery(query); - } - - void OnNickForbidden(NickAlias *na) - { - std::string flags = BuildFlagsList(na); - mysqlpp::Query query(me->Con); - query << "UPDATE `anope_ns_alias` SET `flags` = '" << (!flags.empty() ? flags : "") << "' WHERE `nick` = " << mysqlpp::quote << na->nick; - ExecuteQuery(query); - } - - void OnNickGroup(User *u, NickAlias *) - { - OnNickRegister(findnick(u->nick)); - } - - void OnMakeNickRequest(NickRequest *nr) - { - mysqlpp::Query query(me->Con); - query << "INSERT DELAYED INTO `anope_ns_request` (nick, passcode, password, email, requested) VALUES(" << mysqlpp::quote << nr->nick << ", "; - query << mysqlpp::quote << nr->passcode << ", " << mysqlpp::quote << nr->password << ", " << mysqlpp::quote << nr->email << ", '"; - query << nr->requested << "')"; - ExecuteQuery(query); - } - - void OnDelNickRequest(NickRequest *nr) - { - mysqlpp::Query query(me->Con); - query << "DELETE FROM `anope_ns_request` WHERE `nick` = " << mysqlpp::quote << nr->nick; - ExecuteQuery(query); - } - - void OnNickRegister(NickAlias *na) - { - std::string flags = BuildFlagsList(na); - mysqlpp::Query query(me->Con); - query << "INSERT DELAYED INTO `anope_ns_alias` (nick, last_quit, last_realname, last_usermask, time_registered, last_seen, flags, display) VALUES("; - query << mysqlpp::quote << na->nick << ", " << mysqlpp::quote << (na->last_quit ? na->last_quit : "") << ", "; - query << mysqlpp::quote << (na->last_realname ? na->last_realname : "") << ", "; - query << mysqlpp::quote << (na->last_usermask ? na->last_usermask : "") << ", " << na->time_registered << ", " << na->last_seen; - query << ", '" << (!flags.empty() ? flags : "") << "', " << mysqlpp::quote << na->nc->display << ") "; - query << "ON DUPLICATE KEY UPDATE last_quit=VALUES(last_quit), last_realname=VALUES(last_realname), last_usermask=VALUES(last_usermask), time_registered=VALUES(time_registered), last_seen=VALUES(last_seen), flags=VALUES(flags), display=VALUES(display)"; - ExecuteQuery(query); - - flags = BuildFlagsList(na->nc); - query << "INSERT DELAYED INTO `anope_ns_core` (display, pass, email, greet, icq, url, flags, language, channelcount, memomax) VALUES("; - query << mysqlpp::quote << na->nc->display << ", " << mysqlpp::quote << na->nc->pass << ", "; - query << mysqlpp::quote << (na->nc->email ? na->nc->email : "") << ", " << mysqlpp::quote << (na->nc->greet ? na->nc->greet : ""); - query << ", " << na->nc->icq << ", " << mysqlpp::quote << (na->nc->url ? na->nc->url : ""); - query << ", '" << (!flags.empty() ? flags : "") << "', " << na->nc->language << ", " << na->nc->channelcount << ", "; - query << na->nc->memos.memomax << ") "; - query << "ON DUPLICATE KEY UPDATE pass=VALUES(pass), email=VALUES(email), greet=VALUES(greet), icq=VALUES(icq), flags=VALUES(flags), language=VALUES(language), "; - query << "channelcount=VALUES(channelcount), memomax=VALUES(memomax)"; - ExecuteQuery(query); - } - - void OnChangeCoreDisplay(NickCore *nc, const Anope::string &newdisplay) - { - mysqlpp::Query query(me->Con); - query << "UPDATE `anope_ns_core` SET `display` = " << mysqlpp::quote << newdisplay << " WHERE `display` = " << mysqlpp::quote << nc->display; - ExecuteQuery(query); - query << "UPDATE `anope_ns_alias` SET `display` = " << mysqlpp::quote << newdisplay << " WHERE `display` = " << mysqlpp::quote << nc->display; - ExecuteQuery(query); - query << "UPDATE `anope_ns_access` SET `display` = " << mysqlpp::quote << newdisplay << " WHERE `display` = " << mysqlpp::quote << nc->display; - ExecuteQuery(query); - query << "UPDATE `anope_cs_access` SET `display` = " << mysqlpp::quote << newdisplay << " WHERE `display` = " << mysqlpp::quote << nc->display; - ExecuteQuery(query); - query << "UPDATE `anope_cs_info` SET `founder` = " << mysqlpp::quote << newdisplay << " WHERE `founder` = " << mysqlpp::quote << nc->display; - ExecuteQuery(query); - query << "UPDATE `anope_cs_info` SET `successor` = " << mysqlpp::quote << newdisplay << " WHERE `successor` = " << mysqlpp::quote << nc->display; - ExecuteQuery(query); - query << "UPDATE `anope_ms_info` SET `receiver` = " << mysqlpp::quote << newdisplay << " WHERE `receiver` = " << mysqlpp::quote << nc->display; - ExecuteQuery(query); - } - - void OnNickSuspend(NickAlias *na) - { - mysqlpp::Query query(me->Con); - query << "UPDATE `anope_ns_core` SET `flags` = '" << BuildFlagsList(na->nc) << "' WHERE `display` = " << mysqlpp::quote << na->nc->display; - ExecuteQuery(query); - } - - void OnAccessAdd(ChannelInfo *ci, User *u, NickAlias *na, int level) - { - mysqlpp::Query query(me->Con); - query << "INSERT DELAYED INTO `anope_cs_access` (level, display, channel, last_seen, creator) VALUES (" << level << ", " << mysqlpp::quote << na->nc->display << ", " << mysqlpp::quote << ci->name << ", " << time(NULL) << ", " << mysqlpp::quote << u->nick << ")"; - ExecuteQuery(query); - } - - void OnAccessDel(ChannelInfo *ci, User *u, NickCore *nc) - { - mysqlpp::Query query(me->Con); - query << "DELETE FROM `anope_cs_access` WHERE `display` = " << mysqlpp::quote << nc->display << " AND `channel` = " << mysqlpp::quote << ci->name; - ExecuteQuery(query); - } - - void OnAccessChange(ChannelInfo *ci, User *u, NickAlias *na, int level) - { - mysqlpp::Query query(me->Con); - query << "INSERT DELAYED INTO `anope_cs_access` (level, display, channel, last_seen, creator) VALUES (" << level << ", " << mysqlpp::quote << na->nc->display << ", " << mysqlpp::quote << ci->name << ", " << time(NULL) << ", " << mysqlpp::quote << u->nick << ") ON DUPLICATE KEY UPDATE level=VALUES(level), display=VALUES(display), channel=VALUES(channel), last_seen=VALUES(last_seen), creator=VALUES(creator)"; - ExecuteQuery(query); - } - - void OnAccessClear(ChannelInfo *ci, User *u) - { - mysqlpp::Query query(me->Con); - query << "DELETE FROM `anope_cs_access` WHERE `channel` = " << mysqlpp::quote << ci->name; - ExecuteQuery(query); - } - - void OnLevelChange(User *u, ChannelInfo *ci, int pos, int what) - { - mysqlpp::Query query(me->Con); - - if (pos >= 0) - { - query << "UPDATE `anope_cs_levels` SET `level` = " << what << " WHERE `channel` = " << mysqlpp::quote << ci->name << " AND `position` = " << pos; - ExecuteQuery(query); - } - else - for (int i = 0; i < CA_SIZE; ++i) - { - query << "UPDATE `anope_cs_levels` SET `level` = " << ci->levels[i] << " WHERE `channel` = " << mysqlpp::quote << ci->name << " AND `position` = " << i; - ExecuteQuery(query); - } - } - - void OnChanForbidden(ChannelInfo *ci) - { - mysqlpp::Query query(me->Con); - query << "INSERT DELAYED INTO `anope_cs_info` (name, time_registered, last_used, flags, forbidby, forbidreason) VALUES ("; - query << mysqlpp::quote << ci->name << ", " << ci->time_registered << ", " << ci->last_used << ", '" << BuildFlagsList(ci) << "', " << mysqlpp::quote << ci->forbidby << ", " << mysqlpp::quote << ci->forbidreason << ")"; - ExecuteQuery(query); - } - - void OnDelChan(ChannelInfo *ci) - { - mysqlpp::Query query(me->Con); - query << "DELETE FROM `anope_cs_access` WHERE `channel` = " << mysqlpp::quote << ci->name; - ExecuteQuery(query); - query << "DELETE FROM `anope_cs_akick` WHERE `channel` = " << mysqlpp::quote << ci->name; - ExecuteQuery(query); - query << "DELETE FROM `anope_cs_info` WHERE `name` = " << mysqlpp::quote << ci->name; - ExecuteQuery(query); - query << "DELETE FROM `anope_cs_levels` WHERE `channel` = " << mysqlpp::quote << ci->name; - ExecuteQuery(query); - query << "DELETE From `anope_cs_ttb` WHERE `channel` = " << mysqlpp::quote << ci->name; - ExecuteQuery(query); - query << "DELETE FROM `anope_bs_badwords` WHERE `channel` = " << mysqlpp::quote << ci->name; - ExecuteQuery(query); - } - - void OnChanRegistered(ChannelInfo *ci) - { - mysqlpp::Query query(me->Con); - std::string flags = BuildFlagsList(ci), mlockon = GetMLockOn(ci), mlockoff = GetMLockOff(ci), mlockparams = GetMLockParams(ci); - query << "INSERT DELAYED INTO `anope_cs_info` (name, founder, successor, descr, url, email, time_registered, last_used, last_topic, last_topic_setter, last_topic_time, flags, forbidby, forbidreason, bantype, mlock_on, mlock_off, mlock_params, entry_message, memomax, botnick, botflags, capsmin, capspercent, floodlines, floodsecs, repeattimes) VALUES("; - query << mysqlpp::quote << ci->name << ", " << mysqlpp::quote << (ci->founder ? ci->founder->display : "") << ", "; - query << mysqlpp::quote << (ci->successor ? ci->successor->display : "") << ", " << mysqlpp::quote << ci->desc << ", "; - query << mysqlpp::quote << (ci->url ? ci->url : "") << ", " << mysqlpp::quote << (ci->email ? ci->email : "") << ", "; - query << ci->time_registered << ", " << ci->last_used << ", " << mysqlpp::quote << (ci->last_topic ? ci->last_topic : ""); - query << ", " << mysqlpp::quote << (!ci->last_topic_setter.empty() ? ci->last_topic_setter : ""); - query << ", " << ci->last_topic_time << ", '" << (!flags.empty() ? flags : "") << "', "; - query << mysqlpp::quote << (ci->forbidby ? ci->forbidby : "") << ", " << mysqlpp::quote << (ci->forbidreason ? ci->forbidreason : "") << ", " << ci->bantype << ", '"; - query << mlockon << "', '" << mlockoff << "', '"; - query << mlockparams << "', " << mysqlpp::quote << (ci->entry_message ? ci->entry_message : "") << ", "; - query << ci->memos.memomax << ", " << mysqlpp::quote << (ci->bi ? ci->bi->nick : "") << ", '" << GetBotFlags(ci->botflags); - query << "', " << ci->capsmin << ", " << ci->capspercent << ", " << ci->floodlines; - query << ", " << ci->floodsecs << ", " << ci->repeattimes << ") "; - query << "ON DUPLICATE KEY UPDATE founder=VALUES(founder), successor=VALUES(successor), descr=VALUES(descr), url=VALUES(url), email=VALUES(email), time_registered=VALUES(time_registered), last_used=VALUES(last_used), last_topic=VALUES(last_topic), last_topic_setter=VALUES(last_topic_setter), last_topic_time=VALUES(last_topic_time), flags=VALUES(flags), forbidby=VALUES(forbidby), forbidreason=VALUES(forbidreason), bantype=VALUES(bantype), mlock_on=VALUES(mlock_on), mlock_off=VALUES(mlock_off), mlock_params=VALUES(mlock_params), entry_message=VALUES(entry_message), memomax=VALUES(memomax), botnick=VALUES(botnick), botflags=VALUES(botflags), capsmin=VALUES(capsmin), capspercent=VALUES(capspercent), floodlines=VALUES(floodlines), floodsecs=VALUES(floodsecs), repeattimes=VALUES(repeattimes)"; - ExecuteQuery(query); - } - - void OnChanSuspend(ChannelInfo *ci) - { - mysqlpp::Query query(me->Con); - query << "UPDATE `anope_cs_info` SET `flags` = '" << BuildFlagsList(ci) << "' WHERE `name` = " << mysqlpp::quote << ci->name; - ExecuteQuery(query); - query << "UPDATE `anope_cs_info` SET `forbidby` = " << mysqlpp::quote << ci->forbidby << " WHERE `name` = " << mysqlpp::quote << ci->name; - ExecuteQuery(query); - query << "UPDATE `anope_cs_info` SET `forbidreason` = " << mysqlpp::quote << ci->forbidreason << " WHERE `name` = " << mysqlpp::quote << ci->name; - ExecuteQuery(query); - } - - void OnAkickAdd(ChannelInfo *ci, AutoKick *ak) - { - mysqlpp::Query query(me->Con); - query << "INSERT DELAYED INTO `anope_cs_akick` (channel, flags, mask, reason, creator, created, last_used) VALUES("; - query << mysqlpp::quote << ci->name << ", '"; - if (ak->HasFlag(AK_ISNICK)) - query << "ISNICK "; - if (ak->HasFlag(AK_STUCK)) - query << "STUCK "; - query << "', " << mysqlpp::quote << (ak->HasFlag(AK_ISNICK) ? ak->nc->display : ak->mask) << ", "; - query << mysqlpp::quote << ak->reason << ", " << mysqlpp::quote << ak->creator << ", " << ak->addtime; - query << ", " << ak->last_used << ")"; - ExecuteQuery(query); - } - - void OnAkickDel(ChannelInfo *ci, AutoKick *ak) - { - mysqlpp::Query query(me->Con); - query << "DELETE FROM `anope_cs_akick` WHERE `channel`= " << mysqlpp::quote << ci->name << " AND `mask` = " << mysqlpp::quote << (ak->HasFlag(AK_ISNICK) ? ak->nc->display : ak->mask); - ExecuteQuery(query); - } - - void OnBotCreate(BotInfo *bi) - { - mysqlpp::Query query(me->Con); - 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 << ", " << bi->chancount << ") "; - query << "ON DUPLICATE KEY UPDATE nick=VALUES(nick), user=VALUES(user), host=VALUES(host), rname=VALUES(rname), flags=VALUES(flags), created=VALUES(created), chancount=VALUES(chancount)"; - ExecuteQuery(query); - } - - void OnBotChange(BotInfo *bi) - { - OnBotCreate(bi); - } - - void OnBotDelete(BotInfo *bi) - { - mysqlpp::Query query(me->Con); - query << "DELETE FROM `anope_bs_core` WHERE `nick` = " << mysqlpp::quote << bi->nick; - ExecuteQuery(query); - query << "UPDATE `anope_cs_info` SET `botnick` = '' WHERE `botnick` = " << mysqlpp::quote << bi->nick; - ExecuteQuery(query); - } - - EventReturn OnBotAssign(User *sender, ChannelInfo *ci, BotInfo *bi) - { - mysqlpp::Query query(me->Con); - query << "UPDATE `anope_cs_info` SET `botnick` = " << mysqlpp::quote << bi->nick << " WHERE `name` = " << mysqlpp::quote << ci->name; - ExecuteQuery(query); - return EVENT_CONTINUE; - } - - EventReturn OnBotUnAssign(User *sender, ChannelInfo *ci) - { - mysqlpp::Query query(me->Con); - query << "UPDATE `anope_cs_info` SET `botnick` = '' WHERE `name` = " << mysqlpp::quote << ci->name; - ExecuteQuery(query); - 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 *, 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 << m->sender << ", " << mysqlpp::quote << m->text << ", 'NICK')"; - ExecuteQuery(query); - } - - void OnMemoSend(User *, 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 << m->sender << ", " << 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 *, XLine *ak) - { - mysqlpp::Query query(me->Con); - query << "INSERT DELAYED INTO `anope_os_akills` (user, host, xby, reason, seton, expire) VALUES("; - query << mysqlpp::quote << ak->GetUser().c_str() << ", " << mysqlpp::quote << ak->GetHost().c_str() << ", " << mysqlpp::quote << ak->By.c_str(); - query << ", " << mysqlpp::quote << ak->Reason << ", " << ak->Created << ", " << ak->Expires << ")"; - ExecuteQuery(query); - return EVENT_CONTINUE; - } - - void OnDelAkill(User *, XLine *ak) - { - mysqlpp::Query query(me->Con); - if (ak) - query << "DELETE FROM `anope_os_akills` WHERE `host` = " << mysqlpp::quote << ak->GetHost().c_str(); - else - query << "TRUNCATE TABLE `anope_os_akills`"; - ExecuteQuery(query); - } - - EventReturn OnExceptionAdd(User *, Exception *ex) - { - mysqlpp::Query query(me->Con); - query << "INSERT DELAYED INTO `anope_os_exceptions` (mask, slimit, 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 *, Exception *ex) - { - mysqlpp::Query query(me->Con); - query << "DELETE FROM `anope_os_exceptions` WHERE `mask` = " << mysqlpp::quote << ex->mask; - ExecuteQuery(query); - } - - EventReturn OnAddXLine(User *, XLine *x, XLineType Type) - { - mysqlpp::Query query(me->Con); - query << "INSERT DELAYED INTO `anope_os_sxlines` (type, mask, xby, reason, seton, expire) VALUES('"; - query << (Type == X_SNLINE ? "SNLINE" : (Type == X_SQLINE ? "SQLINE" : "SZLINE")) << "', "; - query << mysqlpp::quote << x->Mask.c_str() << ", " << mysqlpp::quote << x->By.c_str() << ", " << mysqlpp::quote << x->Reason; - query << ", " << x->Created << ", " << x->Expires << ")"; - ExecuteQuery(query); - return EVENT_CONTINUE; - } - - void OnDelXLine(User *, XLine *x, XLineType Type) - { - mysqlpp::Query query(me->Con); - if (x) - { - query << "DELETE FROM `anope_os_xlines` WHERE `mask` = " << mysqlpp::quote << x->Mask.c_str() << " AND `type` = '"; - query << (Type == X_SNLINE ? "SNLINE" : (Type == X_SQLINE ? "SQLINE" : "SZLINE")) << "'"; - } - else - query << "DELETE FROM `anope_os_xlines` WHERE `type` = '" << (Type == X_SNLINE ? "SNLINE" : (Type == X_SQLINE ? "SQLINE" : "SZLINE")) << "'"; - ExecuteQuery(query); - } -}; - -MODULE_INIT(DBMySQLWrite) |