From 90cc4b0ee93696e6e6b3208cd2877ae6e786440d Mon Sep 17 00:00:00 2001 From: brain Date: Sat, 1 May 2004 16:12:17 +0000 Subject: Provided modules with the ability to sync data on a netjoin git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@767 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/InspIRCd.layout | 56 ++++++------ src/channels.cpp | 91 +++++++++++++++++++- src/commands.cpp | 2 +- src/inspircd.cpp | 18 ++++ src/modules.cpp | 192 +++++++++++++++++++++++++++++++++++++++--- src/modules/m_chanprotect.cpp | 26 +++++- 6 files changed, 338 insertions(+), 47 deletions(-) (limited to 'src') 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 +#include "inspircd_io.h" +#include "inspircd_util.h" +#include "inspircd_config.h" +#include +#include +#include +#include +#include +#include +#include #include +#ifdef GCC3 +#include +#else +#include +#endif +#include +#include #include +#include +#include +#include +#include +#include +#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 modules; +extern vector 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 fd_reap; +extern std::vector 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 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 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 -#include +#include "inspircd.h" +#include "inspircd_io.h" +#include "inspircd_util.h" +#include "inspircd_config.h" +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef GCC3 +#include +#else +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#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 modules; +extern vector 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 fd_reap; +extern std::vector 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 auth_cookies; +extern std::stringstream config_f; + +extern serverrec* me[32]; + +extern FILE *log_file; + + +namespace nspace +{ + template<> struct nspace::hash + { + size_t operator()(const struct in_addr &a) const + { + size_t q; + memcpy(&q,&a,sizeof(size_t)); + return q; + } + }; + + template<> struct nspace::hash + { + size_t operator()(const string &s) const + { + char a[MAXBUF]; + static struct hash 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, StrHashComp> user_hash; +typedef nspace::hash_map, StrHashComp> chan_hash; +typedef nspace::hash_map, InAddr_HashComp> address_cache; +typedef std::deque 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 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; } }; -- cgit v1.2.3