1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/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->clientlist->begin(); i != ServerInstance->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)
59 return MODEACTION_DENY;
61 if (dest->IsModeSet('Q') != adding)
65 for (int j = 0; j < conf->Enumerate("type"); j++)
67 std::string opertype = conf->ReadValue("type","name",j);
68 if (opertype == source->oper)
70 ok = conf->ReadFlag("type", "canquiet", j);
77 source->WriteServ("481 %s :Permission Denied - You do not have access to become invisible via user mode +Q", source->nick);
78 return MODEACTION_DENY;
81 dest->SetMode('Q', adding);
83 /* Fix for bug #379 reported by stealth. On +/-Q make m_watch think the user has signed on/off */
84 Module* m = ServerInstance->Modules->Find("m_watch.so");
86 /* This must come before setting/unsetting the handler */
88 m->OnUserQuit(dest, "Connection closed", "Connection closed");
90 /* Set visibility handler object */
91 dest->Visibility = adding ? qo : NULL;
93 /* This has to come after setting/unsetting the handler */
95 m->OnPostConnect(dest);
97 /* User appears to vanish or appear from nowhere */
98 for (UCListIter f = dest->chans.begin(); f != dest->chans.end(); f++)
100 CUList *ulist = f->first->GetUsers();
103 snprintf(tb,MAXBUF,":%s %s %s", dest->GetFullHost(), adding ? "PART" : "JOIN", f->first->name);
104 std::string out = tb;
105 std::string n = this->ServerInstance->Modes->ModeString(dest, f->first);
107 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
109 /* User only appears to vanish for non-opers */
110 if (IS_LOCAL(i->first) && !IS_OPER(i->first))
112 i->first->Write(out);
113 if (!n.empty() && !adding)
114 i->first->WriteServ("MODE %s +%s", f->first->name, n.c_str());
118 ServerInstance->WriteOpers("*** \2NOTICE\2: Oper %s has become %svisible (%sQ)", dest->GetFullHost(), adding ? "in" : "", adding ? "+" : "-");
120 return MODEACTION_ALLOW;
124 return MODEACTION_DENY;
129 class InvisibleDeOper : public ModeWatcher
134 InvisibleDeOper(InspIRCd* Instance) : ModeWatcher(Instance, 'o', MODETYPE_USER), Srv(Instance)
138 bool BeforeMode(User* source, User* dest, Channel* channel, std::string ¶m, bool adding, ModeType type)
140 /* Users who are opers and have +Q get their +Q removed when they deoper */
141 if ((!adding) && (dest->IsModeSet('Q')))
143 const char* newmodes[] = { dest->nick, "-Q" };
144 ServerInstance->Modes->Process(newmodes, 2, source, true);
151 class ModuleInvisible : public Module
155 InvisibleDeOper* ido;
157 ModuleInvisible(InspIRCd* Me)
160 conf = new ConfigReader(ServerInstance);
161 qm = new InvisibleMode(ServerInstance);
162 if (!ServerInstance->AddMode(qm))
163 throw ModuleException("Could not add new modes!");
164 ido = new InvisibleDeOper(ServerInstance);
165 if (!ServerInstance->AddModeWatcher(ido))
166 throw ModuleException("Could not add new mode watcher on usermode +o!");
168 /* Yeah i know people can take this out. I'm not about to obfuscate code just to be a pain in the ass. */
169 ServerInstance->ServerNoticeAll("*** m_invisible.so has just been loaded on this network. For more information, please visit http://inspircd.org/wiki/Modules/invisible");
170 Implementation eventlist[] = { I_OnUserPreMessage, I_OnUserPreNotice, I_OnUserJoin, I_OnUserPart, I_OnUserQuit, I_OnRehash };
171 ServerInstance->Modules->Attach(eventlist, this, 6);
174 virtual ~ModuleInvisible()
176 ServerInstance->Modes->DelMode(qm);
177 ServerInstance->Modes->DelModeWatcher(ido);
183 virtual Version GetVersion()
185 return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
189 virtual void OnUserJoin(User* user, Channel* channel, bool &silent)
191 if (user->IsModeSet('Q'))
194 /* Because we silenced the event, make sure it reaches the user whos joining (but only them of course) */
195 this->WriteCommonFrom(user, channel, "JOIN %s", channel->name);
196 ServerInstance->WriteOpers("*** \2NOTICE\2: Oper %s has joined %s invisibly (+Q)", user->GetFullHost(), channel->name);
200 virtual void OnRehash(User* user, const std::string ¶meter)
203 conf = new ConfigReader(ServerInstance);
206 void OnUserPart(User* user, Channel* channel, const std::string &partmessage, bool &silent)
208 if (user->IsModeSet('Q'))
211 /* Because we silenced the event, make sure it reaches the user whos leaving (but only them of course) */
212 this->WriteCommonFrom(user, channel, "PART %s%s%s", channel->name,
213 partmessage.empty() ? "" : " :",
214 partmessage.empty() ? "" : partmessage.c_str());
218 void OnUserQuit(User* user, const std::string &reason, const std::string &oper_message)
220 if (user->IsModeSet('Q'))
222 Command* parthandler = ServerInstance->Parser->GetHandler("PART");
223 std::vector<std::string> to_leave;
224 const char* parameters[2];
227 for (UCListIter f = user->chans.begin(); f != user->chans.end(); f++)
228 to_leave.push_back(f->first->name);
229 /* We cant do this neatly in one loop, as we are modifying the map we are iterating */
230 for (std::vector<std::string>::iterator n = to_leave.begin(); n != to_leave.end(); n++)
232 parameters[0] = n->c_str();
233 /* This triggers our OnUserPart, above, making the PART silent */
234 parthandler->Handle(parameters, 1, user);
240 /* No privmsg response when hiding - submitted by Eric at neowin */
241 virtual int OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
243 if ((target_type == TYPE_USER) && (IS_LOCAL(user)))
245 User* target = (User*)dest;
246 if(target->IsModeSet('Q') && !*user->oper)
248 user->WriteServ("401 %s %s :No such nick/channel",user->nick, target->nick);
255 virtual int OnUserPreMessage(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
257 return OnUserPreNotice(user, dest, target_type, text, status, exempt_list);
260 /* Fix by Eric @ neowin.net, thanks :) -- Brain */
261 void WriteCommonFrom(User *user, Channel* channel, const char* text, ...)
264 char textbuffer[MAXBUF];
267 va_start(argsPtr, text);
268 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
270 snprintf(tb,MAXBUF,":%s %s",user->GetFullHost(),textbuffer);
272 CUList *ulist = channel->GetUsers();
274 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
276 /* User only appears to vanish for non-opers */
277 if (IS_LOCAL(i->first) && IS_OPER(i->first))
279 i->first->Write(std::string(tb));
286 MODULE_INIT(ModuleInvisible)