summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/configreader.h2
-rw-r--r--include/inspircd.h2
-rw-r--r--include/xline.h95
-rw-r--r--src/cmd_eline.cpp4
-rw-r--r--src/cmd_gline.cpp6
-rw-r--r--src/cmd_kline.cpp6
-rw-r--r--src/cmd_nick.cpp8
-rw-r--r--src/cmd_qline.cpp8
-rw-r--r--src/cmd_stats.cpp10
-rw-r--r--src/cmd_zline.cpp6
-rw-r--r--src/configreader.cpp4
-rw-r--r--src/inspircd.cpp5
-rw-r--r--src/modules.cpp28
-rw-r--r--src/userprocess.cpp12
-rw-r--r--src/users.cpp12
-rw-r--r--src/xline.cpp120
16 files changed, 170 insertions, 158 deletions
diff --git a/include/configreader.h b/include/configreader.h
index b95cdede5..a63e31d71 100644
--- a/include/configreader.h
+++ b/include/configreader.h
@@ -84,6 +84,8 @@ class ServerConfig : public Extensible
bool CheckOnce(char* tag, bool bail, userrec* user);
public:
+
+ InspIRCd* GetInstance();
/** This holds all the information in the config file,
* it's indexed by tag name to a vector of key/values.
diff --git a/include/inspircd.h b/include/inspircd.h
index 7808ad4e6..699d910dc 100644
--- a/include/inspircd.h
+++ b/include/inspircd.h
@@ -77,6 +77,7 @@ class serverstats : public classbase
}
};
+class XLineManager;
class InspIRCd : public classbase
{
@@ -132,6 +133,7 @@ class InspIRCd : public classbase
DNS* Res;
TimerManager* Timers;
command_table cmdlist;
+ XLineManager* XLines;
ModuleList modules;
FactoryList factory;
diff --git a/include/xline.h b/include/xline.h
index b04d2224d..f393abc76 100644
--- a/include/xline.h
+++ b/include/xline.h
@@ -124,6 +124,7 @@ class QLine : public XLine
};
class ServerConfig;
+class InspIRCd;
bool InitXLine(ServerConfig* conf, const char* tag);
bool DoneXLine(ServerConfig* conf, const char* tag);
@@ -133,39 +134,67 @@ bool DoQLine(ServerConfig* conf, const char* tag, char** entries, void** values,
bool DoKLine(ServerConfig* conf, const char* tag, char** entries, void** values, int* types);
bool DoELine(ServerConfig* conf, const char* tag, char** entries, void** values, int* types);
-bool add_gline(long duration, const char* source, const char* reason, const char* hostmask);
-bool add_qline(long duration, const char* source, const char* reason, const char* nickname);
-bool add_zline(long duration, const char* source, const char* reason, const char* ipaddr);
-bool add_kline(long duration, const char* source, const char* reason, const char* hostmask);
-bool add_eline(long duration, const char* source, const char* reason, const char* hostmask);
-
-bool del_gline(const char* hostmask);
-bool del_qline(const char* nickname);
-bool del_zline(const char* ipaddr);
-bool del_kline(const char* hostmask);
-bool del_eline(const char* hostmask);
-
-char* matches_qline(const char* nick);
-char* matches_gline(const char* host);
-char* matches_zline(const char* ipaddr);
-char* matches_kline(const char* host);
-char* matches_exception(const char* host);
-
-void expire_lines();
-void apply_lines(const int What);
-
-void stats_k(userrec* user, string_list &results);
-void stats_g(userrec* user, string_list &results);
-void stats_q(userrec* user, string_list &results);
-void stats_z(userrec* user, string_list &results);
-void stats_e(userrec* user, string_list &results);
-
-void gline_set_creation_time(const char* host, time_t create_time);
-void qline_set_creation_time(const char* nick, time_t create_time);
-void zline_set_creation_time(const char* ip, time_t create_time);
-void eline_set_creation_time(const char* host, time_t create_time);
+class XLineManager
+{
+ protected:
+ InspIRCd* ServerInstance;
+
+ static bool XLineManager::GSortComparison ( const GLine one, const GLine two );
+ static bool XLineManager::ESortComparison ( const ELine one, const ELine two );
+ static bool XLineManager::ZSortComparison ( const ZLine one, const ZLine two );
+ static bool XLineManager::KSortComparison ( const KLine one, const KLine two );
+ static bool XLineManager::QSortComparison ( const QLine one, const QLine two );
+ public:
+ /* Lists for temporary lines with an expiry time */
+ std::vector<KLine> klines;
+ std::vector<GLine> glines;
+ std::vector<ZLine> zlines;
+ std::vector<QLine> qlines;
+ std::vector<ELine> elines;
+
+ /* Seperate lists for perm XLines that isnt checked by expiry functions */
+ std::vector<KLine> pklines;
+ std::vector<GLine> pglines;
+ std::vector<ZLine> pzlines;
+ std::vector<QLine> pqlines;
+ std::vector<ELine> pelines;
+
+ XLineManager(InspIRCd* Instance);
+
+ bool add_gline(long duration, const char* source, const char* reason, const char* hostmask);
+ bool add_qline(long duration, const char* source, const char* reason, const char* nickname);
+ bool add_zline(long duration, const char* source, const char* reason, const char* ipaddr);
+ bool add_kline(long duration, const char* source, const char* reason, const char* hostmask);
+ bool add_eline(long duration, const char* source, const char* reason, const char* hostmask);
+
+ bool del_gline(const char* hostmask);
+ bool del_qline(const char* nickname);
+ bool del_zline(const char* ipaddr);
+ bool del_kline(const char* hostmask);
+ bool del_eline(const char* hostmask);
+
+ char* matches_qline(const char* nick);
+ char* matches_gline(const char* host);
+ char* matches_zline(const char* ipaddr);
+ char* matches_kline(const char* host);
+ char* matches_exception(const char* host);
+
+ void expire_lines();
+ void apply_lines(const int What);
+
+ void stats_k(userrec* user, string_list &results);
+ void stats_g(userrec* user, string_list &results);
+ void stats_q(userrec* user, string_list &results);
+ void stats_z(userrec* user, string_list &results);
+ void stats_e(userrec* user, string_list &results);
+
+ void gline_set_creation_time(const char* host, time_t create_time);
+ void qline_set_creation_time(const char* nick, time_t create_time);
+ void zline_set_creation_time(const char* ip, time_t create_time);
+ void eline_set_creation_time(const char* host, time_t create_time);
-bool zline_make_global(const char* ipaddr);
-bool qline_make_global(const char* nickname);
+ bool zline_make_global(const char* ipaddr);
+ bool qline_make_global(const char* nickname);
+};
#endif
diff --git a/src/cmd_eline.cpp b/src/cmd_eline.cpp
index 011cb6851..67874b5d7 100644
--- a/src/cmd_eline.cpp
+++ b/src/cmd_eline.cpp
@@ -33,7 +33,7 @@ void cmd_eline::Handle (const char** parameters, int pcnt, userrec *user)
if (host_matches_everyone(parameters[0],user))
return;
- add_eline(duration(parameters[1]),user->nick,parameters[2],parameters[0]);
+ ServerInstance->XLines->add_eline(duration(parameters[1]),user->nick,parameters[2],parameters[0]);
FOREACH_MOD(I_OnAddELine,OnAddELine(duration(parameters[1]), user, parameters[2], parameters[0]));
if (!duration(parameters[1]))
@@ -47,7 +47,7 @@ void cmd_eline::Handle (const char** parameters, int pcnt, userrec *user)
}
else
{
- if (del_eline(parameters[0]))
+ if (ServerInstance->XLines->del_eline(parameters[0]))
{
FOREACH_MOD(I_OnDelELine,OnDelELine(user, parameters[0]));
ServerInstance->WriteOpers("*** %s Removed E-line on %s.",user->nick,parameters[0]);
diff --git a/src/cmd_gline.cpp b/src/cmd_gline.cpp
index 7eeec2820..91f2e6b1c 100644
--- a/src/cmd_gline.cpp
+++ b/src/cmd_gline.cpp
@@ -33,7 +33,7 @@ void cmd_gline::Handle (const char** parameters, int pcnt, userrec *user)
if (host_matches_everyone(parameters[0],user))
return;
- add_gline(duration(parameters[1]),user->nick,parameters[2],parameters[0]);
+ ServerInstance->XLines->add_gline(duration(parameters[1]),user->nick,parameters[2],parameters[0]);
FOREACH_MOD(I_OnAddGLine,OnAddGLine(duration(parameters[1]), user, parameters[2], parameters[0]));
if (!duration(parameters[1]))
@@ -45,11 +45,11 @@ void cmd_gline::Handle (const char** parameters, int pcnt, userrec *user)
ServerInstance->WriteOpers("*** %s added timed G-line for %s, expires in %d seconds.",user->nick,parameters[0],duration(parameters[1]));
}
- apply_lines(APPLY_GLINES);
+ ServerInstance->XLines->apply_lines(APPLY_GLINES);
}
else
{
- if (del_gline(parameters[0]))
+ if (ServerInstance->XLines->del_gline(parameters[0]))
{
FOREACH_MOD(I_OnDelGLine,OnDelGLine(user, parameters[0]));
ServerInstance->WriteOpers("*** %s Removed G-line on %s.",user->nick,parameters[0]);
diff --git a/src/cmd_kline.cpp b/src/cmd_kline.cpp
index 4cd114dad..3ed25602c 100644
--- a/src/cmd_kline.cpp
+++ b/src/cmd_kline.cpp
@@ -38,7 +38,7 @@ void cmd_kline::Handle (const char** parameters, int pcnt, userrec *user)
if (host_matches_everyone(parameters[0],user))
return;
- add_kline(duration(parameters[1]),user->nick,parameters[2],parameters[0]);
+ ServerInstance->XLines->add_kline(duration(parameters[1]),user->nick,parameters[2],parameters[0]);
FOREACH_MOD(I_OnAddKLine,OnAddKLine(duration(parameters[1]), user, parameters[2], parameters[0]));
if (!duration(parameters[1]))
@@ -50,11 +50,11 @@ void cmd_kline::Handle (const char** parameters, int pcnt, userrec *user)
ServerInstance->WriteOpers("*** %s added timed K-line for %s, expires in %d seconds.",user->nick,parameters[0],duration(parameters[1]));
}
- apply_lines(APPLY_KLINES);
+ ServerInstance->XLines->apply_lines(APPLY_KLINES);
}
else
{
- if (del_kline(parameters[0]))
+ if (ServerInstance->XLines->del_kline(parameters[0]))
{
FOREACH_MOD(I_OnDelKLine,OnDelKLine(user, parameters[0]));
ServerInstance->WriteOpers("*** %s Removed K-line on %s.",user->nick,parameters[0]);
diff --git a/src/cmd_nick.cpp b/src/cmd_nick.cpp
index a7472bd95..2ed79b434 100644
--- a/src/cmd_nick.cpp
+++ b/src/cmd_nick.cpp
@@ -25,6 +25,7 @@
#include "xline.h"
#include "dns.h"
#include "helperfuncs.h"
+#include "inspircd.h"
#include "hashcomp.h"
#include "commands/cmd_nick.h"
@@ -84,10 +85,11 @@ void cmd_nick::Handle (const char** parameters, int pcnt, userrec *user)
{
parameters[0]++;
}
- if (matches_qline(parameters[0]))
+ char* mq = ServerInstance->XLines->matches_qline(parameters[0]);
+ if (mq)
{
- ServerInstance->WriteOpers("*** Q-Lined nickname %s from %s!%s@%s: %s",parameters[0],user->nick,user->ident,user->host,matches_qline(parameters[0]));
- user->WriteServ("432 %s %s :Invalid nickname: %s",user->nick,parameters[0],matches_qline(parameters[0]));
+ ServerInstance->WriteOpers("*** Q-Lined nickname %s from %s!%s@%s: %s",parameters[0],user->nick,user->ident,user->host,mq);
+ user->WriteServ("432 %s %s :Invalid nickname: %s",user->nick,parameters[0],mq);
return;
}
if ((ServerInstance->FindNick(parameters[0])) && (ServerInstance->FindNick(parameters[0]) != user))
diff --git a/src/cmd_qline.cpp b/src/cmd_qline.cpp
index 90e3c99fc..c82b5f53c 100644
--- a/src/cmd_qline.cpp
+++ b/src/cmd_qline.cpp
@@ -23,15 +23,13 @@
#include "helperfuncs.h"
#include "commands/cmd_qline.h"
-
-
void cmd_qline::Handle (const char** parameters, int pcnt, userrec *user)
{
if (pcnt >= 3)
{
if (nick_matches_everyone(parameters[0],user))
return;
- add_qline(duration(parameters[1]),user->nick,parameters[2],parameters[0]);
+ ServerInstance->XLines->add_qline(duration(parameters[1]),user->nick,parameters[2],parameters[0]);
FOREACH_MOD(I_OnAddQLine,OnAddQLine(duration(parameters[1]), user, parameters[2], parameters[0]));
if (!duration(parameters[1]))
{
@@ -41,11 +39,11 @@ void cmd_qline::Handle (const char** parameters, int pcnt, userrec *user)
{
ServerInstance->WriteOpers("*** %s added timed Q-line for %s, expires in %d seconds.",user->nick,parameters[0],duration(parameters[1]));
}
- apply_lines(APPLY_QLINES);
+ ServerInstance->XLines->apply_lines(APPLY_QLINES);
}
else
{
- if (del_qline(parameters[0]))
+ if (ServerInstance->XLines->del_qline(parameters[0]))
{
FOREACH_MOD(I_OnDelQLine,OnDelQLine(user, parameters[0]));
ServerInstance->WriteOpers("*** %s Removed Q-line on %s.",user->nick,parameters[0]);
diff --git a/src/cmd_stats.cpp b/src/cmd_stats.cpp
index b3ae20a5e..8187f8812 100644
--- a/src/cmd_stats.cpp
+++ b/src/cmd_stats.cpp
@@ -115,27 +115,27 @@ void DoStats(InspIRCd* ServerInstance, char statschar, userrec* user, string_lis
if (statschar == 'k')
{
- stats_k(user,results);
+ ServerInstance->XLines->stats_k(user,results);
}
if (statschar == 'g')
{
- stats_g(user,results);
+ ServerInstance->XLines->stats_g(user,results);
}
if (statschar == 'q')
{
- stats_q(user,results);
+ ServerInstance->XLines->stats_q(user,results);
}
if (statschar == 'Z')
{
- stats_z(user,results);
+ ServerInstance->XLines->stats_z(user,results);
}
if (statschar == 'e')
{
- stats_e(user,results);
+ ServerInstance->XLines->stats_e(user,results);
}
/* stats m (list number of times each command has been used, plus bytecount) */
diff --git a/src/cmd_zline.cpp b/src/cmd_zline.cpp
index 00396a1ae..61615da46 100644
--- a/src/cmd_zline.cpp
+++ b/src/cmd_zline.cpp
@@ -37,7 +37,7 @@ void cmd_zline::Handle (const char** parameters, int pcnt, userrec *user)
}
if (ip_matches_everyone(parameters[0],user))
return;
- add_zline(duration(parameters[1]),user->nick,parameters[2],parameters[0]);
+ ServerInstance->XLines->add_zline(duration(parameters[1]),user->nick,parameters[2],parameters[0]);
FOREACH_MOD(I_OnAddZLine,OnAddZLine(duration(parameters[1]), user, parameters[2], parameters[0]));
if (!duration(parameters[1]))
{
@@ -47,11 +47,11 @@ void cmd_zline::Handle (const char** parameters, int pcnt, userrec *user)
{
ServerInstance->WriteOpers("*** %s added timed Z-line for %s, expires in %d seconds.",user->nick,parameters[0],duration(parameters[1]));
}
- apply_lines(APPLY_ZLINES);
+ ServerInstance->XLines->apply_lines(APPLY_ZLINES);
}
else
{
- if (del_zline(parameters[0]))
+ if (ServerInstance->XLines->del_zline(parameters[0]))
{
FOREACH_MOD(I_OnDelZLine,OnDelZLine(user, parameters[0]));
ServerInstance->WriteOpers("*** %s Removed Z-line on %s.",user->nick,parameters[0]);
diff --git a/src/configreader.cpp b/src/configreader.cpp
index de46a1f29..b57de1692 100644
--- a/src/configreader.cpp
+++ b/src/configreader.cpp
@@ -1424,4 +1424,8 @@ std::string ServerConfig::GetFullProgDir(char** argv, int argc)
return otherdir;
}
+InspIRCd* ServerConfig::GetInstance()
+{
+ return ServerInstance;
+}
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index 1e2f16e07..22d2e51a9 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -273,9 +273,10 @@ InspIRCd::InspIRCd(int argc, char** argv) : ModCount(-1)
this->Timers = new TimerManager();
Config->ClearStack();
Config->Read(true, NULL);
- CheckRoot();
+ this->CheckRoot();
this->ModeGrok = new ModeParser(this);
this->AddServerName(Config->ServerName);
+ this->XLines = new XLineManager(this);
CheckDie();
InitializeDisabledCommands(Config->DisabledCommands, this);
stats->BoundPortCount = BindPorts(true);
@@ -674,7 +675,7 @@ void InspIRCd::DoOneIteration(bool process_module_sockets)
*/
if (((TIME % 5) == 0) && (!expire_run))
{
- expire_lines();
+ XLines->expire_lines();
if (process_module_sockets)
{
FOREACH_MOD(I_OnBackgroundTimer,OnBackgroundTimer(TIME));
diff --git a/src/modules.cpp b/src/modules.cpp
index f04745008..ed2d5a2fd 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -472,56 +472,56 @@ bool InspIRCd::PseudoToUser(userrec* alive, userrec* zombie, const std::string &
void InspIRCd::AddGLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask)
{
- add_gline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
- apply_lines(APPLY_GLINES);
+ XLines->add_gline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
+ XLines->apply_lines(APPLY_GLINES);
}
void InspIRCd::AddQLine(long duration, const std::string &source, const std::string &reason, const std::string &nickname)
{
- add_qline(duration, source.c_str(), reason.c_str(), nickname.c_str());
- apply_lines(APPLY_QLINES);
+ XLines->add_qline(duration, source.c_str(), reason.c_str(), nickname.c_str());
+ XLines->apply_lines(APPLY_QLINES);
}
void InspIRCd::AddZLine(long duration, const std::string &source, const std::string &reason, const std::string &ipaddr)
{
- add_zline(duration, source.c_str(), reason.c_str(), ipaddr.c_str());
- apply_lines(APPLY_ZLINES);
+ XLines->add_zline(duration, source.c_str(), reason.c_str(), ipaddr.c_str());
+ XLines->apply_lines(APPLY_ZLINES);
}
void InspIRCd::AddKLine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask)
{
- add_kline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
- apply_lines(APPLY_KLINES);
+ XLines->add_kline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
+ XLines->apply_lines(APPLY_KLINES);
}
void InspIRCd::AddELine(long duration, const std::string &source, const std::string &reason, const std::string &hostmask)
{
- add_eline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
+ XLines->add_eline(duration, source.c_str(), reason.c_str(), hostmask.c_str());
}
bool InspIRCd::DelGLine(const std::string &hostmask)
{
- return del_gline(hostmask.c_str());
+ return XLines->del_gline(hostmask.c_str());
}
bool InspIRCd::DelQLine(const std::string &nickname)
{
- return del_qline(nickname.c_str());
+ return XLines->del_qline(nickname.c_str());
}
bool InspIRCd::DelZLine(const std::string &ipaddr)
{
- return del_zline(ipaddr.c_str());
+ return XLines->del_zline(ipaddr.c_str());
}
bool InspIRCd::DelKLine(const std::string &hostmask)
{
- return del_kline(hostmask.c_str());
+ return XLines->del_kline(hostmask.c_str());
}
bool InspIRCd::DelELine(const std::string &hostmask)
{
- return del_eline(hostmask.c_str());
+ return XLines->del_eline(hostmask.c_str());
}
long InspIRCd::CalcDuration(const std::string &delta)
diff --git a/src/userprocess.cpp b/src/userprocess.cpp
index 565b7df05..2a4f57b93 100644
--- a/src/userprocess.cpp
+++ b/src/userprocess.cpp
@@ -151,8 +151,8 @@ void InspIRCd::ProcessUser(userrec* cu)
{
this->WriteOpers("*** Excess flood from %s",current->GetIPString());
log(DEFAULT,"Excess flood from: %s",current->GetIPString());
- add_zline(120,this->Config->ServerName,"Flood from unregistered connection",current->GetIPString());
- apply_lines(APPLY_ZLINES);
+ XLines->add_zline(120,this->Config->ServerName,"Flood from unregistered connection",current->GetIPString());
+ XLines->apply_lines(APPLY_ZLINES);
}
return;
@@ -168,8 +168,8 @@ void InspIRCd::ProcessUser(userrec* cu)
{
this->WriteOpers("*** Excess flood from %s",current->GetIPString());
log(DEFAULT,"Excess flood from: %s",current->GetIPString());
- add_zline(120,this->Config->ServerName,"Flood from unregistered connection",current->GetIPString());
- apply_lines(APPLY_ZLINES);
+ XLines->add_zline(120,this->Config->ServerName,"Flood from unregistered connection",current->GetIPString());
+ XLines->apply_lines(APPLY_ZLINES);
}
return;
@@ -202,8 +202,8 @@ void InspIRCd::ProcessUser(userrec* cu)
}
else
{
- add_zline(120,this->Config->ServerName,"Flood from unregistered connection",current->GetIPString());
- apply_lines(APPLY_ZLINES);
+ XLines->add_zline(120,this->Config->ServerName,"Flood from unregistered connection",current->GetIPString());
+ XLines->apply_lines(APPLY_ZLINES);
}
return;
diff --git a/src/users.cpp b/src/users.cpp
index 4529a3484..938557b59 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -894,10 +894,10 @@ void userrec::AddClient(InspIRCd* Instance, int socket, int port, bool iscached,
userrec::QuitUser(Instance, _new,"Server is full");
return;
}
- char* e = matches_exception(ipaddr);
+ char* e = Instance->XLines->matches_exception(ipaddr);
if (!e)
{
- char* r = matches_zline(ipaddr);
+ char* r = Instance->XLines->matches_zline(ipaddr);
if (r)
{
char reason[MAXBUF];
@@ -991,11 +991,11 @@ void userrec::FullConnect(CullList* Goners)
char match_against[MAXBUF];
snprintf(match_against,MAXBUF,"%s@%s", this->ident, this->host);
- char* e = matches_exception(match_against);
+ char* e = ServerInstance->XLines->matches_exception(match_against);
if (!e)
{
- char* r = matches_gline(match_against);
+ char* r = ServerInstance->XLines->matches_gline(match_against);
if (r)
{
@@ -1005,7 +1005,7 @@ void userrec::FullConnect(CullList* Goners)
return;
}
- r = matches_kline(match_against);
+ r = ServerInstance->XLines->matches_kline(match_against);
if (r)
{
@@ -1092,7 +1092,7 @@ bool userrec::ForceNickChange(const char* newnick)
return false;
}
- if (matches_qline(newnick))
+ if (ServerInstance->XLines->matches_qline(newnick))
{
ServerInstance->stats->statsCollisions++;
return false;
diff --git a/src/xline.cpp b/src/xline.cpp
index 6e40180ff..99b6fecf9 100644
--- a/src/xline.cpp
+++ b/src/xline.cpp
@@ -38,8 +38,6 @@ using namespace std;
#include "configreader.h"
#include "cull_list.h"
-extern InspIRCd* ServerInstance;
-
/* Version two, now with optimized expiry!
*
* Because the old way was horrendously slow, the new way of expiring xlines is very
@@ -58,34 +56,6 @@ extern InspIRCd* ServerInstance;
* -- Brain
*/
-/* Lists for temporary lines with an expiry time */
-
-std::vector<KLine> klines;
-std::vector<GLine> glines;
-std::vector<ZLine> zlines;
-std::vector<QLine> qlines;
-std::vector<ELine> elines;
-
-/* Seperate lists for perm XLines that isnt checked by expiry functions */
-
-std::vector<KLine> pklines;
-std::vector<GLine> pglines;
-std::vector<ZLine> pzlines;
-std::vector<QLine> pqlines;
-std::vector<ELine> pelines;
-
-
-bool GSortComparison ( const GLine one, const GLine two );
-bool ZSortComparison ( const ZLine one, const ZLine two );
-bool ESortComparison ( const ELine one, const ELine two );
-bool QSortComparison ( const QLine one, const QLine two );
-bool KSortComparison ( const KLine one, const KLine two );
-
-// Reads the default bans from the config file.
-// only a very small number of bans are defined
-// this way these days, such as qlines against
-// services nicks, etc.
-
bool InitXLine(ServerConfig* conf, const char* tag)
{
return true;
@@ -93,7 +63,7 @@ bool InitXLine(ServerConfig* conf, const char* tag)
bool DoneXLine(ServerConfig* conf, const char* tag)
{
- apply_lines(APPLY_ALL);
+ conf->GetInstance()->XLines->apply_lines(APPLY_ALL);
return true;
}
@@ -102,7 +72,7 @@ bool DoZLine(ServerConfig* conf, const char* tag, char** entries, void** values,
char* reason = (char*)values[0];
char* ipmask = (char*)values[1];
- add_zline(0,"<Config>",reason,ipmask);
+ conf->GetInstance()->XLines->add_zline(0,"<Config>",reason,ipmask);
log(DEBUG,"Read Z line (badip tag): ipmask=%s reason=%s",ipmask,reason);
return true;
}
@@ -112,7 +82,7 @@ bool DoQLine(ServerConfig* conf, const char* tag, char** entries, void** values,
char* reason = (char*)values[0];
char* nick = (char*)values[1];
- add_qline(0,"<Config>",reason,nick);
+ conf->GetInstance()->XLines->add_qline(0,"<Config>",reason,nick);
log(DEBUG,"Read Q line (badnick tag): nick=%s reason=%s",nick,reason);
return true;
}
@@ -122,7 +92,7 @@ bool DoKLine(ServerConfig* conf, const char* tag, char** entries, void** values,
char* reason = (char*)values[0];
char* host = (char*)values[1];
- add_kline(0,"<Config>",reason,host);
+ conf->GetInstance()->XLines->add_kline(0,"<Config>",reason,host);
log(DEBUG,"Read K line (badhost tag): host=%s reason=%s",host,reason);
return true;
}
@@ -132,14 +102,14 @@ bool DoELine(ServerConfig* conf, const char* tag, char** entries, void** values,
char* reason = (char*)values[0];
char* host = (char*)values[1];
- add_eline(0,"<Config>",reason,host);
+ conf->GetInstance()->XLines->add_eline(0,"<Config>",reason,host);
log(DEBUG,"Read E line (exception tag): host=%s reason=%s",host,reason);
return true;
}
// adds a g:line
-bool add_gline(long duration, const char* source,const char* reason,const char* hostmask)
+bool XLineManager::add_gline(long duration, const char* source,const char* reason,const char* hostmask)
{
bool ret = del_gline(hostmask);
@@ -154,7 +124,7 @@ bool add_gline(long duration, const char* source,const char* reason,const char*
if (duration)
{
glines.push_back(item);
- sort(glines.begin(), glines.end(),GSortComparison);
+ sort(glines.begin(), glines.end(),XLineManager::GSortComparison);
}
else
{
@@ -166,7 +136,7 @@ bool add_gline(long duration, const char* source,const char* reason,const char*
// adds an e:line (exception to bans)
-bool add_eline(long duration, const char* source, const char* reason, const char* hostmask)
+bool XLineManager::add_eline(long duration, const char* source, const char* reason, const char* hostmask)
{
bool ret = del_eline(hostmask);
ELine item;
@@ -179,7 +149,7 @@ bool add_eline(long duration, const char* source, const char* reason, const char
if (duration)
{
elines.push_back(item);
- sort(elines.begin(), elines.end(),ESortComparison);
+ sort(elines.begin(), elines.end(),XLineManager::ESortComparison);
}
else
{
@@ -190,7 +160,7 @@ bool add_eline(long duration, const char* source, const char* reason, const char
// adds a q:line
-bool add_qline(long duration, const char* source, const char* reason, const char* nickname)
+bool XLineManager::add_qline(long duration, const char* source, const char* reason, const char* nickname)
{
bool ret = del_qline(nickname);
QLine item;
@@ -204,7 +174,7 @@ bool add_qline(long duration, const char* source, const char* reason, const char
if (duration)
{
qlines.push_back(item);
- sort(qlines.begin(), qlines.end(),QSortComparison);
+ sort(qlines.begin(), qlines.end(),XLineManager::QSortComparison);
}
else
{
@@ -215,7 +185,7 @@ bool add_qline(long duration, const char* source, const char* reason, const char
// adds a z:line
-bool add_zline(long duration, const char* source, const char* reason, const char* ipaddr)
+bool XLineManager::add_zline(long duration, const char* source, const char* reason, const char* ipaddr)
{
bool ret = del_zline(ipaddr);
ZLine item;
@@ -235,7 +205,7 @@ bool add_zline(long duration, const char* source, const char* reason, const char
if (duration)
{
zlines.push_back(item);
- sort(zlines.begin(), zlines.end(),ZSortComparison);
+ sort(zlines.begin(), zlines.end(),XLineManager::ZSortComparison);
}
else
{
@@ -246,7 +216,7 @@ bool add_zline(long duration, const char* source, const char* reason, const char
// adds a k:line
-bool add_kline(long duration, const char* source, const char* reason, const char* hostmask)
+bool XLineManager::add_kline(long duration, const char* source, const char* reason, const char* hostmask)
{
bool ret = del_kline(hostmask);
KLine item;
@@ -259,7 +229,7 @@ bool add_kline(long duration, const char* source, const char* reason, const char
if (duration)
{
klines.push_back(item);
- sort(klines.begin(), klines.end(),KSortComparison);
+ sort(klines.begin(), klines.end(),XLineManager::KSortComparison);
}
else
{
@@ -270,7 +240,7 @@ bool add_kline(long duration, const char* source, const char* reason, const char
// deletes a g:line, returns true if the line existed and was removed
-bool del_gline(const char* hostmask)
+bool XLineManager::del_gline(const char* hostmask)
{
for (std::vector<GLine>::iterator i = glines.begin(); i != glines.end(); i++)
{
@@ -293,7 +263,7 @@ bool del_gline(const char* hostmask)
// deletes a e:line, returns true if the line existed and was removed
-bool del_eline(const char* hostmask)
+bool XLineManager::del_eline(const char* hostmask)
{
for (std::vector<ELine>::iterator i = elines.begin(); i != elines.end(); i++)
{
@@ -316,7 +286,7 @@ bool del_eline(const char* hostmask)
// deletes a q:line, returns true if the line existed and was removed
-bool del_qline(const char* nickname)
+bool XLineManager::del_qline(const char* nickname)
{
for (std::vector<QLine>::iterator i = qlines.begin(); i != qlines.end(); i++)
{
@@ -337,7 +307,7 @@ bool del_qline(const char* nickname)
return false;
}
-bool qline_make_global(const char* nickname)
+bool XLineManager::qline_make_global(const char* nickname)
{
for (std::vector<QLine>::iterator i = qlines.begin(); i != qlines.end(); i++)
{
@@ -350,7 +320,7 @@ bool qline_make_global(const char* nickname)
return false;
}
-bool zline_make_global(const char* ipaddr)
+bool XLineManager::zline_make_global(const char* ipaddr)
{
for (std::vector<ZLine>::iterator i = zlines.begin(); i != zlines.end(); i++)
{
@@ -365,7 +335,7 @@ bool zline_make_global(const char* ipaddr)
// deletes a z:line, returns true if the line existed and was removed
-bool del_zline(const char* ipaddr)
+bool XLineManager::del_zline(const char* ipaddr)
{
for (std::vector<ZLine>::iterator i = zlines.begin(); i != zlines.end(); i++)
{
@@ -388,7 +358,7 @@ bool del_zline(const char* ipaddr)
// deletes a k:line, returns true if the line existed and was removed
-bool del_kline(const char* hostmask)
+bool XLineManager::del_kline(const char* hostmask)
{
for (std::vector<KLine>::iterator i = klines.begin(); i != klines.end(); i++)
{
@@ -411,7 +381,7 @@ bool del_kline(const char* hostmask)
// returns a pointer to the reason if a nickname matches a qline, NULL if it didnt match
-char* matches_qline(const char* nick)
+char* XLineManager::matches_qline(const char* nick)
{
if ((qlines.empty()) && (pqlines.empty()))
return NULL;
@@ -426,7 +396,7 @@ char* matches_qline(const char* nick)
// returns a pointer to the reason if a host matches a gline, NULL if it didnt match
-char* matches_gline(const char* host)
+char* XLineManager::matches_gline(const char* host)
{
if ((glines.empty()) && (pglines.empty()))
return NULL;
@@ -439,7 +409,7 @@ char* matches_gline(const char* host)
return NULL;
}
-char* matches_exception(const char* host)
+char* XLineManager::matches_exception(const char* host)
{
if ((elines.empty()) && (pelines.empty()))
return NULL;
@@ -455,7 +425,7 @@ char* matches_exception(const char* host)
}
-void gline_set_creation_time(const char* host, time_t create_time)
+void XLineManager::gline_set_creation_time(const char* host, time_t create_time)
{
for (std::vector<GLine>::iterator i = glines.begin(); i != glines.end(); i++)
{
@@ -476,7 +446,7 @@ void gline_set_creation_time(const char* host, time_t create_time)
return ;
}
-void eline_set_creation_time(const char* host, time_t create_time)
+void XLineManager::eline_set_creation_time(const char* host, time_t create_time)
{
for (std::vector<ELine>::iterator i = elines.begin(); i != elines.end(); i++)
{
@@ -497,7 +467,7 @@ void eline_set_creation_time(const char* host, time_t create_time)
return;
}
-void qline_set_creation_time(const char* nick, time_t create_time)
+void XLineManager::qline_set_creation_time(const char* nick, time_t create_time)
{
for (std::vector<QLine>::iterator i = qlines.begin(); i != qlines.end(); i++)
{
@@ -518,7 +488,7 @@ void qline_set_creation_time(const char* nick, time_t create_time)
return;
}
-void zline_set_creation_time(const char* ip, time_t create_time)
+void XLineManager::zline_set_creation_time(const char* ip, time_t create_time)
{
for (std::vector<ZLine>::iterator i = zlines.begin(); i != zlines.end(); i++)
{
@@ -541,7 +511,7 @@ void zline_set_creation_time(const char* ip, time_t create_time)
// returns a pointer to the reason if an ip address matches a zline, NULL if it didnt match
-char* matches_zline(const char* ipaddr)
+char* XLineManager::matches_zline(const char* ipaddr)
{
if ((zlines.empty()) && (pzlines.empty()))
return NULL;
@@ -556,7 +526,7 @@ char* matches_zline(const char* ipaddr)
// returns a pointer to the reason if a host matches a kline, NULL if it didnt match
-char* matches_kline(const char* host)
+char* XLineManager::matches_kline(const char* host)
{
if ((klines.empty()) && (pklines.empty()))
return NULL;
@@ -569,34 +539,34 @@ char* matches_kline(const char* host)
return NULL;
}
-bool GSortComparison ( const GLine one, const GLine two )
+bool XLineManager::GSortComparison ( const GLine one, const GLine two )
{
return (one.duration + one.set_time) < (two.duration + two.set_time);
}
-bool ESortComparison ( const ELine one, const ELine two )
+bool XLineManager::ESortComparison ( const ELine one, const ELine two )
{
return (one.duration + one.set_time) < (two.duration + two.set_time);
}
-bool ZSortComparison ( const ZLine one, const ZLine two )
+bool XLineManager::ZSortComparison ( const ZLine one, const ZLine two )
{
return (one.duration + one.set_time) < (two.duration + two.set_time);
}
-bool KSortComparison ( const KLine one, const KLine two )
+bool XLineManager::KSortComparison ( const KLine one, const KLine two )
{
return (one.duration + one.set_time) < (two.duration + two.set_time);
}
-bool QSortComparison ( const QLine one, const QLine two )
+bool XLineManager::QSortComparison ( const QLine one, const QLine two )
{
return (one.duration + one.set_time) < (two.duration + two.set_time);
}
// removes lines that have expired
-void expire_lines()
+void XLineManager::expire_lines()
{
time_t current = ServerInstance->Time();
@@ -644,7 +614,7 @@ void expire_lines()
// applies lines, removing clients and changing nicks etc as applicable
-void apply_lines(const int What)
+void XLineManager::apply_lines(const int What)
{
char reason[MAXBUF];
char host[MAXBUF];
@@ -703,7 +673,7 @@ void apply_lines(const int What)
DELETE(Goners);
}
-void stats_k(userrec* user, string_list &results)
+void XLineManager::stats_k(userrec* user, string_list &results)
{
std::string sn = ServerInstance->Config->ServerName;
for (std::vector<KLine>::iterator i = klines.begin(); i != klines.end(); i++)
@@ -712,7 +682,7 @@ void stats_k(userrec* user, string_list &results)
results.push_back(sn+" 216 "+user->nick+" :"+i->hostmask+" "+ConvToStr(i->set_time)+" "+ConvToStr(i->duration)+" "+i->source+" :"+i->reason);
}
-void stats_g(userrec* user, string_list &results)
+void XLineManager::stats_g(userrec* user, string_list &results)
{
std::string sn = ServerInstance->Config->ServerName;
for (std::vector<GLine>::iterator i = glines.begin(); i != glines.end(); i++)
@@ -721,7 +691,7 @@ void stats_g(userrec* user, string_list &results)
results.push_back(sn+" 223 "+user->nick+" :"+i->hostmask+" "+ConvToStr(i->set_time)+" "+ConvToStr(i->duration)+" "+i->source+" :"+i->reason);
}
-void stats_q(userrec* user, string_list &results)
+void XLineManager::stats_q(userrec* user, string_list &results)
{
std::string sn = ServerInstance->Config->ServerName;
for (std::vector<QLine>::iterator i = qlines.begin(); i != qlines.end(); i++)
@@ -730,7 +700,7 @@ void stats_q(userrec* user, string_list &results)
results.push_back(sn+" 217 "+user->nick+" :"+i->nick+" "+ConvToStr(i->set_time)+" "+ConvToStr(i->duration)+" "+i->source+" :"+i->reason);
}
-void stats_z(userrec* user, string_list &results)
+void XLineManager::stats_z(userrec* user, string_list &results)
{
std::string sn = ServerInstance->Config->ServerName;
for (std::vector<ZLine>::iterator i = zlines.begin(); i != zlines.end(); i++)
@@ -739,7 +709,7 @@ void stats_z(userrec* user, string_list &results)
results.push_back(sn+" 223 "+user->nick+" :"+i->ipaddr+" "+ConvToStr(i->set_time)+" "+ConvToStr(i->duration)+" "+i->source+" :"+i->reason);
}
-void stats_e(userrec* user, string_list &results)
+void XLineManager::stats_e(userrec* user, string_list &results)
{
std::string sn = ServerInstance->Config->ServerName;
for (std::vector<ELine>::iterator i = elines.begin(); i != elines.end(); i++)
@@ -747,3 +717,7 @@ void stats_e(userrec* user, string_list &results)
for (std::vector<ELine>::iterator i = pelines.begin(); i != pelines.end(); i++)
results.push_back(sn+" 223 "+user->nick+" :"+i->hostmask+" "+ConvToStr(i->set_time)+" "+ConvToStr(i->duration)+" "+i->source+" :"+i->reason);
}
+
+XLineManager::XLineManager(InspIRCd* Instance) : ServerInstance(Instance)
+{
+}