summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bots.cpp32
-rw-r--r--src/channels.cpp2
-rw-r--r--src/config.cpp153
-rw-r--r--src/logger.cpp2
-rw-r--r--src/servers.cpp18
5 files changed, 94 insertions, 113 deletions
diff --git a/src/bots.cpp b/src/bots.cpp
index b794610e6..379836ec2 100644
--- a/src/bots.cpp
+++ b/src/bots.cpp
@@ -38,32 +38,6 @@ BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const A
XLine x(this->nick, "Reserved for services");
ircdproto->SendSQLine(NULL, &x);
}
-
- if (Config)
- for (unsigned i = 0; i < Config->LogInfos.size(); ++i)
- {
- LogInfo *l = Config->LogInfos[i];
-
- if (ircd && !ircd->join2msg && !l->Inhabit)
- continue;
-
- for (std::list<Anope::string>::const_iterator sit = l->Targets.begin(), sit_end = l->Targets.end(); sit != sit_end; ++sit)
- {
- const Anope::string &target = *sit;
-
- if (target[0] == '#')
- {
- Channel *c = findchan(target);
- if (!c)
- c = new Channel(target);
- c->SetFlag(CH_LOGCHAN);
- c->SetFlag(CH_PERSIST);
-
- if (!c->FindUser(this))
- this->Join(c, &Config->BotModeList);
- }
- }
- }
}
BotInfo::~BotInfo()
@@ -160,6 +134,9 @@ void BotInfo::UnAssign(User *u, ChannelInfo *ci)
void BotInfo::Join(Channel *c, ChannelStatus *status)
{
+ if (c->FindUser(this) != NULL)
+ return;
+
if (Config && ircdproto && Config->BSSmartJoin)
{
std::pair<Channel::ModeList::iterator, Channel::ModeList::iterator> bans = c->GetModeList(CMODE_BAN);
@@ -199,6 +176,9 @@ void BotInfo::Join(const Anope::string &chname, ChannelStatus *status)
void BotInfo::Part(Channel *c, const Anope::string &reason)
{
+ if (c->FindUser(this) == NULL)
+ return;
+
ircdproto->SendPart(this, c, "%s", !reason.empty() ? reason.c_str() : "");
c->DeleteUser(this);
}
diff --git a/src/channels.cpp b/src/channels.cpp
index 0cd5481eb..52b0b86c5 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -401,7 +401,7 @@ void Channel::RemoveModeInternal(ChannelMode *cm, const Anope::string &param, bo
if (EnforceMLock)
{
/* Reset modes on bots if we're supposed to */
- if (bi)
+ if (this->ci && this->ci->bi && this->ci->bi == bi)
{
if (Config->BotModeList.HasFlag(cm->Name))
this->SetMode(bi, cm, bi->nick);
diff --git a/src/config.cpp b/src/config.cpp
index 4a1f02f64..6f2557510 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -778,40 +778,7 @@ static bool DoneModules(ServerConfig *config, const Anope::string &)
bool InitLogs(ServerConfig *config, const Anope::string &)
{
- for (unsigned i = 0; i < config->LogInfos.size(); ++i)
- {
- LogInfo *l = config->LogInfos[i];
-
- for (std::list<Anope::string>::const_iterator sit = l->Targets.begin(), sit_end = l->Targets.end(); sit != sit_end; ++sit)
- {
- const Anope::string &target = *sit;
-
- if (target[0] == '#')
- {
- Channel *c = findchan(target);
- if (c && c->HasFlag(CH_LOGCHAN))
- {
- for (CUserList::const_iterator cit = c->users.begin(), cit_end = c->users.end(); cit != cit_end; ++cit)
- {
- UserContainer *uc = *cit;
- BotInfo *bi = findbot(uc->user->nick);
-
- if (bi)
- bi->Part(c, "Reloading configuration");
- }
-
- c->UnsetFlag(CH_PERSIST);
- c->UnsetFlag(CH_LOGCHAN);
- if (c->users.empty())
- delete c;
- }
- }
- }
-
- delete config->LogInfos[i];
- }
config->LogInfos.clear();
-
return true;
}
@@ -825,18 +792,17 @@ static bool DoLogs(ServerConfig *config, const Anope::string &, const Anope::str
Anope::string source = values[1].GetValue();
int logage = values[2].GetInteger();
- bool inhabit = values[3].GetBool();
- Anope::string admin = values[4].GetValue();
- Anope::string override = values[5].GetValue();
- Anope::string commands = values[6].GetValue();
- Anope::string servers = values[7].GetValue();
- Anope::string channels = values[8].GetValue();
- Anope::string users = values[9].GetValue();
- Anope::string normal = values[10].GetValue();
- bool rawio = values[11].GetBool();
- bool ldebug = values[12].GetBool();
-
- LogInfo *l = new LogInfo(logage, inhabit, rawio, ldebug);
+ Anope::string admin = values[3].GetValue();
+ Anope::string override = values[4].GetValue();
+ Anope::string commands = values[5].GetValue();
+ Anope::string servers = values[6].GetValue();
+ Anope::string channels = values[7].GetValue();
+ Anope::string users = values[8].GetValue();
+ Anope::string normal = values[9].GetValue();
+ bool rawio = values[10].GetBool();
+ bool ldebug = values[11].GetBool();
+
+ LogInfo *l = new LogInfo(logage, rawio, ldebug);
l->Targets = BuildStringList(targets);
l->Sources = BuildStringList(source);
l->Admin = BuildStringList(admin);
@@ -855,36 +821,6 @@ static bool DoLogs(ServerConfig *config, const Anope::string &, const Anope::str
static bool DoneLogs(ServerConfig *config, const Anope::string &)
{
Log() << "Loaded " << config->LogInfos.size() << " log blocks";
-
- for (unsigned i = 0; i < config->LogInfos.size(); ++i)
- {
- LogInfo *l = config->LogInfos[i];
-
- if ((!ircd || !ircd->join2msg) && !l->Inhabit)
- continue;
-
- for (std::list<Anope::string>::const_iterator sit = l->Targets.begin(), sit_end = l->Targets.end(); sit != sit_end; ++sit)
- {
- const Anope::string &target = *sit;
-
- if (target[0] == '#')
- {
- Channel *c = findchan(target);
- if (!c)
- c = new Channel(target);
- c->SetFlag(CH_LOGCHAN);
- c->SetFlag(CH_PERSIST);
-
- for (Anope::insensitive_map<BotInfo *>::const_iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end; ++it)
- {
- BotInfo *bi = it->second;
- if (!c->FindUser(bi))
- bi->Join(c, NULL);
- }
- }
- }
- }
-
return true;
}
@@ -948,6 +884,7 @@ static bool DoServices(ServerConfig *config, const Anope::string &, const Anope:
Anope::string host = values[2].GetValue();
Anope::string gecos = values[3].GetValue();
Anope::string modes = values[4].GetValue();
+ Anope::string channels = values[5].GetValue();
ValueItem vi(nick);
if (!ValidateNotEmpty(config, "service", "nick", vi))
@@ -967,10 +904,58 @@ static bool DoServices(ServerConfig *config, const Anope::string &, const Anope:
services.insert(nick);
BotInfo *bi = findbot(nick);
- if (bi != NULL)
- return true;
- bi = new BotInfo(nick, user, host, gecos, modes);
+ if (bi == NULL)
+ bi = new BotInfo(nick, user, host, gecos, modes);
bi->SetFlag(BI_CONF);
+
+ Anope::string token;
+ commasepstream sep(channels);
+ std::vector<Anope::string> oldchannels = bi->botchannels;
+ bi->botchannels.clear();
+ while (sep.GetToken(token))
+ {
+ bi->botchannels.push_back(token);
+ size_t ch = token.find('#');
+ Anope::string chname, want_modes;
+ if (ch == Anope::string::npos)
+ chname = token;
+ else
+ {
+ want_modes = token.substr(0, ch);
+ chname = token.substr(ch);
+ }
+ bi->Join(chname);
+ Channel *c = findchan(chname);
+ if (!c)
+ continue; // Can't happen
+
+ /* Remove all existing modes */
+ for (unsigned i = 0; i < ModeManager::ChannelModes.size(); ++i)
+ {
+ ChannelMode *cm = ModeManager::ChannelModes[i];
+ if (cm && cm->Type == MODE_STATUS)
+ c->RemoveMode(bi, cm, bi->nick);
+ }
+ /* Set the new modes */
+ for (unsigned j = 0; j < want_modes.length(); ++j)
+ {
+ ChannelMode *cm = ModeManager::FindChannelModeByChar(ModeManager::GetStatusChar(want_modes[j]));
+ if (cm && cm->Type == MODE_STATUS)
+ c->SetMode(bi, cm, bi->nick);
+ }
+ }
+ for (unsigned i = 0; i < oldchannels.size(); ++i)
+ {
+ size_t ch = oldchannels[i].find('#');
+ Anope::string chname = oldchannels[i].substr(ch != Anope::string::npos ? ch : 0);
+ if (std::find(bi->botchannels.begin(), bi->botchannels.end(), chname) == bi->botchannels.end())
+ {
+ Channel *c = findchan(chname);
+ if (c)
+ bi->Part(c);
+ }
+ }
+
return true;
}
@@ -1267,14 +1252,14 @@ ConfigItems::ConfigItems(ServerConfig *conf)
{DT_STRING, DT_STRING, DT_STRING, DT_STRING},
InitOpers, DoOper, DoneOpers},
{"service",
- {"nick", "user", "host", "gecos", "modes", ""},
- {"", "", "", "", "", ""},
- {DT_STRING, DT_STRING, DT_STRING, DT_STRING, DT_STRING},
+ {"nick", "user", "host", "gecos", "modes", "channels", ""},
+ {"", "", "", "", "", "", ""},
+ {DT_STRING, DT_STRING, DT_STRING, DT_STRING, DT_STRING, DT_STRING},
InitServices, DoServices, DoneServices},
{"log",
- {"target", "source", "logage", "inhabitlogchannel", "admin", "override", "commands", "servers", "channels", "users", "other", "rawio", "debug", ""},
- {"", "", "7", "yes", "", "", "", "", "", "", "", "no", "no", ""},
- {DT_STRING, DT_STRING, DT_INTEGER, DT_BOOLEAN, DT_STRING, DT_STRING, DT_STRING, DT_STRING, DT_STRING, DT_STRING, DT_STRING, DT_BOOLEAN, DT_BOOLEAN},
+ {"target", "source", "logage", "admin", "override", "commands", "servers", "channels", "users", "other", "rawio", "debug", ""},
+ {"", "", "7", "", "", "", "", "", "", "", "no", "no", ""},
+ {DT_STRING, DT_STRING, DT_INTEGER, DT_STRING, DT_STRING, DT_STRING, DT_STRING, DT_STRING, DT_STRING, DT_STRING, DT_BOOLEAN, DT_BOOLEAN},
InitLogs, DoLogs, DoneLogs},
{"command",
{"service", "name", "command", "permission", ""},
diff --git a/src/logger.cpp b/src/logger.cpp
index 1725e8670..dbaba975a 100644
--- a/src/logger.cpp
+++ b/src/logger.cpp
@@ -176,7 +176,7 @@ Log::~Log()
}
}
-LogInfo::LogInfo(int logage, bool inhabit, bool rawio, bool ldebug) : LogAge(logage), Inhabit(inhabit), RawIO(rawio), Debug(ldebug)
+LogInfo::LogInfo(int logage, bool rawio, bool ldebug) : LogAge(logage), RawIO(rawio), Debug(ldebug)
{
}
diff --git a/src/servers.cpp b/src/servers.cpp
index d1e20e515..dccea8929 100644
--- a/src/servers.cpp
+++ b/src/servers.cpp
@@ -52,7 +52,7 @@ Server::Server(Server *uplink, const Anope::string &name, unsigned hops, const A
/* Check to be sure this isn't a juped server */
if (Me == this->UplinkServer && !this->HasFlag(SERVER_JUPED))
{
- /* Load MLock from the database now that we know what modes exist */
+ /* Now do mode related stuff as we know what modes exist .. */
for (registered_channel_map::iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end; ++it)
it->second->LoadMLock();
for (botinfo_map::iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end; ++it)
@@ -60,6 +60,22 @@ Server::Server(Server *uplink, const Anope::string &name, unsigned hops, const A
BotInfo *bi = it->second;
Anope::string modes = !bi->botmodes.empty() ? ("+" + bi->botmodes) : ircd->pseudoclient_mode;
bi->SetModesInternal(modes.c_str());
+ for (unsigned i = 0; i < bi->botchannels.size(); ++i)
+ {
+ size_t h = bi->botchannels[i].find('#');
+ Anope::string chname = bi->botchannels[i].substr(h != Anope::string::npos ? h : 0);
+ Channel *c = findchan(chname);
+ if (c && c->FindUser(bi))
+ {
+ Anope::string want_modes = bi->botchannels[i].substr(0, h);
+ for (unsigned j = 0; j < want_modes.length(); ++j)
+ {
+ ChannelMode *cm = ModeManager::FindChannelModeByChar(ModeManager::GetStatusChar(want_modes[j]));
+ if (cm && cm->Type == MODE_STATUS)
+ c->SetModeInternal(cm, bi->nick);
+ }
+ }
+ }
}
ircdproto->SendBOB();