summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/CMakeLists.txt4
-rw-r--r--src/modules/Makefile12
-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.h53
-rw-r--r--src/modules/mysql/db_mysql_execute.cpp45
-rw-r--r--src/modules/mysql/db_mysql_read.cpp118
-rw-r--r--src/modules/mysql/db_mysql_write.cpp385
-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.cpp148
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> &params)
{
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)
+ {
+ me->OnAddXLine(NULL, SNLine->GetEntry(i), X_SNLINE);
+ }
}
for (int i = 0; i < nexceptions; ++i)
@@ -382,7 +374,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")
{
}
@@ -399,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
@@ -410,7 +407,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();
@@ -441,67 +438,51 @@ class DBMySQLWrite : public DBMySQL
/* MemoServ */
I_OnMemoSend, I_OnMemoDel,
/* OperServ */
- I_OnOperServHelp, I_OnAddAkill, I_OnDelAkill, I_OnExceptionAdd, I_OnExceptionDel,
- I_OnAddSXLine, I_OnDelSXLine
+ 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()
{
- mysqlpp::Query query(Me->Con);
+ mysqlpp::Query query(me->Con);
query << "TRUNCATE TABLE `anope_os_core`";
ExecuteQuery(query);
query << "INSERT DELAYED INTO `anope_os_core` (maxusercnt, maxusertime, akills_count, sglines_count, sqlines_count, szlines_count) VALUES(";
- query << maxusercnt << ", " << maxusertime << ", " << 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 (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 = BotListByNick.begin(); it != BotListByNick.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));
@@ -511,14 +492,14 @@ class DBMySQLWrite : public DBMySQL
void OnPostCommand(User *u, const std::string &service, const ci::string &command, const std::vector<ci::string> &params)
{
- mysqlpp::Query query(Me->Con);
+ mysqlpp::Query query(me->Con);
if (service == Config.s_NickServ)
{
if (u->Account() && ((command == "SET" && !params.empty()) || (command == "SASET" && u->Account()->HasCommand("nickserv/saset") && params.size() > 1)))
{
ci::string cmd = (command == "SET" ? params[0] : params[1]);
- NickCore *nc = (command == "SET" ? u->Account() : findcore(params[0].c_str()));
+ NickCore *nc = (command == "SET" ? u->Account() : findcore(params[0]));
if (!nc)
return;
if (cmd == "PASSWORD" && params.size() > 1)
@@ -562,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))
@@ -622,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"))
@@ -660,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;
@@ -685,28 +666,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 +705,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 +717,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 +726,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 +734,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 +757,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,42 +776,42 @@ 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);
}
void OnLevelChange(User *u, ChannelInfo *ci, int pos, int what)
{
- mysqlpp::Query query(Me->Con);
+ mysqlpp::Query query(me->Con);
if (pos >= 0)
{
@@ -849,7 +830,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 +838,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 +855,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 +876,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 +887,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 +902,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 +924,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 +933,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 +941,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 +949,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 +971,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 +993,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 +1002,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 +1011,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 +1021,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
@@ -1048,21 +1029,21 @@ class DBMySQLWrite : public DBMySQL
ExecuteQuery(query);
}
- EventReturn OnAddAkill(User *, Akill *ak)
+ EventReturn OnAddAkill(User *, XLine *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 << ")";
+ 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);
+ 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);
@@ -1070,7 +1051,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,32 +1061,32 @@ 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)
+ EventReturn OnAddXLine(User *, XLine *x, XLineType 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;
- 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)
+ mysqlpp::Query query(me->Con);
+ 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);
}
};
diff --git a/src/modules/ns_maxemail.c b/src/modules/ns_maxemail.cpp
index e98dc62d7..2399dba68 100644
--- a/src/modules/ns_maxemail.c
+++ b/src/modules/ns_maxemail.cpp
@@ -127,20 +127,17 @@ class NSMaxEmail : public Module
int count_email_in_use(const char *email, User * u)
{
- NickCore *nc;
- int i;
int count = 0;
if (!email)
return 0;
- for (i = 0; i < 1024; ++i)
+ for (nickcore_map::const_iterator it = NickCoreList.begin(); it != NickCoreList.end(); ++it)
{
- for (nc = nclists[i]; nc; nc = nc->next)
- {
- if (!(u->Account() && u->Account() == nc) && nc->email && !stricmp(nc->email, email))
- ++count;
- }
+ NickCore *nc = it->second;
+
+ if (!(u->Account() && u->Account() == nc) && nc->email && !stricmp(nc->email, email))
+ ++count;
}
return count;
diff --git a/src/modules/os_info.c b/src/modules/os_info.cpp
index 87d8ea298..38d9c99c5 100644
--- a/src/modules/os_info.c
+++ b/src/modules/os_info.cpp
@@ -116,6 +116,11 @@ class CommandNSOInfo : public Command
{
me->NoticeLang(Config.s_NickServ, u, OINFO_SYNTAX);
}
+
+ void OnServHelp(User *u)
+ {
+ me->NoticeLang(Config.s_NickServ, u, OINFO_HELP_CMD);
+ }
};
class CommandCSOInfo : public Command
@@ -180,6 +185,11 @@ class CommandCSOInfo : public Command
{
me->NoticeLang(Config.s_ChanServ, u, OCINFO_SYNTAX);
}
+
+ void OnServHelp(User *u)
+ {
+ me->NoticeLang(Config.s_ChanServ, u, OCINFO_HELP_CMD);
+ }
};
class OSInfo : public Module
@@ -193,8 +203,8 @@ class OSInfo : public Module
this->SetVersion(VERSION);
this->SetType(SUPPORTED);
- this->AddCommand(NICKSERV, new CommandNSOInfo());
- this->AddCommand(CHANSERV, new CommandCSOInfo());
+ this->AddCommand(NickServ, new CommandNSOInfo());
+ this->AddCommand(ChanServ, new CommandCSOInfo());
const char* langtable_en_us[] = {
/* OINFO_SYNTAX */
@@ -409,83 +419,47 @@ class OSInfo : public Module
this->InsertLanguage(LANG_RU, LANG_NUM_STRINGS, langtable_ru);
this->InsertLanguage(LANG_IT, LANG_NUM_STRINGS, langtable_it);
- Implementation i[] = { I_OnNickServHelp, I_OnChanServHelp, I_OnPostCommand, I_OnDatabaseReadMetadata, I_OnDatabaseWriteMetadata };
- ModuleManager::Attach(i, this, 5);
+ Implementation i[] = { I_OnNickInfo, I_OnChanInfo, I_OnDatabaseReadMetadata, I_OnDatabaseWriteMetadata };
+ ModuleManager::Attach(i, this, 4);
}
~OSInfo()
{
- int i;
- NickCore *nc;
- ChannelInfo *ci;
-
OnSaveDatabase();
- for (i = 0; i < 1024; ++i)
+ for (nickcore_map::const_iterator it = NickCoreList.begin(); it != NickCoreList.end(); ++it)
{
- /* Remove the nick Cores */
- for (nc = nclists[i]; nc; nc = nc->next)
- {
- nc->Shrink("os_info");
- }
+ NickCore *nc = it->second;
+
+ nc->Shrink("os_info");
}
- for (i = 0; i < 256; ++i)
+ for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(); it != RegisteredChannelList.end(); ++it)
{
- for (ci = chanlists[i]; ci; ci = ci->next)
- {
- ci->Shrink("os_info");
- }
+ ChannelInfo *ci = it->second;
+
+ ci->Shrink("os_info");
}
}
- void OnPostCommand(User *u, const std::string &service, const ci::string &command, const std::vector<ci::string> &params)
+ void OnNickInfo(User *u, NickAlias *na, bool)
{
- if (command == "INFO")
+ if (is_oper(u))
{
- if (service == Config.s_NickServ)
- {
- const char *nick = params[0].c_str();
- NickAlias *na = NULL;
-
- if (is_oper(u)) /* Only show our goodies to opers */
- {
- if ((na = findnick(nick))) /* ok we've found the user */
- {
- /* If we have any info on this user */
- char *c;
- if (na->nc->GetExtArray("os_info", c))
- u->SendMessage(Config.s_NickServ, " OperInfo: %s", c);
- }
- }
- }
- else if (service == Config.s_ChanServ)
- {
- const char *chan = params[0].c_str();
- ChannelInfo *ci = NULL;
-
- if (is_oper(u)) /* Only show our goodies to opers */
- {
- if ((ci = cs_findchan(chan)))
- {
- /* If we have any info on this channel */
- char *c;
- if (ci->GetExtArray("os_info", c))
- u->SendMessage(Config.s_ChanServ, " OperInfo: %s", c);
- }
- }
- }
+ char *c;
+ if (na->nc->GetExtArray("os_info", c))
+ u->SendMessage(Config.s_NickServ, " OperInfo: %s", c);
}
}
- void OnNickServHelp(User *u)
- {
- this->NoticeLang(Config.s_NickServ, u, OINFO_HELP_CMD);
- }
-
- void OnChanServHelp(User *u)
+ void OnChanInfo(User *u, ChannelInfo *ci, bool)
{
- this->NoticeLang(Config.s_ChanServ, u, OCINFO_HELP_CMD);
+ if (is_oper(u))
+ {
+ char *c;
+ if (ci->GetExtArray("os_info", c))
+ u->SendMessage(Config.s_ChanServ, " OperInfo: %s", c);
+ }
}
void OnDatabaseWriteMetadata(void (*WriteMetadata)(const std::string &, const std::string &), NickCore *nc)
diff --git a/src/modules/ssl/m_ssl.cpp b/src/modules/ssl/m_ssl.cpp
new file mode 100644
index 000000000..be3e5da1f
--- /dev/null
+++ b/src/modules/ssl/m_ssl.cpp
@@ -0,0 +1,148 @@
+/* RequiredLibraries: ssl,crypt */
+
+#include "module.h"
+
+#include <openssl/bio.h>
+#include <openssl/ssl.h>
+#include <openssl/err.h>
+#include <openssl/crypto.h>
+#include <openssl/evp.h>
+
+#define CERTFILE "anope.cert"
+#define KEYFILE "anope.key"
+
+static SSL_CTX *ctx;
+
+class SSLSocket : public Socket
+{
+ private:
+ SSL *sslsock;
+
+ int RecvInternal(char *buf, size_t sz) const
+ {
+ return SSL_read(sslsock, buf, sz);
+ }
+
+ int SendInternal(const std::string &buf) const
+ {
+ return SSL_write(sslsock, buf.c_str(), buf.size());
+ }
+ public:
+ SSLSocket(const std::string &nTargetHost, int nPort, const std::string &nBindHost = "", bool nIPv6 = false) : Socket(nTargetHost, nPort, nBindHost, nIPv6)
+ {
+ sslsock = SSL_new(ctx);
+
+ if (!sslsock)
+ throw CoreException("Unable to initialize SSL socket");
+
+ SSL_set_connect_state(sslsock);
+ SSL_set_fd(sslsock, Sock);
+ SSL_connect(sslsock);
+
+ UplinkSock = this;
+ }
+
+ ~SSLSocket()
+ {
+ SSL_shutdown(sslsock);
+ SSL_free(sslsock);
+
+ UplinkSock = NULL;
+ }
+
+ bool Read(const std::string &buf)
+ {
+ process(buf);
+ return true;
+ }
+};
+
+class SSLModule : public Module
+{
+ public:
+ SSLModule(const std::string &modname, const std::string &creator) : Module(modname, creator)
+ {
+ this->SetAuthor("Anope");
+ this->SetVersion("$Id$");
+ this->SetType(SUPPORTED);
+ this->SetPermanent(true);
+
+ SSL_load_error_strings();
+ SSLeay_add_ssl_algorithms();
+
+ ctx = SSL_CTX_new(SSLv23_client_method());
+
+ if (!ctx)
+ {
+ throw ModuleException("Error initializing SSL CTX");
+ }
+
+ if (IsFile(CERTFILE))
+ {
+ if (!SSL_CTX_use_certificate_file(ctx, CERTFILE, SSL_FILETYPE_PEM))
+ {
+ SSL_CTX_free(ctx);
+ throw ModuleException("Error loading certificate");
+ }
+ }
+ else
+ {
+ Alog() << "m_ssl: No certificate file found";
+ }
+
+ if (IsFile(KEYFILE))
+ {
+ if (!SSL_CTX_use_PrivateKey_file(ctx, KEYFILE, SSL_FILETYPE_PEM))
+ {
+ SSL_CTX_free(ctx);
+ throw ModuleException("Error loading private key");
+ }
+ }
+ else
+ {
+ if (IsFile(CERTFILE))
+ {
+ SSL_CTX_free(ctx);
+ throw ModuleException("Error loading private key - file not found");
+ }
+ else
+ {
+ Alog() << "m_ssl: No private key found";
+ }
+ }
+
+ SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv2);
+ SSL_CTX_set_options(ctx, SSL_OP_TLS_ROLLBACK_BUG | SSL_OP_ALL);
+
+ ModuleManager::Attach(I_OnPreServerConnect, this);
+ }
+
+ ~SSLModule()
+ {
+ SSL_CTX_free(ctx);
+ }
+
+ EventReturn OnPreServerConnect(Uplink *u, int Number)
+ {
+ ConfigReader config;
+
+ if (config.ReadFlag("uplink", "ssl", "no", Number - 1))
+ {
+ try
+ {
+ new SSLSocket(u->host, u->port, Config.LocalHost ? Config.LocalHost : "", u->ipv6);
+ Alog() << "Connected to Server " << Number << " (" << u->host << ":" << u->port << ")";
+ }
+ catch (SocketException& ex)
+ {
+ Alog() << "Unable to connect with SSL to server" << Number << " (" << u->host << ":" << u->port << "), " << ex.GetReason();
+ }
+
+ return EVENT_ALLOW;
+ }
+
+ return EVENT_CONTINUE;
+ }
+};
+
+MODULE_INIT(SSLModule)