1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 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 static ConfigReader* conf;
21 class QuietOper : public VisData
32 virtual bool VisibleTo(User* user)
39 class InvisibleMode : public ModeHandler
43 InvisibleMode(InspIRCd* Instance) : ModeHandler(Instance, 'Q', 0, 0, false, MODETYPE_USER, true)
50 for (user_hash::iterator i = ServerInstance->Users->clientlist->begin(); i != ServerInstance->Users->clientlist->end(); i++)
51 if (i->second->Visibility == qo)
52 i->second->Visibility = NULL;
56 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
58 if (dest->IsModeSet('Q') != adding)
60 dest->SetMode('Q', adding);
62 /* Fix for bug #379 reported by stealth. On +/-Q make m_watch think the user has signed on/off */
63 Module* m = ServerInstance->Modules->Find("m_watch.so");
65 /* This must come before setting/unsetting the handler */
67 m->OnUserQuit(dest, "Connection closed", "Connection closed");
69 /* Set visibility handler object */
70 dest->Visibility = adding ? qo : NULL;
72 /* This has to come after setting/unsetting the handler */
74 m->OnPostConnect(dest);
76 /* User appears to vanish or appear from nowhere */
77 for (UCListIter f = dest->chans.begin(); f != dest->chans.end(); f++)
79 CUList *ulist = f->first->GetUsers();
82 snprintf(tb,MAXBUF,":%s %s %s", dest->GetFullHost().c_str(), adding ? "PART" : "JOIN", f->first->name.c_str());
84 std::string n = this->ServerInstance->Modes->ModeString(dest, f->first);
86 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
88 /* User only appears to vanish for non-opers */
89 if (IS_LOCAL(i->first) && !IS_OPER(i->first))
92 if (!n.empty() && !adding)
93 i->first->WriteServ("MODE %s +%s", f->first->name.c_str(), n.c_str());
98 ServerInstance->SNO->WriteToSnoMask('a', "\2NOTICE\2: Oper %s has become %svisible (%cQ)", dest->GetFullHost().c_str(), adding ? "in" : "", adding ? '+' : '-');
99 return MODEACTION_ALLOW;
103 return MODEACTION_DENY;
108 class InvisibleDeOper : public ModeWatcher
111 InvisibleDeOper(InspIRCd* Instance) : ModeWatcher(Instance, 'o', MODETYPE_USER)
115 bool BeforeMode(User* source, User* dest, Channel* channel, std::string ¶m, bool adding, ModeType type, bool)
117 /* Users who are opers and have +Q get their +Q removed when they deoper */
118 if ((!adding) && (dest->IsModeSet('Q')))
120 std::vector<std::string> newmodes;
121 newmodes.push_back(dest->nick);
122 newmodes.push_back("-Q");
123 ServerInstance->Modes->Process(newmodes, source, true);
130 class ModuleInvisible : public Module
136 ModuleInvisible(InspIRCd* Me)
137 : Module(Me), qm(Me), ido(Me)
139 conf = new ConfigReader(ServerInstance);
140 if (!ServerInstance->Modes->AddMode(&qm))
141 throw ModuleException("Could not add new modes!");
142 if (!ServerInstance->Modes->AddModeWatcher(&ido))
143 throw ModuleException("Could not add new mode watcher on usermode +o!");
145 /* Yeah i know people can take this out. I'm not about to obfuscate code just to be a pain in the ass. */
146 ServerInstance->Users->ServerNoticeAll("*** m_invisible.so has just been loaded on this network. For more information, please visit http://inspircd.org/wiki/Modules/invisible");
147 Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice, I_OnUserJoin, I_OnUserPart, I_OnUserQuit, I_OnRehash, I_OnHostCycle };
148 ServerInstance->Modules->Attach(eventlist, this, 7);
151 virtual ~ModuleInvisible()
153 ServerInstance->Modes->DelMode(&qm);
154 ServerInstance->Modes->DelModeWatcher(&ido);
158 virtual Version GetVersion();
159 virtual void OnUserJoin(User* user, Channel* channel, bool sync, bool &silent);
160 virtual void OnRehash(User* user);
161 void OnUserPart(User* user, Channel* channel, std::string &partmessage, bool &silent);
162 void OnUserQuit(User* user, const std::string &reason, const std::string &oper_message);
163 bool OnHostCycle(User* user);
164 /* No privmsg response when hiding - submitted by Eric at neowin */
165 virtual int OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list);
166 virtual int OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list);
167 /* Fix by Eric @ neowin.net, thanks :) -- Brain */
168 void WriteCommonFrom(User *user, Channel* channel, const char* text, ...) CUSTOM_PRINTF(4, 5);
171 Version ModuleInvisible::GetVersion()
173 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
176 void ModuleInvisible::OnUserJoin(User* user, Channel* channel, bool sync, bool &silent)
178 if (user->IsModeSet('Q'))
181 /* Because we silenced the event, make sure it reaches the user whos joining (but only them of course) */
182 this->WriteCommonFrom(user, channel, "JOIN %s", channel->name.c_str());
183 ServerInstance->SNO->WriteToSnoMask('a', "\2NOTICE\2: Oper %s has joined %s invisibly (+Q)", user->GetFullHost().c_str(), channel->name.c_str());
187 void ModuleInvisible::OnRehash(User* user)
190 conf = new ConfigReader(ServerInstance);
193 void ModuleInvisible::OnUserPart(User* user, Channel* channel, std::string &partmessage, bool &silent)
195 if (user->IsModeSet('Q'))
198 /* Because we silenced the event, make sure it reaches the user whos leaving (but only them of course) */
199 this->WriteCommonFrom(user, channel, "PART %s%s%s", channel->name.c_str(),
200 partmessage.empty() ? "" : " :",
201 partmessage.empty() ? "" : partmessage.c_str());
205 void ModuleInvisible::OnUserQuit(User* user, const std::string &reason, const std::string &oper_message)
207 if (user->IsModeSet('Q'))
209 Command* parthandler = ServerInstance->Parser->GetHandler("PART");
210 std::vector<std::string> to_leave;
213 for (UCListIter f = user->chans.begin(); f != user->chans.end(); f++)
214 to_leave.push_back(f->first->name);
215 /* We cant do this neatly in one loop, as we are modifying the map we are iterating */
216 for (std::vector<std::string>::iterator n = to_leave.begin(); n != to_leave.end(); n++)
218 std::vector<std::string> parameters;
219 parameters.push_back(*n);
220 /* This triggers our OnUserPart, above, making the PART silent */
221 parthandler->Handle(parameters, user);
227 bool ModuleInvisible::OnHostCycle(User* user)
229 return user->IsModeSet('Q');
232 /* No privmsg response when hiding - submitted by Eric at neowin */
233 int ModuleInvisible::OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
235 if ((target_type == TYPE_USER) && (IS_LOCAL(user)))
237 User* target = (User*)dest;
238 if(target->IsModeSet('Q') && !IS_OPER(user))
240 user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick.c_str(), target->nick.c_str());
247 int ModuleInvisible::OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
249 return OnUserPreNotice(user, dest, target_type, text, status, exempt_list);
252 /* Fix by Eric @ neowin.net, thanks :) -- Brain */
253 void ModuleInvisible::WriteCommonFrom(User *user, Channel* channel, const char* text, ...)
256 char textbuffer[MAXBUF];
259 va_start(argsPtr, text);
260 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
262 snprintf(tb,MAXBUF,":%s %s",user->GetFullHost().c_str(), textbuffer);
264 CUList *ulist = channel->GetUsers();
266 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
268 /* User only appears to vanish for non-opers */
269 if (IS_LOCAL(i->first) && IS_OPER(i->first))
271 i->first->Write(std::string(tb));
276 MODULE_INIT(ModuleInvisible)