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 * ---------------------------------------------------
20 /* $ModDesc: Allows for opered clients to join channels without being seen, similar to unreal 3.1 +I mode */
22 static ConfigReader* conf;
24 class QuietOper : public VisData
35 virtual bool VisibleTo(userrec* user)
42 class InvisibleMode : public ModeHandler
46 InvisibleMode(InspIRCd* Instance) : ModeHandler(Instance, 'Q', 0, 0, false, MODETYPE_USER, true)
53 for (user_hash::iterator i = ServerInstance->clientlist->begin(); i != ServerInstance->clientlist->end(); i++)
54 if (i->second->Visibility == qo)
55 i->second->Visibility = NULL;
59 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
62 return MODEACTION_DENY;
64 if (dest->IsModeSet('Q') != adding)
68 for (int j = 0; j < conf->Enumerate("type"); j++)
70 std::string opertype = conf->ReadValue("type","name",j);
71 if (opertype == source->oper)
73 ok = conf->ReadFlag("type", "canquiet", j);
80 source->WriteServ("481 %s :Permission Denied - You do not have access to become invisible via user mode +Q", source->nick);
81 return MODEACTION_DENY;
84 dest->SetMode('Q', adding);
86 /* Set visibility handler object */
87 dest->Visibility = adding ? qo : NULL;
89 /* User appears to vanish or appear from nowhere */
90 for (UCListIter f = dest->chans.begin(); f != dest->chans.end(); f++)
92 CUList *ulist = f->first->GetUsers();
95 snprintf(tb,MAXBUF,":%s %s %s", dest->GetFullHost(), adding ? "PART" : "JOIN", f->first->name);
97 std::string n = this->ServerInstance->Modes->ModeString(dest, f->first);
99 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
101 /* User only appears to vanish for non-opers */
102 if (IS_LOCAL(i->first) && !IS_OPER(i->first))
104 i->first->Write(out);
105 if (!n.empty() && !adding)
106 i->first->WriteServ("MODE %s +%s", f->first->name, n.c_str());
110 ServerInstance->WriteOpers("*** \2NOTICE\2: Oper %s has become %svisible (%sQ)", dest->GetFullHost(), adding ? "in" : "", adding ? "+" : "-");
112 return MODEACTION_ALLOW;
116 return MODEACTION_DENY;
121 class InvisibleDeOper : public ModeWatcher
126 InvisibleDeOper(InspIRCd* Instance) : ModeWatcher(Instance, 'o', MODETYPE_USER), Srv(Instance)
130 bool BeforeMode(userrec* source, userrec* dest, chanrec* channel, std::string ¶m, bool adding, ModeType type)
132 /* Users who are opers and have +Q get their +Q removed when they deoper */
133 if ((!adding) && (dest->IsModeSet('Q')))
135 const char* newmodes[] = { dest->nick, "-Q" };
136 ServerInstance->Modes->Process(newmodes, 2, source, true);
143 class ModuleInvisible : public Module
147 InvisibleDeOper* ido;
149 ModuleInvisible(InspIRCd* Me)
152 conf = new ConfigReader(ServerInstance);
153 qm = new InvisibleMode(ServerInstance);
154 if (!ServerInstance->AddMode(qm, 'Q'))
155 throw ModuleException("Could not add new modes!");
156 ido = new InvisibleDeOper(ServerInstance);
157 if (!ServerInstance->AddModeWatcher(ido))
158 throw ModuleException("Could not add new mode watcher on usermode +o!");
161 virtual ~ModuleInvisible()
163 ServerInstance->Modes->DelMode(qm);
164 ServerInstance->Modes->DelModeWatcher(ido);
170 virtual Version GetVersion()
172 return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
175 void Implements(char* List)
177 List[I_OnUserPreMessage] = List[I_OnUserPreNotice] = List[I_OnUserJoin] = List[I_OnUserPart] = List[I_OnUserQuit] = List[I_OnRehash] = 1;
180 virtual void OnUserJoin(userrec* user, chanrec* channel, bool &silent)
182 if (user->IsModeSet('Q'))
185 /* Because we silenced the event, make sure it reaches the user whos joining (but only them of course) */
186 this->WriteCommonFrom(user, channel, "JOIN %s", channel->name);
187 ServerInstance->WriteOpers("*** \2NOTICE\2: Oper %s has joined %s invisibly (+Q)", user->GetFullHost(), channel->name);
191 virtual void OnRehash(userrec* user, const std::string ¶meter)
194 conf = new ConfigReader(ServerInstance);
197 void OnUserPart(userrec* user, chanrec* channel, const std::string &partmessage, bool &silent)
199 if (user->IsModeSet('Q'))
202 /* Because we silenced the event, make sure it reaches the user whos leaving (but only them of course) */
203 this->WriteCommonFrom(user, channel, "PART %s%s%s", channel->name,
204 partmessage.empty() ? "" : " :",
205 partmessage.empty() ? "" : partmessage.c_str());
209 void OnUserQuit(userrec* user, const std::string &reason, const std::string &oper_message)
211 if (user->IsModeSet('Q'))
213 command_t* parthandler = ServerInstance->Parser->GetHandler("PART");
214 std::vector<std::string> to_leave;
215 const char* parameters[2];
218 for (UCListIter f = user->chans.begin(); f != user->chans.end(); f++)
219 to_leave.push_back(f->first->name);
220 /* We cant do this neatly in one loop, as we are modifying the map we are iterating */
221 for (std::vector<std::string>::iterator n = to_leave.begin(); n != to_leave.end(); n++)
223 parameters[0] = n->c_str();
224 /* This triggers our OnUserPart, above, making the PART silent */
225 parthandler->Handle(parameters, 1, user);
231 /* No privmsg response when hiding - submitted by Eric at neowin */
232 virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
234 if ((target_type == TYPE_USER) && (IS_LOCAL(user)))
236 userrec* target = (userrec*)dest;
237 if(target->IsModeSet('Q') && !*user->oper)
239 user->WriteServ("401 %s %s :No such nick/channel",user->nick, target->nick);
246 virtual int OnUserPreMessage(userrec* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
248 return OnUserPreNotice(user, dest, target_type, text, status, exempt_list);
251 /* Fix by Eric @ neowin.net, thanks :) -- Brain */
252 void WriteCommonFrom(userrec *user, chanrec* channel, const char* text, ...)
255 char textbuffer[MAXBUF];
258 va_start(argsPtr, text);
259 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
261 snprintf(tb,MAXBUF,":%s %s",user->GetFullHost(),textbuffer);
263 CUList *ulist = channel->GetUsers();
265 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
267 /* User only appears to vanish for non-opers */
268 if (IS_LOCAL(i->first) && IS_OPER(i->first))
270 i->first->Write(std::string(tb));
277 class ModuleInvisibleFactory : public ModuleFactory
280 ModuleInvisibleFactory()
284 ~ModuleInvisibleFactory()
288 virtual Module * CreateModule(InspIRCd* Me)
290 return new ModuleInvisible(Me);
295 extern "C" DllExport void * init_module( void )
297 return new ModuleInvisibleFactory;