X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fsnomasks.cpp;h=c67afcdc5da730a84dd74dd2e3a6bfa3c31a39fc;hb=dc7927e17cffb2ee3c50ef9f037ed873d378f679;hp=fdedc7d645e7553e1f0997f9af0b1290cab2cf8e;hpb=05d6973c72d019def3e89ac68c19b4fab94d3369;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/snomasks.cpp b/src/snomasks.cpp index fdedc7d64..c67afcdc5 100644 --- a/src/snomasks.cpp +++ b/src/snomasks.cpp @@ -14,18 +14,90 @@ * --------------------------------------------------- */ -#include -#include +#include #include "configreader.h" #include "users.h" -#include "modules.h" -#include "commands.h" -#include "xline.h" -#include "helperfuncs.h" #include "snomasks.h" -extern ServerConfig* Config; -extern int MODCOUNT; -extern std::vector modules; -extern std::vector factory; +SnomaskManager::SnomaskManager(InspIRCd* Instance) : ServerInstance(Instance) +{ + SnoMasks.clear(); + this->SetupDefaults(); +} + +SnomaskManager::~SnomaskManager() +{ +} + +bool SnomaskManager::EnableSnomask(char letter, const std::string &type) +{ + if (SnoMasks.find(letter) == SnoMasks.end()) + { + SnoMasks[letter] = type; + return true; + } + return false; +} + +bool SnomaskManager::DisableSnomask(char letter) +{ + SnoList::iterator n = SnoMasks.find(letter); + if (n != SnoMasks.end()) + { + SnoMasks.erase(n); + return true; + } + return false; +} + +void SnomaskManager::WriteToSnoMask(char letter, const std::string &text) +{ + /* Only send to snomask chars which are enabled */ + SnoList::iterator n = SnoMasks.find(letter); + if (n != SnoMasks.end()) + { + /* Only opers can receive snotices, so we iterate the oper list */ + for (std::vector::iterator i = ServerInstance->all_opers.begin(); i != ServerInstance->all_opers.end(); i++) + { + userrec* a = *i; + if (IS_LOCAL(a) && a->modes[UM_SERVERNOTICE] && a->modes[UM_SNOMASK] && a->IsNoticeMaskSet(n->first)) + { + /* send server notices to all with +ns */ + a->WriteServ("NOTICE %s :*** %s: %s",a->nick, n->second.c_str(), text.c_str()); + } + } + } +} + +void SnomaskManager::WriteToSnoMask(char letter, const char* text, ...) +{ + char textbuffer[MAXBUF]; + va_list argsPtr; + + va_start(argsPtr, text); + vsnprintf(textbuffer, MAXBUF, text, argsPtr); + va_end(argsPtr); + + this->WriteToSnoMask(letter, std::string(textbuffer)); +} + +bool SnomaskManager::IsEnabled(char letter) +{ + return (SnoMasks.find(letter) != SnoMasks.end()); +} + +void SnomaskManager::SetupDefaults() +{ + this->EnableSnomask('c',"CONNECT"); /* Local connect notices */ + this->EnableSnomask('C',"REMOTECONNECT"); /* Remote connect notices */ + this->EnableSnomask('q',"QUIT"); /* Local quit notices */ + this->EnableSnomask('Q',"REMOTEQUIT"); /* Remote quit notices */ + this->EnableSnomask('k',"KILL"); /* Kill notices */ + this->EnableSnomask('l',"LINK"); /* Link notices */ + this->EnableSnomask('o',"OPER"); /* Oper up/down notices */ + this->EnableSnomask('d',"DEBUG"); /* Debug notices */ + this->EnableSnomask('x',"XLINE"); /* Xline notice (g/z/q/k/e) */ + this->EnableSnomask('t',"STATS"); /* Local or remote stats request */ + this->EnableSnomask('f',"FLOOD"); /* Flooding notices */ +}