bool DoneZLine(ServerConfig* conf, const char* tag)
{
// XXX we should really only call this once - after we've finished processing configuration all together
- conf->GetInstance()->XLines->apply_lines();
+ conf->GetInstance()->XLines->ApplyLines();
return true;
}
bool DoneQLine(ServerConfig* conf, const char* tag)
{
// XXX we should really only call this once - after we've finished processing configuration all together
- conf->GetInstance()->XLines->apply_lines();
+ conf->GetInstance()->XLines->ApplyLines();
return true;
}
bool DoneKLine(ServerConfig* conf, const char* tag)
{
// XXX we should really only call this once - after we've finished processing configuration all together
- conf->GetInstance()->XLines->apply_lines();
+ conf->GetInstance()->XLines->ApplyLines();
return true;
}
bool DoneELine(ServerConfig* conf, const char* tag)
{
// XXX we should really only call this once - after we've finished processing configuration all together
- conf->GetInstance()->XLines->apply_lines();
+ conf->GetInstance()->XLines->ApplyLines();
return true;
}
const char* reason = values[0].GetString();
const char* ipmask = values[1].GetString();
- conf->GetInstance()->XLines->add_zline(0,"<Config>",reason,ipmask);
+ conf->GetInstance()->XLines->AddZLine(0,"<Config>",reason,ipmask);
return true;
}
const char* reason = values[0].GetString();
const char* nick = values[1].GetString();
- conf->GetInstance()->XLines->add_qline(0,"<Config>",reason,nick);
+ conf->GetInstance()->XLines->AddQLine(0,"<Config>",reason,nick);
return true;
}
const char* reason = values[0].GetString();
const char* host = values[1].GetString();
- conf->GetInstance()->XLines->add_kline(0,"<Config>",reason,host);
+ conf->GetInstance()->XLines->AddKLine(0,"<Config>",reason,host);
return true;
}
const char* reason = values[0].GetString();
const char* host = values[1].GetString();
- conf->GetInstance()->XLines->add_eline(0,"<Config>",reason,host);
+ conf->GetInstance()->XLines->AddELine(0,"<Config>",reason,host);
return true;
}
+bool XLine::Matches(User *u)
+{
+ return false;
+}
+
+//XXX perhaps move into xlinemanager
+void CheckELines(InspIRCd *ServerInstance, std::vector<ELine *> &ELines)
+{
+ for (std::vector<User*>::const_iterator u2 = ServerInstance->local_users.begin(); u2 != ServerInstance->local_users.end(); u2++)
+ {
+ User* u = (User*)(*u2);
+
+ for (std::vector<ELine *>::iterator i = ELines.begin(); i != ELines.end(); i++)
+ {
+ ELine *e = (*i);
+
+ u->exempt = e->Matches(u);
+ }
+ }
+}
+
+
IdentHostPair XLineManager::IdentSplit(const std::string &ident_and_host)
{
IdentHostPair n = std::make_pair<std::string,std::string>("*","*");
// adds a g:line
-bool XLineManager::add_gline(long duration, const char* source,const char* reason,const char* hostmask)
+bool XLineManager::AddGLine(long duration, const char* source,const char* reason,const char* hostmask)
{
IdentHostPair ih = IdentSplit(hostmask);
- if (del_gline(hostmask, true))
+ if (DelGLine(hostmask, true))
return false;
- GLine* item = new GLine(ServerInstance->Time(), duration, source, reason, ih.first.c_str(), ih.second.c_str());
+ GLine* item = new GLine(ServerInstance, ServerInstance->Time(), duration, source, reason, ih.first.c_str(), ih.second.c_str());
glines.push_back(item);
sort(glines.begin(), glines.end(),XLineManager::XSortComparison);
+ pending_lines.push_back(item);
return true;
}
// adds an e:line (exception to bans)
-bool XLineManager::add_eline(long duration, const char* source, const char* reason, const char* hostmask)
+bool XLineManager::AddELine(long duration, const char* source, const char* reason, const char* hostmask)
{
IdentHostPair ih = IdentSplit(hostmask);
- if (del_eline(hostmask, true))
+ if (DelELine(hostmask, true))
return false;
- ELine* item = new ELine(ServerInstance->Time(), duration, source, reason, ih.first.c_str(), ih.second.c_str());
+ ELine* item = new ELine(ServerInstance, ServerInstance->Time(), duration, source, reason, ih.first.c_str(), ih.second.c_str());
elines.push_back(item);
sort(elines.begin(), elines.end(),XLineManager::XSortComparison);
+ // XXX we really only need to check one line (the new one) - this is a bit wasteful!
+ CheckELines(ServerInstance, elines);
+
return true;
}
// adds a q:line
-bool XLineManager::add_qline(long duration, const char* source, const char* reason, const char* nickname)
+bool XLineManager::AddQLine(long duration, const char* source, const char* reason, const char* nickname)
{
- if (del_qline(nickname, true))
+ if (DelQLine(nickname, true))
return false;
- QLine* item = new QLine(ServerInstance->Time(), duration, source, reason, nickname);
+ QLine* item = new QLine(ServerInstance, ServerInstance->Time(), duration, source, reason, nickname);
qlines.push_back(item);
sort(qlines.begin(), qlines.end(),XLineManager::XSortComparison);
+ pending_lines.push_back(item);
return true;
}
// adds a z:line
-bool XLineManager::add_zline(long duration, const char* source, const char* reason, const char* ipaddr)
+bool XLineManager::AddZLine(long duration, const char* source, const char* reason, const char* ipaddr)
{
if (strchr(ipaddr,'@'))
{
ipaddr++;
}
- if (del_zline(ipaddr, true))
+ if (DelZLine(ipaddr, true))
return false;
- ZLine* item = new ZLine(ServerInstance->Time(), duration, source, reason, ipaddr);
+ ZLine* item = new ZLine(ServerInstance, ServerInstance->Time(), duration, source, reason, ipaddr);
zlines.push_back(item);
sort(zlines.begin(), zlines.end(),XLineManager::XSortComparison);
+ pending_lines.push_back(item);
return true;
}
// adds a k:line
-bool XLineManager::add_kline(long duration, const char* source, const char* reason, const char* hostmask)
+bool XLineManager::AddKLine(long duration, const char* source, const char* reason, const char* hostmask)
{
IdentHostPair ih = IdentSplit(hostmask);
- if (del_kline(hostmask, true))
+ if (DelKLine(hostmask, true))
return false;
- KLine* item = new KLine(ServerInstance->Time(), duration, source, reason, ih.first.c_str(), ih.second.c_str());
+ KLine* item = new KLine(ServerInstance, ServerInstance->Time(), duration, source, reason, ih.first.c_str(), ih.second.c_str());
klines.push_back(item);
sort(klines.begin(), klines.end(),XLineManager::XSortComparison);
+ pending_lines.push_back(item);
return true;
}
// deletes a g:line, returns true if the line existed and was removed
-bool XLineManager::del_gline(const char* hostmask, bool simulate)
+bool XLineManager::DelGLine(const char* hostmask, bool simulate)
{
IdentHostPair ih = IdentSplit(hostmask);
for (std::vector<GLine*>::iterator i = glines.begin(); i != glines.end(); i++)
// deletes a e:line, returns true if the line existed and was removed
-bool XLineManager::del_eline(const char* hostmask, bool simulate)
+bool XLineManager::DelELine(const char* hostmask, bool simulate)
{
IdentHostPair ih = IdentSplit(hostmask);
for (std::vector<ELine*>::iterator i = elines.begin(); i != elines.end(); i++)
{
if (!simulate)
{
+ /* remove exempt from everyone and force recheck after deleting eline */
+ for (std::vector<User*>::const_iterator u2 = ServerInstance->local_users.begin(); u2 != ServerInstance->local_users.end(); u2++)
+ {
+ User* u = (User*)(*u2);
+ u->exempt = false;
+ }
+
delete *i;
elines.erase(i);
+ CheckELines(ServerInstance, elines);
}
return true;
}
// deletes a q:line, returns true if the line existed and was removed
-bool XLineManager::del_qline(const char* nickname, bool simulate)
+bool XLineManager::DelQLine(const char* nickname, bool simulate)
{
for (std::vector<QLine*>::iterator i = qlines.begin(); i != qlines.end(); i++)
{
// deletes a z:line, returns true if the line existed and was removed
-bool XLineManager::del_zline(const char* ipaddr, bool simulate)
+bool XLineManager::DelZLine(const char* ipaddr, bool simulate)
{
for (std::vector<ZLine*>::iterator i = zlines.begin(); i != zlines.end(); i++)
{
// deletes a k:line, returns true if the line existed and was removed
-bool XLineManager::del_kline(const char* hostmask, bool simulate)
+bool XLineManager::DelKLine(const char* hostmask, bool simulate)
{
IdentHostPair ih = IdentSplit(hostmask);
for (std::vector<KLine*>::iterator i = klines.begin(); i != klines.end(); i++)
return NULL;
for (std::vector<QLine*>::iterator i = qlines.begin(); i != qlines.end(); i++)
- if (match(nick,(*i)->nick))
+ if ((*i)->Matches(nick))
return (*i);
return NULL;
}
for (std::vector<GLine*>::iterator i = glines.begin(); i != glines.end(); i++)
{
- if ((match(user->ident,(*i)->identmask)))
- {
- if ((match(user->host,(*i)->hostmask, true)) || (match(user->GetIPString(),(*i)->hostmask, true)))
- {
- return (*i);
- }
- }
+ if ((*i)->Matches(user))
+ return (*i);
}
return NULL;
{
if (elines.empty())
return NULL;
- char host2[MAXBUF];
- snprintf(host2,MAXBUF,"*@%s",user->host);
for (std::vector<ELine*>::iterator i = elines.begin(); i != elines.end(); i++)
{
- if ((match(user->ident,(*i)->identmask)))
- {
- if ((match(user->host,(*i)->hostmask, true)) || (match(user->GetIPString(),(*i)->hostmask, true)))
- {
- return (*i);
- }
- }
+ if ((*i)->Matches(user))
+ return (*i);
}
return NULL;
}
// returns a pointer to the reason if an ip address matches a zline, NULL if it didnt match
-ZLine* XLineManager::matches_zline(const char* ipaddr)
+ZLine* XLineManager::matches_zline(User *u)
{
if (zlines.empty())
return NULL;
for (std::vector<ZLine*>::iterator i = zlines.begin(); i != zlines.end(); i++)
- if (match(ipaddr,(*i)->ipaddr, true))
+ if ((*i)->Matches(u))
return (*i);
return NULL;
}
for (std::vector<KLine*>::iterator i = klines.begin(); i != klines.end(); i++)
{
- if ((match(user->ident,(*i)->identmask)))
- {
- if ((match(user->host,(*i)->hostmask, true)) || (match(user->GetIPString(),(*i)->hostmask, true)))
- {
- return (*i);
- }
- }
+ if ((*i)->Matches(user))
+ return (*i);
}
return NULL;
}
// applies lines, removing clients and changing nicks etc as applicable
-
-void XLineManager::apply_lines()
+void XLineManager::ApplyLines()
{
- int What = 0; // XXX remove me
- char reason[MAXBUF];
-
- XLine* check = NULL;
for (std::vector<User*>::const_iterator u2 = ServerInstance->local_users.begin(); u2 != ServerInstance->local_users.end(); u2++)
{
User* u = (User*)(*u2);
- if (elines.size())
- {
- // ignore people matching exempts
- if (matches_exception(u))
- continue;
- }
- if ((What & APPLY_GLINES) && (glines.size()))
+ for (std::vector<XLine *>::iterator i = pending_lines.begin(); i != pending_lines.end(); i++)
{
- if ((check = matches_gline(u)))
- {
- snprintf(reason,MAXBUF,"G-Lined: %s",check->reason);
- if (*ServerInstance->Config->MoronBanner)
- u->WriteServ("NOTICE %s :*** %s", u->nick, ServerInstance->Config->MoronBanner);
- if (ServerInstance->Config->HideBans)
- User::QuitUser(ServerInstance, u, "G-Lined", reason);
- else
- User::QuitUser(ServerInstance, u, reason);
- }
- }
- if ((What & APPLY_KLINES) && (klines.size()))
- {
- if ((check = matches_kline(u)))
- {
- snprintf(reason,MAXBUF,"K-Lined: %s",check->reason);
- if (*ServerInstance->Config->MoronBanner)
- u->WriteServ("NOTICE %s :*** %s", u->nick, ServerInstance->Config->MoronBanner);
- if (ServerInstance->Config->HideBans)
- User::QuitUser(ServerInstance, u, "K-Lined", reason);
- else
- User::QuitUser(ServerInstance, u, reason);
- }
- }
- if ((What & APPLY_QLINES) && (qlines.size()))
- {
- if ((check = matches_qline(u->nick)))
- {
- snprintf(reason,MAXBUF,"Q-Lined: %s",check->reason);
- if (*ServerInstance->Config->MoronBanner)
- u->WriteServ("NOTICE %s :*** %s", u->nick, ServerInstance->Config->MoronBanner);
- if (ServerInstance->Config->HideBans)
- User::QuitUser(ServerInstance, u, "Q-Lined", reason);
- else
- User::QuitUser(ServerInstance, u, reason);
- }
- }
- if ((What & APPLY_ZLINES) && (zlines.size()))
- {
- if ((check = matches_zline(u->GetIPString())))
- {
- snprintf(reason,MAXBUF,"Z-Lined: %s", check->reason);
- if (*ServerInstance->Config->MoronBanner)
- u->WriteServ("NOTICE %s :*** %s", u->nick, ServerInstance->Config->MoronBanner);
- if (ServerInstance->Config->HideBans)
- User::QuitUser(ServerInstance, u, "Z-Lined", reason);
- else
- User::QuitUser(ServerInstance, u, reason);
- }
+ XLine *x = *i;
+ if (x->Matches(u))
+ x->Apply(u);
}
}
+
+ pending_lines.clear();
}
void XLineManager::stats_k(User* user, string_list &results)
XLineManager::XLineManager(InspIRCd* Instance) : ServerInstance(Instance)
{
}
+
+bool XLine::Matches(const std::string &str)
+{
+ return false;
+}
+
+void XLine::Apply(User* u)
+{
+}
+
+void XLine::DefaultApply(User* u, char line)
+{
+ char reason[MAXBUF];
+ snprintf(reason, MAXBUF, "%c-Lined: %s", line, this->reason);
+ if (*ServerInstance->Config->MoronBanner)
+ u->WriteServ("NOTICE %s :*** %s", u->nick, ServerInstance->Config->MoronBanner);
+ if (ServerInstance->Config->HideBans)
+ User::QuitUser(ServerInstance, u, line + std::string("-Lined"), reason);
+ else
+ User::QuitUser(ServerInstance, u, reason);
+}
+
+bool KLine::Matches(User *u)
+{
+ if (u->exempt)
+ return false;
+
+ if ((match(u->ident, this->identmask)))
+ {
+ if ((match(u->host, this->hostmask, true)) || (match(u->GetIPString(), this->hostmask, true)))
+ {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+void KLine::Apply(User* u)
+{
+ DefaultApply(u, 'K');
+}
+
+bool GLine::Matches(User *u)
+{
+ if (u->exempt)
+ return false;
+
+ if ((match(u->ident, this->identmask)))
+ {
+ if ((match(u->host, this->hostmask, true)) || (match(u->GetIPString(), this->hostmask, true)))
+ {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+void GLine::Apply(User* u)
+{
+ DefaultApply(u, 'G');
+}
+
+bool ELine::Matches(User *u)
+{
+ if (u->exempt)
+ return false;
+
+ if ((match(u->ident, this->identmask)))
+ {
+ if ((match(u->host, this->hostmask, true)) || (match(u->GetIPString(), this->hostmask, true)))
+ {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+bool ZLine::Matches(User *u)
+{
+ if (u->exempt)
+ return false;
+
+ if (match(u->GetIPString(), this->ipaddr, true))
+ return true;
+ else
+ return false;
+}
+
+void ZLine::Apply(User* u)
+{
+ DefaultApply(u, 'Z');
+}
+
+
+bool QLine::Matches(User *u)
+{
+ if (u->exempt)
+ return false;
+
+ if (match(u->nick, this->nick))
+ return true;
+
+ return false;
+}
+
+void QLine::Apply(User* u)
+{
+ /* Can we force the user to their uid here instead? */
+ DefaultApply(u, 'Q');
+}
+
+
+bool ZLine::Matches(const std::string &str)
+{
+ if (match(str.c_str(), this->ipaddr, true))
+ return true;
+ else
+ return false;
+}
+
+bool QLine::Matches(const std::string &str)
+{
+ if (match(str.c_str(), this->nick))
+ return true;
+
+ return false;
+}
+