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_read.cpp | 43 +++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 14 deletions(-) (limited to 'src/modules/mysql/db_mysql_read.cpp') 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; + } } } } -- 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_read.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/modules/mysql/db_mysql_read.cpp') 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"])); -- 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 ++++++++++--------------------------- 1 file changed, 15 insertions(+), 45 deletions(-) (limited to 'src/modules/mysql/db_mysql_read.cpp') 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()); -- 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 +++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 24 deletions(-) (limited to 'src/modules/mysql/db_mysql_read.cpp') 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; + } } } } -- cgit