diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-08-09 18:55:52 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-08-09 18:55:52 +0000 |
commit | 9bc04a302572eb311a147a32ff1d36f1d91f2d7a (patch) | |
tree | 847f867baeefde36c133387b578aa937c37b4360 | |
parent | 2591562ada4cb1f866e5d1c98340fb19332b3844 (diff) |
userrec and chanrec now have their own independent pointer back to their 'creator' InspIRCd* object, extern now longer required in channels.cpp or users.cpp
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4820 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | include/channels.h | 12 | ||||
-rw-r--r-- | include/modules.h | 36 | ||||
-rw-r--r-- | include/users.h | 14 | ||||
-rw-r--r-- | src/channels.cpp | 38 | ||||
-rw-r--r-- | src/cmd_join.cpp | 4 | ||||
-rw-r--r-- | src/cmd_kill.cpp | 2 | ||||
-rw-r--r-- | src/cull_list.cpp | 2 | ||||
-rw-r--r-- | src/inspircd.cpp | 4 | ||||
-rw-r--r-- | src/modules.cpp | 2 | ||||
-rw-r--r-- | src/modules/extra/m_filter_pcre.cpp | 4 | ||||
-rw-r--r-- | src/modules/extra/m_sqlauth.cpp | 6 | ||||
-rw-r--r-- | src/modules/m_blockamsg.cpp | 3 | ||||
-rw-r--r-- | src/modules/m_conn_waitpong.cpp | 4 | ||||
-rw-r--r-- | src/modules/m_connflood.cpp | 8 | ||||
-rw-r--r-- | src/modules/m_filter.cpp | 4 | ||||
-rw-r--r-- | src/modules/m_nicklock.cpp | 3 | ||||
-rw-r--r-- | src/modules/m_operjoin.cpp | 4 | ||||
-rw-r--r-- | src/modules/m_park.cpp | 2 | ||||
-rw-r--r-- | src/modules/m_redirect.cpp | 2 | ||||
-rw-r--r-- | src/modules/m_sajoin.cpp | 3 | ||||
-rw-r--r-- | src/modules/m_samode.cpp | 3 | ||||
-rw-r--r-- | src/modules/m_sanick.cpp | 3 | ||||
-rw-r--r-- | src/modules/m_saquit.cpp | 3 | ||||
-rw-r--r-- | src/modules/m_spanningtree.cpp | 18 | ||||
-rw-r--r-- | src/modules/m_timedbans.cpp | 5 | ||||
-rw-r--r-- | src/userprocess.cpp | 12 | ||||
-rw-r--r-- | src/users.cpp | 77 |
27 files changed, 171 insertions, 107 deletions
diff --git a/include/channels.h b/include/channels.h index aa34ceb3c..32f28c751 100644 --- a/include/channels.h +++ b/include/channels.h @@ -142,6 +142,8 @@ class ucrec : public classbase virtual ~ucrec() { /* stub */ } }; +class InspIRCd; + /** Holds all relevent information for a channel. * This class represents a channel, and contains its name, modes, time created, topic, topic set time, @@ -151,9 +153,13 @@ class chanrec : public Extensible { private: + /** Pointer to creator object + */ + InspIRCd* ServerInstance; + /** Connect a chanrec to a userrec */ - static chanrec* ForceChan(chanrec* Ptr,ucrec *a,userrec* user, int created); + static chanrec* ForceChan(InspIRCd* Instance, chanrec* Ptr,ucrec *a,userrec* user, int created); public: /** The channels name. @@ -341,7 +347,7 @@ class chanrec : public Extensible /** Creates a channel record and initialises it with default values * @throw Nothing at present. */ - chanrec(); + chanrec(InspIRCd* Instance); /** Make src kick user from this channel with the given reason. * @param src The source of the kick @@ -379,7 +385,7 @@ class chanrec : public Extensible * been created if the channel did not exist before the user was joined to it. * If the user could not be joined to a channel, the return value may be NULL. */ - static chanrec* JoinUser(userrec *user, const char* cn, bool override, const char* key = ""); + static chanrec* JoinUser(InspIRCd* ServerInstance, userrec *user, const char* cn, bool override, const char* key = ""); /** Write to a channel, from a user, using va_args for text * @param user User whos details to prefix the line with diff --git a/include/modules.h b/include/modules.h index 6f9ebf9e9..b0d249c7c 100644 --- a/include/modules.h +++ b/include/modules.h @@ -103,6 +103,19 @@ typedef std::map<std::string,Module*> featurelist; } \ } +#define FOREACH_MOD_I(z,y,x) if (z->Config->global_implementation[y] > 0) { \ + for (int _i = 0; _i <= MODCOUNT; _i++) { \ + if (z->Config->implement_lists[_i][y]) \ + try \ + { \ + modules[_i]->x ; \ + } \ + catch (ModuleException& modexcept) \ + { \ + log(DEBUG,"Module exception caught: %s",modexcept.GetReason()); \ + } \ + } \ +} /** * This define is similar to the one above but returns a result in MOD_RESULT. * The first module to return a nonzero result is the value to be accepted, @@ -111,7 +124,7 @@ typedef std::map<std::string,Module*> featurelist; #define FOREACH_RESULT(y,x) { if (ServerInstance->Config->global_implementation[y] > 0) { \ MOD_RESULT = 0; \ for (int _i = 0; _i <= MODCOUNT; _i++) { \ - if (ServerInstance->Config->implement_lists[_i][y]) {\ + if (ServerInstance->Config->implement_lists[_i][y]) { \ try \ { \ int res = modules[_i]->x ; \ @@ -129,6 +142,27 @@ typedef std::map<std::string,Module*> featurelist; } \ } +#define FOREACH_RESULT_I(z,y,x) { if (z->Config->global_implementation[y] > 0) { \ + MOD_RESULT = 0; \ + for (int _i = 0; _i <= MODCOUNT; _i++) { \ + if (z->Config->implement_lists[_i][y]) { \ + try \ + { \ + int res = modules[_i]->x ; \ + if (res != 0) { \ + MOD_RESULT = res; \ + break; \ + } \ + } \ + catch (ModuleException& modexcept) \ + { \ + log(DEBUG,"Module exception cought: %s",modexcept.GetReason()); \ + } \ + } \ + } \ + } \ +} + #define FD_MAGIC_NUMBER -42 // useful macros diff --git a/include/users.h b/include/users.h index 6e5a60b23..8e3fddfcd 100644 --- a/include/users.h +++ b/include/users.h @@ -66,6 +66,8 @@ class Invited : public classbase +class InspIRCd; + /** Derived from Resolver, and performs user forward/reverse lookups. */ class UserResolver : public Resolver @@ -76,8 +78,9 @@ class UserResolver : public Resolver userrec* bound_user; int bound_fd; bool fwd; + InspIRCd* ServerInstance; public: - UserResolver(userrec* user, std::string to_resolve, bool forward); + UserResolver(InspIRCd* Instance, userrec* user, std::string to_resolve, bool forward); void OnLookupComplete(const std::string &result); void OnError(ResolverError e, const std::string &errormessage); @@ -156,6 +159,9 @@ typedef std::vector<ucrec*> UserChanList; class userrec : public connection { private: + /** Pointer to creator + */ + InspIRCd* ServerInstance; /** A list of channels the user has a pending invite to. */ @@ -324,7 +330,7 @@ class userrec : public connection /** Default constructor * @throw Nothing at present */ - userrec(); + userrec(InspIRCd* Instance); /** Returns the full displayed host of the user * This member function returns the hostname of the user as seen by other users @@ -500,7 +506,7 @@ class userrec : public connection * @param user The user to remove * @param r The quit reason */ - static void QuitUser(userrec *user, const std::string &r); + static void QuitUser(InspIRCd* Instance, userrec *user, const std::string &r); /** Add the user to WHOWAS system */ @@ -542,7 +548,7 @@ class userrec : public connection * This will create a new userrec, insert it into the user_hash, * initialize it as not yet registered, and add it to the socket engine. */ - static void AddClient(int socket, int port, bool iscached, insp_inaddr ip); + static void AddClient(InspIRCd* Instance, int socket, int port, bool iscached, insp_inaddr ip); /** Oper down. * This will clear the +o usermode and unset the user's oper type diff --git a/src/channels.cpp b/src/channels.cpp index b9e88a5bd..d50841de7 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -39,14 +39,12 @@ using namespace std; #include "helperfuncs.h" #include "typedefs.h" -extern InspIRCd* ServerInstance; - extern int MODCOUNT; extern std::vector<Module*> modules; extern std::vector<ircd_module*> factory; extern time_t TIME; -chanrec::chanrec() +chanrec::chanrec(InspIRCd* Instance) : ServerInstance(Instance) { *name = *topic = *setby = *key = 0; created = topicset = limit = 0; @@ -216,7 +214,7 @@ CUList* chanrec::GetVoicedUsers() * add a channel to a user, creating the record for it if needed and linking * it to the user record */ -chanrec* chanrec::JoinUser(userrec *user, const char* cn, bool override, const char* key) +chanrec* chanrec::JoinUser(InspIRCd* Instance, userrec *user, const char* cn, bool override, const char* key) { if (!user || !cn) return NULL; @@ -233,14 +231,14 @@ chanrec* chanrec::JoinUser(userrec *user, const char* cn, bool override, const c if (user->fd > -1) { MOD_RESULT = 0; - FOREACH_RESULT(I_OnUserPreJoin,OnUserPreJoin(user,NULL,cname)); + FOREACH_RESULT_I(Instance,I_OnUserPreJoin,OnUserPreJoin(user,NULL,cname)); if (MOD_RESULT == 1) return NULL; } /* create a new one */ - Ptr = new chanrec(); - ServerInstance->chanlist[cname] = Ptr; + Ptr = new chanrec(Instance); + Instance->chanlist[cname] = Ptr; strlcpy(Ptr->name, cname,CHANMAX); Ptr->modes[CM_TOPICLOCK] = Ptr->modes[CM_NOEXTERNAL] = 1; @@ -269,7 +267,7 @@ chanrec* chanrec::JoinUser(userrec *user, const char* cn, bool override, const c if (IS_LOCAL(user)) /* was a check on fd > -1 */ { MOD_RESULT = 0; - FOREACH_RESULT(I_OnUserPreJoin,OnUserPreJoin(user,Ptr,cname)); + FOREACH_RESULT_I(Instance,I_OnUserPreJoin,OnUserPreJoin(user,Ptr,cname)); if (MOD_RESULT == 1) { return NULL; @@ -279,7 +277,7 @@ chanrec* chanrec::JoinUser(userrec *user, const char* cn, bool override, const c if (*Ptr->key) { MOD_RESULT = 0; - FOREACH_RESULT(I_OnCheckKey,OnCheckKey(user, Ptr, key ? key : "")); + FOREACH_RESULT_I(Instance,I_OnCheckKey,OnCheckKey(user, Ptr, key ? key : "")); if (!MOD_RESULT) { if (!key) @@ -303,7 +301,7 @@ chanrec* chanrec::JoinUser(userrec *user, const char* cn, bool override, const c { MOD_RESULT = 0; irc::string xname(Ptr->name); - FOREACH_RESULT(I_OnCheckInvite,OnCheckInvite(user, Ptr)); + FOREACH_RESULT_I(Instance,I_OnCheckInvite,OnCheckInvite(user, Ptr)); if (!MOD_RESULT) { if (user->IsInvited(xname)) @@ -322,7 +320,7 @@ chanrec* chanrec::JoinUser(userrec *user, const char* cn, bool override, const c if (Ptr->limit) { MOD_RESULT = 0; - FOREACH_RESULT(I_OnCheckLimit,OnCheckLimit(user, Ptr)); + FOREACH_RESULT_I(Instance,I_OnCheckLimit,OnCheckLimit(user, Ptr)); if (!MOD_RESULT) { if (Ptr->GetUserCounter() >= Ptr->limit) @@ -335,7 +333,7 @@ chanrec* chanrec::JoinUser(userrec *user, const char* cn, bool override, const c if (Ptr->bans.size()) { MOD_RESULT = 0; - FOREACH_RESULT(I_OnCheckBan,OnCheckBan(user, Ptr)); + FOREACH_RESULT_I(Instance,I_OnCheckBan,OnCheckBan(user, Ptr)); char mask[MAXBUF]; sprintf(mask,"%s!%s@%s",user->nick, user->ident, user->GetIPString()); if (!MOD_RESULT) @@ -367,7 +365,7 @@ chanrec* chanrec::JoinUser(userrec *user, const char* cn, bool override, const c { if ((*index)->channel == NULL) { - return chanrec::ForceChan(Ptr, *index, user, created); + return chanrec::ForceChan(Instance, Ptr, *index, user, created); } } @@ -379,7 +377,7 @@ chanrec* chanrec::JoinUser(userrec *user, const char* cn, bool override, const c if (!IS_LOCAL(user)) /* was a check on fd < 0 */ { ucrec* a = new ucrec(); - chanrec* c = chanrec::ForceChan(Ptr,a,user,created); + chanrec* c = chanrec::ForceChan(Instance, Ptr,a,user,created); user->chans.push_back(a); return c; } @@ -389,7 +387,7 @@ chanrec* chanrec::JoinUser(userrec *user, const char* cn, bool override, const c if (user->chans.size() < OPERMAXCHANS) { ucrec* a = new ucrec(); - chanrec* c = chanrec::ForceChan(Ptr,a,user,created); + chanrec* c = chanrec::ForceChan(Instance, Ptr,a,user,created); user->chans.push_back(a); return c; } @@ -401,12 +399,12 @@ chanrec* chanrec::JoinUser(userrec *user, const char* cn, bool override, const c { log(DEBUG,"BLAMMO, Whacking channel."); /* Things went seriously pear shaped, so take this away. bwahaha. */ - chan_hash::iterator n = ServerInstance->chanlist.find(cname); - if (n != ServerInstance->chanlist.end()) + chan_hash::iterator n = Instance->chanlist.find(cname); + if (n != Instance->chanlist.end()) { Ptr->DelUser(user); DELETE(Ptr); - ServerInstance->chanlist.erase(n); + Instance->chanlist.erase(n); for (unsigned int index =0; index < user->chans.size(); index++) { if (user->chans[index]->channel == Ptr) @@ -431,7 +429,7 @@ chanrec* chanrec::JoinUser(userrec *user, const char* cn, bool override, const c return NULL; } -chanrec* chanrec::ForceChan(chanrec* Ptr,ucrec *a,userrec* user, int created) +chanrec* chanrec::ForceChan(InspIRCd* Instance, chanrec* Ptr,ucrec *a,userrec* user, int created) { if (created == 2) { @@ -460,7 +458,7 @@ chanrec* chanrec::ForceChan(chanrec* Ptr,ucrec *a,userrec* user, int created) userlist(user,Ptr); user->WriteServ("366 %s %s :End of /NAMES list.", user->nick, Ptr->name); } - FOREACH_MOD(I_OnUserJoin,OnUserJoin(user,Ptr)); + FOREACH_MOD_I(Instance,I_OnUserJoin,OnUserJoin(user,Ptr)); return Ptr; } diff --git a/src/cmd_join.cpp b/src/cmd_join.cpp index bf60e6543..99a8b36e0 100644 --- a/src/cmd_join.cpp +++ b/src/cmd_join.cpp @@ -31,7 +31,7 @@ void cmd_join::Handle (const char** parameters, int pcnt, userrec *user) if (IsValidChannelName(parameters[0])) { - chanrec::JoinUser(user, parameters[0], false, parameters[1]); + chanrec::JoinUser(ServerInstance, user, parameters[0], false, parameters[1]); return; } } @@ -42,7 +42,7 @@ void cmd_join::Handle (const char** parameters, int pcnt, userrec *user) if (IsValidChannelName(parameters[0])) { - chanrec::JoinUser(user, parameters[0], false); + chanrec::JoinUser(ServerInstance, user, parameters[0], false); return; } } diff --git a/src/cmd_kill.cpp b/src/cmd_kill.cpp index a7c710968..22525e8cf 100644 --- a/src/cmd_kill.cpp +++ b/src/cmd_kill.cpp @@ -78,7 +78,7 @@ void cmd_kill::Handle (const char** parameters, int pcnt, userrec *user) user->WriteTo(u, "KILL %s :%s!%s!%s (%s)", u->nick, ServerInstance->Config->ServerName, user->dhost, user->nick, parameters[1]); WriteOpers("*** Local Kill by %s: %s!%s@%s (%s)", user->nick, u->nick, u->ident, u->host, parameters[1]); snprintf(killreason,MAXQUIT,"Killed (%s (%s))", user->nick, parameters[1]); - userrec::QuitUser(u, killreason); + userrec::QuitUser(ServerInstance, u, killreason); } } else diff --git a/src/cull_list.cpp b/src/cull_list.cpp index bfa37e51a..2fb31014b 100644 --- a/src/cull_list.cpp +++ b/src/cull_list.cpp @@ -132,7 +132,7 @@ int CullList::Apply() { std::vector<CullItem>::iterator a = list.begin(); - userrec::QuitUser(a->GetUser(), a->GetReason().c_str()); + userrec::QuitUser(ServerInstance, a->GetUser(), a->GetReason().c_str()); list.erase(list.begin()); } return n; diff --git a/src/inspircd.cpp b/src/inspircd.cpp index ecda5abb9..b0e6b1073 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -853,10 +853,10 @@ void InspIRCd::DoOneIteration(bool process_module_sockets) stats->statsAccept++; #ifdef IPV6 log(DEBUG,"Add ipv6 client"); - AddClient(incomingSockfd, in_port, false, client.sin6_addr); + userrec::AddClient(this, incomingSockfd, in_port, false, client.sin6_addr); #else log(DEBUG,"Add ipv4 client"); - userrec::AddClient(incomingSockfd, in_port, false, client.sin_addr); + userrec::AddClient(this, incomingSockfd, in_port, false, client.sin_addr); #endif log(DEBUG,"Adding client on port %d fd=%d",in_port,incomingSockfd); } diff --git a/src/modules.cpp b/src/modules.cpp index 46b6a16d1..22083fa66 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -538,7 +538,7 @@ bool InspIRCd::PseudoToUser(userrec* alive, userrec* zombie, const std::string & std::string oldnick = alive->nick; std::string oldhost = alive->host; std::string oldident = alive->ident; - userrec::QuitUser(alive,message.c_str()); + userrec::QuitUser(this,alive,message.c_str()); if (find(local_users.begin(),local_users.end(),alive) != local_users.end()) { local_users.erase(find(local_users.begin(),local_users.end(),alive)); diff --git a/src/modules/extra/m_filter_pcre.cpp b/src/modules/extra/m_filter_pcre.cpp index da7559914..08068db59 100644 --- a/src/modules/extra/m_filter_pcre.cpp +++ b/src/modules/extra/m_filter_pcre.cpp @@ -29,6 +29,8 @@ using namespace std; #include "helperfuncs.h" #include "inspircd.h" +extern InspIRCd* ServerInstance; + class FilterPCREException : public ModuleException { public: @@ -145,7 +147,7 @@ class ModuleFilterPCRE : public Module if (do_action == "kill") { - userrec::QuitUser(user,reason); + userrec::QuitUser(ServerInstance,user,reason); } return 1; } diff --git a/src/modules/extra/m_sqlauth.cpp b/src/modules/extra/m_sqlauth.cpp index e6878777d..93d763cb5 100644 --- a/src/modules/extra/m_sqlauth.cpp +++ b/src/modules/extra/m_sqlauth.cpp @@ -27,6 +27,8 @@ /* $ModDesc: Allow/Deny connections based upon an arbitary SQL table */ +extern InspIRCd* ServerInstance; + class ModuleSQLAuth : public Module { Server* Srv; @@ -94,7 +96,7 @@ public: if (!CheckCredentials(user)) { - userrec::QuitUser(user,killreason); + userrec::QuitUser(ServerInstance,user,killreason); } } @@ -202,7 +204,7 @@ public: { if(user->GetExt("sqlauth_failed")) { - userrec::QuitUser(user,killreason); + userrec::QuitUser(ServerInstance,user,killreason); return false; } diff --git a/src/modules/m_blockamsg.cpp b/src/modules/m_blockamsg.cpp index 97c255501..9567f2de7 100644 --- a/src/modules/m_blockamsg.cpp +++ b/src/modules/m_blockamsg.cpp @@ -30,6 +30,7 @@ /* $ModDesc: Attempt to block /amsg, at least some of the irritating mIRC scripts. */ extern time_t TIME; +extern InspIRCd* ServerInstance; enum BlockAction { IBLOCK_KILL, IBLOCK_KILLOPERS, IBLOCK_NOTICE, IBLOCK_NOTICEOPERS, IBLOCK_SILENT }; @@ -142,7 +143,7 @@ public: WriteOpers("*** %s had an /amsg or /ame denied", user->nick); if(action == IBLOCK_KILL || action == IBLOCK_KILLOPERS) - userrec::QuitUser(user, "Global message (/amsg or /ame) detected"); + userrec::QuitUser(ServerInstance, user, "Global message (/amsg or /ame) detected"); else if(action == IBLOCK_NOTICE || action == IBLOCK_NOTICEOPERS) user->WriteServ( "NOTICE %s :Global message (/amsg or /ame) detected", user->nick); diff --git a/src/modules/m_conn_waitpong.cpp b/src/modules/m_conn_waitpong.cpp index 6021d7058..558e98696 100644 --- a/src/modules/m_conn_waitpong.cpp +++ b/src/modules/m_conn_waitpong.cpp @@ -9,6 +9,8 @@ /* $ModDesc: Forces connecting clients to send a PONG message back to the server before they can complete their connection */ +extern InspIRCd* ServerInstance; + char* RandString(unsigned int length) { unsigned char* tmp = new unsigned char[(length/4)*3]; @@ -95,7 +97,7 @@ class ModuleWaitPong : public Module else { if(killonbadreply) - userrec::QuitUser(user, "Incorrect ping reply for registration"); + userrec::QuitUser(ServerInstance, user, "Incorrect ping reply for registration"); return 1; } } diff --git a/src/modules/m_connflood.cpp b/src/modules/m_connflood.cpp index e5d3fd2ad..b1a9d8c7c 100644 --- a/src/modules/m_connflood.cpp +++ b/src/modules/m_connflood.cpp @@ -20,12 +20,16 @@ using namespace std; #include "users.h" #include "modules.h" +#include "helperfuncs.h" +#include "inspircd.h" /* $ModDesc: Connection throttle */ int conns = 0, throttled = 0; extern time_t TIME; +extern InspIRCd* ServerInstance; + class ModuleConnFlood : public Module { private: @@ -94,7 +98,7 @@ public: Srv->SendOpers("*** Connection throttle deactivated"); return; } - userrec::QuitUser(user, quitmsg); + userrec::QuitUser(ServerInstance, user, quitmsg); return; } @@ -104,7 +108,7 @@ public: { throttled = 1; Srv->SendOpers("*** Connection throttle activated"); - userrec::QuitUser(user, quitmsg); + userrec::QuitUser(ServerInstance, user, quitmsg); return; } } diff --git a/src/modules/m_filter.cpp b/src/modules/m_filter.cpp index 9b4a12e39..0f9477921 100644 --- a/src/modules/m_filter.cpp +++ b/src/modules/m_filter.cpp @@ -30,6 +30,8 @@ using namespace std; /* $ModDesc: An enhanced version of the unreal m_filter.so used by chatspike.net */ +extern InspIRCd* ServerInstance; + class Filter : public classbase { public: @@ -117,7 +119,7 @@ class ModuleFilter : public Module if (f->action == "kill") { - userrec::QuitUser(user,f->reason); + userrec::QuitUser(ServerInstance,user,f->reason); } return 1; } diff --git a/src/modules/m_nicklock.cpp b/src/modules/m_nicklock.cpp index 6369e34d7..e46b56901 100644 --- a/src/modules/m_nicklock.cpp +++ b/src/modules/m_nicklock.cpp @@ -27,6 +27,7 @@ using namespace std; /* $ModDesc: Provides the NICKLOCK command, allows an oper to chage a users nick and lock them to it until they quit */ static Server *Srv; +extern InspIRCd* ServerInstance; class cmd_nicklock : public command_t { @@ -57,7 +58,7 @@ class cmd_nicklock : public command_t Srv->SendOpers(std::string(user->nick)+" used NICKLOCK to change and hold "+std::string(parameters[0])+" to "+parameters[1]); if (!source->ForceNickChange(parameters[1])) { - userrec::QuitUser(source, "Nickname collision"); + userrec::QuitUser(ServerInstance, source, "Nickname collision"); return; } source->Extend("nick_locked", "ON"); diff --git a/src/modules/m_operjoin.cpp b/src/modules/m_operjoin.cpp index 801e0ac10..750f98c96 100644 --- a/src/modules/m_operjoin.cpp +++ b/src/modules/m_operjoin.cpp @@ -10,6 +10,8 @@ using namespace std; /* $ModDesc: Forces opers to join the specified channel(s) on oper-up */ +extern InspIRCd* ServerInstance; + class ModuleOperjoin : public Module { private: @@ -73,7 +75,7 @@ class ModuleOperjoin : public Module std::vector<std::string> operChans; tokenize(operChan,operChans); for(std::vector<std::string>::iterator it = operChans.begin(); it != operChans.end(); it++) - chanrec::JoinUser(user, it->c_str(), false); + chanrec::JoinUser(ServerInstance, user, it->c_str(), false); } } diff --git a/src/modules/m_park.cpp b/src/modules/m_park.cpp index 779a4e8a0..8502fbfdb 100644 --- a/src/modules/m_park.cpp +++ b/src/modules/m_park.cpp @@ -328,7 +328,7 @@ class ModulePark : public Module // and then corrupt the pointer! pinfo.erase(j); if (thisnick) - userrec::QuitUser(thisnick,"PARK timeout"); + userrec::QuitUser(ServerInstance,thisnick,"PARK timeout"); go_again = true; break; } diff --git a/src/modules/m_redirect.cpp b/src/modules/m_redirect.cpp index d7f82f38e..4d8d717ab 100644 --- a/src/modules/m_redirect.cpp +++ b/src/modules/m_redirect.cpp @@ -139,7 +139,7 @@ class ModuleRedirect : public Module { std::string channel = chan->GetModeParameter('L'); user->WriteServ("470 %s :%s has become full, so you are automatically being transferred to the linked channel %s",user->nick,cname,channel.c_str()); - chanrec::JoinUser(user, channel.c_str(), false); + chanrec::JoinUser(ServerInstance, user, channel.c_str(), false); return 1; } } diff --git a/src/modules/m_sajoin.cpp b/src/modules/m_sajoin.cpp index 54f9ad066..af03f47d7 100644 --- a/src/modules/m_sajoin.cpp +++ b/src/modules/m_sajoin.cpp @@ -27,6 +27,7 @@ using namespace std; /* $ModDesc: Provides support for unreal-style SAJOIN command */ static Server *Srv; +extern InspIRCd* ServerInstance; class cmd_sajoin : public command_t { @@ -55,7 +56,7 @@ class cmd_sajoin : public command_t } Srv->SendOpers(std::string(user->nick)+" used SAJOIN to make "+std::string(dest->nick)+" join "+parameters[1]); - chanrec::JoinUser(dest, parameters[1], true); + chanrec::JoinUser(ServerInstance, dest, parameters[1], true); } } }; diff --git a/src/modules/m_samode.cpp b/src/modules/m_samode.cpp index 3e6c256a0..012bfed89 100644 --- a/src/modules/m_samode.cpp +++ b/src/modules/m_samode.cpp @@ -38,6 +38,7 @@ using namespace std; #include "inspircd.h" static Server *Srv; +extern InspIRCd* ServerInstance; class cmd_samode : public command_t { @@ -55,7 +56,7 @@ class cmd_samode : public command_t */ std::string result; Srv->Log(DEBUG,"SAMODE: Being handled"); - userrec* n = new userrec(); + userrec* n = new userrec(ServerInstance); n->fd = FD_MAGIC_NUMBER; Srv->SendMode(parameters,pcnt,n); delete n; diff --git a/src/modules/m_sanick.cpp b/src/modules/m_sanick.cpp index 1299332fe..db35b9ba5 100644 --- a/src/modules/m_sanick.cpp +++ b/src/modules/m_sanick.cpp @@ -25,6 +25,7 @@ using namespace std; /* $ModDesc: Provides support for SANICK command */ +extern InspIRCd* ServerInstance; static Server *Srv; class cmd_sanick : public command_t @@ -54,7 +55,7 @@ class cmd_sanick : public command_t if (!source->ForceNickChange(parameters[1])) { /* We couldnt change the nick */ - userrec::QuitUser(source, "Nickname collision"); + userrec::QuitUser(ServerInstance, source, "Nickname collision"); return; } } diff --git a/src/modules/m_saquit.cpp b/src/modules/m_saquit.cpp index 3c9d95189..dd02d4e41 100644 --- a/src/modules/m_saquit.cpp +++ b/src/modules/m_saquit.cpp @@ -36,6 +36,7 @@ using namespace std; /* $ModDesc: Provides support for an SAQUIT command, exits user with a reason */ static Server *Srv; +extern InspIRCd* ServerInstance; class cmd_saquit : public command_t { @@ -64,7 +65,7 @@ class cmd_saquit : public command_t line = line + std::string(parameters[pcnt-1]); Srv->SendOpers(std::string(user->nick)+" used SAQUIT to make "+std::string(dest->nick)+" quit with a reason of "+line); - userrec::QuitUser(dest, line); + userrec::QuitUser(ServerInstance, dest, line); } } }; diff --git a/src/modules/m_spanningtree.cpp b/src/modules/m_spanningtree.cpp index 3206c5621..75fa76489 100644 --- a/src/modules/m_spanningtree.cpp +++ b/src/modules/m_spanningtree.cpp @@ -325,7 +325,7 @@ class TreeServer : public classbase userrec* a = (userrec*)*n; log(DEBUG,"Kill %s fd=%d",a->nick,a->fd); if (!IS_LOCAL(a)) - userrec::QuitUser(a,reason_s); + userrec::QuitUser(ServerInstance,a,reason_s); } return time_to_die.size(); } @@ -945,7 +945,7 @@ class TreeSocket : public InspSocket else { /* FMODE from a server, create a fake user to receive mode feedback */ - who = new userrec(); + who = new userrec(ServerInstance); who->fd = FD_MAGIC_NUMBER; smode = true; /* Setting this flag tells us we should free the userrec later */ sourceserv = source; /* Set sourceserv to the actual source string */ @@ -1424,7 +1424,7 @@ class TreeSocket : public InspSocket who = Srv->FindNick(usr); if (who) { - chanrec::JoinUser(who, channel.c_str(), true, key); + chanrec::JoinUser(this->Instance, who, channel.c_str(), true, key); if (modectr >= (MAXMODES-1)) { /* theres a mode for this user. push them onto the mode queue, and flush it @@ -1554,7 +1554,7 @@ class TreeSocket : public InspSocket return true; } - userrec* _new = new userrec(); + userrec* _new = new userrec(this->Instance); this->Instance->clientlist[tempnick] = _new; _new->fd = FD_MAGIC_NUMBER; strlcpy(_new->nick, tempnick,NICKMAX-1); @@ -2005,7 +2005,7 @@ class TreeSocket : public InspSocket //DoOneToMany(u->nick,"NICK",par); if (!u->ForceNickChange(params[1].c_str())) { - userrec::QuitUser(u, "Nickname collision"); + userrec::QuitUser(this->Instance, u, "Nickname collision"); return true; } u->age = atoi(params[2].c_str()); @@ -2023,7 +2023,7 @@ class TreeSocket : public InspSocket if (u) { - chanrec::JoinUser(u, params[1].c_str(), false); + chanrec::JoinUser(this->Instance, u, params[1].c_str(), false); DoOneToAllButSender(prefix,"SVSJOIN",params,prefix); } return true; @@ -2071,7 +2071,7 @@ class TreeSocket : public InspSocket params[1] = ":" + params[1]; DoOneToAllButSender(prefix,"KILL",params,sourceserv); who->Write(":%s KILL %s :%s (%s)", sourceserv.c_str(), who->nick, sourceserv.c_str(), reason.c_str()); - userrec::QuitUser(who,reason); + userrec::QuitUser(this->Instance,who,reason); } return true; } @@ -2958,11 +2958,11 @@ class TreeSocket : public InspSocket p.push_back(prefix); p.push_back("Nickname collision"); DoOneToMany(Srv->GetServerName(),"KILL",p); - userrec::QuitUser(x,"Nickname collision ("+prefix+" -> "+params[0]+")"); + userrec::QuitUser(this->Instance,x,"Nickname collision ("+prefix+" -> "+params[0]+")"); userrec* y = Srv->FindNick(prefix); if (y) { - userrec::QuitUser(y,"Nickname collision"); + userrec::QuitUser(this->Instance,y,"Nickname collision"); } return DoOneToAllButSenderRaw(line,sourceserv,prefix,command,params); } diff --git a/src/modules/m_timedbans.cpp b/src/modules/m_timedbans.cpp index fad2409dc..426859390 100644 --- a/src/modules/m_timedbans.cpp +++ b/src/modules/m_timedbans.cpp @@ -28,7 +28,8 @@ using namespace std; #include "inspircd.h" static Server *Srv; - +extern InspIRCd* ServerInstance; + class TimedBan : public classbase { public: @@ -172,7 +173,7 @@ class ModuleTimedBans : public Module // back to, so we create it a fake user that isnt in the user // hash and set its descriptor to FD_MAGIC_NUMBER so the data // falls into the abyss :p - userrec* temp = new userrec; + userrec* temp = new userrec(ServerInstance); temp->fd = FD_MAGIC_NUMBER; temp->server = ""; Srv->SendMode(setban,3,temp); diff --git a/src/userprocess.cpp b/src/userprocess.cpp index 8b9235436..42c3bd3db 100644 --- a/src/userprocess.cpp +++ b/src/userprocess.cpp @@ -147,7 +147,7 @@ void InspIRCd::ProcessUser(userrec* cu) { log(DEFAULT,"Excess flood from: %s!%s@%s",current->nick,current->ident,current->host); WriteOpers("*** Excess flood from: %s!%s@%s",current->nick,current->ident,current->host); - userrec::QuitUser(current,"Excess flood"); + userrec::QuitUser(this, current,"Excess flood"); return; } else @@ -171,7 +171,7 @@ void InspIRCd::ProcessUser(userrec* cu) { if (current->registered == REG_ALL) { - userrec::QuitUser(current,"RecvQ exceeded"); + userrec::QuitUser(this, current,"RecvQ exceeded"); } else { @@ -197,7 +197,7 @@ void InspIRCd::ProcessUser(userrec* cu) { log(DEFAULT,"Excess flood from: %s!%s@%s",current->nick,current->ident,current->host); WriteOpers("*** Excess flood from: %s!%s@%s",current->nick,current->ident,current->host); - userrec::QuitUser(current,"Excess flood"); + userrec::QuitUser(this, current,"Excess flood"); return; } @@ -207,7 +207,7 @@ void InspIRCd::ProcessUser(userrec* cu) { log(DEFAULT,"Excess flood from: %s!%s@%s",current->nick,current->ident,current->host); WriteOpers("*** Excess flood from: %s!%s@%s",current->nick,current->ident,current->host); - userrec::QuitUser(current,"Excess flood"); + userrec::QuitUser(this, current,"Excess flood"); } else { @@ -252,7 +252,7 @@ void InspIRCd::ProcessUser(userrec* cu) if ((result == -1) && (errno != EAGAIN) && (errno != EINTR)) { log(DEBUG,"killing: %s",cu->nick); - userrec::QuitUser(cu,strerror(errno)); + userrec::QuitUser(this,cu,strerror(errno)); return; } } @@ -265,7 +265,7 @@ void InspIRCd::ProcessUser(userrec* cu) else if (result == 0) { log(DEBUG,"InspIRCd: Exited: %s",cu->nick); - userrec::QuitUser(cu,"Client exited"); + userrec::QuitUser(this,cu,"Client exited"); log(DEBUG,"Bailing from client exit"); return; } diff --git a/src/users.cpp b/src/users.cpp index 40c29ded1..e35c5cab8 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -32,10 +32,8 @@ #include "xline.h" #include "cull_list.h" -extern InspIRCd* ServerInstance; extern std::vector<Module*> modules; extern std::vector<ircd_module*> factory; -extern std::vector<InspSocket*> module_sockets; extern int MODCOUNT; extern time_t TIME; extern Server* MyServer; @@ -134,7 +132,7 @@ void userrec::StartDNSLookup() log(DEBUG,"Commencing reverse lookup"); try { - res_reverse = new UserResolver(this, this->GetIPString(), false); + res_reverse = new UserResolver(ServerInstance, this, this->GetIPString(), false); MyServer->AddResolver(res_reverse); } catch (ModuleException& e) @@ -143,7 +141,8 @@ void userrec::StartDNSLookup() } } -UserResolver::UserResolver(userrec* user, std::string to_resolve, bool forward) : Resolver(to_resolve, forward ? DNS_QUERY_FORWARD : DNS_QUERY_REVERSE), bound_user(user) +UserResolver::UserResolver(InspIRCd* Instance, userrec* user, std::string to_resolve, bool forward) : + Resolver(to_resolve, forward ? DNS_QUERY_FORWARD : DNS_QUERY_REVERSE), bound_user(user), ServerInstance(Instance) { this->fwd = forward; this->bound_fd = user->fd; @@ -157,7 +156,7 @@ void UserResolver::OnLookupComplete(const std::string &result) this->bound_user->stored_host = result; try { - bound_user->res_forward = new UserResolver(this->bound_user, result, true); + bound_user->res_forward = new UserResolver(this->ServerInstance, this->bound_user, result, true); MyServer->AddResolver(bound_user->res_forward); } catch (ModuleException& e) @@ -255,11 +254,11 @@ const char* userrec::FormatModes() return data; } -userrec::userrec() +userrec::userrec(InspIRCd* Instance) : ServerInstance(Instance) { // the PROPER way to do it, AVOID bzero at *ALL* costs *password = *nick = *ident = *host = *dhost = *fullname = *awaymsg = *oper = 0; - server = (char*)ServerInstance->FindServerNamePtr(ServerInstance->Config->ServerName); + server = (char*)Instance->FindServerNamePtr(Instance->Config->ServerName); reset_due = TIME; lines_in = fd = lastping = signon = idle_lastmsg = nping = registered = 0; timeout = flood = bytes_in = bytes_out = cmds_in = cmds_out = 0; @@ -639,9 +638,9 @@ void userrec::UnOper() } } -void userrec::QuitUser(userrec *user,const std::string &quitreason) +void userrec::QuitUser(InspIRCd* Instance, userrec *user,const std::string &quitreason) { - user_hash::iterator iter = ServerInstance->clientlist.find(user->nick); + user_hash::iterator iter = Instance->clientlist.find(user->nick); /* * I'm pretty sure returning here is causing a desync when part of the net thinks a user is gone, @@ -664,22 +663,22 @@ void userrec::QuitUser(userrec *user,const std::string &quitreason) if (user->registered == REG_ALL) { purge_empty_chans(user); - FOREACH_MOD(I_OnUserQuit,OnUserQuit(user,reason)); + FOREACH_MOD_I(Instance,I_OnUserQuit,OnUserQuit(user,reason)); user->WriteCommonExcept("QUIT :%s",reason.c_str()); } if (IS_LOCAL(user)) user->FlushWriteBuf(); - FOREACH_MOD(I_OnUserDisconnect,OnUserDisconnect(user)); + FOREACH_MOD_I(Instance,I_OnUserDisconnect,OnUserDisconnect(user)); if (IS_LOCAL(user)) { - if (ServerInstance->Config->GetIOHook(user->GetPort())) + if (Instance->Config->GetIOHook(user->GetPort())) { try { - ServerInstance->Config->GetIOHook(user->GetPort())->OnRawSocketClose(user->fd); + Instance->Config->GetIOHook(user->GetPort())->OnRawSocketClose(user->fd); } catch (ModuleException& modexcept) { @@ -687,7 +686,7 @@ void userrec::QuitUser(userrec *user,const std::string &quitreason) } } - ServerInstance->SE->DelFd(user->fd); + Instance->SE->DelFd(user->fd); user->CloseSocket(); } @@ -706,16 +705,16 @@ void userrec::QuitUser(userrec *user,const std::string &quitreason) user->AddToWhoWas(); } - if (iter != ServerInstance->clientlist.end()) + if (iter != Instance->clientlist.end()) { log(DEBUG,"deleting user hash value %lx",(unsigned long)user); if (IS_LOCAL(user)) { - ServerInstance->fd_ref_table[user->fd] = NULL; - if (find(ServerInstance->local_users.begin(),ServerInstance->local_users.end(),user) != ServerInstance->local_users.end()) - ServerInstance->local_users.erase(find(ServerInstance->local_users.begin(),ServerInstance->local_users.end(),user)); + Instance->fd_ref_table[user->fd] = NULL; + if (find(Instance->local_users.begin(),Instance->local_users.end(),user) != Instance->local_users.end()) + Instance->local_users.erase(find(Instance->local_users.begin(),Instance->local_users.end(),user)); } - ServerInstance->clientlist.erase(iter); + Instance->clientlist.erase(iter); DELETE(user); } } @@ -795,10 +794,10 @@ void userrec::AddToWhoWas() } /* add a client connection to the sockets list */ -void userrec::AddClient(int socket, int port, bool iscached, insp_inaddr ip) +void userrec::AddClient(InspIRCd* Instance, int socket, int port, bool iscached, insp_inaddr ip) { std::string tempnick = ConvToStr(socket) + "-unknown"; - user_hash::iterator iter = ServerInstance->clientlist.find(tempnick); + user_hash::iterator iter = Instance->clientlist.find(tempnick); const char *ipaddr = insp_ntoa(ip); userrec* _new; int j = 0; @@ -812,26 +811,26 @@ void userrec::AddClient(int socket, int port, bool iscached, insp_inaddr ip) * this was probably the cause of 'server ignores me when i hammer it with reconnects' * issue in earlier alphas/betas */ - if (iter != ServerInstance->clientlist.end()) + if (iter != Instance->clientlist.end()) { userrec* goner = iter->second; DELETE(goner); - ServerInstance->clientlist.erase(iter); + Instance->clientlist.erase(iter); } log(DEBUG,"AddClient: %d %d %s",socket,port,ipaddr); - _new = new userrec(); - ServerInstance->clientlist[tempnick] = _new; + _new = new userrec(Instance); + Instance->clientlist[tempnick] = _new; _new->fd = socket; strlcpy(_new->nick,tempnick.c_str(),NICKMAX-1); - _new->server = ServerInstance->FindServerNamePtr(ServerInstance->Config->ServerName); + _new->server = Instance->FindServerNamePtr(Instance->Config->ServerName); /* We don't need range checking here, we KNOW 'unknown\0' will fit into the ident field. */ strcpy(_new->ident, "unknown"); _new->registered = REG_NONE; - _new->signon = TIME + ServerInstance->Config->dns_timeout; + _new->signon = TIME + Instance->Config->dns_timeout; _new->lastping = 1; log(DEBUG,"Setting socket addresses"); @@ -850,7 +849,7 @@ void userrec::AddClient(int socket, int port, bool iscached, insp_inaddr ip) long class_sqmax = 262144; // 256kb long class_rqmax = 4096; // 4k - for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++) + for (ClassVector::iterator i = Instance->Config->Classes.begin(); i != Instance->Config->Classes.end(); i++) { if ((i->type == CC_ALLOW) && (match(ipaddr,i->host.c_str(),true))) { @@ -864,25 +863,25 @@ void userrec::AddClient(int socket, int port, bool iscached, insp_inaddr ip) } } - _new->nping = TIME + _new->pingmax + ServerInstance->Config->dns_timeout; + _new->nping = TIME + _new->pingmax + Instance->Config->dns_timeout; _new->timeout = TIME+class_regtimeout; _new->flood = class_flood; _new->threshold = class_threshold; _new->sendqmax = class_sqmax; _new->recvqmax = class_rqmax; - ServerInstance->fd_ref_table[socket] = _new; - ServerInstance->local_users.push_back(_new); + Instance->fd_ref_table[socket] = _new; + Instance->local_users.push_back(_new); - if (ServerInstance->local_users.size() > ServerInstance->Config->SoftLimit) + if (Instance->local_users.size() > Instance->Config->SoftLimit) { - userrec::QuitUser(_new,"No more connections allowed"); + userrec::QuitUser(Instance, _new,"No more connections allowed"); return; } - if (ServerInstance->local_users.size() >= MAXCLIENTS) + if (Instance->local_users.size() >= MAXCLIENTS) { - userrec::QuitUser(_new,"No more connections allowed"); + userrec::QuitUser(Instance, _new,"No more connections allowed"); return; } @@ -898,7 +897,7 @@ void userrec::AddClient(int socket, int port, bool iscached, insp_inaddr ip) */ if ((unsigned)socket >= MAX_DESCRIPTORS) { - userrec::QuitUser(_new,"Server is full"); + userrec::QuitUser(Instance, _new,"Server is full"); return; } char* e = matches_exception(ipaddr); @@ -909,16 +908,16 @@ void userrec::AddClient(int socket, int port, bool iscached, insp_inaddr ip) { char reason[MAXBUF]; snprintf(reason,MAXBUF,"Z-Lined: %s",r); - userrec::QuitUser(_new,reason); + userrec::QuitUser(Instance, _new,reason); return; } } if (socket > -1) { - if (!ServerInstance->SE->AddFd(socket,true,X_ESTAB_CLIENT)) + if (!Instance->SE->AddFd(socket,true,X_ESTAB_CLIENT)) { - userrec::QuitUser(_new, "Internal error handling connection"); + userrec::QuitUser(Instance, _new, "Internal error handling connection"); return; } } |