diff options
-rw-r--r-- | include/channels.h | 2 | ||||
-rw-r--r-- | include/modules.h | 28 | ||||
-rw-r--r-- | include/users.h | 2 | ||||
-rw-r--r-- | src/InspIRCd.layout | 56 | ||||
-rw-r--r-- | src/channels.cpp | 91 | ||||
-rw-r--r-- | src/commands.cpp | 2 | ||||
-rw-r--r-- | src/inspircd.cpp | 18 | ||||
-rw-r--r-- | src/modules.cpp | 192 | ||||
-rw-r--r-- | src/modules/m_chanprotect.cpp | 26 |
9 files changed, 366 insertions, 51 deletions
diff --git a/include/channels.h b/include/channels.h index 9cce9feb3..c0df69513 100644 --- a/include/channels.h +++ b/include/channels.h @@ -188,7 +188,7 @@ class chanrec : public Extensible * a userrec and chanrec class. The uc_modes member holds a bitmask of which privilages the user * has on the channel, such as op, voice, etc. */ -class ucrec : public Extensible +class ucrec : public classbase { public: /** Contains a bitmask of the UCMODE_OP ... UCMODE_FOUNDER values. diff --git a/include/modules.h b/include/modules.h index 866bed269..df971b611 100644 --- a/include/modules.h +++ b/include/modules.h @@ -50,6 +50,10 @@ typedef std::deque<std::string> file_cache; typedef file_cache string_list; +/** Holds a list of users in a channel + */ +typedef std::deque<userrec*> chanuserlist; + // This #define allows us to call a method in all // loaded modules in a readable simple way, e.g.: @@ -266,7 +270,7 @@ class Module : public classbase * This function is called before many functions which check a users status on a channel, for example * before opping a user, deopping a user, kicking a user, etc. * There are several values for access_type which indicate for what reason access is being checked. - * These are:<br> + * These are:<br><br> * AC_KICK (0) - A user is being kicked<br> * AC_DEOP (1) - a user is being deopped<br> * AC_OP (2) - a user is being opped<br> @@ -275,7 +279,7 @@ class Module : public classbase * AC_HALFOP (5) - a user is being halfopped<br> * AC_DEHALFOP (6) - a user is being dehalfopped<br> * AC_INVITE (7) - a user is being invited<br> - * AC_GENERAL_MODE (8) - a user channel mode is being changed<br> + * AC_GENERAL_MODE (8) - a user channel mode is being changed<br><br> * Upon returning from your function you must return either ACR_DEFAULT, to indicate the module wishes * to do nothing, or ACR_DENY where approprate to deny the action, and ACR_ALLOW where appropriate to allow * the action. Please note that in the case of some access checks (such as AC_GENERAL_MODE) access may be @@ -283,7 +287,21 @@ class Module : public classbase * AC_GENERAL_MODE type, as it may inadvertently override the behaviour of other modules. When the access_type * is AC_GENERAL_MODE, the destination of the mode will be NULL (as it has not yet been determined). */ + virtual int OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type); + /** Called during a netburst to sync user data. + * This is called during the netburst on a per-user basis. You should use this call to up any special + * user-related things which are implemented by your module, e.g. sending listmodes. You may return + * multiple commands in the string_list. + */ + virtual string_list OnUserSync(userrec* user); + + /** Called during a netburst to sync channel data. + * This is called during the netburst on a per-channel basis. You should use this call to up any special + * channel-related things which are implemented by your module, e.g. sending listmodes. You may return + * multiple commands in the string_list. + */ + virtual string_list OnChannelSync(chanrec* chan); }; @@ -577,6 +595,12 @@ class Server : public classbase * links and must operate in this manner. */ virtual bool IsUlined(std::string server); + + /** Fetches the userlist of a channel. This function must be here and not a member of userrec or + * chanrec due to include constraints. + */ + virtual chanuserlist Server::GetUsers(chanrec* chan); + }; /** Allows reading of values from configuration files diff --git a/include/users.h b/include/users.h index 741e94dfb..a1739a2a1 100644 --- a/include/users.h +++ b/include/users.h @@ -179,7 +179,7 @@ class userrec : public connection * This is done by looking up their oper type from userrec::oper, then referencing * this to their oper classes and checking the commands they can execute. */ - virtual bool HasPermission(char* command); + bool HasPermission(char* command); }; diff --git a/src/InspIRCd.layout b/src/InspIRCd.layout index 1e1e0138c..97a83473e 100644 --- a/src/InspIRCd.layout +++ b/src/InspIRCd.layout @@ -13,9 +13,9 @@ LeftChar=1 [Editor_1] Open=1 Top=0 -CursorCol=23 -CursorRow=1610 -TopLine=1575 +CursorCol=40 +CursorRow=2952 +TopLine=2928 LeftChar=1 [Editor_2] @@ -37,9 +37,9 @@ LeftChar=1 [Editor_4] Open=1 Top=0 -CursorCol=1 -CursorRow=330 -TopLine=298 +CursorCol=48 +CursorRow=160 +TopLine=132 LeftChar=1 [Editor_5] @@ -101,8 +101,8 @@ LeftChar=1 [Editor_12] Open=1 Top=0 -CursorCol=32 -CursorRow=191 +CursorCol=1 +CursorRow=16 TopLine=1 LeftChar=1 @@ -164,10 +164,10 @@ LeftChar=1 [Editor_20] Open=1 -Top=1 -CursorCol=1 -CursorRow=40 -TopLine=1 +Top=0 +CursorCol=71 +CursorRow=279 +TopLine=259 LeftChar=1 [Editor_21] @@ -180,10 +180,10 @@ LeftChar=1 [Editor_22] Open=1 -Top=0 +Top=1 CursorCol=1 -CursorRow=182 -TopLine=92 +CursorRow=190 +TopLine=135 LeftChar=1 [Editor_23] @@ -205,8 +205,8 @@ LeftChar=1 Open=1 Top=0 CursorCol=1 -CursorRow=23 -TopLine=46 +CursorRow=1 +TopLine=1 LeftChar=1 [Editor_26] Open=1 @@ -323,16 +323,16 @@ LeftChar=1 [Editor_42] Open=1 Top=0 -CursorCol=128 -CursorRow=1210 -TopLine=1187 +CursorCol=41 +CursorRow=510 +TopLine=481 LeftChar=1 [Editor_43] Open=1 Top=0 CursorCol=1 -CursorRow=217 -TopLine=203 +CursorRow=90 +TopLine=52 LeftChar=1 [Editor_44] Open=1 @@ -358,9 +358,9 @@ LeftChar=1 [Editor_47] Open=1 Top=0 -CursorCol=32 -CursorRow=46 -TopLine=4 +CursorCol=1 +CursorRow=35 +TopLine=10 LeftChar=1 [Editor_48] Open=1 @@ -379,7 +379,7 @@ LeftChar=1 [Editor_50] Open=1 Top=0 -CursorCol=1 -CursorRow=9 -TopLine=37 +CursorCol=2 +CursorRow=250 +TopLine=196 LeftChar=1 diff --git a/src/channels.cpp b/src/channels.cpp index 85aad0c57..86df2124a 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -1,9 +1,93 @@ -#include "inspircd_config.h" -#include "channels.h" #include "inspircd.h" -#include <stdio.h> +#include "inspircd_io.h" +#include "inspircd_util.h" +#include "inspircd_config.h" +#include <unistd.h> +#include <fcntl.h> +#include <sys/errno.h> +#include <sys/ioctl.h> +#include <sys/utsname.h> +#include <cstdio> +#include <time.h> #include <string> +#ifdef GCC3 +#include <ext/hash_map> +#else +#include <hash_map> +#endif +#include <map> +#include <sstream> #include <vector> +#include <errno.h> +#include <deque> +#include <errno.h> +#include <unistd.h> +#include <sched.h> +#include "connection.h" +#include "users.h" +#include "servers.h" +#include "ctables.h" +#include "globals.h" +#include "modules.h" +#include "dynamic.h" +#include "wildcard.h" +#include "message.h" +#include "mode.h" +#include "xline.h" + +#ifdef GCC3 +#define nspace __gnu_cxx +#else +#define nspace std +#endif + +using namespace std; + +extern int MODCOUNT; +extern vector<Module*> modules; +extern vector<ircd_module*> factory; + +extern int LogLevel; +extern char ServerName[MAXBUF]; +extern char Network[MAXBUF]; +extern char ServerDesc[MAXBUF]; +extern char AdminName[MAXBUF]; +extern char AdminEmail[MAXBUF]; +extern char AdminNick[MAXBUF]; +extern char diepass[MAXBUF]; +extern char restartpass[MAXBUF]; +extern char motd[MAXBUF]; +extern char rules[MAXBUF]; +extern char list[MAXBUF]; +extern char PrefixQuit[MAXBUF]; +extern char DieValue[MAXBUF]; + +extern int debugging; +extern int WHOWAS_STALE; +extern int WHOWAS_MAX; +extern int DieDelay; +extern time_t startup_time; +extern int NetBufferSize; +int MaxWhoResults; +extern time_t nb_start; + +extern std::vector<int> fd_reap; +extern std::vector<std::string> module_names; + +extern char bannerBuffer[MAXBUF]; +extern int boundPortCount; +extern int portCount; +extern int UDPportCount; +extern int ports[MAXSOCKS]; +extern int defaultRoute; + +extern std::vector<long> auth_cookies; +extern std::stringstream config_f; + +extern serverrec* me[32]; + +extern FILE *log_file; + using namespace std; @@ -47,6 +131,7 @@ void chanrec::SetCustomMode(char mode,bool mode_on) } } + void chanrec::SetCustomModeParam(char mode,char* parameter,bool mode_on) { diff --git a/src/commands.cpp b/src/commands.cpp index c280d0699..97aa6e254 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -68,7 +68,7 @@ extern int WHOWAS_MAX; extern int DieDelay; extern time_t startup_time; extern int NetBufferSize; -int MaxWhoResults; +extern int MaxWhoResults; extern time_t nb_start; extern std::vector<int> fd_reap; diff --git a/src/inspircd.cpp b/src/inspircd.cpp index eb4199f28..6fc06f0e7 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -2947,6 +2947,15 @@ void DoSync(serverrec* serv, char* tcp_host) { snprintf(data,MAXBUF,"N %d %s %s %s %s +%s %s %s :%s",u->second->age,u->second->nick,u->second->host,u->second->dhost,u->second->ident,u->second->modes,u->second->ip,u->second->server,u->second->fullname); serv->SendPacket(data,tcp_host); + for (int i = 0; i <= MODCOUNT; i++) + { + string_list l = modules[i]->OnUserSync(u->second); + for (int j = 0; j < l.size(); j++) + { + strncpy(data,l[j].c_str(),MAXBUF); + serv->SendPacket(data,tcp_host); + } + } if (strcmp(chlist(u->second),"")) { snprintf(data,MAXBUF,"J %s %s",u->second->nick,chlist(u->second)); @@ -2958,6 +2967,15 @@ void DoSync(serverrec* serv, char* tcp_host) { snprintf(data,MAXBUF,"M %s +%s",c->second->name,chanmodes(c->second)); serv->SendPacket(data,tcp_host); + for (int i = 0; i <= MODCOUNT; i++) + { + string_list l = modules[i]->OnChannelSync(c->second); + for (int j = 0; j < l.size(); j++) + { + strncpy(data,l[j].c_str(),MAXBUF); + serv->SendPacket(data,tcp_host); + } + } if (strcmp(c->second->topic,"")) { snprintf(data,MAXBUF,"T %d %s %s :%s",c->second->topicset,c->second->setby,c->second->name,c->second->topic); diff --git a/src/modules.cpp b/src/modules.cpp index d4d647d7e..e05ab4566 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -1,21 +1,166 @@ -/* - - -*/ - - - -#include <typeinfo> -#include <iostream> +#include "inspircd.h" +#include "inspircd_io.h" +#include "inspircd_util.h" +#include "inspircd_config.h" +#include <unistd.h> +#include <fcntl.h> +#include <sys/errno.h> +#include <sys/ioctl.h> +#include <sys/utsname.h> +#include <cstdio> +#include <time.h> +#include <string> +#ifdef GCC3 +#include <ext/hash_map> +#else +#include <hash_map> +#endif +#include <map> +#include <sstream> +#include <vector> +#include <errno.h> +#include <deque> +#include <errno.h> +#include <unistd.h> +#include <sched.h> +#include "connection.h" +#include "users.h" +#include "servers.h" +#include "ctables.h" #include "globals.h" #include "modules.h" -#include "ctables.h" -#include "inspircd_io.h" +#include "dynamic.h" #include "wildcard.h" -#include "mode.h" #include "message.h" +#include "mode.h" +#include "xline.h" #include "commands.h" +#ifdef GCC3 +#define nspace __gnu_cxx +#else +#define nspace std +#endif + +using namespace std; + +extern int MODCOUNT; +extern vector<Module*> modules; +extern vector<ircd_module*> factory; + +extern int LogLevel; +extern char ServerName[MAXBUF]; +extern char Network[MAXBUF]; +extern char ServerDesc[MAXBUF]; +extern char AdminName[MAXBUF]; +extern char AdminEmail[MAXBUF]; +extern char AdminNick[MAXBUF]; +extern char diepass[MAXBUF]; +extern char restartpass[MAXBUF]; +extern char motd[MAXBUF]; +extern char rules[MAXBUF]; +extern char list[MAXBUF]; +extern char PrefixQuit[MAXBUF]; +extern char DieValue[MAXBUF]; + +extern int debugging; +extern int WHOWAS_STALE; +extern int WHOWAS_MAX; +extern int DieDelay; +extern time_t startup_time; +extern int NetBufferSize; +extern int MaxWhoResults; +extern time_t nb_start; + +extern std::vector<int> fd_reap; +extern std::vector<std::string> module_names; + +extern char bannerBuffer[MAXBUF]; +extern int boundPortCount; +extern int portCount; +extern int UDPportCount; +extern int ports[MAXSOCKS]; +extern int defaultRoute; + +extern std::vector<long> auth_cookies; +extern std::stringstream config_f; + +extern serverrec* me[32]; + +extern FILE *log_file; + + +namespace nspace +{ + template<> struct nspace::hash<in_addr> + { + size_t operator()(const struct in_addr &a) const + { + size_t q; + memcpy(&q,&a,sizeof(size_t)); + return q; + } + }; + + template<> struct nspace::hash<string> + { + size_t operator()(const string &s) const + { + char a[MAXBUF]; + static struct hash<const char *> strhash; + strcpy(a,s.c_str()); + strlower(a); + return strhash(a); + } + }; +} + + +struct StrHashComp +{ + + bool operator()(const string& s1, const string& s2) const + { + char a[MAXBUF],b[MAXBUF]; + strcpy(a,s1.c_str()); + strcpy(b,s2.c_str()); + return (strcasecmp(a,b) == 0); + } + +}; + +struct InAddr_HashComp +{ + + bool operator()(const in_addr &s1, const in_addr &s2) const + { + size_t q; + size_t p; + + memcpy(&q,&s1,sizeof(size_t)); + memcpy(&p,&s2,sizeof(size_t)); + + return (q == p); + } + +}; + + +typedef nspace::hash_map<std::string, userrec*, nspace::hash<string>, StrHashComp> user_hash; +typedef nspace::hash_map<std::string, chanrec*, nspace::hash<string>, StrHashComp> chan_hash; +typedef nspace::hash_map<in_addr,string*, nspace::hash<in_addr>, InAddr_HashComp> address_cache; +typedef std::deque<command_t> command_table; + + +extern user_hash clientlist; +extern chan_hash chanlist; +extern user_hash whowas; +extern command_table cmdlist; +extern file_cache MOTD; +extern file_cache RULES; +extern address_cache IP; + + // class type for holding an extended mode character - internal to core class ExtMode : public classbase @@ -33,6 +178,7 @@ public: typedef std::vector<ExtMode> ExtModeList; typedef ExtModeList::iterator ExtModeListIter; + ExtModeList EMode; // returns true if an extended mode character is in use @@ -156,6 +302,9 @@ int Module::OnUserPreMessage(userrec* user,void* dest,int target_type, std::stri int Module::OnUserPreNotice(userrec* user,void* dest,int target_type, std::string text) { return 0; }; int Module::OnUserPreNick(userrec* user, std::string newnick) { return 0; }; int Module::OnAccessCheck(userrec* source,userrec* dest,chanrec* channel,int access_type) { return ACR_DEFAULT; }; +string_list Module::OnUserSync(userrec* user) { string_list empty; return empty; } +string_list Module::OnChannelSync(chanrec* chan) { string_list empty; return empty; } + // server is a wrapper class that provides methods to all of the C-style // exports in the core @@ -197,6 +346,25 @@ chanrec* Server::PartUserFromChannel(userrec* user, std::string cname, std::stri return del_channel(user,cname.c_str(),reason.c_str(),false); } +chanuserlist Server::GetUsers(chanrec* chan) +{ + chanuserlist userl; + userl.clear(); + for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++) + { + if (i->second) + { + if (has_channel(i->second,chan)) + { + if (isnick(i->second->nick)) + { + userl.push_back(i->second); + } + } + } + } + return userl; +} void Server::ChangeUserNick(userrec* user, std::string nickname) { force_nickchange(user,nickname.c_str()); diff --git a/src/modules/m_chanprotect.cpp b/src/modules/m_chanprotect.cpp index a6d6a8a9f..a37b4d325 100644 --- a/src/modules/m_chanprotect.cpp +++ b/src/modules/m_chanprotect.cpp @@ -18,8 +18,13 @@ class ModuleChanProtect : public Module ModuleChanProtect() { + + // here we initialise our module. Use new to create new instances of the required + // classes. + Srv = new Server; Conf = new ConfigReader; + // set up our modes. We're using listmodes and not normal extmodes here. // listmodes only need one parameter as everything else is assumed by the // nature of the mode thats being created. @@ -33,6 +38,7 @@ class ModuleChanProtect : public Module virtual void OnRehash() { + // on a rehash we delete our classes for good measure and create them again. delete Conf; Conf = new ConfigReader; // re-read our config options on a rehash @@ -188,7 +194,7 @@ class ModuleChanProtect : public Module { if (mode_on) { - if (!theuser->GetExt("cm_founder_"+std::string(chan->name))) + if (!theuser->GetExt("cm_protect_"+std::string(chan->name))) { theuser->Extend("cm_protect_"+std::string(chan->name),dummyvalue); return 1; @@ -196,7 +202,7 @@ class ModuleChanProtect : public Module } else { - if (theuser->GetExt("cm_founder_"+std::string(chan->name))) + if (theuser->GetExt("cm_protect_"+std::string(chan->name))) { theuser->Shrink("cm_protect_"+std::string(chan->name)); return 1; @@ -225,8 +231,22 @@ class ModuleChanProtect : public Module return Version(1,0,0,0); } - virtual void OnUserConnect(userrec* user) + virtual string_list OnChannelSync(chanrec* chan) { + chanuserlist cl = Srv->GetUsers(chan); + string_list commands; + for (int i = 0; i < cl.size(); i++) + { + if (cl[i]->GetExt("cm_founder_"+std::string(chan->name))) + { + commands.push_back("M "+std::string(chan->name)+" +q "+std::string(cl[i]->nick)); + } + if (cl[i]->GetExt("cm_protect_"+std::string(chan->name))) + { + commands.push_back("M "+std::string(chan->name)+" +a "+std::string(cl[i]->nick)); + } + } + return commands; } }; |