Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

modules.h

Go to the documentation of this file.
00001 /*       +------------------------------------+
00002  *       | Inspire Internet Relay Chat Daemon |
00003  *       +------------------------------------+
00004  *
00005  *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
00006  *                       E-mail:
00007  *                <brain@chatspike.net>
00008  *                <Craig@chatspike.net>
00009  *     
00010  * Written by Craig Edwards, Craig McLure, and others.
00011  * This program is free but copyrighted software; see
00012  *            the file COPYING for details.
00013  *
00014  * ---------------------------------------------------
00015  */
00016 
00017 
00018 #ifndef __PLUGIN_H
00019 #define __PLUGIN_H
00020 
00021 // log levels
00022 
00023 #define DEBUG 10
00024 #define VERBOSE 20
00025 #define DEFAULT 30
00026 #define SPARSE 40
00027 #define NONE 50
00028 
00029 // used with OnExtendedMode() method of modules
00030 
00031 #define MT_CHANNEL 1
00032 #define MT_CLIENT 2
00033 #define MT_SERVER 3
00034 
00035 // used with OnAccessCheck() method of modules
00036 
00037 #define ACR_DEFAULT 0           // Do default action (act as if the module isnt even loaded)
00038 #define ACR_DENY 1              // deny the action
00039 #define ACR_ALLOW 2             // allow the action
00040 
00041 #define AC_KICK 0               // a user is being kicked
00042 #define AC_DEOP 1               // a user is being deopped
00043 #define AC_OP 2                 // a user is being opped
00044 #define AC_VOICE 3              // a user is being voiced
00045 #define AC_DEVOICE 4            // a user is being devoiced
00046 #define AC_HALFOP 5             // a user is being halfopped
00047 #define AC_DEHALFOP 6           // a user is being dehalfopped
00048 #define AC_INVITE 7             // a user is being invited
00049 #define AC_GENERAL_MODE 8       // a user channel mode is being changed
00050 
00051 // used to define a set of behavior bits for a module
00052 
00053 #define VF_STATIC               1       // module is static, cannot be /unloadmodule'd
00054 #define VF_VENDOR               2       // module is a vendor module (came in the original tarball, not 3rd party)
00055 #define VF_SERVICEPROVIDER      4       // module provides a service to other modules (can be a dependency)
00056 #define VF_COMMON               8       // module needs to be common on all servers in a mesh to link
00057 
00058 #include "dynamic.h"
00059 #include "base.h"
00060 #include "ctables.h"
00061 #include <string>
00062 #include <deque>
00063 #include <sstream>
00064 
00067 typedef std::deque<std::string> file_cache;
00068 typedef file_cache string_list;
00069 
00072 typedef std::deque<userrec*> chanuserlist;
00073 
00074 
00075 // This #define allows us to call a method in all
00076 // loaded modules in a readable simple way, e.g.:
00077 // 'FOREACH_MOD OnConnect(user);'
00078 
00079 #define FOREACH_MOD for (int i = 0; i <= MODCOUNT; i++) modules[i]->
00080 
00081 // This define is similar to the one above but returns a result in MOD_RESULT.
00082 // The first module to return a nonzero result is the value to be accepted,
00083 // and any modules after are ignored.
00084 
00085 // *********************************************************************************************
00086 
00087 #define FOREACH_RESULT(x) { MOD_RESULT = 0; \
00088                         for (int i = 0; i <= MODCOUNT; i++) { \
00089                         int res = modules[i]->x ; \
00090                         if (res != 0) { \
00091                                 MOD_RESULT = res; \
00092                                 break; \
00093                         } \
00094                 } \
00095         } 
00096    
00097 // *********************************************************************************************
00098 
00099 #define FD_MAGIC_NUMBER -42
00100 
00101 extern void createcommand(char* cmd, handlerfunc f, char flags, int minparams, char* source);
00102 extern void server_mode(char **parameters, int pcnt, userrec *user);
00103 
00104 // class Version holds the version information of a Module, returned
00105 // by Module::GetVersion (thanks RD)
00106 
00111 class Version : public classbase
00112 {
00113  public:
00114          const int Major, Minor, Revision, Build, Flags;
00115          Version(int major, int minor, int revision, int build, int flags);
00116 };
00117 
00123 class Admin : public classbase
00124 {
00125  public:
00126          const std::string Name, Email, Nick;
00127          Admin(std::string name, std::string email, std::string nick);
00128 };
00129 
00135 class Module : public classbase
00136 {
00137  public:
00138 
00142         Module();
00143 
00147         virtual ~Module();
00148 
00153         virtual Version GetVersion();
00154 
00158         virtual void OnUserConnect(userrec* user);
00159 
00163         virtual void OnUserQuit(userrec* user);
00164 
00169         virtual void OnUserJoin(userrec* user, chanrec* channel);
00170 
00175         virtual void OnUserPart(userrec* user, chanrec* channel);
00176 
00182         virtual void OnPacketTransmit(std::string &data, std::string serv);
00183 
00190         virtual void OnPacketReceive(std::string &data, std::string serv);
00191 
00197         virtual void OnRehash();
00198 
00207         virtual void OnServerRaw(std::string &raw, bool inbound, userrec* user);
00208 
00218         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params);
00219         
00233         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname);
00234         
00235         
00240         virtual void OnOper(userrec* user);
00241         
00250         virtual void OnInfo(userrec* user);
00251         
00256         virtual void OnWhois(userrec* source, userrec* dest);
00257         
00263         virtual int OnUserPreInvite(userrec* source,userrec* dest,chanrec* channel);
00264         
00273         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text);
00274 
00286         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text);
00287         
00295         virtual int OnUserPreNick(userrec* user, std::string newnick);
00296         
00304         virtual void OnUserPostNick(userrec* user, std::string oldnick);
00305 
00327         virtual int OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type);
00328 
00334         virtual string_list OnUserSync(userrec* user);
00335 
00341         virtual string_list OnChannelSync(chanrec* chan);
00342 
00346         virtual void On005Numeric(std::string &output);
00347 
00357         virtual int OnKill(userrec* source, userrec* dest, std::string reason);
00358 
00369         virtual void OnLoadModule(Module* mod,std::string name);
00370 
00376         virtual void OnBackgroundTimer(time_t curtime);
00377 
00385         virtual void OnSendList(userrec* user, chanrec* channel, char mode);
00386 
00387 };
00388 
00389 
00395 class Server : public classbase
00396 {
00397  public:
00401         Server();
00405         virtual ~Server();
00406 
00410         virtual void SendOpers(std::string s);
00415         virtual void Log(int level, std::string s);
00420         virtual void Send(int Socket, std::string s);
00425         virtual void SendServ(int Socket, std::string s);
00430         virtual void SendFrom(int Socket, userrec* User, std::string s);
00445         virtual void SendTo(userrec* Source, userrec* Dest, std::string s);
00452         virtual void SendChannel(userrec* User, chanrec* Channel, std::string s,bool IncludeSender);
00457         virtual bool CommonChannels(userrec* u1, userrec* u2);
00465         virtual void SendCommon(userrec* User, std::string text,bool IncludeSender);
00470         virtual void SendWallops(userrec* User, std::string text);
00471 
00475         virtual bool IsNick(std::string nick);
00479         virtual int CountUsers(chanrec* c);
00483         virtual userrec* FindNick(std::string nick);
00487         virtual chanrec* FindChannel(std::string channel);
00492         virtual std::string ChanMode(userrec* User, chanrec* Chan);
00496         virtual bool IsOnChannel(userrec* User, chanrec* Chan);
00499         virtual std::string GetServerName();
00502         virtual std::string GetNetworkName();
00508         virtual Admin GetAdmin();
00527         virtual bool AddExtendedMode(char modechar, int type, bool requires_oper, int params_when_on, int params_when_off);
00528 
00550         virtual bool AddExtendedListMode(char modechar);
00551 
00569         virtual void AddCommand(char* cmd, handlerfunc f, char flags, int minparams, char* source);
00570          
00592         virtual void SendMode(char **parameters, int pcnt, userrec *user);
00593         
00606         virtual void SendToModeMask(std::string modes, int flags, std::string text);
00607 
00613         virtual chanrec* JoinUserToChannel(userrec* user, std::string cname, std::string key);
00614         
00620         virtual chanrec* PartUserFromChannel(userrec* user, std::string cname, std::string reason);
00621         
00627         virtual void ChangeUserNick(userrec* user, std::string nickname);
00628         
00639         virtual void QuitUser(userrec* user, std::string reason);
00640         
00645         virtual bool MatchText(std::string sliteral, std::string spattern);
00646         
00658         virtual void CallCommandHandler(std::string commandname, char** parameters, int pcnt, userrec* user);
00659         
00665         virtual void ChangeHost(userrec* user, std::string host);
00666         
00672         virtual void ChangeGECOS(userrec* user, std::string gecos);
00673         
00682         virtual bool IsUlined(std::string server);
00683         
00687         virtual chanuserlist GetUsers(chanrec* chan);
00688 
00695         virtual bool UserToPseudo(userrec* user,std::string message);
00696 
00703         virtual bool PseudoToUser(userrec* alive,userrec* zombie,std::string message);
00704 
00712         virtual void AddGLine(long duration, std::string source, std::string reason, std::string hostmask);
00713 
00721         virtual void AddQLine(long duration, std::string source, std::string reason, std::string nickname);
00722 
00730         virtual void AddZLine(long duration, std::string source, std::string reason, std::string ipaddr);
00731 
00739         virtual void AddKLine(long duration, std::string source, std::string reason, std::string hostmask);
00740 
00748         virtual void AddELine(long duration, std::string source, std::string reason, std::string hostmask);
00749 
00752         virtual bool DelGLine(std::string hostmask);
00753 
00756         virtual bool DelQLine(std::string nickname);
00757 
00760         virtual bool DelZLine(std::string ipaddr);
00761 
00764         virtual bool DelKLine(std::string hostmask);
00765 
00768         virtual bool DelELine(std::string hostmask);
00769 
00775         virtual long CalcDuration(std::string duration);
00776 
00777 };
00778 
00779 #define CONF_NOT_A_NUMBER       0x000010
00780 #define CONF_NOT_UNSIGNED       0x000080
00781 #define CONF_VALUE_NOT_FOUND    0x000100
00782 #define CONF_FILE_NOT_FOUND     0x000200
00783 
00790 class ConfigReader : public classbase
00791 {
00792   protected:
00798         std::stringstream *cache;
00799         std::stringstream *errorlog;
00802         bool readerror;
00803         long error;
00804         
00805   public:
00810         ConfigReader();                 // default constructor reads ircd.conf
00814         ConfigReader(std::string filename);     // read a module-specific config
00818         ~ConfigReader();
00823         std::string ReadValue(std::string tag, std::string name, int index);
00829         bool ReadFlag(std::string tag, std::string name, int index);
00838         long ReadInteger(std::string tag, std::string name, int index, bool needs_unsigned);
00843         long GetError();
00850         int Enumerate(std::string tag);
00855         bool Verify();
00862         void DumpErrors(bool bail,userrec* user);
00863 
00869         int EnumerateValues(std::string tag, int index);
00870 };
00871 
00872 
00873 
00879 class FileReader : public classbase
00880 {
00881  file_cache fc;
00882  public:
00887          FileReader();
00888 
00894          FileReader(std::string filename);
00895 
00899          ~FileReader();
00900 
00906          void LoadFile(std::string filename);
00907 
00911          bool Exists();
00912          
00917          std::string GetLine(int x);
00918 
00924          int FileSize();
00925 };
00926 
00927 
00934 class ModuleFactory : public classbase
00935 {
00936  public:
00937         ModuleFactory() { }
00938         virtual ~ModuleFactory() { }
00943         virtual Module * CreateModule() = 0;
00944 };
00945 
00946 
00947 typedef DLLFactory<ModuleFactory> ircd_module;
00948 
00949 #endif

Generated on Wed Apr 13 13:06:54 2005 for InspIRCd by doxygen 1.3.3