diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2004-04-05 16:06:32 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2004-04-05 16:06:32 +0000 |
commit | cbc730ec3bd2c080d08fa735af58ffd871b55ca4 (patch) | |
tree | 8f633daab8464e77b8a8a8ba24986a2bfde34642 | |
parent | 829b139abdef2e07254f7237e4fbb8481a0b62ca (diff) |
Added support for OnWhois, OnOper, OnInfo and SendToModeMask in the API
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@388 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | include/inspircd.h | 14 | ||||
-rw-r--r-- | include/modules.h | 40 | ||||
-rw-r--r-- | src/InspIRCd.layout | 30 | ||||
-rw-r--r-- | src/inspircd.cpp | 65 | ||||
-rw-r--r-- | src/modules.cpp | 8 |
5 files changed, 140 insertions, 17 deletions
diff --git a/include/inspircd.h b/include/inspircd.h index 4a0762dbd..3d1872d01 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -19,11 +19,13 @@ #include <assert.h> #include <sys/param.h> #include <sys/types.h> + #ifndef _LINUX_C_LIB_VERSION #include <sys/socket.h> #include <sys/stat.h> #include <netinet/in.h> #endif + #include <arpa/inet.h> #include <string> #include <deque> @@ -34,23 +36,34 @@ #include "users.h" #include "channels.h" +// some misc defines + #define ERROR -1 #define TRUE 1 #define FALSE 0 #define IDENTMAX 9 #define MAXSOCKS 64 +// maximum lengths of items + #define MAXQUIT 255 #define MAXCOMMAND 32 #define MAXTOPIC 307 #define MAXKICK 255 +// flags for use with log() + #define DEBUG 10 #define VERBOSE 20 #define DEFAULT 30 #define SPARSE 40 #define NONE 50 +// flags for use with WriteMode + +#define WM_AND 1 +#define WM_OR 2 + typedef std::deque<std::string> file_cache; /* prototypes */ @@ -62,6 +75,7 @@ void ReadConfig(void); void strlower(char *n); void WriteOpers(char* text, ...); +void WriteMode(const char* modes, int flags, const char* text, ...); void log(int level, char *text, ...); void Write(int sock,char *text, ...); void WriteServ(int sock, char* text, ...); diff --git a/include/modules.h b/include/modules.h index 2e6fbf860..089ef0afc 100644 --- a/include/modules.h +++ b/include/modules.h @@ -184,8 +184,30 @@ class Module : public classbase * processing on the actual channel record at this point, however the channel NAME will still be passed in * char* cname, so that you could for example implement a channel blacklist or whitelist, etc. */ - virtual int Module::OnUserPreJoin(userrec* user, chanrec* chan, char* cname); - + virtual int OnUserPreJoin(userrec* user, chanrec* chan, char* cname); + + + /** Called whenever a user opers locally. + * The userrec will contain the oper mode 'o' as this function is called after any modifications + * are made to the user's structure by the core. + */ + virtual void OnOper(userrec* user); + + /** Called whenever a user types /INFO. + * The userrec will contain the information of the user who typed the command. Modules may use this + * method to output their own credits in /INFO (which is the ircd's version of an about box). + * It is purposefully not possible to modify any info that has already been output, or halt the list. + * You must write a 371 numeric to the user, containing your info in the following format: + * + * <nick> :information here + */ + virtual void OnInfo(userrec* user); + + /** Called whenever a /WHOIS is performed on a local user. + * The source parameter contains the details of the user who issued the WHOIS command, and + * the dest parameter contains the information of the user they are whoising. + */ + void Module::OnWhois(userrec* source, userrec* dest); }; @@ -348,6 +370,20 @@ class Server : public classbase */ virtual void SendMode(char **parameters, int pcnt, userrec *user); + + /** Sends to all users matching a mode mask + * You must specify one or more usermodes as the first parameter. These can be RFC specified modes such as +i, + * or module provided modes, including ones provided by your own module. + * In the second parameter you must place a flag value which indicates wether the modes you have given will be + * logically ANDed or OR'ed. You may use one of either WM_AND or WM_OR. + * for example, if you were to use: + * + * Serv->SendToModeMask("xi", WM_OR, "m00"); + * + * Then the text 'm00' will be sent to all users with EITHER mode x or i. Conversely if you used WM_AND, the + * user must have both modes set to receive the message. + */ + virtual void SendToModeMask(std::string modes, int flags, std::string text); }; /** Allows reading of values from configuration files diff --git a/src/InspIRCd.layout b/src/InspIRCd.layout index aaa0daa11..efa8d0220 100644 --- a/src/InspIRCd.layout +++ b/src/InspIRCd.layout @@ -13,9 +13,9 @@ LeftChar=1 [Editor_1] Open=1 Top=1 -CursorCol=22 -CursorRow=5263 -TopLine=5236 +CursorCol=4 +CursorRow=830 +TopLine=776 LeftChar=1 [Editor_2] @@ -37,9 +37,9 @@ LeftChar=1 [Editor_4] Open=1 Top=0 -CursorCol=56 -CursorRow=118 -TopLine=91 +CursorCol=1 +CursorRow=140 +TopLine=123 LeftChar=1 [Editor_5] @@ -141,9 +141,9 @@ LeftChar=1 [Editor_17] Open=1 Top=0 -CursorCol=6 -CursorRow=86 -TopLine=34 +CursorCol=58 +CursorRow=78 +TopLine=49 LeftChar=1 [Editor_18] @@ -165,10 +165,10 @@ LeftChar=1 [Editor_20] Open=1 Top=0 -CursorCol=58 -CursorRow=171 -TopLine=148 -LeftChar=1 +CursorCol=7 +CursorRow=385 +TopLine=333 +LeftChar=3 [Editor_21] Open=1 @@ -204,8 +204,8 @@ LeftChar=1 [Editor_25] Open=1 Top=0 -CursorCol=4 -CursorRow=76 +CursorCol=6 +CursorRow=10 TopLine=1 LeftChar=1 [Editor_26] diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 26c952062..5f6cebe52 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -773,6 +773,68 @@ void WriteOpers(char* text, ...) } } +bool hasumode(userrec* user, char mode) +{ + if (user) + { + return (strchr(user->modes,mode)>0); + } + else return false; +} + +void WriteMode(const char* modes, int flags, const char* text, ...) +{ + if ((!text) || (!modes) || (!flags)) + { + log(DEFAULT,"*** BUG *** WriteMode was given an invalid parameter"); + return; + } + + char textbuffer[MAXBUF]; + va_list argsPtr; + va_start (argsPtr, text); + vsnprintf(textbuffer, MAXBUF, text, argsPtr); + va_end(argsPtr); + + for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++) + { + if (i->second) + { + bool send_to_user = false; + + if (flags == WM_AND) + { + send_to_user = true; + for (int n = 0; n < strlen(modes); n++) + { + if (!hasumode(i->second,modes[n])) + { + send_to_user = false; + break; + } + } + } + else if (flags == WM_OR) + { + send_to_user = false; + for (int n = 0; n < strlen(modes); n++) + { + if (hasumode(i->second,modes[n])) + { + send_to_user = true; + break; + } + } + } + + if (send_to_user) + { + WriteServ(i->second->fd,"NOTICE %s :%s",i->second->nick,textbuffer); + } + } + } +} + void WriteWallOps(userrec *source, char* text, ...) { if ((!text) || (!source)) @@ -3672,6 +3734,7 @@ void handle_info(char **parameters, int pcnt, userrec *user) WriteServ(user->fd,"371 %s :The Inspire IRCd Project Has been brought to you by the following people..",user->nick); WriteServ(user->fd,"371 %s :Craig Edwards, Craig McLure, and Others..",user->nick); WriteServ(user->fd,"371 %s :Will finish this later when i can be arsed :p",user->nick); + FOREACH_MOD OnInfo(user); WriteServ(user->fd,"374 %s :End of /INFO list",user->nick); } @@ -3717,6 +3780,7 @@ void handle_whois(char **parameters, int pcnt, userrec *user) { WriteServ(user->fd,"313 %s %s :is an IRC operator",user->nick, dest->nick); } + FOREACH_MOD OnWhois(user,dest); //WriteServ(user->fd,"310 %s %s :is available for help.",user->nick, dest->nick); WriteServ(user->fd,"317 %s %s %d %d :seconds idle, signon time",user->nick, dest->nick, abs((dest->idle_lastmsg)-time(NULL)), dest->signon); @@ -4382,6 +4446,7 @@ void handle_oper(char **parameters, int pcnt, userrec *user) { strcat(user->modes,"o"); } + FOREACH_MOD OnOper(user); return; } } diff --git a/src/modules.cpp b/src/modules.cpp index 8ff5874af..5bea5133f 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -117,6 +117,9 @@ void Module::OnServerRaw(std::string &raw, bool inbound) { } int Module::OnUserPreJoin(userrec* user, chanrec* chan, char* cname) { return 0; } bool Module::OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms) { } Version Module::GetVersion() { return Version(1,0,0,0); } +void Module::OnOper(userrec* user) { }; +void Module::OnInfo(userrec* user) { }; +void Module::OnWhois(userrec* source, userrec* dest) { }; // server is a wrapper class that provides methods to all of the C-style // exports in the core @@ -135,6 +138,11 @@ void Server::SendOpers(std::string s) WriteOpers("%s",s.c_str()); } +void Server::SendToModeMask(std::string modes, int flags, std::string text) +{ + WriteMode(modes.c_str(),flags,"%s",text.c_str()); +} + void Server::Log(int level, std::string s) { log(level,"%s",s.c_str()); |