modes.h

Go to the documentation of this file.
00001 /* Mode support
00002  *
00003  * Copyright (C) 2008-2011 Adam <Adam@anope.org>
00004  * Copyright (C) 2008-2013 Anope Team <team@anope.org>
00005  *
00006  * Please read COPYING and README for further details.
00007  */
00008 
00009 #ifndef MODES_H
00010 #define MODES_H
00011 
00012 #include "anope.h"
00013 #include "base.h"
00014 
00017 enum ModeType
00018 {
00019         /* Regular mode */
00020         MODE_REGULAR,
00021         /* b/e/I */
00022         MODE_LIST,
00023         /* k/l etc */
00024         MODE_PARAM,
00025         /* v/h/o/a/q */
00026         MODE_STATUS
00027 };
00028 
00029 /* Classes of modes, Channel modes and User modes
00030  */
00031 enum ModeClass
00032 {
00033         MC_CHANNEL,
00034         MC_USER
00035 };
00036 
00039 class CoreExport Mode : public Base
00040 {
00041  public:
00042         /* Mode name */
00043         Anope::string name;
00044         /* Class of mode this is (user/channel) */
00045         ModeClass mclass;
00046         /* Mode char for this, eg 'b' */
00047         char mchar;
00048         /* Type of mode this is, eg MODE_LIST */
00049         ModeType type;
00050 
00057         Mode(const Anope::string &mname, ModeClass mclass, char mc, ModeType type);
00058         virtual ~Mode();
00059 };
00060 
00063 class CoreExport UserMode : public Mode
00064 {
00065  public:
00070         UserMode(const Anope::string &name, char mc);
00071         virtual ~UserMode();
00072 };
00073 
00074 class CoreExport UserModeParam : public UserMode
00075 {
00076  public:
00081         UserModeParam(const Anope::string &name, char mc);
00082 
00087         virtual bool IsValid(const Anope::string &value) const { return true; }
00088 };
00089 
00092 class CoreExport ChannelMode : public Mode
00093 {
00094  public:
00099         ChannelMode(const Anope::string &name, char mc);
00100         virtual ~ChannelMode();
00101 
00106         virtual bool CanSet(User *u) const;
00107 };
00108 
00109 
00112 class CoreExport ChannelModeList : public ChannelMode
00113 {
00114  public:
00119         ChannelModeList(const Anope::string &name, char mc);
00120 
00123         virtual ~ChannelModeList();
00124 
00129         virtual bool IsValid(const Anope::string &mask) const { return true; }
00130 
00137         virtual bool Matches(const User *u, const Entry *e) { return false; }
00138 
00143         virtual void OnAdd(Channel *chan, const Anope::string &mask) { }
00144 
00149         virtual void OnDel(Channel *chan, const Anope::string &mask) { }
00150 };
00151 
00154 class CoreExport ChannelModeParam : public ChannelMode
00155 {
00156  public:
00162         ChannelModeParam(const Anope::string &name, char mc, bool minus_no_arg = false);
00163 
00166         virtual ~ChannelModeParam();
00167 
00168         /* Should we send an arg when unsetting this mode? */
00169         bool minus_no_arg;
00170 
00175         virtual bool IsValid(const Anope::string &value) const { return true; }
00176 };
00177 
00180 class CoreExport ChannelModeStatus : public ChannelMode
00181 {
00182  public:
00183         /* The symbol, eg @ % + */
00184         char Symbol;
00185         /* The "level" of the mode, used to compare with other modes.
00186          * Used so we know op > halfop > voice etc.
00187          */
00188         short level;
00189 
00196         ChannelModeStatus(const Anope::string &name, char mc, char mSymbol, short mlevel = 0);
00197 
00200         virtual ~ChannelModeStatus();
00201 };
00202 
00203 /* The status a user has on a channel (+v, +h, +o) etc */
00204 class CoreExport ChannelStatus
00205 {
00206  public:
00207         std::set<Anope::string> modes;
00208         Anope::string BuildCharPrefixList() const;
00209         Anope::string BuildModePrefixList() const;
00210 };
00211 
00214 class CoreExport ChannelModeKey : public ChannelModeParam
00215 {
00216  public:
00217         ChannelModeKey(char mc) : ChannelModeParam("KEY", mc) { }
00218 
00219         bool IsValid(const Anope::string &value) const anope_override;
00220 };
00221 
00225 class CoreExport ChannelModeAdmin : public ChannelMode
00226 {
00227  public:
00228         ChannelModeAdmin(char mc) : ChannelMode("ADMINONLY", mc) { }
00229 
00230         /* Opers only */
00231         bool CanSet(User *u) const anope_override;
00232 };
00233 
00237 class CoreExport ChannelModeOper : public ChannelMode
00238 {
00239  public:
00240         ChannelModeOper(char mc) : ChannelMode("OPERONLY", mc) { }
00241 
00242         /* Opers only */
00243         bool CanSet(User *u) const anope_override;
00244 };
00245 
00249 class CoreExport ChannelModeRegistered : public ChannelMode
00250 {
00251  public:
00252         ChannelModeRegistered(char mc) : ChannelMode("REGISTERED", mc) { }
00253 
00254         /* No one mlocks +r */
00255         bool CanSet(User *u) const anope_override;
00256 };
00257 
00258 class StackerInfo
00259 {
00260  public:
00261         /* Modes to be added */
00262         std::list<std::pair<Mode *, Anope::string> > AddModes;
00263         /* Modes to be deleted */
00264         std::list<std::pair<Mode *, Anope::string> > DelModes;
00265         /* Bot this is sent from */
00266         const BotInfo *bi;
00267 
00273         void AddMode(Mode *mode, bool set, const Anope::string &param);
00274 };
00275 
00282 class CoreExport ModeManager
00283 {
00284  protected:
00285         /* List of pairs of user/channels and their stacker info */
00286         static std::map<User *, StackerInfo *> UserStackerObjects;
00287         static std::map<Channel *, StackerInfo *> ChannelStackerObjects;
00288 
00293         static std::list<Anope::string> BuildModeStrings(StackerInfo *info);
00294 
00295  public:
00296         /* List of all modes Anope knows about */
00297         static std::vector<ChannelMode *> ChannelModes;
00298         static std::vector<UserMode *> UserModes;
00299 
00300         /* Number of generic channel and user modes we are tracking */
00301         static unsigned GenericChannelModes;
00302         static unsigned GenericUserModes;
00303         /* Default channel mode lock */
00304         static std::list<std::pair<Anope::string, Anope::string> > ModeLockOn;
00305         static std::list<Anope::string> ModeLockOff;
00306         /* Default modes bots have on channels */
00307         static ChannelStatus DefaultBotModes;
00308 
00313         static bool AddUserMode(UserMode *um);
00314 
00319         static bool AddChannelMode(ChannelMode *cm);
00320 
00324         static void RemoveUserMode(UserMode *um);
00325 
00329         static void RemoveChannelMode(ChannelMode *cm);
00330 
00335         static ChannelMode *FindChannelModeByChar(char mode);
00336 
00341         static UserMode *FindUserModeByChar(char mode);
00342 
00347         static ChannelMode *FindChannelModeByName(const Anope::string &name);
00348 
00353         static UserMode *FindUserModeByName(const Anope::string &name);
00354 
00359         static char GetStatusChar(char symbol);
00360 
00368         static void StackerAdd(const BotInfo *bi, Channel *c, ChannelMode *cm, bool set, const Anope::string &param = "");
00369 
00377         static void StackerAdd(const BotInfo *bi, User *u, UserMode *um, bool set, const Anope::string &param = "");
00378 
00381         static void ProcessModes();
00382 
00385         static void StackerDel(User *u);
00386         static void StackerDel(Channel *c);
00387         static void StackerDel(Mode *m);
00388 
00393         static void UpdateDefaultMLock(ServerConfig *config);
00394 };
00395 
00398 class CoreExport Entry
00399 {
00400         Anope::string name;
00401         Anope::string mask;
00402  public:
00403         unsigned short cidr_len;
00404         Anope::string nick, user, host, real;
00405 
00410         Entry(const Anope::string &mode, const Anope::string &host);
00411 
00415         const Anope::string GetMask() const;
00416 
00422         bool Matches(const User *u, bool full = false) const;
00423 };
00424 
00425 #endif // MODES_H