diff options
-rw-r--r-- | include/mode.h | 60 | ||||
-rw-r--r-- | src/mode.cpp | 88 |
2 files changed, 148 insertions, 0 deletions
diff --git a/include/mode.h b/include/mode.h index 08ac33597..cfac562e6 100644 --- a/include/mode.h +++ b/include/mode.h @@ -35,6 +35,66 @@ enum UserModeBits { UM_WALLOPS = 4 }; +enum ModeType { + MODETYPE_USER = 0, + MODETYPE_CHANNEL = 1 +}; + +enum ModeAction { + MODEACTION_DENY = 0, /* Drop the mode change, AND a parameter if its a parameterized mode */ + MODEACTION_ALLOW = 1 /* Allow the mode */ +}; + +class ModeOutput +{ + private: + std::string par; + ModeAction act; + public: + ModeOutput(std::string parameter, ModeAction action); + ModeAction GetAction(); + std::string& GetParameter(); +}; + +class ModeHandler +{ + char mode; + int n_params; + bool list; + ModeType m_type; + bool oper; + + public: + ModeHandler(char modeletter, int parameters, bool listmode, ModeType type, bool operonly); + virtual ~ModeHandler(); + + bool IsListMode(); + ModeType GetModeType(); + bool NeedsOper(); + int GetNumParams(); + char GetModeChar(); + + virtual ModeOutput OnModeChange(userrec* source, userrec* dest, chanrec* channel, const std::string ¶meter, bool adding); + virtual void DisplayList(userrec* user, chanrec* channel); + virtual bool CheckTimeStamp(time_t theirs, time_t ours, const std::string &their_param, const std::string &our_param, chanrec* channel); +}; + +class ModeWatcher +{ + char mode; + ModeType m_type; + + public: + ModeWatcher(char modeletter, ModeType type); + virtual ~ModeWatcher(); + + char GetModeChar(); + ModeType GetModeType(); + + virtual bool BeforeMode(userrec* source, userrec* dest, chanrec* channel, const std::string ¶meter, bool adding); + virtual void AfterMode(userrec* source, userrec* dest, chanrec* channel, const std::string ¶meter, bool adding); +}; + class ModeParser { private: diff --git a/src/mode.cpp b/src/mode.cpp index b6905df9e..d61725eef 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -54,6 +54,94 @@ extern ServerConfig* Config; extern time_t TIME; +ModeOutput::ModeOutput(std::string parameter, ModeAction action) : par(parameter), act(action) +{ +} + +ModeAction ModeOutput::GetAction() +{ + return act; +} + +std::string& ModeOutput::GetParameter() +{ + return par; +} + +ModeHandler::ModeHandler(char modeletter, int parameters, bool listmode, ModeType type, bool operonly) : mode(modeletter), n_params(parameters), list(listmode), m_type(type), oper(operonly) +{ +} + +ModeHandler::~ModeHandler() +{ +} + +bool ModeHandler::IsListMode() +{ + return list; +} + +ModeType ModeHandler::GetModeType() +{ + return m_type; +} + +bool ModeHandler::NeedsOper() +{ + return oper; +} + +int ModeHandler::GetNumParams() +{ + return n_params; +} + +char ModeHandler::GetModeChar() +{ + return mode; +} + +ModeOutput ModeHandler::OnModeChange(userrec* source, userrec* dest, chanrec* channel, const std::string ¶meter, bool adding) +{ + return ModeOutput("", MODEACTION_DENY); +} + +void ModeHandler::DisplayList(userrec* user, chanrec* channel) +{ +} + +bool ModeHandler::CheckTimeStamp(time_t theirs, time_t ours, const std::string &their_param, const std::string &our_param, chanrec* channel) +{ + return (ours < theirs); +} + +ModeWatcher::ModeWatcher(char modeletter, ModeType type) : mode(modeletter), m_type(type) +{ +} + +ModeWatcher::~ModeWatcher() +{ +} + +char ModeWatcher::GetModeChar() +{ + return mode; +} + +ModeType ModeWatcher::GetModeType() +{ + return m_type; +} + +bool ModeWatcher::BeforeMode(userrec* source, userrec* dest, chanrec* channel, const std::string ¶meter, bool adding) +{ + return true; +} + +void ModeWatcher::AfterMode(userrec* source, userrec* dest, chanrec* channel, const std::string ¶meter, bool adding) +{ +} + userrec* ModeParser::SanityChecks(userrec *user,char *dest,chanrec *chan,int status) { userrec *d; |