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 #include "dynamic.h"
00052 #include "base.h"
00053 #include "ctables.h"
00054 #include <string>
00055 #include <deque>
00056 #include <sstream>
00057 
00060 typedef std::deque<std::string> file_cache;
00061 typedef file_cache string_list;
00062 
00065 typedef std::deque<userrec*> chanuserlist;
00066 
00067 
00068 // This #define allows us to call a method in all
00069 // loaded modules in a readable simple way, e.g.:
00070 // 'FOREACH_MOD OnConnect(user);'
00071 
00072 #define FOREACH_MOD for (int i = 0; i <= MODCOUNT; i++) modules[i]->
00073 
00074 // This define is similar to the one above but returns a result in MOD_RESULT.
00075 // The first module to return a nonzero result is the value to be accepted,
00076 // and any modules after are ignored.
00077 
00078 // *********************************************************************************************
00079 
00080 #define FOREACH_RESULT(x) { MOD_RESULT = 0; \
00081                         for (int i = 0; i <= MODCOUNT; i++) { \
00082                         int res = modules[i]->x ; \
00083                         if (res != 0) { \
00084                                 MOD_RESULT = res; \
00085                                 break; \
00086                         } \
00087                 } \
00088         } 
00089    
00090 // *********************************************************************************************
00091 
00092 extern void createcommand(char* cmd, handlerfunc f, char flags, int minparams);
00093 extern void server_mode(char **parameters, int pcnt, userrec *user);
00094 
00095 // class Version holds the version information of a Module, returned
00096 // by Module::GetVersion (thanks RD)
00097 
00102 class Version : public classbase
00103 {
00104  public:
00105          const int Major, Minor, Revision, Build;
00106          Version(int major, int minor, int revision, int build);
00107 };
00108 
00114 class Admin : public classbase
00115 {
00116  public:
00117          const std::string Name, Email, Nick;
00118          Admin(std::string name, std::string email, std::string nick);
00119 };
00120 
00126 class Module : public classbase
00127 {
00128  public:
00129 
00133         Module();
00134 
00138         virtual ~Module();
00139 
00144         virtual Version GetVersion();
00145 
00149         virtual void OnUserConnect(userrec* user);
00150 
00154         virtual void OnUserQuit(userrec* user);
00155 
00160         virtual void OnUserJoin(userrec* user, chanrec* channel);
00161 
00166         virtual void OnUserPart(userrec* user, chanrec* channel);
00167 
00174         virtual void OnPacketTransmit(char *p);
00175 
00183         virtual void OnPacketReceive(char *p);
00184 
00190         virtual void OnRehash();
00191 
00200         virtual void OnServerRaw(std::string &raw, bool inbound, userrec* user);
00201 
00211         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params);
00212         
00226         virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname);
00227         
00228         
00233         virtual void OnOper(userrec* user);
00234         
00243         virtual void OnInfo(userrec* user);
00244         
00249         virtual void OnWhois(userrec* source, userrec* dest);
00250         
00256         virtual int OnUserPreInvite(userrec* source,userrec* dest,chanrec* channel);
00257         
00266         virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text);
00267 
00279         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text);
00280         
00291         virtual int OnUserPreNick(userrec* user, std::string newnick);
00292         
00314         virtual int OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type);
00315 
00321         virtual string_list OnUserSync(userrec* user);
00322 
00328         virtual string_list OnChannelSync(chanrec* chan);
00329 
00333         virtual void On005Numeric(std::string &output);
00334 
00344         virtual int OnKill(userrec* source, userrec* dest, std::string reason);
00345 
00356         virtual void OnLoadModule(Module* mod,std::string name);
00357 };
00358 
00359 
00365 class Server : public classbase
00366 {
00367  public:
00371         Server();
00375         virtual ~Server();
00376 
00380         virtual void SendOpers(std::string s);
00385         virtual void Log(int level, std::string s);
00390         virtual void Send(int Socket, std::string s);
00395         virtual void SendServ(int Socket, std::string s);
00400         virtual void SendFrom(int Socket, userrec* User, std::string s);
00415         virtual void SendTo(userrec* Source, userrec* Dest, std::string s);
00422         virtual void SendChannel(userrec* User, chanrec* Channel, std::string s,bool IncludeSender);
00427         virtual bool CommonChannels(userrec* u1, userrec* u2);
00435         virtual void SendCommon(userrec* User, std::string text,bool IncludeSender);
00440         virtual void SendWallops(userrec* User, std::string text);
00441 
00445         virtual bool IsNick(std::string nick);
00449         virtual int CountUsers(chanrec* c);
00453         virtual userrec* FindNick(std::string nick);
00457         virtual chanrec* FindChannel(std::string channel);
00462         virtual std::string ChanMode(userrec* User, chanrec* Chan);
00466         virtual bool IsOnChannel(userrec* User, chanrec* Chan);
00469         virtual std::string GetServerName();
00472         virtual std::string GetNetworkName();
00478         virtual Admin GetAdmin();
00497         virtual bool AddExtendedMode(char modechar, int type, bool requires_oper, int params_when_on, int params_when_off);
00498 
00520         virtual bool AddExtendedListMode(char modechar);
00521         
00536         virtual void AddCommand(char* cmd, handlerfunc f, char flags, int minparams);
00537          
00559         virtual void SendMode(char **parameters, int pcnt, userrec *user);
00560         
00573         virtual void SendToModeMask(std::string modes, int flags, std::string text);
00574 
00580         virtual chanrec* JoinUserToChannel(userrec* user, std::string cname, std::string key);
00581         
00587         virtual chanrec* PartUserFromChannel(userrec* user, std::string cname, std::string reason);
00588         
00594         virtual void ChangeUserNick(userrec* user, std::string nickname);
00595         
00606         virtual void QuitUser(userrec* user, std::string reason);
00607         
00612         virtual bool MatchText(std::string sliteral, std::string spattern);
00613         
00625         virtual void CallCommandHandler(std::string commandname, char** parameters, int pcnt, userrec* user);
00626         
00632         virtual void ChangeHost(userrec* user, std::string host);
00633         
00639         virtual void ChangeGECOS(userrec* user, std::string gecos);
00640         
00649         virtual bool IsUlined(std::string server);
00650         
00654         virtual chanuserlist GetUsers(chanrec* chan);
00655 
00656 };
00657 
00658 #define CONF_NOT_A_NUMBER       0x000010
00659 #define CONF_NOT_UNSIGNED       0x000080
00660 #define CONF_VALUE_NOT_FOUND    0x000100
00661 #define CONF_FILE_NOT_FOUND     0x000200
00662 
00669 class ConfigReader : public classbase
00670 {
00671   protected:
00677         std::stringstream *cache;
00678         std::stringstream *errorlog;
00681         bool readerror;
00682         long error;
00683         
00684   public:
00689         ConfigReader();                 // default constructor reads ircd.conf
00693         ConfigReader(std::string filename);     // read a module-specific config
00697         ~ConfigReader();
00702         std::string ReadValue(std::string tag, std::string name, int index);
00708         bool ReadFlag(std::string tag, std::string name, int index);
00717         long ReadInteger(std::string tag, std::string name, int index, bool needs_unsigned);
00722         long GetError();
00729         int Enumerate(std::string tag);
00734         bool Verify();
00741         void DumpErrors(bool bail,userrec* user);
00742 
00748         int EnumerateValues(std::string tag, int index);
00749 };
00750 
00751 
00752 
00758 class FileReader : public classbase
00759 {
00760  file_cache fc;
00761  public:
00766          FileReader();
00767 
00773          FileReader(std::string filename);
00774 
00778          ~FileReader();
00779 
00785          void LoadFile(std::string filename);
00786 
00790          bool Exists();
00791          
00796          std::string GetLine(int x);
00797 
00803          int FileSize();
00804 };
00805 
00806 
00813 class ModuleFactory : public classbase
00814 {
00815  public:
00816         ModuleFactory() { }
00817         virtual ~ModuleFactory() { }
00822         virtual Module * CreateModule() = 0;
00823 };
00824 
00825 
00826 typedef DLLFactory<ModuleFactory> ircd_module;
00827 
00828 #endif

Generated on Sat Apr 2 19:27:01 2005 for InspIRCd by doxygen 1.3.3