From 631d11d6a81e8c5f63a19fc279606a61ab1a0563 Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 10 May 2010 17:55:23 -0400 Subject: Store a plaintext version of mode names in the mode structures, removes alot of unneeded code from db_plain/db_mysql. --- src/modules/mysql/db_mysql.h | 46 +------------ src/modules/mysql/db_mysql_execute.cpp | 10 ++- src/modules/mysql/db_mysql_read.cpp | 43 ++++++++---- src/modules/mysql/db_mysql_write.cpp | 118 ++++++++++++++++++--------------- 4 files changed, 98 insertions(+), 119 deletions(-) (limited to 'src/modules/mysql') diff --git a/src/modules/mysql/db_mysql.h b/src/modules/mysql/db_mysql.h index b62f52524..12956262a 100644 --- a/src/modules/mysql/db_mysql.h +++ b/src/modules/mysql/db_mysql.h @@ -39,48 +39,6 @@ NickCoreFlagInfo NickCoreFlags[] = { {"", static_cast(-1)} }; -struct ChannelModeInfo -{ - std::string Name; - ChannelModeName Mode; -}; - -ChannelModeInfo ChannelModes[] = { - {"CMODE_BLOCKCOLOR", CMODE_BLOCKCOLOR}, - {"CMODE_FLOOD", CMODE_FLOOD}, - {"CMODE_INVITE", CMODE_INVITE}, - {"CMODE_KEY", CMODE_KEY}, - {"CMODE_LIMIT", CMODE_LIMIT}, - {"CMODE_MODERATED", CMODE_MODERATED}, - {"CMODE_NOEXTERNAL", CMODE_NOEXTERNAL}, - {"CMODE_PRIVATE", CMODE_PRIVATE}, - {"CMODE_REGISTERED", CMODE_REGISTERED}, - {"CMODE_SECRET", CMODE_SECRET}, - {"CMODE_TOPIC", CMODE_TOPIC}, - {"CMODE_AUDITORIUM", CMODE_AUDITORIUM}, - {"CMODE_SSL", CMODE_SSL}, - {"CMODE_ADMINONLY", CMODE_ADMINONLY}, - {"CMODE_NOCTCP", CMODE_NOCTCP}, - {"CMODE_FILTER", CMODE_FILTER}, - {"CMODE_NOKNOCK", CMODE_NOKNOCK}, - {"CMODE_REDIRECT", CMODE_REDIRECT}, - {"CMODE_REGMODERATED", CMODE_REGMODERATED}, - {"CMODE_NONICK", CMODE_NONICK}, - {"CMODE_OPERONLY", CMODE_OPERONLY}, - {"CMODE_NONICK", CMODE_NONICK}, - {"CMODE_REGISTEREDONLY", CMODE_REGISTEREDONLY}, - {"CMODE_STRIPCOLOR", CMODE_STRIPCOLOR}, - {"CMODE_NONOTICE", CMODE_NONOTICE}, - {"CMODE_NOINVITE", CMODE_NOINVITE}, - {"CMODE_ALLINVITE", CMODE_ALLINVITE}, - {"CMODE_BLOCKCAPS", CMODE_BLOCKCAPS}, - {"CMODE_PERM", CMODE_PERM}, - {"CMODE_NICKFLOOD", CMODE_NICKFLOOD}, - {"CMODE_JOINFLOOD", CMODE_JOINFLOOD}, - {"CMODE_NOREJOIN", CMODE_NOREJOIN}, - {"", static_cast(-1)} -}; - struct BotFlagInfo { std::string Name; @@ -169,7 +127,7 @@ MemoFlagInfo MemoFlags[] = { inline std::string SQLAssign(const mysqlpp::String& s) { return s.c_str(); } class DBMySQL; -static DBMySQL *Me; +static DBMySQL *me; bool ExecuteQuery(mysqlpp::Query& query) { @@ -226,7 +184,7 @@ class DBMySQL : public Module DBMySQL(const std::string &modname, const std::string &creator) : Module(modname, creator) { - Me = this; + me = this; this->SetAuthor("Anope"); this->SetVersion(VERSION_STRING); diff --git a/src/modules/mysql/db_mysql_execute.cpp b/src/modules/mysql/db_mysql_execute.cpp index 0c7c4de65..3933d54d1 100644 --- a/src/modules/mysql/db_mysql_execute.cpp +++ b/src/modules/mysql/db_mysql_execute.cpp @@ -37,7 +37,7 @@ class FakeUser : public User this->realname = sstrdup("Fake SQL User"); this->hostip = sstrdup("255.255.255.255"); this->vhost = NULL; - this->server = serv_uplink; // XXX Need a good way to set this to ourself + this->server = Me; if (this->prev) this->prev->next = this->next; @@ -50,8 +50,6 @@ class FakeUser : public User ~FakeUser() { - this->server = serv_uplink; // XXX Need a good way to set this to ourself - User **list = &userlist[HASH(this->nick.c_str())]; this->next = *list; if (*list) @@ -73,16 +71,16 @@ class FakeUser : public User class SQLTimer : public Timer { public: - SQLTimer() : Timer(Me->Delay, time(NULL), true) + SQLTimer() : Timer(me->Delay, time(NULL), true) { - mysqlpp::Query query(Me->Con); + mysqlpp::Query query(me->Con); query << "TRUNCATE TABLE `anope_commands`"; ExecuteQuery(query); } void Tick(time_t) { - mysqlpp::Query query(Me->Con); + mysqlpp::Query query(me->Con); mysqlpp::StoreQueryResult qres; query << "SELECT * FROM `anope_commands`"; diff --git a/src/modules/mysql/db_mysql_read.cpp b/src/modules/mysql/db_mysql_read.cpp index 5c498b008..728e4b882 100644 --- a/src/modules/mysql/db_mysql_read.cpp +++ b/src/modules/mysql/db_mysql_read.cpp @@ -27,7 +27,7 @@ static std::vector MakeVector(std::string buf) static void LoadDatabase() { - mysqlpp::Query query(Me->Con); + mysqlpp::Query query(me->Con); mysqlpp::StoreQueryResult qres; query << "SELECT * FROM `anope_ns_core`"; @@ -270,12 +270,17 @@ static void LoadDatabase() spacesepstream sep(SQLAssign(qres[i]["mlock_on"])); while (sep.GetToken(buf)) { - for (int j = 0; ChannelModes[j].Mode != -1; ++j) + for (std::list::iterator it = ModeManager::Modes.begin(); it != ModeManager::Modes.end(); ++it) { - if (buf == ChannelModes[j].Name) + if ((*it)->Class == MC_CHANNEL) { - ci->SetMLock(ChannelModes[j].Mode, true); - break; + ChannelMode *cm = dynamic_cast(*it); + + if (buf == cm->NameAsString) + { + ci->SetMLock(cm->Name, true); + break; + } } } } @@ -286,12 +291,17 @@ static void LoadDatabase() spacesepstream sep(SQLAssign(qres[i]["mlock_off"])); while (sep.GetToken(buf)) { - for (int j = 0; ChannelModes[j].Mode != -1; ++j) + for (std::list::iterator it = ModeManager::Modes.begin(); it != ModeManager::Modes.end(); ++it) { - if (buf == ChannelModes[j].Name) + if ((*it)->Class == MC_CHANNEL) { - ci->SetMLock(ChannelModes[j].Mode, false); - break; + ChannelMode *cm = dynamic_cast(*it); + + if (buf == cm->NameAsString) + { + ci->SetMLock(cm->Name, false); + break; + } } } } @@ -302,13 +312,18 @@ static void LoadDatabase() spacesepstream sep(SQLAssign(qres[i]["mlock_params"])); while (sep.GetToken(buf)) { - for (int j = 0; ChannelModes[j].Mode != -1; ++j) + for (std::list::iterator it = ModeManager::Modes.begin(); it != ModeManager::Modes.end(); ++it) { - if (buf == ChannelModes[j].Name) + if ((*it)->Class == MC_CHANNEL) { - sep.GetToken(buf); - ci->SetMLock(ChannelModes[j].Mode, true, buf); - break; + ChannelMode *cm = dynamic_cast(*it); + + if (buf == cm->NameAsString) + { + sep.GetToken(buf); + ci->SetMLock(cm->Name, true, buf); + break; + } } } } diff --git a/src/modules/mysql/db_mysql_write.cpp b/src/modules/mysql/db_mysql_write.cpp index b7b94a3a3..5f3218381 100644 --- a/src/modules/mysql/db_mysql_write.cpp +++ b/src/modules/mysql/db_mysql_write.cpp @@ -2,8 +2,6 @@ #include "db_mysql.h" -static Module *me; - static std::string BuildFlagsList(ChannelInfo *ci) { std::string ret; @@ -80,11 +78,16 @@ static std::string MakeMLock(ChannelInfo *ci, bool status) { std::string ret; - for (int i = 0; ChannelModes[i].Mode != -1; ++i) + for (std::list::iterator it = ModeManager::Modes.begin(); it != ModeManager::Modes.end(); ++it) { - if (ci->HasMLock(ChannelModes[i].Mode, status)) + if ((*it)->Class == MC_CHANNEL) { - ret += " " + ChannelModes[i].Name; + ChannelMode *cm = dynamic_cast(*it); + + if (ci->HasMLock(cm->Name, status)) + { + ret += " " + cm->NameAsString; + } } } @@ -108,12 +111,17 @@ static std::string GetMLockParams(ChannelInfo *ci) { std::string ret; - for (int i = 0; ChannelModes[i].Mode != -1; ++i) + for (std::list::iterator it = ModeManager::Modes.begin(); it != ModeManager::Modes.end(); ++it) { - std::string param; - if (ci->GetParam(ChannelModes[i].Mode, param)) + if ((*it)->Class == MC_CHANNEL) { - ret += " " + ChannelModes[i].Name + " " + param; + ChannelMode *cm = dynamic_cast(*it); + + std::string param; + if (ci->GetParam(cm->Name, param)) + { + ret += " " + cm->NameAsString + " " + param; + } } } @@ -166,14 +174,14 @@ static BotInfo *CurBot = NULL; void Write(const std::string &data) { - mysqlpp::Query query(Me->Con); + 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); + mysqlpp::Query query(me->Con); query << "INSERT DELAYED INTO `anope_metadata` (name, value) VALUES(" << mysqlpp::quote << key << ", " << mysqlpp::quote << data << ")"; ExecuteQuery(query); } @@ -183,7 +191,7 @@ void WriteNickMetadata(const std::string &key, const std::string &data) if (!CurNick) throw CoreException("WriteNickMetadata without a nick to write"); - mysqlpp::Query query(Me->Con); + 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); } @@ -193,7 +201,7 @@ void WriteCoreMetadata(const std::string &key, const std::string &data) if (!CurCore) throw CoreException("WritCoreMetadata without a core to write"); - mysqlpp::Query query(Me->Con); + 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); } @@ -203,7 +211,7 @@ void WriteChannelMetadata(const std::string &key, const std::string &data) if (!CurChannel) throw CoreException("WriteChannelMetadata without a channel to write"); - mysqlpp::Query query(Me->Con); + 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); } @@ -213,14 +221,14 @@ 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); + 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); + mysqlpp::Query query(me->Con); query << "TRUNCATE TABLE `anope_ns_core`"; ExecuteQuery(query); @@ -382,7 +390,7 @@ static void SaveDatabases() class CommandSyncSQL : public Command { public: - CommandSyncSQL(const std::string &cname) : Command(cname, 0, 0, "operserv/sqlsync") + CommandSyncSQL(const ci::string &cname) : Command(cname, 0, 0, "operserv/sqlsync") { } @@ -454,7 +462,7 @@ class DBMySQLWrite : public DBMySQL EventReturn OnSaveDatabase() { - mysqlpp::Query query(Me->Con); + mysqlpp::Query query(me->Con); query << "TRUNCATE TABLE `anope_os_core`"; ExecuteQuery(query); @@ -511,7 +519,7 @@ class DBMySQLWrite : public DBMySQL void OnPostCommand(User *u, const std::string &service, const ci::string &command, const std::vector ¶ms) { - mysqlpp::Query query(Me->Con); + mysqlpp::Query query(me->Con); if (service == Config.s_NickServ) { @@ -685,28 +693,28 @@ class DBMySQLWrite : public DBMySQL void OnNickAddAccess(NickCore *nc, const std::string &entry) { - mysqlpp::Query query(Me->Con); + 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 std::string &entry) { - mysqlpp::Query query(Me->Con); + 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); + 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); + 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; @@ -724,7 +732,7 @@ class DBMySQLWrite : public DBMySQL void OnNickForbidden(NickAlias *na) { std::string flags = BuildFlagsList(na); - mysqlpp::Query query(Me->Con); + mysqlpp::Query query(me->Con); query << "UPDATE `anope_ns_alias` SET `flags` = '" << (!flags.empty() ? flags : "") << "' WHERE `nick` = " << mysqlpp::quote << na->nick; ExecuteQuery(query); } @@ -736,7 +744,7 @@ class DBMySQLWrite : public DBMySQL void OnMakeNickRequest(NickRequest *nr) { - mysqlpp::Query query(Me->Con); + 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 << "')"; @@ -745,7 +753,7 @@ class DBMySQLWrite : public DBMySQL void OnDelNickRequest(NickRequest *nr) { - mysqlpp::Query query(Me->Con); + mysqlpp::Query query(me->Con); query << "DELETE FROM `anope_ns_request` WHERE `nick` = " << mysqlpp::quote << nr->nick; ExecuteQuery(query); } @@ -753,7 +761,7 @@ class DBMySQLWrite : public DBMySQL void OnNickRegister(NickAlias *na) { std::string flags = BuildFlagsList(na); - mysqlpp::Query query(Me->Con); + 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 : "") << ", "; @@ -776,7 +784,7 @@ class DBMySQLWrite : public DBMySQL void OnChangeCoreDisplay(NickCore *nc, const std::string &newdisplay) { - mysqlpp::Query query(Me->Con); + 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; @@ -795,35 +803,35 @@ class DBMySQLWrite : public DBMySQL void OnNickSuspend(NickAlias *na) { - mysqlpp::Query query(Me->Con); + 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); + 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); + 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); + 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); + mysqlpp::Query query(me->Con); query << "DELETE FROM `anope_cs_access` WHERE `channel` = " << mysqlpp::quote << ci->name; ExecuteQuery(query); } @@ -849,7 +857,7 @@ class DBMySQLWrite : public DBMySQL void OnChanForbidden(ChannelInfo *ci) { - mysqlpp::Query query(Me->Con); + 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); @@ -857,7 +865,7 @@ class DBMySQLWrite : public DBMySQL void OnDelChan(ChannelInfo *ci) { - mysqlpp::Query query(Me->Con); + 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; @@ -874,7 +882,7 @@ class DBMySQLWrite : public DBMySQL void OnChanRegistered(ChannelInfo *ci) { - mysqlpp::Query query(Me->Con); + 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 : "") << ", "; @@ -895,7 +903,7 @@ class DBMySQLWrite : public DBMySQL void OnChanSuspend(ChannelInfo *ci) { - mysqlpp::Query query(Me->Con); + 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; @@ -906,7 +914,7 @@ class DBMySQLWrite : public DBMySQL void OnAkickAdd(ChannelInfo *ci, AutoKick *ak) { - mysqlpp::Query query(Me->Con); + 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)) @@ -921,14 +929,14 @@ class DBMySQLWrite : public DBMySQL void OnAkickDel(ChannelInfo *ci, AutoKick *ak) { - mysqlpp::Query query(Me->Con); + 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); + 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 << ") "; @@ -943,7 +951,7 @@ class DBMySQLWrite : public DBMySQL void OnBotDelete(BotInfo *bi) { - mysqlpp::Query query(Me->Con); + 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; @@ -952,7 +960,7 @@ class DBMySQLWrite : public DBMySQL EventReturn OnBotAssign(User *sender, ChannelInfo *ci, BotInfo *bi) { - mysqlpp::Query query(Me->Con); + 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; @@ -960,7 +968,7 @@ class DBMySQLWrite : public DBMySQL EventReturn OnBotUnAssign(User *sender, ChannelInfo *ci) { - mysqlpp::Query query(Me->Con); + mysqlpp::Query query(me->Con); query << "UPDATE `anope_cs_info` SET `botnick` = '' WHERE `name` = " << mysqlpp::quote << ci->name; ExecuteQuery(query); return EVENT_CONTINUE; @@ -968,7 +976,7 @@ class DBMySQLWrite : public DBMySQL void OnBadWordAdd(ChannelInfo *ci, BadWord *bw) { - mysqlpp::Query query(Me->Con); + 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) { @@ -990,7 +998,7 @@ class DBMySQLWrite : public DBMySQL void OnBadWordDel(ChannelInfo *ci, BadWord *bw) { - mysqlpp::Query query(Me->Con); + 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) { @@ -1012,7 +1020,7 @@ class DBMySQLWrite : public DBMySQL void OnMemoSend(User *, NickCore *nc, Memo *m) { - mysqlpp::Query query(Me->Con); + 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')"; @@ -1021,7 +1029,7 @@ class DBMySQLWrite : public DBMySQL void OnMemoSend(User *, ChannelInfo *ci, Memo *m) { - mysqlpp::Query query(Me->Con); + 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')"; @@ -1030,7 +1038,7 @@ class DBMySQLWrite : public DBMySQL void OnMemoDel(NickCore *nc, MemoInfo *mi, int number) { - mysqlpp::Query query(Me->Con); + mysqlpp::Query query(me->Con); if (number) query << "DELETE FROM `anope_ms_info` WHERE `receiver` = " << mysqlpp::quote << nc->display << " AND `number` = " << number; else @@ -1040,7 +1048,7 @@ class DBMySQLWrite : public DBMySQL void OnMemoDel(ChannelInfo *ci, MemoInfo *mi, int number) { - mysqlpp::Query query(Me->Con); + mysqlpp::Query query(me->Con); if (number) query << "DELETE FROM `anope_ms_info` WHERE `receiver` = " << mysqlpp::quote << ci->name << " AND `number` = " << number; else @@ -1050,7 +1058,7 @@ class DBMySQLWrite : public DBMySQL EventReturn OnAddAkill(User *, Akill *ak) { - mysqlpp::Query query(Me->Con); + 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 << ")"; @@ -1060,7 +1068,7 @@ class DBMySQLWrite : public DBMySQL void OnDelAkill(User *, Akill *ak) { - mysqlpp::Query query(Me->Con); + mysqlpp::Query query(me->Con); if (ak) query << "DELETE FROM `anope_os_akills` WHERE `host` = " << mysqlpp::quote << ak->host; else @@ -1070,7 +1078,7 @@ class DBMySQLWrite : public DBMySQL EventReturn OnExceptionAdd(User *, Exception *ex) { - mysqlpp::Query query(Me->Con); + 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 << ")"; @@ -1080,14 +1088,14 @@ class DBMySQLWrite : public DBMySQL void OnExceptionDel(User *, Exception *ex) { - mysqlpp::Query query(Me->Con); + mysqlpp::Query query(me->Con); query << "DELETE FROM `anope_os_exceptions` WHERE `mask` = " << mysqlpp::quote << ex->mask; ExecuteQuery(query); } EventReturn OnAddSXLine(User *, SXLine *sx, SXLineType Type) { - mysqlpp::Query query(Me->Con); + 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; @@ -1098,7 +1106,7 @@ class DBMySQLWrite : public DBMySQL void OnDelSXLine(User *, SXLine *sx, SXLineType Type) { - mysqlpp::Query query(Me->Con); + mysqlpp::Query query(me->Con); if (sx) { query << "DELETE FROM `anope_os_sxlines` WHERE `mask` = " << mysqlpp::quote << sx->mask << " AND `type` = '"; -- cgit From f049124905bd9f53439293e873003cb027a17b91 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 14 May 2010 20:35:38 -0400 Subject: Rewrote the hashing system to use std::tr1::unordered_map --- src/modules/mysql/db_mysql.h | 7 -- src/modules/mysql/db_mysql_execute.cpp | 25 ++--- src/modules/mysql/db_mysql_read.cpp | 8 +- src/modules/mysql/db_mysql_write.cpp | 174 ++++++++++++++------------------- 4 files changed, 86 insertions(+), 128 deletions(-) (limited to 'src/modules/mysql') diff --git a/src/modules/mysql/db_mysql.h b/src/modules/mysql/db_mysql.h index 12956262a..f2885408f 100644 --- a/src/modules/mysql/db_mysql.h +++ b/src/modules/mysql/db_mysql.h @@ -98,13 +98,6 @@ struct BotServFlagInfo BotServFlagInfo BotServFlags[] = { {"PRIVATE", BI_PRIVATE}, - {"CHANSERV", BI_CHANSERV}, - {"BOTSERV", BI_BOTSERV}, - {"HOSTSERV", BI_HOSTSERV}, - {"OPERSERV", BI_OPERSERV}, - {"MEMOSERV", BI_MEMOSERV}, - {"NICKSERV", BI_NICKSERV}, - {"GLOBAL", BI_GLOBAL}, {"", static_cast(-1)} }; diff --git a/src/modules/mysql/db_mysql_execute.cpp b/src/modules/mysql/db_mysql_execute.cpp index 3933d54d1..356f7c0f2 100644 --- a/src/modules/mysql/db_mysql_execute.cpp +++ b/src/modules/mysql/db_mysql_execute.cpp @@ -8,17 +8,12 @@ class FakeNickCore : public NickCore public: FakeNickCore() : NickCore("-SQLUser") { - if (this->next) - this->next->prev = this->prev; - if (this->prev) - this->prev->next = this->next; - else - nclists[HASH(this->display)] = this->next; + NickCoreList.erase(this->display); } ~FakeNickCore() { - insert_core(this); + NickCoreList[this->display] = this; Users.clear(); } @@ -39,23 +34,15 @@ class FakeUser : public User this->vhost = NULL; this->server = Me; - if (this->prev) - this->prev->next = this->next; - else - userlist[HASH(this->nick.c_str())] = this->next; - if (this->next) - this->next->prev = this->prev; + UserListByNick.erase("-SQLUser"); --usercnt; } ~FakeUser() { - User **list = &userlist[HASH(this->nick.c_str())]; - this->next = *list; - if (*list) - (*list)->prev = this; - *list = this; + UserListByNick["-SQLUser"] = this; ++usercnt; + nc = NULL; } @@ -145,7 +132,7 @@ class SQLTimer : public Timer // XXX this whole strtok thing needs to die char *cmdbuf = sstrdup(qres[i]["command"].c_str()); char *cmd = strtok(cmdbuf, " "); - mod_run_cmd(bi->nick, u, bi->cmdTable, cmd); + mod_run_cmd(bi, u, cmd); delete [] cmdbuf; if (logout) diff --git a/src/modules/mysql/db_mysql_read.cpp b/src/modules/mysql/db_mysql_read.cpp index 728e4b882..79e59c9eb 100644 --- a/src/modules/mysql/db_mysql_read.cpp +++ b/src/modules/mysql/db_mysql_read.cpp @@ -166,7 +166,13 @@ static void LoadDatabase() { for (size_t i = 0; i < qres.num_rows(); ++i) { - BotInfo *bi = new BotInfo(SQLAssign(qres[i]["nick"]), SQLAssign(qres[i]["user"]), SQLAssign(qres[i]["host"]), SQLAssign(qres[i]["rname"])); + 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"])); diff --git a/src/modules/mysql/db_mysql_write.cpp b/src/modules/mysql/db_mysql_write.cpp index 5f3218381..2f7a42bb3 100644 --- a/src/modules/mysql/db_mysql_write.cpp +++ b/src/modules/mysql/db_mysql_write.cpp @@ -230,51 +230,47 @@ static void SaveDatabases() { mysqlpp::Query query(me->Con); - query << "TRUNCATE TABLE `anope_ns_core`"; - ExecuteQuery(query); query << "TRUNCATE TABLE `anope_ns_alias`"; ExecuteQuery(query); - for (int i = 0; i < 1024; ++i) + for (nickalias_map::const_iterator it = NickAliasList.begin(); it != NickAliasList.end(); ++it) { - for (NickAlias *na = nalists[i]; na; na = na->next) - { - me->OnNickRegister(na); - } + NickAlias *na = it->second; + + me->OnNickRegister(na); } - query << "TRUNCATE TABLE `anope_ns_access`"; + query << "TRUNCATE TABLE `anope_ns_core`"; ExecuteQuery(query); query << "TRUNCATE TABLE `anope_ms_info`"; ExecuteQuery(query); - - for (int i = 0; i < 1024; ++i) + + for (nickcore_map::const_iterator nit = NickCoreList.begin(); nit != NickCoreList.end(); ++nit) { - for (NickCore *nc = nclists[i]; nc; nc = nc->next) + NickCore *nc = nit->second; + + for (std::vector::iterator it = nc->access.begin(); it != nc->access.end(); ++it) { - for (std::vector::iterator it = nc->access.begin(); it != nc->access.end(); ++it) - { - query << "INSERT DELAYED INTO `anope_ns_access` (display, access) VALUES(" << mysqlpp::quote << nc->display << ", " << mysqlpp::quote << *it << ")"; - ExecuteQuery(query); - } + query << "INSERT DELAYED INTO `anope_ns_access` (display, access) VALUES(" << mysqlpp::quote << nc->display << ", " << mysqlpp::quote << *it << ")"; + ExecuteQuery(query); + } - for (unsigned j = 0; j < nc->memos.memos.size(); ++j) - { - Memo *m = nc->memos.memos[j]; + for (unsigned j = 0; j < nc->memos.memos.size(); ++j) + { + Memo *m = nc->memos.memos[j]; - me->OnMemoSend(NULL, nc, m); - } + me->OnMemoSend(NULL, nc, m); } } + query << "TRUNCATE TABLE `anope_bs_core`"; ExecuteQuery(query); - for (int i = 0; i < 256; ++i) + + for (botinfo_map::const_iterator it = BotList.begin(); it != BotList.end(); ++it) { - for (BotInfo *bi = botlists[i]; bi; bi = bi->next) - { - me->OnBotCreate(bi); - } + BotInfo *bi = it->second; + me->OnBotCreate(bi); } query << "TRUNCATE TABLE `anope_cs_info`"; @@ -288,67 +284,54 @@ static void SaveDatabases() query << "TRUNCATE TABLE `anope_cs_levels`"; ExecuteQuery(query); - for (int i = 0; i < 256; ++i) + for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(); it != RegisteredChannelList.end(); ++it) { - for (ChannelInfo *ci = chanlists[i]; ci; ci = ci->next) - { - me->OnChanRegistered(ci); + ChannelInfo *ci = it->second; + + me->OnChanRegistered(ci); - for (unsigned j = 0; j < ci->GetBadWordCount(); ++j) - { - BadWord *bw = ci->GetBadWord(j); + for (unsigned j = 0; j < ci->GetBadWordCount(); ++j) + { + BadWord *bw = ci->GetBadWord(j); - if (bw->InUse) - { - me->OnBadWordAdd(ci, bw); - } - } + me->OnBadWordAdd(ci, bw); + } - for (unsigned j = 0; j < ci->GetAccessCount(); ++j) - { - ChanAccess *access = ci->GetAccess(j); + for (unsigned j = 0; j < ci->GetAccessCount(); ++j) + { + ChanAccess *access = ci->GetAccess(j); - if (access->in_use) - { - 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); - } - } + 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; j < ci->GetAkickCount(); ++j) - { - AutoKick *ak = ci->GetAkick(j); + for (unsigned j = 0; j < ci->GetAkickCount(); ++j) + { + AutoKick *ak = ci->GetAkick(j); - if (ak->InUse) - { - me->OnAkickAdd(ci, ak); - } - } + me->OnAkickAdd(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 (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; j < ci->memos.memos.size(); ++j) - { - Memo *m = ci->memos.memos[j]; + for (unsigned j = 0; j < ci->memos.memos.size(); ++j) + { + Memo *m = ci->memos.memos[j]; - me->OnMemoSend(NULL, ci, m); - } + me->OnMemoSend(NULL, ci, m); } } query << "TRUNCATE TABLE `anope_ns_request`"; ExecuteQuery(query); - for (int i = 0; i < 1024; i++) + for (nickrequest_map::const_iterator it = NickRequestList.begin(); it != NickRequestList.end(); ++it) { - for (NickRequest *nr = nrlists[i]; nr; nr = nr->next) - { - me->OnMakeNickRequest(nr); - } + me->OnMakeNickRequest(it->second); } for (int i = 0; i < akills.count; ++i) @@ -418,7 +401,7 @@ class DBMySQLWrite : public DBMySQL ModuleManager::Attach(I_OnServerConnect, this); - this->AddCommand(OPERSERV, new CommandSyncSQL("SQLSYNC")); + this->AddCommand(OperServ, new CommandSyncSQL("SQLSYNC")); if (uplink_server) OnServerConnect(); @@ -470,46 +453,35 @@ class DBMySQLWrite : public DBMySQL query << maxusercnt << ", " << maxusertime << ", " << akills.count << ", " << sqlines.count << ", " << sglines.count << ", " << szlines.count << ")"; ExecuteQuery(query); - for (int i = 0; i < 1024; ++i) + for (nickcore_map::const_iterator it = NickCoreList.begin(); it != NickCoreList.end(); ++it) { - for (NickCore *nc = nclists[i]; nc; nc = nc->next) - { - CurCore = nc; - FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteCoreMetadata, nc)); - } + CurCore = it->second; + FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteCoreMetadata, CurCore)); } - for (int i = 0; i < 1024; ++i) + for (nickalias_map::const_iterator it = NickAliasList.begin(); it != NickAliasList.end(); ++it) { - for (NickAlias *na = nalists[i]; na; na = na->next) - { - CurNick = na; - FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteNickMetadata, na)); - } + CurNick = it->second; + FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteNickMetadata, CurNick)); } - for (int i = 0; i < 256; ++i) + for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(); it != RegisteredChannelList.end(); ++it) { - for (ChannelInfo *ci = chanlists[i]; ci; ci = ci->next) - { - CurChannel = ci; - FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteChannelMetadata, ci)); - } + CurChannel = it->second; + FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteChannelMetadata, CurChannel)); } - for (int i = 0; i < 256; ++i) + for (botinfo_map::const_iterator it = BotList.begin(); it != BotList.end(); ++it) { - 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); - } + 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)); -- cgit From 3a2c2a916a26f4fa1844e71a9f1c2fc25337fd2b Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 19 May 2010 16:59:16 -0400 Subject: Dont load mlock from the database until after Anope is connected, it doesnt know all of the available modes until then --- src/modules/mysql/db_mysql_read.cpp | 60 +++++++++--------------------------- src/modules/mysql/db_mysql_write.cpp | 4 +-- 2 files changed, 17 insertions(+), 47 deletions(-) (limited to 'src/modules/mysql') diff --git a/src/modules/mysql/db_mysql_read.cpp b/src/modules/mysql/db_mysql_read.cpp index 79e59c9eb..1b4ce33fa 100644 --- a/src/modules/mysql/db_mysql_read.cpp +++ b/src/modules/mysql/db_mysql_read.cpp @@ -272,67 +272,37 @@ static void LoadDatabase() ci->bantype = atoi(qres[i]["bantype"].c_str()); if (qres[i]["mlock_on"].size()) { + std::vector modes; std::string buf; + spacesepstream sep(SQLAssign(qres[i]["mlock_on"])); while (sep.GetToken(buf)) - { - for (std::list::iterator it = ModeManager::Modes.begin(); it != ModeManager::Modes.end(); ++it) - { - if ((*it)->Class == MC_CHANNEL) - { - ChannelMode *cm = dynamic_cast(*it); + modes.push_back(buf); - if (buf == cm->NameAsString) - { - ci->SetMLock(cm->Name, true); - break; - } - } - } - } + ci->Extend("db_mlock_modes_on", new ExtensibleItemRegular >(modes)); } if (qres[i]["mlock_off"].size()) { + std::vector modes; std::string buf; + spacesepstream sep(SQLAssign(qres[i]["mlock_off"])); while (sep.GetToken(buf)) - { - for (std::list::iterator it = ModeManager::Modes.begin(); it != ModeManager::Modes.end(); ++it) - { - if ((*it)->Class == MC_CHANNEL) - { - ChannelMode *cm = dynamic_cast(*it); + modes.push_back(buf); - if (buf == cm->NameAsString) - { - ci->SetMLock(cm->Name, false); - break; - } - } - } - } + ci->Extend("db_mlock_modes_off", new ExtensibleItemRegular >(modes)); } if (qres[i]["mlock_params"].size()) { - std::string buf; + std::vector > mlp; + std::string buf, buf2; + spacesepstream sep(SQLAssign(qres[i]["mlock_params"])); - while (sep.GetToken(buf)) - { - for (std::list::iterator it = ModeManager::Modes.begin(); it != ModeManager::Modes.end(); ++it) - { - if ((*it)->Class == MC_CHANNEL) - { - ChannelMode *cm = dynamic_cast(*it); - if (buf == cm->NameAsString) - { - sep.GetToken(buf); - ci->SetMLock(cm->Name, true, buf); - break; - } - } - } - } + while (sep.GetToken(buf) && sep.GetToken(buf2)) + mlp.push_back(std::make_pair(buf, buf2)); + + ci->Extend("db_mlp", new ExtensibleItemRegular > >(mlp)); } if (qres[i]["entry_message"].size()) ci->entry_message = sstrdup(qres[i]["entry_message"].c_str()); diff --git a/src/modules/mysql/db_mysql_write.cpp b/src/modules/mysql/db_mysql_write.cpp index 2f7a42bb3..1888195f3 100644 --- a/src/modules/mysql/db_mysql_write.cpp +++ b/src/modules/mysql/db_mysql_write.cpp @@ -309,7 +309,7 @@ static void SaveDatabases() { AutoKick *ak = ci->GetAkick(j); - me->OnAkickAdd(ci, ak); + me->OnAkickAdd(NULL, ci, ak); } for (int k = 0; k < CA_SIZE; ++k) @@ -810,7 +810,7 @@ class DBMySQLWrite : public DBMySQL void OnLevelChange(User *u, ChannelInfo *ci, int pos, int what) { - mysqlpp::Query query(Me->Con); + mysqlpp::Query query(me->Con); if (pos >= 0) { -- cgit From 2fba686904e6f78ebab35df171c5757afeebf05d Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 24 May 2010 23:36:40 -0500 Subject: Burned slist, rewrote operservs XLine code --- src/modules/mysql/db_mysql_read.cpp | 57 +++++++++++++++----------- src/modules/mysql/db_mysql_write.cpp | 77 ++++++++++++++++++------------------ 2 files changed, 72 insertions(+), 62 deletions(-) (limited to 'src/modules/mysql') diff --git a/src/modules/mysql/db_mysql_read.cpp b/src/modules/mysql/db_mysql_read.cpp index 1b4ce33fa..3c5fb359a 100644 --- a/src/modules/mysql/db_mysql_read.cpp +++ b/src/modules/mysql/db_mysql_read.cpp @@ -620,42 +620,51 @@ static void LoadDatabase() query << "SELECT * FROM `anope_os_akills`"; qres = StoreQuery(query); - if (qres) + if (qres && SGLine) { 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); + 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_sxlines`"; + query << "SELECT * FROM `anope_os_xlines`"; 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; + 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; + } } } } diff --git a/src/modules/mysql/db_mysql_write.cpp b/src/modules/mysql/db_mysql_write.cpp index 1888195f3..427be43bd 100644 --- a/src/modules/mysql/db_mysql_write.cpp +++ b/src/modules/mysql/db_mysql_write.cpp @@ -235,9 +235,7 @@ static void SaveDatabases() for (nickalias_map::const_iterator it = NickAliasList.begin(); it != NickAliasList.end(); ++it) { - NickAlias *na = it->second; - - me->OnNickRegister(na); + me->OnNickRegister(it->second); } query << "TRUNCATE TABLE `anope_ns_core`"; @@ -269,8 +267,7 @@ static void SaveDatabases() for (botinfo_map::const_iterator it = BotList.begin(); it != BotList.end(); ++it) { - BotInfo *bi = it->second; - me->OnBotCreate(bi); + me->OnBotCreate(it->second); } query << "TRUNCATE TABLE `anope_cs_info`"; @@ -311,7 +308,7 @@ static void SaveDatabases() 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)"; @@ -334,32 +331,36 @@ static void SaveDatabases() me->OnMakeNickRequest(it->second); } - for (int i = 0; i < akills.count; ++i) + if (SGLine) { - Akill *ak = static_cast(akills.list[i]); - - me->OnAddAkill(NULL, ak); + for (unsigned i = 0; i < SGLine->GetCount(); ++i) + { + me->OnAddAkill(NULL, SGLine->GetEntry(i)); + } } - for (int i = 0; i < sglines.count; ++i) + if (SZLine) { - SXLine *x = static_cast(sglines.list[i]); - - me->OnAddSXLine(NULL, x, SX_SGLINE); + for (unsigned i = 0; i < SZLine->GetCount(); ++i) + { + me->OnAddXLine(NULL, SZLine->GetEntry(i), X_SZLINE); + } } - for (int i = 0; i < sqlines.count; ++i) + if (SQLine) { - SXLine *x = static_cast(sqlines.list[i]); - - me->OnAddSXLine(NULL, x, SX_SQLINE); + for (unsigned i = 0; i < SQLine->GetCount(); ++i) + { + me->OnAddXLine(NULL, SQLine->GetEntry(i), X_SQLINE); + } } - for (int i = 0; i < szlines.count; ++i) + if (SNLine) { - SXLine *x = static_cast(szlines.list[i]); - - me->OnAddSXLine(NULL, x, SX_SZLINE); + for (unsigned i = 0; i < SNLine->GetCount(); ++i) + { + me->OnAddXLine(NULL, SNLine->GetEntry(i), X_SNLINE); + } } for (int i = 0; i < nexceptions; ++i) @@ -433,7 +434,7 @@ class DBMySQLWrite : public DBMySQL I_OnMemoSend, I_OnMemoDel, /* OperServ */ I_OnOperServHelp, I_OnAddAkill, I_OnDelAkill, I_OnExceptionAdd, I_OnExceptionDel, - I_OnAddSXLine, I_OnDelSXLine + I_OnAddXLine, I_OnDelXLine }; ModuleManager::Attach(i, this, 40); } @@ -450,7 +451,7 @@ class DBMySQLWrite : public DBMySQL 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 << ", " << akills.count << ", " << sqlines.count << ", " << sglines.count << ", " << szlines.count << ")"; + 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 != NickCoreList.end(); ++it) @@ -1028,21 +1029,21 @@ class DBMySQLWrite : public DBMySQL ExecuteQuery(query); } - EventReturn OnAddAkill(User *, Akill *ak) + 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->user << ", " << mysqlpp::quote << ak->host << ", " << mysqlpp::quote << ak->by; - query << ", " << mysqlpp::quote << ak->reason << ", " << ak->seton << ", " << ak->expires << ")"; + 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 *, Akill *ak) + void OnDelAkill(User *, XLine *ak) { mysqlpp::Query query(me->Con); if (ak) - query << "DELETE FROM `anope_os_akills` WHERE `host` = " << mysqlpp::quote << ak->host; + query << "DELETE FROM `anope_os_akills` WHERE `host` = " << mysqlpp::quote << ak->GetHost().c_str(); else query << "TRUNCATE TABLE `anope_os_akills`"; ExecuteQuery(query); @@ -1065,27 +1066,27 @@ class DBMySQLWrite : public DBMySQL ExecuteQuery(query); } - EventReturn OnAddSXLine(User *, SXLine *sx, SXLineType Type) + 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 == 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 << ")"; + 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 OnDelSXLine(User *, SXLine *sx, SXLineType Type) + void OnDelXLine(User *, XLine *x, XLineType Type) { mysqlpp::Query query(me->Con); - if (sx) + if (x) { - query << "DELETE FROM `anope_os_sxlines` WHERE `mask` = " << mysqlpp::quote << sx->mask << " AND `type` = '"; - query << (Type == SX_SGLINE ? "SGLINE" : (Type == SX_SQLINE ? "SQLINE" : "SZLINE")) << "'"; + 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_sxlines` WHERE `type` = '" << (Type == SX_SGLINE ? "SGLINE" : (Type == SX_SQLINE ? "SQLINE" : "SZLINE")) << "'"; + query << "DELETE FROM `anope_os_xlines` WHERE `type` = '" << (Type == X_SNLINE ? "SNLINE" : (Type == X_SQLINE ? "SQLINE" : "SZLINE")) << "'"; ExecuteQuery(query); } }; -- cgit From 1394c96173cec02d148dfece563bb186cf2f33b6 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 26 May 2010 02:53:08 -0500 Subject: Removed a lot of unnecessary .c_str() calls in the find* functions --- src/modules/mysql/db_mysql_execute.cpp | 1 - src/modules/mysql/db_mysql_write.cpp | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) (limited to 'src/modules/mysql') diff --git a/src/modules/mysql/db_mysql_execute.cpp b/src/modules/mysql/db_mysql_execute.cpp index 356f7c0f2..4e4e859cb 100644 --- a/src/modules/mysql/db_mysql_execute.cpp +++ b/src/modules/mysql/db_mysql_execute.cpp @@ -1,7 +1,6 @@ /* RequiredLibraries: mysqlpp */ #include "db_mysql.h" -#define HASH(nick) (((nick)[0]&31)<<5 | ((nick)[1]&31)) class FakeNickCore : public NickCore { diff --git a/src/modules/mysql/db_mysql_write.cpp b/src/modules/mysql/db_mysql_write.cpp index 427be43bd..4c9772eef 100644 --- a/src/modules/mysql/db_mysql_write.cpp +++ b/src/modules/mysql/db_mysql_write.cpp @@ -499,7 +499,7 @@ class DBMySQLWrite : public DBMySQL 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].c_str())); + NickCore *nc = (command == "SET" ? u->Account() : findcore(params[0])); if (!nc) return; if (cmd == "PASSWORD" && params.size() > 1) @@ -543,7 +543,7 @@ class DBMySQLWrite : public DBMySQL { if (command == "SET" && u->Account() && params.size() > 1) { - ChannelInfo *ci = cs_findchan(params[0].c_str()); + ChannelInfo *ci = cs_findchan(params[0]); if (!ci) return; if (!u->Account()->HasPriv("chanserv/set") && check_access(u, ci, CA_SET)) @@ -603,7 +603,7 @@ class DBMySQLWrite : public DBMySQL { if (command == "KICK" && params.size() > 2) { - ChannelInfo *ci = cs_findchan(params[0].c_str()); + ChannelInfo *ci = cs_findchan(params[0]); if (!ci) return; if (!check_access(u, ci, CA_SET) && !u->Account()->HasPriv("botserv/administration")) @@ -641,12 +641,12 @@ class DBMySQLWrite : public DBMySQL } else if (command == "SET" && params.size() > 2) { - ChannelInfo *ci = cs_findchan(params[0].c_str()); + 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].c_str()); + 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; -- cgit From 435c9116e9997634eb7215e998c8f01a5e46fb2c Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 28 May 2010 18:27:22 -0400 Subject: Added an arg to User::IsRecognized to check for NI_SECURE --- src/modules/mysql/db_mysql_execute.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/modules/mysql') diff --git a/src/modules/mysql/db_mysql_execute.cpp b/src/modules/mysql/db_mysql_execute.cpp index 4e4e859cb..572dd2917 100644 --- a/src/modules/mysql/db_mysql_execute.cpp +++ b/src/modules/mysql/db_mysql_execute.cpp @@ -52,6 +52,7 @@ class FakeUser : public User 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 @@ -155,7 +156,7 @@ class DBMySQLExecute : public DBMySQL ~DBMySQLExecute() { - TimerManager::DelTimer(_SQLTimer); + delete _SQLTimer; } }; -- cgit From b8f9116b19eb511c4f5e6a683725f50bf732a7dd Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 29 May 2010 20:44:31 -0400 Subject: Rewrote all of the command handling to get rid of all the nasty strtoks() everywhere, and added a bot map by uid --- src/modules/mysql/db_mysql_execute.cpp | 6 +----- src/modules/mysql/db_mysql_write.cpp | 4 ++-- 2 files changed, 3 insertions(+), 7 deletions(-) (limited to 'src/modules/mysql') diff --git a/src/modules/mysql/db_mysql_execute.cpp b/src/modules/mysql/db_mysql_execute.cpp index 572dd2917..2313edd37 100644 --- a/src/modules/mysql/db_mysql_execute.cpp +++ b/src/modules/mysql/db_mysql_execute.cpp @@ -129,11 +129,7 @@ class SQLTimer : public Timer continue; } - // XXX this whole strtok thing needs to die - char *cmdbuf = sstrdup(qres[i]["command"].c_str()); - char *cmd = strtok(cmdbuf, " "); - mod_run_cmd(bi, u, cmd); - delete [] cmdbuf; + mod_run_cmd(bi, u, qres[i]["command"].c_str()); if (logout) u->Logout(); diff --git a/src/modules/mysql/db_mysql_write.cpp b/src/modules/mysql/db_mysql_write.cpp index 4c9772eef..fdb11562f 100644 --- a/src/modules/mysql/db_mysql_write.cpp +++ b/src/modules/mysql/db_mysql_write.cpp @@ -265,7 +265,7 @@ static void SaveDatabases() query << "TRUNCATE TABLE `anope_bs_core`"; ExecuteQuery(query); - for (botinfo_map::const_iterator it = BotList.begin(); it != BotList.end(); ++it) + for (botinfo_map::const_iterator it = BotListByNick.begin(); it != BotListByNick.end(); ++it) { me->OnBotCreate(it->second); } @@ -472,7 +472,7 @@ class DBMySQLWrite : public DBMySQL FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteChannelMetadata, CurChannel)); } - for (botinfo_map::const_iterator it = BotList.begin(); it != BotList.end(); ++it) + for (botinfo_map::const_iterator it = BotListByNick.begin(); it != BotListByNick.end(); ++it) { CurBot = it->second; FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteBotMetadata, CurBot)); -- cgit From 6cd88494662c5c4af2da891926dcc82367596cb9 Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 30 May 2010 17:21:44 -0400 Subject: Moved the *Serv help functions to Command, will come in use later with subcommands --- src/modules/mysql/db_mysql_write.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/modules/mysql') diff --git a/src/modules/mysql/db_mysql_write.cpp b/src/modules/mysql/db_mysql_write.cpp index fdb11562f..b5686fa2f 100644 --- a/src/modules/mysql/db_mysql_write.cpp +++ b/src/modules/mysql/db_mysql_write.cpp @@ -391,6 +391,11 @@ class CommandSyncSQL : public Command 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 @@ -433,15 +438,10 @@ class DBMySQLWrite : public DBMySQL /* MemoServ */ I_OnMemoSend, I_OnMemoDel, /* OperServ */ - I_OnOperServHelp, I_OnAddAkill, I_OnDelAkill, I_OnExceptionAdd, I_OnExceptionDel, + I_OnAddAkill, I_OnDelAkill, I_OnExceptionAdd, I_OnExceptionDel, I_OnAddXLine, I_OnDelXLine }; - ModuleManager::Attach(i, this, 40); - } - - void OnOperServHelp(User *u) - { - notice_lang(Config.s_OperServ, u, OPER_HELP_CMD_SQLSYNC); + ModuleManager::Attach(i, this, 39); } EventReturn OnSaveDatabase() -- cgit