1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
17 /* $ModDesc: Allows for opered clients to join channels without being seen, similar to unreal 3.1 +I mode */
19 class InvisibleMode : public ModeHandler
22 InvisibleMode(Module* Creator) : ModeHandler(Creator, "invis-oper", 'Q', PARAM_NONE, MODETYPE_USER)
31 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
33 if (dest->IsModeSet('Q') != adding)
35 dest->SetMode('Q', adding);
37 /* Fix for bug #379 reported by stealth. On +/-Q make m_watch think the user has signed on/off */
38 Module* m = ServerInstance->Modules->Find("m_watch.so");
40 /* This must come before setting/unsetting the handler */
42 m->OnUserQuit(dest, "Connection closed", "Connection closed");
44 /* User appears to vanish or appear from nowhere */
45 for (UCListIter f = dest->chans.begin(); f != dest->chans.end(); f++)
47 const UserMembList *ulist = (*f)->GetUsers();
50 snprintf(tb,MAXBUF,":%s %s %s", dest->GetFullHost().c_str(), adding ? "PART" : "JOIN", (*f)->name.c_str());
52 Membership* memb = (**f).GetUser(dest);
53 std::string ms = memb->modes;
54 for(unsigned int i=0; i < memb->modes.length(); i++)
55 ms.append(" ").append(dest->nick);
58 for (UserMembCIter i = ulist->begin(); i != ulist->end(); i++)
60 /* User only appears to vanish for non-opers */
61 if (IS_LOCAL(i->first) && !IS_OPER(i->first))
64 if (!ms.empty() && !adding)
65 i->first->WriteServ("MODE %s +%s", (**f).name.c_str(), ms.c_str());
70 ServerInstance->SNO->WriteToSnoMask('a', "\2NOTICE\2: Oper %s has become %svisible (%cQ)", dest->GetFullHost().c_str(), adding ? "in" : "", adding ? '+' : '-');
71 return MODEACTION_ALLOW;
75 return MODEACTION_DENY;
80 class InvisibleDeOper : public ModeWatcher
83 InvisibleDeOper(Module* parent) : ModeWatcher(parent, 'o', MODETYPE_USER)
87 bool BeforeMode(User* source, User* dest, Channel* channel, std::string ¶m, bool adding, ModeType type)
89 /* Users who are opers and have +Q get their +Q removed when they deoper */
90 if ((!adding) && (dest->IsModeSet('Q')))
92 std::vector<std::string> newmodes;
93 newmodes.push_back(dest->nick);
94 newmodes.push_back("-Q");
95 ServerInstance->Modes->Process(newmodes, source);
102 class ModuleInvisible : public Module
108 ModuleInvisible() : qm(this), ido(this)
110 if (!ServerInstance->Modes->AddMode(&qm))
111 throw ModuleException("Could not add new modes!");
112 if (!ServerInstance->Modes->AddModeWatcher(&ido))
113 throw ModuleException("Could not add new mode watcher on usermode +o!");
115 /* Yeah i know people can take this out. I'm not about to obfuscate code just to be a pain in the ass. */
116 ServerInstance->Users->ServerNoticeAll("*** m_invisible.so has just been loaded on this network. For more information, please visit http://inspircd.org/wiki/Modules/invisible");
117 Implementation eventlist[] = {
118 I_OnUserPreMessage, I_OnUserPreNotice, I_OnUserJoin,
119 I_OnBuildNeighborList, I_OnSendWhoLine, I_OnNamesListItem
121 ServerInstance->Modules->Attach(eventlist, this, 6);
126 /* XXX is this the best place to do this? */
127 if (!ServerInstance->Modes->DelModeWatcher(&ido))
128 ServerInstance->Logs->Log("m_banredirect.so", DEBUG, "Failed to delete modewatcher!");
131 Version GetVersion();
132 void OnUserJoin(Membership* memb, bool sync, bool created, CUList& excepts);
133 void OnBuildNeighborList(User* source, UserChanList &include, std::map<User*,bool> &exceptions);
134 ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list);
135 ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list);
136 void OnSendWhoLine(User* source, User* user, Channel* channel, std::string& line);
137 void OnNamesListItem(User* issuer, Membership* memb, std::string &prefixes, std::string &nick);
140 Version ModuleInvisible::GetVersion()
142 return Version("Allows opers to join channels invisibly", VF_VENDOR);
145 static void BuildExcept(Membership* memb, CUList& excepts)
147 const UserMembList* users = memb->chan->GetUsers();
148 for(UserMembCIter i = users->begin(); i != users->end(); i++)
150 // hide from all local non-opers
151 if (IS_LOCAL(i->first) && !IS_OPER(i->first))
152 excepts.insert(i->first);
156 void ModuleInvisible::OnUserJoin(Membership* memb, bool sync, bool created, CUList& excepts)
158 if (memb->user->IsModeSet('Q'))
160 BuildExcept(memb, excepts);
161 ServerInstance->SNO->WriteToSnoMask('a', "\2NOTICE\2: Oper %s has joined %s invisibly (+Q)",
162 memb->user->GetFullHost().c_str(), memb->chan->name.c_str());
166 void ModuleInvisible::OnBuildNeighborList(User* source, UserChanList &include, std::map<User*,bool> &exceptions)
168 if (source->IsModeSet('Q'))
174 /* No privmsg response when hiding - submitted by Eric at neowin */
175 ModResult ModuleInvisible::OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
177 if ((target_type == TYPE_USER) && (IS_LOCAL(user)))
179 User* target = (User*)dest;
180 if(target->IsModeSet('Q') && !IS_OPER(user))
182 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), target->nick.c_str());
186 return MOD_RES_PASSTHRU;
189 ModResult ModuleInvisible::OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
191 return OnUserPreNotice(user, dest, target_type, text, status, exempt_list);
194 void ModuleInvisible::OnSendWhoLine(User* source, User* user, Channel* channel, std::string& line)
196 if (user->IsModeSet('Q') && !IS_OPER(source))
200 void ModuleInvisible::OnNamesListItem(User* issuer, Membership* memb, std::string &prefixes, std::string &nick)
202 if (memb->user->IsModeSet('Q') && !IS_OPER(issuer))
206 MODULE_INIT(ModuleInvisible)