diff options
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | src/modules/Makefile | 12 | ||||
| -rw-r--r-- | src/modules/cs_appendtopic.cpp (renamed from src/modules/cs_appendtopic.c) | 13 | ||||
| -rw-r--r-- | src/modules/cs_enforce.cpp (renamed from src/modules/cs_enforce.c) | 13 | ||||
| -rw-r--r-- | src/modules/cs_tban.cpp (renamed from src/modules/cs_tban.c) | 17 | ||||
| -rw-r--r-- | src/modules/hs_request.cpp (renamed from src/modules/hs_request.c) | 32 | ||||
| -rw-r--r-- | src/modules/mysql/db_mysql.h | 53 | ||||
| -rw-r--r-- | src/modules/mysql/db_mysql_execute.cpp | 45 | ||||
| -rw-r--r-- | src/modules/mysql/db_mysql_read.cpp | 118 | ||||
| -rw-r--r-- | src/modules/mysql/db_mysql_write.cpp | 385 | ||||
| -rw-r--r-- | src/modules/ns_maxemail.cpp (renamed from src/modules/ns_maxemail.c) | 13 | ||||
| -rw-r--r-- | src/modules/os_info.cpp (renamed from src/modules/os_info.c) | 94 | ||||
| -rw-r--r-- | src/modules/ssl/m_ssl.cpp | 148 |
13 files changed, 487 insertions, 460 deletions
diff --git a/src/modules/CMakeLists.txt b/src/modules/CMakeLists.txt index ad66663c3..a7feab5d0 100644 --- a/src/modules/CMakeLists.txt +++ b/src/modules/CMakeLists.txt @@ -1,5 +1,4 @@ -# Find all the *.c and *.cpp files within the current source directory, and sort the list -file(GLOB MODULES_SRCS_C RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.c") +# Find all the *.cpp files within the current source directory, and sort the list file(GLOB MODULES_SRCS_CPP RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cpp") set(MODULES_SRCS ${MODULES_SRCS_C} ${MODULES_SRCS_CPP}) sort_list(MODULES_SRCS) @@ -58,6 +57,7 @@ endforeach(SRC) file(GLOB MODULES_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*") remove_item_from_list(MODULES_FILES "CMakeFiles") remove_item_from_list(MODULES_FILES "mysql") +remove_item_from_list(MODULES_FILES "ssl") # Iterate through this directory searching for subdirectories, and creating modules for those subdirectories foreach(FILE ${MODULES_FILES}) diff --git a/src/modules/Makefile b/src/modules/Makefile index 3ab2a7803..c69128ea3 100644 --- a/src/modules/Makefile +++ b/src/modules/Makefile @@ -8,8 +8,7 @@ MAKEARGS = 'CFLAGS=${CFLAGS}' 'CC=${CC}' 'ANOPELIBS=${ANOPELIBS}' \ 'PROFILE=${PROFILE}' 'SHARED=${SHARED}' 'MODULEFLAGS=${MODULEFLAGS}'\ 'MAKEBIN=${MAKEBIN}' 'MYSQLDIR=${MYSQLDIR}' -OBJECTS= $(SRCS:.c=.so) -OBJECTS+= $(SRCS:.cpp=.so) +OBJECTS= $(SRCS:.cpp=.so) CDEFS= -rdynamic -Wall MYSQL_ARGS = -I$(MYSQLDIR)/include/ -L$(MYSQLDIR)/lib/ -Wl,-rpath -Wl,$(MYSQLDIR)/lib/ -lmysqlpp @@ -25,16 +24,11 @@ install: distclean: spotless -.SUFFIXES: .c .cpp .so - -.c.so: - $(MAKEBIN) $(CC) ${CFLAGS} ${CDEFS} ${MODULEFLAGS} \ - $(if $(shell grep RequiredLibraries $< | grep mysqlpp), $(MYSQL_ARGS)) \ - -I../${INCLUDEDIR} -o $@ $< +.SUFFIXES: .cpp .so .cpp.so: $(MAKEBIN) $(CC) ${CFLAGS} ${CDEFS} ${MODULEFLAGS} \ - $(if $(shell grep RequiredLibraries $< | grep mysqlpp), $(MYSQL_ARGS)) \ + $(if $(shell grep RequiredLibraries $< | grep mysqlpp), $(MYSQL_ARGS)) $(if $(shell grep RequiredLibraries $< | grep ssl), -lssl) $(if $(shell grep RequiredLibraries $< | grep crypt), -lcrypt) \ -I../${INCLUDEDIR} -o $@ $< subs: diff --git a/src/modules/cs_appendtopic.c b/src/modules/cs_appendtopic.cpp index 22848b74a..a44e6d1a9 100644 --- a/src/modules/cs_appendtopic.c +++ b/src/modules/cs_appendtopic.cpp @@ -128,6 +128,11 @@ class CommandCSAppendTopic : public Command { me->NoticeLang(Config.s_ChanServ, u, LNG_APPENDTOPIC_SYNTAX); } + + void OnServHelp(User *u) + { + me->NoticeLang(Config.s_ChanServ, u, LNG_CHAN_HELP); + } }; class CSAppendTopic : public Module @@ -141,7 +146,7 @@ class CSAppendTopic : public Module this->SetVersion(VERSION); this->SetType(SUPPORTED); - this->AddCommand(CHANSERV, new CommandCSAppendTopic()); + this->AddCommand(ChanServ, new CommandCSAppendTopic()); /* English (US) */ const char* langtable_en_us[] = { @@ -222,12 +227,6 @@ class CSAppendTopic : public Module this->InsertLanguage(LANG_PT, LNG_NUM_STRINGS, langtable_pt); this->InsertLanguage(LANG_RU, LNG_NUM_STRINGS, langtable_ru); this->InsertLanguage(LANG_IT, LNG_NUM_STRINGS, langtable_it); - - ModuleManager::Attach(I_OnChanServHelp, this); - } - void OnChanServHelp(User *u) - { - this->NoticeLang(Config.s_ChanServ, u, LNG_CHAN_HELP); } }; diff --git a/src/modules/cs_enforce.c b/src/modules/cs_enforce.cpp index 435f07d79..271b9da05 100644 --- a/src/modules/cs_enforce.c +++ b/src/modules/cs_enforce.cpp @@ -216,6 +216,11 @@ class CommandCSEnforce : public Command { me->NoticeLang(Config.s_ChanServ, u, LNG_ENFORCE_SYNTAX); } + + void OnServHelp(User *u) + { + me->NoticeLang(Config.s_ChanServ, u, LNG_CHAN_HELP); + } }; class CSEnforce : public Module @@ -229,7 +234,7 @@ class CSEnforce : public Module this->SetVersion(VERSION); this->SetType(SUPPORTED); - this->AddCommand(CHANSERV, new CommandCSEnforce()); + this->AddCommand(ChanServ, new CommandCSEnforce()); /* English (US) */ const char* langtable_en_us[] = { @@ -438,12 +443,6 @@ class CSEnforce : public Module this->InsertLanguage(LANG_PT, LNG_NUM_STRINGS, langtable_pt); this->InsertLanguage(LANG_RU, LNG_NUM_STRINGS, langtable_ru); this->InsertLanguage(LANG_IT, LNG_NUM_STRINGS, langtable_it); - - ModuleManager::Attach(I_OnChanServHelp, this); - } - void OnChanServHelp(User *u) - { - this->NoticeLang(Config.s_ChanServ, u, LNG_CHAN_HELP); } }; diff --git a/src/modules/cs_tban.c b/src/modules/cs_tban.cpp index 10f295b3d..5a768dc81 100644 --- a/src/modules/cs_tban.c +++ b/src/modules/cs_tban.cpp @@ -83,6 +83,11 @@ class CommandCSTBan : public Command { me->NoticeLang(Config.s_ChanServ, u, TBAN_SYNTAX); } + + void OnServHelp(User *u) + { + me->NoticeLang(Config.s_ChanServ, u, TBAN_HELP); + } }; class CSTBan : public Module @@ -92,7 +97,7 @@ class CSTBan : public Module { me = this; - this->AddCommand(CHANSERV, new CommandCSTBan()); + this->AddCommand(ChanServ, new CommandCSTBan()); this->SetAuthor(AUTHOR); this->SetVersion(VERSION); @@ -154,12 +159,6 @@ class CSTBan : public Module this->InsertLanguage(LANG_PT, LANG_NUM_STRINGS, langtable_pt); this->InsertLanguage(LANG_RU, LANG_NUM_STRINGS, langtable_ru); this->InsertLanguage(LANG_IT, LANG_NUM_STRINGS, langtable_it); - - ModuleManager::Attach(I_OnChanServHelp, this); - } - void OnChanServHelp(User *u) - { - this->NoticeLang(Config.s_ChanServ, u, TBAN_HELP); } }; @@ -181,7 +180,7 @@ class TempBan : public CallBack { Channel *c; - if ((c = findchan(chan.c_str())) && c->ci) + if ((c = findchan(chan)) && c->ci) { c->RemoveMode(NULL, CMODE_BAN, mask); } @@ -203,7 +202,7 @@ int canBanUser(Channel * c, User * u, User * u2) notice_lang(Config.s_ChanServ, u, ACCESS_DENIED); else if (is_excepted(ci, u2)) notice_lang(Config.s_ChanServ, u, CHAN_EXCEPTED, u2->nick.c_str(), ci->name.c_str()); - else if (is_protected(u2)) + else if (u2->IsProtected()) notice_lang(Config.s_ChanServ, u, ACCESS_DENIED); else ok = 1; diff --git a/src/modules/hs_request.c b/src/modules/hs_request.cpp index ebc46dfe8..cc5637bef 100644 --- a/src/modules/hs_request.c +++ b/src/modules/hs_request.cpp @@ -205,6 +205,11 @@ class CommandHSRequest : public Command { me->NoticeLang(Config.s_HostServ, u, LNG_REQUEST_SYNTAX); } + + void OnServHelp(User *u) + { + me->NoticeLang(Config.s_HostServ, u, LNG_HELP); + } }; class CommandHSActivate : public Command @@ -257,6 +262,11 @@ class CommandHSActivate : public Command { me->NoticeLang(Config.s_HostServ, u, LNG_ACTIVATE_SYNTAX); } + + void OnServHelp(User *u) + { + me->NoticeLang(Config.s_HostServ, u, LNG_HELP_SETTER); + } }; class CommandHSReject : public Command @@ -339,7 +349,7 @@ class HSListBase : public Command return MOD_CONT; } public: - HSListBase(const std::string &cmd, int min, int max) : Command(cmd, min, max, "hostserv/set") + HSListBase(const ci::string &cmd, int min, int max) : Command(cmd, min, max, "hostserv/set") { } @@ -378,10 +388,10 @@ class HSRequest : public Module { me = this; - this->AddCommand(HOSTSERV, new CommandHSRequest()); - this->AddCommand(HOSTSERV, new CommandHSActivate()); - this->AddCommand(HOSTSERV, new CommandHSReject()); - this->AddCommand(HOSTSERV, new CommandHSWaiting()); + this->AddCommand(HostServ, new CommandHSRequest()); + this->AddCommand(HostServ, new CommandHSActivate()); + this->AddCommand(HostServ, new CommandHSReject()); + this->AddCommand(HostServ, new CommandHSWaiting()); this->SetAuthor(AUTHOR); this->SetVersion(VERSION); @@ -645,8 +655,8 @@ class HSRequest : public Module this->InsertLanguage(LANG_RU, LNG_NUM_STRINGS, langtable_ru); this->InsertLanguage(LANG_IT, LNG_NUM_STRINGS, langtable_it); - Implementation i[] = { I_OnHostServHelp, I_OnPreCommand, I_OnDatabaseRead, I_OnDatabaseWrite }; - ModuleManager::Attach(i, this, 4); + Implementation i[] = { I_OnPreCommand, I_OnDatabaseRead, I_OnDatabaseWrite }; + ModuleManager::Attach(i, this, 3); } ~HSRequest() @@ -670,7 +680,7 @@ class HSRequest : public Module if (!key.empty() && key == "+req") { std::vector<ci::string> emptyParams; - Command *c = findCommand(HOSTSERV, "WAITING"); + Command *c = FindCommand(HostServ, "WAITING"); c->Execute(u, emptyParams); return EVENT_STOP; } @@ -698,12 +708,6 @@ class HSRequest : public Module return EVENT_CONTINUE; } - void OnHostServHelp(User *u) - { - this->NoticeLang(Config.s_HostServ, u, LNG_HELP); - this->NoticeLang(Config.s_HostServ, u, LNG_HELP_SETTER); - } - EventReturn OnDatabaseRead(const std::vector<std::string> ¶ms) { if (params[0] == "HS_REQUEST" && params.size() >= 5) diff --git a/src/modules/mysql/db_mysql.h b/src/modules/mysql/db_mysql.h index b62f52524..f2885408f 100644 --- a/src/modules/mysql/db_mysql.h +++ b/src/modules/mysql/db_mysql.h @@ -39,48 +39,6 @@ NickCoreFlagInfo NickCoreFlags[] = { {"", static_cast<NickCoreFlag>(-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<ChannelModeName>(-1)} -}; - struct BotFlagInfo { std::string Name; @@ -140,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<BotFlag>(-1)} }; @@ -169,7 +120,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 +177,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..2313edd37 100644 --- a/src/modules/mysql/db_mysql_execute.cpp +++ b/src/modules/mysql/db_mysql_execute.cpp @@ -1,24 +1,18 @@ /* RequiredLibraries: mysqlpp */ #include "db_mysql.h" -#define HASH(nick) (((nick)[0]&31)<<5 | ((nick)[1]&31)) 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(); } @@ -37,27 +31,17 @@ 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 - - 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; + this->server = Me; + + UserListByNick.erase("-SQLUser"); --usercnt; } ~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) - (*list)->prev = this; - *list = this; + UserListByNick["-SQLUser"] = this; ++usercnt; + nc = NULL; } @@ -68,21 +52,22 @@ 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 { 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`"; @@ -144,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->nick, u, bi->cmdTable, cmd); - delete [] cmdbuf; + mod_run_cmd(bi, u, qres[i]["command"].c_str()); if (logout) u->Logout(); @@ -171,7 +152,7 @@ class DBMySQLExecute : public DBMySQL ~DBMySQLExecute() { - TimerManager::DelTimer(_SQLTimer); + delete _SQLTimer; } }; diff --git a/src/modules/mysql/db_mysql_read.cpp b/src/modules/mysql/db_mysql_read.cpp index 5c498b008..3c5fb359a 100644 --- a/src/modules/mysql/db_mysql_read.cpp +++ b/src/modules/mysql/db_mysql_read.cpp @@ -27,7 +27,7 @@ static std::vector<std::string> 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`"; @@ -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"])); @@ -266,52 +272,37 @@ static void LoadDatabase() ci->bantype = atoi(qres[i]["bantype"].c_str()); if (qres[i]["mlock_on"].size()) { + std::vector<std::string> modes; std::string buf; + spacesepstream sep(SQLAssign(qres[i]["mlock_on"])); while (sep.GetToken(buf)) - { - for (int j = 0; ChannelModes[j].Mode != -1; ++j) - { - if (buf == ChannelModes[j].Name) - { - ci->SetMLock(ChannelModes[j].Mode, true); - break; - } - } - } + modes.push_back(buf); + + ci->Extend("db_mlock_modes_on", new ExtensibleItemRegular<std::vector<std::string> >(modes)); } if (qres[i]["mlock_off"].size()) { + std::vector<std::string> modes; std::string buf; + spacesepstream sep(SQLAssign(qres[i]["mlock_off"])); while (sep.GetToken(buf)) - { - for (int j = 0; ChannelModes[j].Mode != -1; ++j) - { - if (buf == ChannelModes[j].Name) - { - ci->SetMLock(ChannelModes[j].Mode, false); - break; - } - } - } + modes.push_back(buf); + + ci->Extend("db_mlock_modes_off", new ExtensibleItemRegular<std::vector<std::string> >(modes)); } if (qres[i]["mlock_params"].size()) { - std::string buf; + std::vector<std::pair<std::string, std::string> > mlp; + std::string buf, buf2; + spacesepstream sep(SQLAssign(qres[i]["mlock_params"])); - while (sep.GetToken(buf)) - { - for (int j = 0; ChannelModes[j].Mode != -1; ++j) - { - if (buf == ChannelModes[j].Name) - { - sep.GetToken(buf); - ci->SetMLock(ChannelModes[j].Mode, true, buf); - break; - } - } - } + + while (sep.GetToken(buf) && sep.GetToken(buf2)) + mlp.push_back(std::make_pair(buf, buf2)); + + ci->Extend("db_mlp", new ExtensibleItemRegular<std::vector<std::pair<std::string, std::string> > >(mlp)); } if (qres[i]["entry_message"].size()) ci->entry_message = sstrdup(qres[i]["entry_message"].c_str()); @@ -629,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 b7b94a3a3..b5686fa2f 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<Mode *>::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<ChannelMode *>(*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<Mode *>::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<ChannelMode *>(*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,60 +221,53 @@ 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); 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); - } + me->OnNickRegister(it->second); } - 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<std::string>::iterator it = nc->access.begin(); it != nc->access.end(); ++it) { - for (std::vector<std::string>::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 = BotListByNick.begin(); it != BotListByNick.end(); ++it) { - for (BotInfo *bi = botlists[i]; bi; bi = bi->next) - { - me->OnBotCreate(bi); - } + me->OnBotCreate(it->second); } query << "TRUNCATE TABLE `anope_cs_info`"; @@ -280,95 +281,86 @@ 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); - - for (unsigned j = 0; j < ci->GetBadWordCount(); ++j) - { - BadWord *bw = ci->GetBadWord(j); + ChannelInfo *ci = it->second; + + me->OnChanRegistered(ci); - if (bw->InUse) - { - me->OnBadWordAdd(ci, bw); - } - } + for (unsigned j = 0; j < ci->GetBadWordCount(); ++j) + { + BadWord *bw = ci->GetBadWord(j); - for (unsigned j = 0; j < ci->GetAccessCount(); ++j) - { - ChanAccess *access = ci->GetAccess(j); + me->OnBadWordAdd(ci, bw); + } - 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); - } - } + for (unsigned j = 0; j < ci->GetAccessCount(); ++j) + { + ChanAccess *access = ci->GetAccess(j); - for (unsigned j = 0; j < ci->GetAkickCount(); ++j) - { - AutoKick *ak = ci->GetAkick(j); + query << "INSERT DELAYED INTO `anope_cs_access` (level, display, channel, last_seen, creator) VALUES('" << access->level << "', " << mysqlpp::quote << access->nc->display << ", " << mysqlpp::quote << ci->name << ", " << access->last_seen << ", " << mysqlpp::quote << access->creator << ") ON DUPLICATE KEY UPDATE level=VALUES(level), last_seen=VALUES(last_seen), creator=VALUES(creator)"; + ExecuteQuery(query); + } - if (ak->InUse) - { - me->OnAkickAdd(ci, ak); - } - } + for (unsigned j = 0; j < ci->GetAkickCount(); ++j) + { + AutoKick *ak = ci->GetAkick(j); - 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); - } + 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) - { - 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) + if (SGLine) { - Akill *ak = static_cast<Akill *>(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<SXLine *>(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<SXLine *>(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<SXLine *>(szlines.list[i]); - - me->OnAddSXLine(NULL, x, SX_SZLINE); + for (unsigned i = 0; i < SNLine->GetCount(); ++i) |
