summaryrefslogtreecommitdiff
path: root/src/modules/mysql
diff options
context:
space:
mode:
authorNaram Qashat <cyberbotx@cyberbotx.com>2010-06-27 23:15:05 -0400
committerNaram Qashat <cyberbotx@cyberbotx.com>2010-06-27 23:15:05 -0400
commit28e12bc24a9c85f4f0d1e37567618ec39cb501f6 (patch)
treecc70ebeef95a9d95174afe3ef038b0d673346f58 /src/modules/mysql
parent051ebe3eea0f8529b64c0e443c61103ba2f7dee8 (diff)
The next of a few "CBX OCDing over code style" commits, maybe the last.
NOTES: I have been unable to compile the db_mysql_* functions on my system here, so those are untested. db-convert seems to be badly programmed and needs more work in my opinion.
Diffstat (limited to 'src/modules/mysql')
-rw-r--r--src/modules/mysql/db_mysql.h16
-rw-r--r--src/modules/mysql/db_mysql_execute.cpp4
-rw-r--r--src/modules/mysql/db_mysql_read.cpp130
-rw-r--r--src/modules/mysql/db_mysql_write.cpp131
4 files changed, 75 insertions, 206 deletions
diff --git a/src/modules/mysql/db_mysql.h b/src/modules/mysql/db_mysql.h
index f2885408f..34ae50931 100644
--- a/src/modules/mysql/db_mysql.h
+++ b/src/modules/mysql/db_mysql.h
@@ -1,3 +1,6 @@
+#ifndef DB_MYSQL_H
+#define DB_MYSQL_H
+
#include "module.h"
struct NickAliasFlagInfo
@@ -117,15 +120,15 @@ MemoFlagInfo MemoFlags[] = {
#define MYSQLPP_MYSQL_HEADERS_BURIED
#include <mysql++/mysql++.h>
-inline std::string SQLAssign(const mysqlpp::String& s) { return s.c_str(); }
+inline std::string SQLAssign(const mysqlpp::String &s) { return s.c_str(); }
class DBMySQL;
static DBMySQL *me;
-bool ExecuteQuery(mysqlpp::Query& query)
+bool ExecuteQuery(mysqlpp::Query &query)
{
Alog(LOG_DEBUG) << "MySQL: " << query.str();
-
+
if (!query.execute())
{
Alog() << "MySQL: error executing query: " << query.error();
@@ -135,15 +138,13 @@ bool ExecuteQuery(mysqlpp::Query& query)
return true;
}
-mysqlpp::StoreQueryResult StoreQuery(mysqlpp::Query& query)
+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;
}
@@ -195,7 +196,7 @@ class DBMySQL : public Module
delete Con;
throw ModuleException(Error.c_str());
}
-
+
mysqlpp::Query query(Con);
query << "SET NAMES 'utf8'";
ExecuteQuery(query);
@@ -208,3 +209,4 @@ class DBMySQL : public Module
}
};
+#endif // DB_MYSQL_H
diff --git a/src/modules/mysql/db_mysql_execute.cpp b/src/modules/mysql/db_mysql_execute.cpp
index 2313edd37..2cc6ab6df 100644
--- a/src/modules/mysql/db_mysql_execute.cpp
+++ b/src/modules/mysql/db_mysql_execute.cpp
@@ -75,7 +75,7 @@ class SQLTimer : public Timer
if (qres && qres.num_rows())
{
- for (size_t i = 0; i < qres.num_rows(); ++i)
+ for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
{
User *u;
NickAlias *na = NULL;
@@ -149,7 +149,7 @@ class DBMySQLExecute : public DBMySQL
{
_SQLTimer = new SQLTimer();
}
-
+
~DBMySQLExecute()
{
delete _SQLTimer;
diff --git a/src/modules/mysql/db_mysql_read.cpp b/src/modules/mysql/db_mysql_read.cpp
index 3c5fb359a..3ffc82366 100644
--- a/src/modules/mysql/db_mysql_read.cpp
+++ b/src/modules/mysql/db_mysql_read.cpp
@@ -34,8 +34,7 @@ static void LoadDatabase()
qres = StoreQuery(query);
if (qres)
- {
- for (size_t i = 0; i < qres.num_rows(); ++i)
+ 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"]);
@@ -51,28 +50,20 @@ static void LoadDatabase()
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; i < qres.num_rows(); ++i)
+ for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
{
NickCore *nc = findcore(qres[i]["display"].c_str());
if (!nc)
@@ -83,14 +74,12 @@ static void LoadDatabase()
nc->AddAccess(SQLAssign(qres[i]["access"]));
}
- }
query << "SELECT * FROM `anope_ns_core_metadata`";
qres = StoreQuery(query);
if (qres)
- {
- for (size_t i = 0; i < qres.num_rows(); ++i)
+ for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
{
NickCore *nc = findcore(qres[i]["display"].c_str());
if (!nc)
@@ -102,14 +91,12 @@ static void LoadDatabase()
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; i < qres.num_rows(); ++i)
+ for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
{
NickCore *nc = findcore(qres[i]["display"].c_str());
if (!nc)
@@ -128,24 +115,16 @@ static void LoadDatabase()
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; i < qres.num_rows(); ++i)
+ for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
{
NickAlias *na = findnick(SQLAssign(qres[i]["nick"]));
if (!na)
@@ -157,14 +136,12 @@ static void LoadDatabase()
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; i < qres.num_rows(); ++i)
+ for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
{
BotInfo *bi = findbot(SQLAssign(qres[i]["nick"]));
if (!bi)
@@ -178,28 +155,22 @@ static void LoadDatabase()
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; i < qres.num_rows(); ++i)
+ for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
{
BotInfo *bi = findbot(SQLAssign(qres[i]["botname"]));
if (!bi)
@@ -212,14 +183,12 @@ static void LoadDatabase()
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; i < qres.num_rows(); ++i)
+ for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
{
NickCore *nc;
if (qres[i]["founder"].size())
@@ -254,16 +223,12 @@ static void LoadDatabase()
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());
@@ -316,16 +281,12 @@ static void LoadDatabase()
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())
@@ -339,14 +300,12 @@ static void LoadDatabase()
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; i < qres.num_rows(); ++i)
+ for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
{
ChannelInfo *ci = cs_findchan(SQLAssign(qres[i]["channel"]));
if (!ci)
@@ -357,14 +316,12 @@ static void LoadDatabase()
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; i < qres.num_rows(); ++i)
+ for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
{
ChannelInfo *ci = cs_findchan(SQLAssign(qres[i]["channel"]));
if (!ci)
@@ -372,7 +329,7 @@ static void LoadDatabase()
Alog() << "MySQL: Channel badwords entry for nonexistant channel " << qres[i]["channel"];
continue;
}
-
+
BadWordType BWTYPE = BW_ANY;
if (qres[i]["type"] == "SINGLE")
BWTYPE = BW_SINGLE;
@@ -382,14 +339,12 @@ static void LoadDatabase()
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; i < qres.num_rows(); ++i)
+ for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
{
ChannelInfo *ci = cs_findchan(SQLAssign(qres[i]["channel"]));
if (!ci)
@@ -406,14 +361,12 @@ static void LoadDatabase()
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; i < qres.num_rows(); ++i)
+ for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
{
ChannelInfo *ci = cs_findchan(SQLAssign(qres[i]["channel"]));
if (!ci)
@@ -426,12 +379,10 @@ static void LoadDatabase()
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()));
@@ -442,14 +393,12 @@ static void LoadDatabase()
if (nc)
ak->SetFlag(AK_ISNICK);
}
- }
query << "SELECT * FROM `anope_cs_levels`";
qres = StoreQuery(query);
if (qres)
- {
- for (size_t i = 0; i < qres.num_rows(); ++i)
+ for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
{
ChannelInfo *ci = cs_findchan(SQLAssign(qres[i]["channel"]));
if (!ci)
@@ -459,14 +408,12 @@ static void LoadDatabase()
}
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; i < qres.num_rows(); ++i)
+ for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
{
ChannelInfo *ci = cs_findchan(SQLAssign(qres[i]["channel"]));
if (!ci)
@@ -474,19 +421,17 @@ static void LoadDatabase()
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; i < qres.num_rows(); ++i)
+ 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"]);
@@ -494,27 +439,23 @@ static void LoadDatabase()
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; i < qres.num_rows(); ++i)
+ 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; i < qres.num_rows(); ++i)
+ for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
{
NickCore *nc = findcore(qres[i]["nick"].c_str());
if (nc)
@@ -523,14 +464,12 @@ static void LoadDatabase()
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; i < qres.num_rows(); ++i)
+ for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
{
NickAlias *na = findnick(SQLAssign(qres[i]["nick"]));
if (na)
@@ -539,14 +478,12 @@ static void LoadDatabase()
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; i < qres.num_rows(); ++i)
+ for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
{
ChannelInfo *ci = cs_findchan(SQLAssign(qres[i]["channel"]));
if (ci)
@@ -555,14 +492,12 @@ static void LoadDatabase()
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; i < qres.num_rows(); ++i)
+ for (size_t i = 0, end = qres.num_rows(); i < end; ++i)
{
MemoInfo *mi = NULL;
if (qres[i]["serv"] == "NICK")
@@ -592,37 +527,27 @@ static void LoadDatabase()
}
}
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; i < qres.size(); ++i)
+ 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();
@@ -638,14 +563,12 @@ static void LoadDatabase()
x->Created = seton;
}
}
- }
query << "SELECT * FROM `anope_os_xlines`";
qres = StoreQuery(query);
if (qres)
- {
- for (size_t i = 0; i < qres.size(); ++i)
+ 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();
@@ -666,7 +589,6 @@ static void LoadDatabase()
x->Created = seton;
}
}
- }
}
class DBMySQLRead : public DBMySQL
diff --git a/src/modules/mysql/db_mysql_write.cpp b/src/modules/mysql/db_mysql_write.cpp
index b5686fa2f..c5c002a7e 100644
--- a/src/modules/mysql/db_mysql_write.cpp
+++ b/src/modules/mysql/db_mysql_write.cpp
@@ -7,12 +7,8 @@ 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());
@@ -25,12 +21,8 @@ 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());
@@ -43,12 +35,8 @@ 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());
@@ -61,16 +49,12 @@ 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;
}
@@ -78,16 +62,14 @@ static std::string MakeMLock(ChannelInfo *ci, bool status)
{
std::string ret;
- for (std::list<Mode *>::iterator it = ModeManager::Modes.begin(); it != ModeManager::Modes.end(); ++it)
+ 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 = dynamic_cast<ChannelMode *>(*it);
if (ci->HasMLock(cm->Name, status))
- {
ret += " " + cm->NameAsString;
- }
}
}
@@ -111,17 +93,15 @@ static std::string GetMLockParams(ChannelInfo *ci)
{
std::string ret;
- for (std::list<Mode *>::iterator it = ModeManager::Modes.begin(); it != ModeManager::Modes.end(); ++it)
+ 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 = dynamic_cast<ChannelMode *>(*it);
-
+
std::string param;
if (ci->GetParam(cm->Name, param))
- {
ret += " " + cm->NameAsString + " " + param;
- }
}
}
@@ -136,12 +116,8 @@ 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());
@@ -154,16 +130,12 @@ 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;
}
@@ -200,7 +172,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);
query << "INSERT DELAYED INTO `anope_ns_core_metadata` (nick, name, value) VALUES(" << mysqlpp::quote << CurCore->display << ", " << mysqlpp::quote << key << ", " << mysqlpp::quote << data << ")";
ExecuteQuery(query);
@@ -220,7 +192,7 @@ 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);
query << "INSERT DELAYED INTO `anope_bs_info_metadata` (botname, name, value) VALUES(" << mysqlpp::quote << CurBot->nick << ", " << mysqlpp::quote << key << ", " << mysqlpp::quote << data << ")";
ExecuteQuery(query);
@@ -233,27 +205,25 @@ static void SaveDatabases()
query << "TRUNCATE TABLE `anope_ns_alias`";
ExecuteQuery(query);
- for (nickalias_map::const_iterator it = NickAliasList.begin(); it != NickAliasList.end(); ++it)
- {
+ 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 != NickCoreList.end(); ++nit)
+
+ 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 != nc->access.end(); ++it)
+
+ 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; j < nc->memos.memos.size(); ++j)
+ for (unsigned j = 0, end = nc->memos.memos.size(); j < end; ++j)
{
Memo *m = nc->memos.memos[j];
@@ -264,11 +234,9 @@ static void SaveDatabases()
query << "TRUNCATE TABLE `anope_bs_core`";
ExecuteQuery(query);
-
- for (botinfo_map::const_iterator it = BotListByNick.begin(); it != BotListByNick.end(); ++it)
- {
+
+ 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);
@@ -281,20 +249,20 @@ static void SaveDatabases()
query << "TRUNCATE TABLE `anope_cs_levels`";
ExecuteQuery(query);
- for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(); it != RegisteredChannelList.end(); ++it)
+ 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; j < ci->GetBadWordCount(); ++j)
+ for (unsigned j = 0, end = ci->GetBadWordCount(); j < end; ++j)
{
BadWord *bw = ci->GetBadWord(j);
me->OnBadWordAdd(ci, bw);
}
- for (unsigned j = 0; j < ci->GetAccessCount(); ++j)
+ for (unsigned j = 0, end = ci->GetAccessCount(); j < end; ++j)
{
ChanAccess *access = ci->GetAccess(j);
@@ -302,20 +270,20 @@ static void SaveDatabases()
ExecuteQuery(query);
}
- for (unsigned j = 0; j < ci->GetAkickCount(); ++j)
+ 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; j < ci->memos.memos.size(); ++j)
+ for (unsigned j = 0, end = ci->memos.memos.size(); j < end; ++j)
{
Memo *m = ci->memos.memos[j];
@@ -326,42 +294,24 @@ static void SaveDatabases()
query << "TRUNCATE TABLE `anope_ns_request`";
ExecuteQuery(query);
- for (nickrequest_map::const_iterator it = NickRequestList.begin(); it != NickRequestList.end(); ++it)
- {
+ 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; i < SGLine->GetCount(); ++i)
- {
+ for (unsigned i = 0, end = SGLine->GetCount(); i < end; ++i)
me->OnAddAkill(NULL, SGLine->GetEntry(i));
- }
- }
if (SZLine)
- {
- for (unsigned i = 0; i < SZLine->GetCount(); ++i)
- {
+ for (unsigned i = 0, end = SZLine->GetCount(); i < end; ++i)
me->OnAddXLine(NULL, SZLine->GetEntry(i), X_SZLINE);
- }
- }
if (SQLine)
- {
- for (unsigned i = 0; i < SQLine->GetCount(); ++i)
- {
+ for (unsigned i = 0, end = SQLine->GetCount(); i < end; ++i)
me->OnAddXLine(NULL, SQLine->GetEntry(i), X_SQLINE);
- }
- }
if (SNLine)
- {
- for (unsigned i = 0; i < SNLine->GetCount(); ++i)
- {
+ 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)
{
@@ -408,7 +358,7 @@ class DBMySQLWrite : public DBMySQL
ModuleManager::Attach(I_OnServerConnect, this);
this->AddCommand(OperServ, new CommandSyncSQL("SQLSYNC"));
-
+
if (uplink_server)
OnServerConnect();
}
@@ -454,25 +404,25 @@ class DBMySQLWrite : public DBMySQL
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)
+ 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 != NickAliasList.end(); ++it)
+ 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 != RegisteredChannelList.end(); ++it)
+ 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 != BotListByNick.end(); ++it)
+
+ 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));
@@ -608,8 +558,7 @@ class DBMySQLWrite : public DBMySQL
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[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")
{
@@ -654,8 +603,7 @@ class DBMySQLWrite : public DBMySQL
}
else if (!ci)
return;
- else if (params[1] == "DONTKICKOPS" || params[1] == "DONTKICKVOICES" || params[1] == "FANTASY" || params[1] == "GREET"
- || params[1] == "SYMBIOSIS" || params[1] == "NOBOT")
+ 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);
@@ -714,7 +662,7 @@ class DBMySQLWrite : public DBMySQL
{
OnNickRegister(findnick(u->nick));
}
-
+
void OnMakeNickRequest(NickRequest *nr)
{
mysqlpp::Query query(me->Con);
@@ -784,7 +732,7 @@ class DBMySQLWrite : public DBMySQL
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 << ")";
+ 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);
}
@@ -819,13 +767,11 @@ class DBMySQLWrite : public DBMySQL
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)
@@ -852,7 +798,7 @@ class DBMySQLWrite : public DBMySQL
query << "DELETE FROM `anope_bs_badwords` WHERE `channel` = " << mysqlpp::quote << ci->name;
ExecuteQuery(query);
}
-
+
void OnChanRegistered(ChannelInfo *ci)
{
mysqlpp::Query query(me->Con);
@@ -1092,4 +1038,3 @@ class DBMySQLWrite : public DBMySQL
};
MODULE_INIT(DBMySQLWrite)
-