diff options
-rw-r--r-- | include/modes/cmode_k.h | 8 | ||||
-rw-r--r-- | src/mode.cpp | 19 | ||||
-rw-r--r-- | src/modes/cmode_k.cpp | 40 |
3 files changed, 53 insertions, 14 deletions
diff --git a/include/modes/cmode_k.h b/include/modes/cmode_k.h new file mode 100644 index 000000000..f855afee9 --- /dev/null +++ b/include/modes/cmode_k.h @@ -0,0 +1,8 @@ +#include "mode.h" + +class ModeChannelKey : public ModeHandler +{ + public: + ModeChannelKey(); + ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding); +}; diff --git a/src/mode.cpp b/src/mode.cpp index 74eb2790b..2a875c06d 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -20,26 +20,14 @@ using namespace std; #include "inspircd.h" #include "configreader.h" #include <unistd.h> -#include <sys/errno.h> -#include <time.h> -#include <string> #include "hash_map.h" -#include <map> -#include <sstream> -#include <vector> -#include <deque> #include "connection.h" #include "users.h" -#include "ctables.h" -#include "globals.h" #include "modules.h" -#include "dynamic.h" -#include "wildcard.h" #include "message.h" -#include "commands.h" -#include "xline.h" #include "inspstring.h" #include "helperfuncs.h" +#include "commands.h" #include "mode.h" /* +s (secret) */ @@ -56,6 +44,8 @@ using namespace std; #include "modes/cmode_n.h" /* +i (invite only) */ #include "modes/cmode_i.h" +/* +k (keyed channel) */ +#include "modes/cmode_k.h" extern int MODCOUNT; extern std::vector<Module*> modules; @@ -655,6 +645,7 @@ ModeParser::ModeParser() this->AddMode(new ModeChannelTopicOps, 't'); this->AddMode(new ModeChannelNoExternal, 'n'); this->AddMode(new ModeChannelInviteOnly, 'i'); - /* TODO: Modes +l, +k, +o, +v, +h */ + this->AddMode(new ModeChannelKey, 'k'); + /* TODO: Modes +l, +o, +v, +h */ } diff --git a/src/modes/cmode_k.cpp b/src/modes/cmode_k.cpp new file mode 100644 index 000000000..9e69ed13b --- /dev/null +++ b/src/modes/cmode_k.cpp @@ -0,0 +1,40 @@ +#include "inspircd.h" +#include "mode.h" +#include "channels.h" +#include "users.h" +#include "modes/cmode_k.h" + +ModeChannelKey::ModeChannelKey() : ModeHandler('k', 1, 1, false, MODETYPE_CHANNEL, false) +{ +} + +ModeAction ModeChannelKey::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding) +{ + if (channel->modes[CM_KEY] != adding) + { + if ((channel->modes[CM_KEY]) && (strcasecmp(parameter.c_str(),channel->key))) + { + /* Key is currently set and the correct key wasnt given */ + return MODEACTION_DENY; + } + else if (!channel->modes[CM_KEY]) + { + /* Key isnt currently set */ + strlcpy(channel->key,parameter.c_str(),32); + channel->modes[CM_KEY] = adding; + return MODEACTION_ALLOW; + } + else if ((channel->modes[CM_KEY]) && (!strcasecmp(parameter.c_str(),channel->key))) + { + /* Key is currently set, and correct key was given */ + *channel->key = 0; + channel->modes[CM_KEY] = adding; + return MODEACTION_ALLOW; + } + return MODEACTION_DENY; + } + else + { + return MODEACTION_DENY; + } +} |