00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef __MODE_H
00015 #define __MODE_H
00016
00017
00018 class User;
00019
00020 #include "channels.h"
00021
00026 enum ModeType
00027 {
00029 MODETYPE_USER = 0,
00031 MODETYPE_CHANNEL = 1
00032 };
00033
00037 enum ModeAction
00038 {
00039 MODEACTION_DENY = 0,
00040 MODEACTION_ALLOW = 1
00041 };
00042
00048 enum ModeMasks
00049 {
00050 MASK_USER = 128,
00051 MASK_CHANNEL = 0
00052 };
00053
00062 enum PrefixModeValue
00063 {
00064
00065 VOICE_VALUE = 10000,
00066
00067 HALFOP_VALUE = 20000,
00068
00069 OP_VALUE = 30000
00070 };
00071
00077 typedef std::pair<bool,std::string> ModePair;
00078
00093 class CoreExport ModeHandler : public Extensible
00094 {
00095 protected:
00099 InspIRCd* ServerInstance;
00103 char mode;
00107 int n_params_on;
00111 int n_params_off;
00122 bool list;
00127 ModeType m_type;
00132 bool oper;
00133
00136 char prefix;
00137
00140 unsigned int count;
00141
00145 char prefixneeded;
00146
00147 public:
00164 ModeHandler(InspIRCd* Instance, char modeletter, int parameters_on, int parameters_off, bool listmode, ModeType type, bool operonly, char mprefix = 0, char prefixrequired = '%');
00168 virtual ~ModeHandler();
00172 bool IsListMode();
00178 char GetPrefix();
00181 virtual unsigned int GetCount();
00184 virtual void ChangeCount(int modifier);
00192 virtual unsigned int GetPrefixRank();
00196 ModeType GetModeType();
00200 bool NeedsOper();
00207 int GetNumParams(bool adding);
00212 char GetModeChar();
00213
00216 virtual std::string GetUserParameter(User* useor);
00217
00230 virtual ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool servermode = false);
00237 virtual void DisplayList(User* user, Channel* channel);
00238
00245 virtual void OnParameterMissing(User* user, User* dest, Channel* channel);
00246
00252 virtual void DisplayEmptyList(User* user, Channel* channel);
00253
00266 virtual bool CheckTimeStamp(time_t theirs, time_t ours, const std::string &their_param, const std::string &our_param, Channel* channel);
00267
00281 virtual ModePair ModeSet(User* source, User* dest, Channel* channel, const std::string ¶meter);
00282
00291 virtual void RemoveMode(User* user, irc::modestacker* stack = NULL);
00292
00301 virtual void RemoveMode(Channel* channel, irc::modestacker* stack = NULL);
00302
00303 char GetNeededPrefix();
00304
00305 void SetNeededPrefix(char needsprefix);
00306 };
00307
00313 class CoreExport SimpleUserModeHandler : public ModeHandler
00314 {
00315 public:
00316 SimpleUserModeHandler(InspIRCd* Instance, char modeletter);
00317 virtual ~SimpleUserModeHandler();
00318 virtual ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool servermode = false);
00319 };
00320
00326 class CoreExport SimpleChannelModeHandler : public ModeHandler
00327 {
00328 public:
00329 SimpleChannelModeHandler(InspIRCd* Instance, char modeletter);
00330 virtual ~SimpleChannelModeHandler();
00331 virtual ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool servermode = false);
00332 };
00333
00340 class CoreExport ModeWatcher : public Extensible
00341 {
00342 protected:
00346 InspIRCd* ServerInstance;
00350 char mode;
00354 ModeType m_type;
00355
00356 public:
00360 ModeWatcher(InspIRCd* Instance, char modeletter, ModeType type);
00364 virtual ~ModeWatcher();
00365
00370 char GetModeChar();
00375 ModeType GetModeType();
00376
00390 virtual bool BeforeMode(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, ModeType type, bool servermode = false);
00401 virtual void AfterMode(User* source, User* dest, Channel* channel, const std::string ¶meter, bool adding, ModeType type, bool servermode = false);
00402 };
00403
00404 typedef std::vector<ModeWatcher*>::iterator ModeWatchIter;
00405
00411 class CoreExport ModeParser : public classbase
00412 {
00413 private:
00417 InspIRCd* ServerInstance;
00423 ModeHandler* modehandlers[256];
00428 std::vector<ModeWatcher*> modewatchers[256];
00432 void DisplayCurrentModes(User *user, User* targetuser, Channel* targetchannel, const char* text);
00433
00437 std::string LastParse;
00438
00439 unsigned int sent[256];
00440
00441 unsigned int seq;
00442
00443 public:
00444
00447 ModeParser(InspIRCd* Instance);
00448
00452 User* SanityChecks(User *user,const char *dest,Channel *chan,int status);
00455 const char* Grant(User *d,Channel *chan,int MASK);
00458 const char* Revoke(User *d,Channel *chan,int MASK);
00472 static void CleanMask(std::string &mask);
00478 const std::string& GetLastParse();
00482 bool AddMode(ModeHandler* mh);
00491 bool DelMode(ModeHandler* mh);
00499 bool AddModeWatcher(ModeWatcher* mw);
00507 bool DelModeWatcher(ModeWatcher* mw);
00516 void Process(const std::vector<std::string>& parameters, User *user, bool servermode);
00517
00523 ModeHandler* FindMode(unsigned const char modeletter, ModeType mt);
00524
00530 ModeHandler* FindPrefix(unsigned const char pfxletter);
00531
00535 std::string UserModeList();
00536
00540 std::string ChannelModeList();
00541
00545 std::string ParaModeList();
00546
00553 std::string GiveModeList(ModeMasks m);
00554
00557 static bool PrefixComparison(prefixtype one, prefixtype two);
00558
00561 std::string BuildPrefixes();
00562
00573 std::string ModeString(User* user, Channel* channel, bool nick_suffix = true);
00574 };
00575
00576 #endif
00577