X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fxline.cpp;h=211194dcfbae85f7b457397d8896b2e365d1b14b;hb=4498f1abd163b140efcbbd9e75173665c9b1c29f;hp=b15a7ce2b22c0b447185972ccf9e625b269eb0f4;hpb=3626aeb9ce4798c73cf3a5621388406062c450f7;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/xline.cpp b/src/xline.cpp index b15a7ce2b..211194dcf 100644 --- a/src/xline.cpp +++ b/src/xline.cpp @@ -2,7 +2,7 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * InspIRCd: (C) 2002-2009 InspIRCd Development Team + * InspIRCd: (C) 2002-2010 InspIRCd Development Team * See: http://wiki.inspircd.org/Credits * * This program is free but copyrighted software; see @@ -11,12 +11,89 @@ * --------------------------------------------------- */ -/* $Core */ - #include "inspircd.h" #include "xline.h" #include "bancache.h" +/** An XLineFactory specialized to generate GLine* pointers + */ +class GLineFactory : public XLineFactory +{ + public: + GLineFactory() : XLineFactory("G") { } + + /** Generate a GLine + */ + XLine* Generate(time_t set_time, long duration, std::string source, std::string reason, std::string xline_specific_mask) + { + IdentHostPair ih = ServerInstance->XLines->IdentSplit(xline_specific_mask); + return new GLine(set_time, duration, source, reason, ih.first, ih.second); + } +}; + +/** An XLineFactory specialized to generate ELine* pointers + */ +class ELineFactory : public XLineFactory +{ + public: + ELineFactory() : XLineFactory("E") { } + + /** Generate an ELine + */ + XLine* Generate(time_t set_time, long duration, std::string source, std::string reason, std::string xline_specific_mask) + { + IdentHostPair ih = ServerInstance->XLines->IdentSplit(xline_specific_mask); + return new ELine(set_time, duration, source, reason, ih.first, ih.second); + } +}; + +/** An XLineFactory specialized to generate KLine* pointers + */ +class KLineFactory : public XLineFactory +{ + public: + KLineFactory() : XLineFactory("K") { } + + /** Generate a KLine + */ + XLine* Generate(time_t set_time, long duration, std::string source, std::string reason, std::string xline_specific_mask) + { + IdentHostPair ih = ServerInstance->XLines->IdentSplit(xline_specific_mask); + return new KLine(set_time, duration, source, reason, ih.first, ih.second); + } +}; + +/** An XLineFactory specialized to generate QLine* pointers + */ +class QLineFactory : public XLineFactory +{ + public: + QLineFactory() : XLineFactory("Q") { } + + /** Generate a QLine + */ + XLine* Generate(time_t set_time, long duration, std::string source, std::string reason, std::string xline_specific_mask) + { + return new QLine(set_time, duration, source, reason, xline_specific_mask); + } +}; + +/** An XLineFactory specialized to generate ZLine* pointers + */ +class ZLineFactory : public XLineFactory +{ + public: + ZLineFactory() : XLineFactory("Z") { } + + /** Generate a ZLine + */ + XLine* Generate(time_t set_time, long duration, std::string source, std::string reason, std::string xline_specific_mask) + { + return new ZLine(set_time, duration, source, reason, xline_specific_mask); + } +}; + + /* * This is now version 3 of the XLine subsystem, let's see if we can get it as nice and * efficient as we can this time so we can close this file and never ever touch it again .. @@ -69,7 +146,7 @@ void XLineManager::CheckELines() if (ELines.empty()) return; - for (std::vector::const_iterator u2 = ServerInstance->Users->local_users.begin(); u2 != ServerInstance->Users->local_users.end(); u2++) + for (std::vector::const_iterator u2 = ServerInstance->Users->local_users.begin(); u2 != ServerInstance->Users->local_users.end(); u2++) { User* u = (User*)(*u2); @@ -181,7 +258,7 @@ bool XLineManager::AddLine(XLine* line, User* user) } } - /*ELine* item = new ELine(ServerInstance, ServerInstance->Time(), duration, source, reason, ih.first.c_str(), ih.second.c_str());*/ + /*ELine* item = new ELine(ServerInstance->Time(), duration, source, reason, ih.first.c_str(), ih.second.c_str());*/ XLineFactory* xlf = GetFactory(line->type); if (!xlf) return false; @@ -234,7 +311,7 @@ bool XLineManager::DelLine(const char* hostmask, const std::string &type, User* void ELine::Unset() { /* remove exempt from everyone and force recheck after deleting eline */ - for (std::vector::const_iterator u2 = ServerInstance->Users->local_users.begin(); u2 != ServerInstance->Users->local_users.end(); u2++) + for (std::vector::const_iterator u2 = ServerInstance->Users->local_users.begin(); u2 != ServerInstance->Users->local_users.end(); u2++) { User* u = (User*)(*u2); u->exempt = false; @@ -338,7 +415,7 @@ void XLineManager::ExpireLine(ContainerIter container, LookupIter item) // applies lines, removing clients and changing nicks etc as applicable void XLineManager::ApplyLines() { - std::vector::reverse_iterator u2 = ServerInstance->Users->local_users.rbegin(); + std::vector::reverse_iterator u2 = ServerInstance->Users->local_users.rbegin(); while (u2 != ServerInstance->Users->local_users.rend()) { User* u = *u2++; @@ -389,13 +466,20 @@ void XLineManager::InvokeStats(const std::string &type, int numeric, User* user, } -XLineManager::XLineManager(InspIRCd* Instance) : ServerInstance(Instance) +XLineManager::XLineManager() { - GFact = new GLineFactory(Instance); - EFact = new ELineFactory(Instance); - KFact = new KLineFactory(Instance); - QFact = new QLineFactory(Instance); - ZFact = new ZLineFactory(Instance); + GLineFactory* GFact; + ELineFactory* EFact; + KLineFactory* KFact; + QLineFactory* QFact; + ZLineFactory* ZFact; + + + GFact = new GLineFactory; + EFact = new ELineFactory; + KFact = new KLineFactory; + QFact = new QLineFactory; + ZFact = new ZLineFactory; RegisterFactory(GFact); RegisterFactory(EFact); @@ -406,17 +490,14 @@ XLineManager::XLineManager(InspIRCd* Instance) : ServerInstance(Instance) XLineManager::~XLineManager() { - UnregisterFactory(GFact); - UnregisterFactory(EFact); - UnregisterFactory(KFact); - UnregisterFactory(QFact); - UnregisterFactory(ZFact); - - delete GFact; - delete EFact; - delete KFact; - delete QFact; - delete ZFact; + const char gekqz[] = "GEKQZ"; + for(unsigned int i=0; i < sizeof(gekqz); i++) + { + XLineFactory* xlf = GetFactory(std::string(1, gekqz[i])); + if (xlf) + UnregisterFactory(xlf); + delete xlf; + } // Delete all existing XLines for (XLineContainer::iterator i = lookup_lines.begin(); i != lookup_lines.end(); i++) @@ -444,8 +525,8 @@ void XLine::DefaultApply(User* u, const std::string &line, bool bancache) { char sreason[MAXBUF]; snprintf(sreason, MAXBUF, "%s-Lined: %s", line.c_str(), this->reason.c_str()); - if (*ServerInstance->Config->MoronBanner) - u->WriteServ("NOTICE %s :*** %s", u->nick.c_str(), ServerInstance->Config->MoronBanner); + if (!ServerInstance->Config->MoronBanner.empty()) + u->WriteServ("NOTICE %s :*** %s", u->nick.c_str(), ServerInstance->Config->MoronBanner.c_str()); if (ServerInstance->Config->HideBans) ServerInstance->Users->QuitUser(u, line + "-Lined", sreason); @@ -590,7 +671,7 @@ bool GLine::Matches(const std::string &str) void ELine::OnAdd() { /* When adding one eline, only check the one eline */ - for (std::vector::const_iterator u2 = ServerInstance->Users->local_users.begin(); u2 != ServerInstance->Users->local_users.end(); u2++) + for (std::vector::const_iterator u2 = ServerInstance->Users->local_users.begin(); u2 != ServerInstance->Users->local_users.end(); u2++) { User* u = (User*)(*u2); if (this->Matches(u))