diff options
author | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2010-02-25 19:42:08 +0000 |
---|---|---|
committer | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2010-02-25 19:42:08 +0000 |
commit | 61197974c5f7ce009096468b208c3abf2c25810b (patch) | |
tree | 9a7cf7a895941d1d734093a3bbc7f9c27f6e734c | |
parent | 52a42b48cd63bd49991130f9cf7f2b0e13c76448 (diff) |
Make remote/local snomasks consistent and allow use without naming
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@12568 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | include/snomasks.h | 43 | ||||
-rw-r--r-- | src/modules/m_chancreate.cpp | 7 | ||||
-rw-r--r-- | src/modules/m_globops.cpp | 16 | ||||
-rw-r--r-- | src/modules/m_override.cpp | 21 | ||||
-rw-r--r-- | src/modules/m_seenicks.cpp | 12 | ||||
-rw-r--r-- | src/snomasks.cpp | 114 | ||||
-rw-r--r-- | src/users.cpp | 19 |
7 files changed, 72 insertions, 160 deletions
diff --git a/include/snomasks.h b/include/snomasks.h index 92773a1b0..d0062e162 100644 --- a/include/snomasks.h +++ b/include/snomasks.h @@ -17,71 +17,48 @@ class Snomask { public: - char MySnomask; std::string Description; std::string LastMessage; + int Count; bool LastBlocked; - unsigned int Count; + char LastLetter; /** Create a new Snomask */ - Snomask(char snomask, const std::string &description) : MySnomask(snomask), Description(description), LastMessage(""), Count(0) + Snomask() : Count(0), LastBlocked(false), LastLetter(0) { } /** Sends a message to all opers with this snomask. */ - void SendMessage(const std::string &message); + void SendMessage(const std::string &message, char letter); /** Sends out the (last message repeated N times) message */ void Flush(); }; -/** A list of snomasks which are valid, and their descriptive texts - */ -typedef std::map<char, Snomask *> SnoList; - /** Snomask manager handles routing of SNOMASK (usermode +n) messages to opers. * Modules and the core can enable and disable snomask characters. If they do, * then sending snomasks using these characters becomes possible. */ class CoreExport SnomaskManager { - private: - /** Currently active snomask list - */ - SnoList SnoMasks; - - /** Set up the default (core available) snomask chars - */ - void SetupDefaults(); public: + Snomask masks[26]; + /** Create a new SnomaskManager */ SnomaskManager(); - /** Delete SnomaskManager - */ - ~SnomaskManager(); - /** Enable a snomask. * @param letter The snomask letter to enable. Once enabled, * server notices may be routed to users with this letter in * their list, and users may add this letter to their list. * @param description The descriptive text sent along with any * server notices, at the start of the notice, e.g. "GLOBOPS". - * @return True if the snomask was enabled, false if it already - * exists. - */ - bool EnableSnomask(char letter, const std::string &description); - - /** Disable a snomask. - * @param letter The snomask letter to disable. - * @return True if the snomask was disabled, false if it didn't - * exist. */ - bool DisableSnomask(char letter); + void EnableSnomask(char letter, const std::string &description); /** Write to all users with a given snomask (local server only) * @param letter The snomask letter to write to @@ -119,12 +96,6 @@ class CoreExport SnomaskManager * is not particularly significant, in order to keep notices going out. */ void FlushSnotices(); - - /** Check if a snomask is enabled. - * @param letter The snomask letter to check. - * @return True if the snomask has been enabled. - */ - bool IsEnabled(char letter); }; #endif diff --git a/src/modules/m_chancreate.cpp b/src/modules/m_chancreate.cpp index 251829ff7..c4c28bc30 100644 --- a/src/modules/m_chancreate.cpp +++ b/src/modules/m_chancreate.cpp @@ -22,17 +22,10 @@ class ModuleChanCreate : public Module ModuleChanCreate() { ServerInstance->SNO->EnableSnomask('j', "CHANCREATE"); - ServerInstance->SNO->EnableSnomask('J', "REMOTECHANCREATE"); Implementation eventlist[] = { I_OnUserJoin }; ServerInstance->Modules->Attach(eventlist, this, 1); } - ~ModuleChanCreate() - { - ServerInstance->SNO->DisableSnomask('j'); - ServerInstance->SNO->DisableSnomask('J'); - } - Version GetVersion() { return Version("Creates a snomask with notices whenever a new channel is created",VF_VENDOR); diff --git a/src/modules/m_globops.cpp b/src/modules/m_globops.cpp index f02f8a1b2..16ce91926 100644 --- a/src/modules/m_globops.cpp +++ b/src/modules/m_globops.cpp @@ -35,8 +35,7 @@ class CommandGlobops : public Command { line = line + parameters[i] + " "; } - ServerInstance->SNO->WriteToSnoMask('g',line); - ServerInstance->PI->SendSNONotice("g", line); + ServerInstance->SNO->WriteGlobalSno('g',line); return CMD_SUCCESS; } @@ -46,22 +45,17 @@ class ModuleGlobops : public Module { CommandGlobops cmd; public: - ModuleGlobops() - : cmd(this) + ModuleGlobops() : cmd(this) {} + + void init() { ServerInstance->AddCommand(&cmd); ServerInstance->SNO->EnableSnomask('g',"GLOBOPS"); - - } - - virtual ~ModuleGlobops() - { - ServerInstance->SNO->DisableSnomask('g'); } virtual Version GetVersion() { - return Version("Provides support for GLOBOPS and user mode +g", VF_OPTCOMMON | VF_VENDOR); + return Version("Provides support for GLOBOPS and user mode +g", VF_VENDOR); } }; diff --git a/src/modules/m_override.cpp b/src/modules/m_override.cpp index c443a88d8..4e120ced1 100644 --- a/src/modules/m_override.cpp +++ b/src/modules/m_override.cpp @@ -26,7 +26,7 @@ class ModuleOverride : public Module { // read our config options (main config file) OnRehash(NULL); - ServerInstance->SNO->EnableSnomask('G', "GODMODE"); + ServerInstance->SNO->EnableSnomask('v', "OVERRIDE"); Implementation eventlist[] = { I_OnRehash, I_OnPreMode, I_On005Numeric, I_OnUserPreJoin, I_OnUserPreKick, I_OnPreTopicChange }; ServerInstance->Modules->Attach(eventlist, this, 6); } @@ -61,7 +61,7 @@ class ModuleOverride : public Module { if (!channel->HasUser(source) || (channel->IsModeSet('t') && channel->GetPrefixValue(source) < HALFOP_VALUE)) { - ServerInstance->SNO->WriteGlobalSno('G',std::string(source->nick)+" used oper override to change a topic on "+std::string(channel->name)); + ServerInstance->SNO->WriteGlobalSno('v',std::string(source->nick)+" used oper override to change a topic on "+std::string(channel->name)); } // Explicit allow @@ -78,7 +78,7 @@ class ModuleOverride : public Module // If the kicker's status is less than the target's, or the kicker's status is less than or equal to voice if ((memb->chan->GetPrefixValue(source) < memb->getRank()) || (memb->chan->GetPrefixValue(source) <= VOICE_VALUE)) { - ServerInstance->SNO->WriteGlobalSno('G',std::string(source->nick)+" used oper override to kick "+std::string(memb->user->nick)+" on "+std::string(memb->chan->name)+" ("+reason+")"); + ServerInstance->SNO->WriteGlobalSno('v',std::string(source->nick)+" used oper override to kick "+std::string(memb->user->nick)+" on "+std::string(memb->chan->name)+" ("+reason+")"); return MOD_RES_ALLOW; } } @@ -99,7 +99,7 @@ class ModuleOverride : public Module std::string msg = std::string(source->nick)+" overriding modes:"; for(unsigned int i=0; i < parameters.size(); i++) msg += " " + parameters[i]; - ServerInstance->SNO->WriteGlobalSno('G',msg); + ServerInstance->SNO->WriteGlobalSno('v',msg); return MOD_RES_ALLOW; } return MOD_RES_PASSTHRU; @@ -125,7 +125,7 @@ class ModuleOverride : public Module if (NoisyOverride) chan->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "NOTICE %s :%s used oper override to bypass invite-only", cname, user->nick.c_str()); - ServerInstance->SNO->WriteGlobalSno('G', user->nick+" used oper override to bypass +i on "+std::string(cname)); + ServerInstance->SNO->WriteGlobalSno('v', user->nick+" used oper override to bypass +i on "+std::string(cname)); } return MOD_RES_ALLOW; } @@ -141,7 +141,7 @@ class ModuleOverride : public Module if (NoisyOverride) chan->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "NOTICE %s :%s used oper override to bypass the channel key", cname, user->nick.c_str()); - ServerInstance->SNO->WriteGlobalSno('G', user->nick+" used oper override to bypass +k on "+std::string(cname)); + ServerInstance->SNO->WriteGlobalSno('v', user->nick+" used oper override to bypass +k on "+std::string(cname)); return MOD_RES_ALLOW; } @@ -156,7 +156,7 @@ class ModuleOverride : public Module if (NoisyOverride) chan->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "NOTICE %s :%s used oper override to bypass the channel limit", cname, user->nick.c_str()); - ServerInstance->SNO->WriteGlobalSno('G', user->nick+" used oper override to bypass +l on "+std::string(cname)); + ServerInstance->SNO->WriteGlobalSno('v', user->nick+" used oper override to bypass +l on "+std::string(cname)); return MOD_RES_ALLOW; } @@ -171,7 +171,7 @@ class ModuleOverride : public Module if (NoisyOverride) chan->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "NOTICE %s :%s used oper override to bypass channel ban", cname, user->nick.c_str()); - ServerInstance->SNO->WriteGlobalSno('G',"%s used oper override to bypass channel ban on %s", user->nick.c_str(), cname); + ServerInstance->SNO->WriteGlobalSno('v',"%s used oper override to bypass channel ban on %s", user->nick.c_str(), cname); return MOD_RES_ALLOW; } } @@ -179,11 +179,6 @@ class ModuleOverride : public Module return MOD_RES_PASSTHRU; } - ~ModuleOverride() - { - ServerInstance->SNO->DisableSnomask('G'); - } - Version GetVersion() { return Version("Provides support for unreal-style oper-override",VF_VENDOR); diff --git a/src/modules/m_seenicks.cpp b/src/modules/m_seenicks.cpp index 006329f53..f1d55297e 100644 --- a/src/modules/m_seenicks.cpp +++ b/src/modules/m_seenicks.cpp @@ -18,26 +18,18 @@ class ModuleSeeNicks : public Module { public: - ModuleSeeNicks() - { + void init() + { ServerInstance->SNO->EnableSnomask('n',"NICK"); - ServerInstance->SNO->EnableSnomask('N',"REMOTENICK"); Implementation eventlist[] = { I_OnUserPostNick }; ServerInstance->Modules->Attach(eventlist, this, 1); } - virtual ~ModuleSeeNicks() - { - ServerInstance->SNO->DisableSnomask('n'); - ServerInstance->SNO->DisableSnomask('N'); - } - virtual Version GetVersion() { return Version("Provides support for seeing local and remote nickchanges via snomasks", VF_VENDOR); } - virtual void OnUserPostNick(User* user, const std::string &oldnick) { ServerInstance->SNO->WriteToSnoMask(IS_LOCAL(user) ? 'n' : 'N',"User %s changed their nickname to %s", oldnick.c_str(), user->nick.c_str()); diff --git a/src/snomasks.cpp b/src/snomasks.cpp index 380416a9d..f8e1fc158 100644 --- a/src/snomasks.cpp +++ b/src/snomasks.cpp @@ -11,66 +11,27 @@ * --------------------------------------------------- */ -/* $Core */ - #include "inspircd.h" #include <stdarg.h> -#include "snomasks.h" - -SnomaskManager::SnomaskManager() -{ - SnoMasks.clear(); - this->SetupDefaults(); -} - -SnomaskManager::~SnomaskManager() -{ - for (std::map<char, Snomask *>::iterator i = SnoMasks.begin(); i != SnoMasks.end(); i++) - { - delete i->second; - } - SnoMasks.clear(); -} void SnomaskManager::FlushSnotices() { - for (std::map<char, Snomask *>::iterator i = SnoMasks.begin(); i != SnoMasks.end(); i++) - { - i->second->Flush(); - } -} - -bool SnomaskManager::EnableSnomask(char letter, const std::string &type) -{ - if (SnoMasks.find(letter) == SnoMasks.end()) - { - Snomask *s = new Snomask(letter, type); - SnoMasks[letter] = s; - return true; - } - return false; + for (int i=0; i < 26; i++) + masks[i].Flush(); } -bool SnomaskManager::DisableSnomask(char letter) +void SnomaskManager::EnableSnomask(char letter, const std::string &type) { - SnoList::iterator n = SnoMasks.find(letter); - if (n != SnoMasks.end()) - { - delete n->second; // destroy the snomask - SnoMasks.erase(n); - return true; - } - return false; + if (letter >= 'a' && letter <= 'z') + masks[letter - 'a'].Description = type; } 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()) - { - n->second->SendMessage(text); - } + if (letter >= 'a' && letter <= 'z') + masks[letter - 'a'].SendMessage(text, letter); + if (letter >= 'A' && letter <= 'Z') + masks[letter - 'A'].SendMessage(text, letter); } void SnomaskManager::WriteGlobalSno(char letter, const std::string& text) @@ -104,44 +65,36 @@ void SnomaskManager::WriteGlobalSno(char letter, const char* text, ...) this->WriteGlobalSno(letter, std::string(textbuffer)); } -bool SnomaskManager::IsEnabled(char letter) -{ - return (SnoMasks.find(letter) != SnoMasks.end()); -} - -void SnomaskManager::SetupDefaults() +SnomaskManager::SnomaskManager() { - 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('K',"REMOTEKILL"); /* Remote kill notices */ - this->EnableSnomask('l',"LINK"); /* Linking notices */ - this->EnableSnomask('L',"REMOTELINK"); /* Remote linking notices */ - this->EnableSnomask('o',"OPER"); /* Oper up/down notices */ - this->EnableSnomask('O',"REMOTEOPER"); /* Remote oper up/down notices */ - this->EnableSnomask('a',"ANNOUNCEMENT"); /* formerly WriteOpers() - generic notices to all opers */ - this->EnableSnomask('A',"REMOTEANNOUNCEMENT"); /* formerly WriteOpers() - generic notices to all opers */ - this->EnableSnomask('d',"DEBUG"); /* Debug notices */ - this->EnableSnomask('x',"XLINE"); /* Xline notice (g/z/q/k/e) */ - this->EnableSnomask('X',"REMOTEXLINE"); /* Remove Xline notice (g/z/q/k/e) */ - this->EnableSnomask('t',"STATS"); /* Local or remote stats request */ - this->EnableSnomask('f',"FLOOD"); /* Flooding notices */ + EnableSnomask('c',"CONNECT"); /* Local connect notices */ + EnableSnomask('q',"QUIT"); /* Local quit notices */ + EnableSnomask('k',"KILL"); /* Kill notices */ + EnableSnomask('l',"LINK"); /* Linking notices */ + EnableSnomask('o',"OPER"); /* Oper up/down notices */ + EnableSnomask('a',"ANNOUNCEMENT"); /* formerly WriteOpers() - generic notices to all opers */ + EnableSnomask('d',"DEBUG"); /* Debug notices */ + EnableSnomask('x',"XLINE"); /* Xline notice (g/z/q/k/e) */ + EnableSnomask('t',"STATS"); /* Local or remote stats request */ + EnableSnomask('f',"FLOOD"); /* Flooding notices */ } /*************************************************************************************/ -void Snomask::SendMessage(const std::string &message) +void Snomask::SendMessage(const std::string &message, char mysnomask) { - if (message != LastMessage) + if (message != LastMessage || mysnomask != LastLetter) { this->Flush(); LastMessage = message; + LastLetter = mysnomask; - std::string desc = this->Description; + std::string desc = Description; + if (desc.empty()) + desc = "SNO-" + tolower(mysnomask); + if (isupper(mysnomask)) + desc = "REMOTE" + desc; ModResult MOD_RESULT; - char mysnomask = MySnomask; ServerInstance->Logs->Log("snomask", DEFAULT, "%s: %s", desc.c_str(), message.c_str()); FIRST_MOD_RESULT(OnSendSnotice, MOD_RESULT, (mysnomask, desc, message)); @@ -172,13 +125,16 @@ void Snomask::Flush() { if (Count > 1) { - std::string desc = this->Description; + std::string desc = Description; + if (desc.empty()) + desc = "SNO-" + tolower(LastLetter); + if (isupper(LastLetter)) + desc = "REMOTE" + desc; std::string mesg = "(last message repeated "+ConvToStr(Count)+" times)"; - char mysnomask = MySnomask; ServerInstance->Logs->Log("snomask", DEFAULT, "%s: %s", desc.c_str(), mesg.c_str()); - FOREACH_MOD(I_OnSendSnotice, OnSendSnotice(mysnomask, desc, mesg)); + FOREACH_MOD(I_OnSendSnotice, OnSendSnotice(LastLetter, desc, mesg)); if (!LastBlocked) { @@ -188,7 +144,7 @@ void Snomask::Flush() while (i != ServerInstance->Users->all_opers.end()) { User* a = *i; - if (IS_LOCAL(a) && a->IsModeSet('s') && a->IsNoticeMaskSet(mysnomask) && !a->quitting) + if (IS_LOCAL(a) && a->IsModeSet('s') && a->IsNoticeMaskSet(LastLetter) && !a->quitting) { a->WriteServ("NOTICE %s :*** %s: %s", a->nick.c_str(), desc.c_str(), mesg.c_str()); } diff --git a/src/users.cpp b/src/users.cpp index f69d34fea..81f830583 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -37,9 +37,9 @@ std::string User::ProcessNoticeMasks(const char *sm) adding = false; break; case '*': - for (unsigned char d = 'A'; d <= 'z'; d++) + for (unsigned char d = 'a'; d <= 'z'; d++) { - if (ServerInstance->SNO->IsEnabled(d)) + if (!ServerInstance->SNO->masks[d - 'a'].Description.empty()) { if ((!IsNoticeMaskSet(d) && adding) || (IsNoticeMaskSet(d) && !adding)) { @@ -50,12 +50,23 @@ std::string User::ProcessNoticeMasks(const char *sm) output += d; } + oldadding = adding; + char u = toupper(d); + if ((!IsNoticeMaskSet(u) && adding) || (IsNoticeMaskSet(u) && !adding)) + { + if ((oldadding != adding) || (!output.length())) + output += (adding ? '+' : '-'); + + this->SetNoticeMask(u, adding); + + output += u; + } + oldadding = adding; } - oldadding = adding; } break; default: - if ((*c >= 'A') && (*c <= 'z') && (ServerInstance->SNO->IsEnabled(*c))) + if (isalpha(*c)) { if ((!IsNoticeMaskSet(*c) && adding) || (IsNoticeMaskSet(*c) && !adding)) { |