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 extern void createcommand(char* cmd, handlerfunc f, char flags, int minparams, char* source);
00100 extern void server_mode(char **parameters, int pcnt, userrec *user);
00101 
00102 // class Version holds the version information of a Module, returned
00103 // by Module::GetVersion (thanks RD)
00104 
00109 class Version : public classbase
00110 {
00111  public:
00112          const int Major, Minor, Revision, Build, Flags;
00113          Version(int major, int minor, int revision, int build, int flags);
00114 };
00115 
00121 class Admin : public classbase
00122 {
00123  public:
00124          const std::string Name, Email, Nick;
00125          Admin(std::string name, std::string email, std::string nick);
00126 };
00127 
00133 class Module : public classbase
00134 {
00135  public:
00136 
00140         Module();
00141 
00145         virtual ~Module();
00146 
00151         virtual Version GetVersion();
00152 
00156         virtual void OnUserConnect(userrec* user);
00157 
00161         virtual void OnUserQuit(userrec* user);
00162 
00167         virtual void OnUserJoin(userrec* user, chanrec* channel);
00168 
00173         virtual void OnUserPart(userrec* user, chanrec* channel);
00174 
00180         virtual void OnPacketTransmit(std::string &data, std::string serv);
00181 
00188         virtual void OnPacketReceive(std::string &data, std::string serv);
00189 
00195         virtual void OnRehash();
00196 
00205         virtual void OnServerRaw(std::string &raw, bool inbound, userrec* user);
00206 
00216         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params);
00217         
00231         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname);
00232         
00233         
00238         virtual void OnOper(userrec* user);
00239         
00248         virtual void OnInfo(userrec* user);
00249         
00254         virtual void OnWhois(userrec* source, userrec* dest);
00255         
00261         virtual int OnUserPreInvite(userrec* source,userrec* dest,chanrec* channel);
00262         
00271         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text);
00272 
00284         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text);
00285         
00293         virtual int OnUserPreNick(userrec* user, std::string newnick);
00294         
00302         virtual void OnUserPostNick(userrec* user, std::string oldnick);
00303 
00325         virtual int OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type);
00326 
00332         virtual string_list OnUserSync(userrec* user);
00333 
00339         virtual string_list OnChannelSync(chanrec* chan);
00340 
00344         virtual void On005Numeric(std::string &output);
00345 
00355         virtual int OnKill(userrec* source, userrec* dest, std::string reason);
00356 
00367         virtual void OnLoadModule(Module* mod,std::string name);
00368 };
00369 
00370 
00376 class Server : public classbase
00377 {
00378  public:
00382         Server();
00386         virtual ~Server();
00387 
00391         virtual void SendOpers(std::string s);
00396         virtual void Log(int level, std::string s);
00401         virtual void Send(int Socket, std::string s);
00406         virtual void SendServ(int Socket, std::string s);
00411         virtual void SendFrom(int Socket, userrec* User, std::string s);
00426         virtual void SendTo(userrec* Source, userrec* Dest, std::string s);
00433         virtual void SendChannel(userrec* User, chanrec* Channel, std::string s,bool IncludeSender);
00438         virtual bool CommonChannels(userrec* u1, userrec* u2);
00446         virtual void SendCommon(userrec* User, std::string text,bool IncludeSender);
00451         virtual void SendWallops(userrec* User, std::string text);
00452 
00456         virtual bool IsNick(std::string nick);
00460         virtual int CountUsers(chanrec* c);
00464         virtual userrec* FindNick(std::string nick);
00468         virtual chanrec* FindChannel(std::string channel);
00473         virtual std::string ChanMode(userrec* User, chanrec* Chan);
00477         virtual bool IsOnChannel(userrec* User, chanrec* Chan);
00480         virtual std::string GetServerName();
00483         virtual std::string GetNetworkName();
00489         virtual Admin GetAdmin();
00508         virtual bool AddExtendedMode(char modechar, int type, bool requires_oper, int params_when_on, int params_when_off);
00509 
00531         virtual bool AddExtendedListMode(char modechar);
00532         
00550         virtual void AddCommand(char* cmd, handlerfunc f, char flags, int minparams, char* source);
00551          
00573         virtual void SendMode(char **parameters, int pcnt, userrec *user);
00574         
00587         virtual void SendToModeMask(std::string modes, int flags, std::string text);
00588 
00594         virtual chanrec* JoinUserToChannel(userrec* user, std::string cname, std::string key);
00595         
00601         virtual chanrec* PartUserFromChannel(userrec* user, std::string cname, std::string reason);
00602         
00608         virtual void ChangeUserNick(userrec* user, std::string nickname);
00609         
00620         virtual void QuitUser(userrec* user, std::string reason);
00621         
00626         virtual bool MatchText(std::string sliteral, std::string spattern);
00627         
00639         virtual void CallCommandHandler(std::string commandname, char** parameters, int pcnt, userrec* user);
00640         
00646         virtual void ChangeHost(userrec* user, std::string host);
00647         
00653         virtual void ChangeGECOS(userrec* user, std::string gecos);
00654         
00663         virtual bool IsUlined(std::string server);
00664         
00668         virtual chanuserlist GetUsers(chanrec* chan);
00669 
00670 };
00671 
00672 #define CONF_NOT_A_NUMBER       0x000010
00673 #define CONF_NOT_UNSIGNED       0x000080
00674 #define CONF_VALUE_NOT_FOUND    0x000100
00675 #define CONF_FILE_NOT_FOUND     0x000200
00676 
00683 class ConfigReader : public classbase
00684 {
00685   protected:
00691         std::stringstream *cache;
00692         std::stringstream *errorlog;
00695         bool readerror;
00696         long error;
00697         
00698   public:
00703         ConfigReader();                 // default constructor reads ircd.conf
00707         ConfigReader(std::string filename);     // read a module-specific config
00711         ~ConfigReader();
00716         std::string ReadValue(std::string tag, std::string name, int index);
00722         bool ReadFlag(std::string tag, std::string name, int index);
00731         long ReadInteger(std::string tag, std::string name, int index, bool needs_unsigned);
00736         long GetError();
00743         int Enumerate(std::string tag);
00748         bool Verify();
00755         void DumpErrors(bool bail,userrec* user);
00756 
00762         int EnumerateValues(std::string tag, int index);
00763 };
00764 
00765 
00766 
00772 class FileReader : public classbase
00773 {
00774  file_cache fc;
00775  public:
00780          FileReader();
00781 
00787          FileReader(std::string filename);
00788 
00792          ~FileReader();
00793 
00799          void LoadFile(std::string filename);
00800 
00804          bool Exists();
00805          
00810          std::string GetLine(int x);
00811 
00817          int FileSize();
00818 };
00819 
00820 
00827 class ModuleFactory : public classbase
00828 {
00829  public:
00830         ModuleFactory() { }
00831         virtual ~ModuleFactory() { }
00836         virtual Module * CreateModule() = 0;
00837 };
00838 
00839 
00840 typedef DLLFactory<ModuleFactory> ircd_module;
00841 
00842 #endif

Generated on Sat Apr 9 14:38:25 2005 for InspIRCd by doxygen 1.3.3