00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __PLUGIN_H
00009 #define __PLUGIN_H
00010
00011
00012
00013 #define DEBUG 10
00014 #define VERBOSE 20
00015 #define DEFAULT 30
00016 #define SPARSE 40
00017 #define NONE 50
00018
00019
00020
00021 #define MT_CHANNEL 1
00022 #define MT_CLIENT 2
00023 #define MT_SERVER 3
00024
00025
00026
00027 #define ACR_DEFAULT 0 // Do default action (act as if the module isnt even loaded)
00028 #define ACR_DENY 1 // deny the action
00029 #define ACR_ALLOW 2 // allow the action
00030
00031 #define AC_KICK 0 // a user is being kicked
00032 #define AC_DEOP 1 // a user is being deopped
00033 #define AC_OP 2 // a user is being opped
00034 #define AC_VOICE 3 // a user is being voiced
00035 #define AC_DEVOICE 4 // a user is being devoiced
00036 #define AC_HALFOP 5 // a user is being halfopped
00037 #define AC_DEHALFOP 6 // a user is being dehalfopped
00038 #define AC_INVITE 7 // a user is being invited
00039 #define AC_GENERAL_MODE 8 // a user channel mode is being changed
00040
00041 #include "dynamic.h"
00042 #include "base.h"
00043 #include "ctables.h"
00044 #include <string>
00045 #include <deque>
00046 #include <sstream>
00047
00050 typedef std::deque<std::string> file_cache;
00051 typedef file_cache string_list;
00052
00055 typedef std::deque<userrec*> chanuserlist;
00056
00057
00058
00059
00060
00061
00062 #define FOREACH_MOD for (int i = 0; i <= MODCOUNT; i++) modules[i]->
00063
00064
00065
00066
00067
00068
00069
00070 #define FOREACH_RESULT(x) { MOD_RESULT = 0; \
00071 for (int i = 0; i <= MODCOUNT; i++) { \
00072 int res = modules[i]->x ; \
00073 if (res) { \
00074 MOD_RESULT = res; \
00075 break; \
00076 } \
00077 } \
00078 }
00079
00080
00081
00082 extern void createcommand(char* cmd, handlerfunc f, char flags, int minparams);
00083 extern void server_mode(char **parameters, int pcnt, userrec *user);
00084
00085
00086
00087
00092 class Version : public classbase
00093 {
00094 public:
00095 const int Major, Minor, Revision, Build;
00096 Version(int major, int minor, int revision, int build);
00097 };
00098
00104 class Admin : public classbase
00105 {
00106 public:
00107 const std::string Name, Email, Nick;
00108 Admin(std::string name, std::string email, std::string nick);
00109 };
00110
00116 class Module : public classbase
00117 {
00118 public:
00119
00123 Module();
00124
00128 virtual ~Module();
00129
00134 virtual Version GetVersion();
00135
00139 virtual void OnUserConnect(userrec* user);
00140
00144 virtual void OnUserQuit(userrec* user);
00145
00150 virtual void OnUserJoin(userrec* user, chanrec* channel);
00151
00156 virtual void OnUserPart(userrec* user, chanrec* channel);
00157
00164 virtual void OnPacketTransmit(char *p);
00165
00173 virtual void OnPacketReceive(char *p);
00174
00180 virtual void OnRehash();
00181
00190 virtual void OnServerRaw(std::string &raw, bool inbound, userrec* user);
00191
00201 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms);
00202
00215 virtual int OnUserPreJoin(userrec* user, chanrec* chan, const char* cname);
00216
00217
00222 virtual void OnOper(userrec* user);
00223
00232 virtual void OnInfo(userrec* user);
00233
00238 virtual void OnWhois(userrec* source, userrec* dest);
00239
00248 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string text);
00249
00258 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string text);
00259
00267 virtual int OnUserPreNick(userrec* user, std::string newnick);
00268
00291 virtual int OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type);
00297 virtual string_list OnUserSync(userrec* user);
00298
00304 virtual string_list OnChannelSync(chanrec* chan);
00305 };
00306
00307
00313 class Server : public classbase
00314 {
00315 public:
00319 Server();
00323 virtual ~Server();
00324
00328 virtual void SendOpers(std::string s);
00333 virtual void Log(int level, std::string s);
00338 virtual void Send(int Socket, std::string s);
00343 virtual void SendServ(int Socket, std::string s);
00348 virtual void SendFrom(int Socket, userrec* User, std::string s);
00363 virtual void SendTo(userrec* Source, userrec* Dest, std::string s);
00370 virtual void SendChannel(userrec* User, chanrec* Channel, std::string s,bool IncludeSender);
00375 virtual bool CommonChannels(userrec* u1, userrec* u2);
00383 virtual void SendCommon(userrec* User, std::string text,bool IncludeSender);
00388 virtual void SendWallops(userrec* User, std::string text);
00389
00393 virtual bool IsNick(std::string nick);
00397 virtual int CountUsers(chanrec* c);
00401 virtual userrec* FindNick(std::string nick);
00405 virtual chanrec* FindChannel(std::string channel);
00410 virtual std::string ChanMode(userrec* User, chanrec* Chan);
00414 virtual bool IsOnChannel(userrec* User, chanrec* Chan);
00417 virtual std::string GetServerName();
00420 virtual std::string GetNetworkName();
00426 virtual Admin GetAdmin();
00445 virtual bool AddExtendedMode(char modechar, int type, bool requires_oper, int params_when_on, int params_when_off);
00446
00468 virtual bool AddExtendedListMode(char modechar);
00469
00484 virtual void AddCommand(char* cmd, handlerfunc f, char flags, int minparams);
00485
00507 virtual void SendMode(char **parameters, int pcnt, userrec *user);
00508
00521 virtual void SendToModeMask(std::string modes, int flags, std::string text);
00522
00528 virtual chanrec* JoinUserToChannel(userrec* user, std::string cname, std::string key);
00529
00535 virtual chanrec* PartUserFromChannel(userrec* user, std::string cname, std::string reason);
00536
00542 virtual void ChangeUserNick(userrec* user, std::string nickname);
00543
00554 virtual void QuitUser(userrec* user, std::string reason);
00555
00560 virtual bool MatchText(std::string sliteral, std::string spattern);
00561
00573 virtual void CallCommandHandler(std::string commandname, char** parameters, int pcnt, userrec* user);
00574
00580 virtual void ChangeHost(userrec* user, std::string host);
00581
00587 virtual void ChangeGECOS(userrec* user, std::string gecos);
00588
00597 virtual bool IsUlined(std::string server);
00598
00602 virtual chanuserlist GetUsers(chanrec* chan);
00603
00604 };
00605
00606 #define CONF_NOT_A_NUMBER 0x000010
00607 #define CONF_NOT_UNSIGNED 0x000080
00608 #define CONF_VALUE_NOT_FOUND 0x000100
00609 #define CONF_FILE_NOT_FOUND 0x000200
00610
00617 class ConfigReader : public classbase
00618 {
00619 protected:
00625 std::stringstream *cache;
00628 bool readerror;
00629 long error;
00630
00631 public:
00636 ConfigReader();
00640 ConfigReader(std::string filename);
00644 ~ConfigReader();
00649 std::string ReadValue(std::string tag, std::string name, int index);
00655 bool ReadFlag(std::string tag, std::string name, int index);
00664 long ReadInteger(std::string tag, std::string name, int index, bool needs_unsigned);
00669 long GetError();
00676 int Enumerate(std::string tag);
00681 bool Verify();
00682
00688 int EnumerateValues(std::string tag, int index);
00689 };
00690
00691
00692
00698 class FileReader : public classbase
00699 {
00700 file_cache fc;
00701 public:
00706 FileReader();
00707
00713 FileReader(std::string filename);
00714
00718 ~FileReader();
00719
00725 void LoadFile(std::string filename);
00726
00730 bool Exists();
00731
00736 std::string GetLine(int x);
00737
00743 int FileSize();
00744 };
00745
00746
00753 class ModuleFactory : public classbase
00754 {
00755 public:
00756 ModuleFactory() { }
00757 virtual ~ModuleFactory() { }
00762 virtual Module * CreateModule() = 0;
00763 };
00764
00765
00766 typedef DLLFactory<ModuleFactory> ircd_module;
00767
00768 #endif