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 * ---------------------------------------------------
19 /* $ModDesc: Allows for opered clients to join channels without being seen, similar to unreal 3.1 +I mode */
21 static ConfigReader* conf;
23 class QuietOper : public VisData
34 virtual bool VisibleTo(userrec* user)
41 class InvisibleMode : public ModeHandler
45 InvisibleMode(InspIRCd* Instance) : ModeHandler(Instance, 'Q', 0, 0, false, MODETYPE_USER, true)
52 for (user_hash::iterator i = ServerInstance->clientlist->begin(); i != ServerInstance->clientlist->end(); i++)
53 if (i->second->Visibility == qo)
54 i->second->Visibility = NULL;
58 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
61 return MODEACTION_DENY;
63 if (dest->IsModeSet('Q') != adding)
67 for (int j = 0; j < conf->Enumerate("type"); j++)
69 std::string opertype = conf->ReadValue("type","name",j);
70 if (opertype == source->oper)
72 ok = conf->ReadFlag("type", "canquiet", j);
79 source->WriteServ("481 %s :Permission Denied - You do not have access to become invisible via user mode +Q", source->nick);
80 return MODEACTION_DENY;
83 dest->SetMode('Q', adding);
85 /* Set visibility handler object */
86 dest->Visibility = adding ? qo : NULL;
88 /* User appears to vanish or appear from nowhere */
89 for (UCListIter f = dest->chans.begin(); f != dest->chans.end(); f++)
91 CUList *ulist = f->first->GetUsers();
94 snprintf(tb,MAXBUF,":%s %s %s", dest->GetFullHost(), adding ? "PART" : "JOIN", f->first->name);
96 std::string n = this->ServerInstance->Modes->ModeString(dest, f->first);
98 for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
100 /* User only appears to vanish for non-opers */
101 if (IS_LOCAL(i->first) && !IS_OPER(i->first))
103 i->first->Write(out);
104 if (!n.empty() && !adding)
105 i->first->WriteServ("MODE %s +%s", f->first->name, n.c_str());
109 ServerInstance->WriteOpers("*** \2NOTICE\2: Oper %s has become %svisible (%sQ)", dest->GetFullHost(), adding ? "in" : "", adding ? "+" : "-");
111 return MODEACTION_ALLOW;
115 return MODEACTION_DENY;
120 class InvisibleDeOper : public ModeWatcher
125 InvisibleDeOper(InspIRCd* Instance) : ModeWatcher(Instance, 'o', MODETYPE_USER), Srv(Instance)
129 bool BeforeMode(userrec* source, userrec* dest, chanrec* channel, std::string ¶m, bool adding, ModeType type)
131 /* Users who are opers and have +Q get their +Q removed when they deoper */
132 if ((!adding) && (dest->IsModeSet('Q')))
134 const char* newmodes[] = { dest->nick, "-Q" };
135 ServerInstance->Modes->Process(newmodes, 2, source, true);
142 class ModuleInvisible : public Module
146 InvisibleDeOper* ido;
148 ModuleInvisible(InspIRCd* Me)
151 conf = new ConfigReader(ServerInstance);
152 qm = new InvisibleMode(ServerInstance);
153 if (!ServerInstance->AddMode(qm, 'Q'))
154 throw ModuleException("Could not add new modes!");
155 ido = new InvisibleDeOper(ServerInstance);
156 if (!ServerInstance->AddModeWatcher(ido))
157 throw ModuleException("Could not add new mode watcher on usermode +o!");
160 virtual ~ModuleInvisible()
162 ServerInstance->Modes->DelMode(qm);
163 ServerInstance->Modes->DelModeWatcher(ido);
169 virtual Version GetVersion()
171 return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
174 void Implements(char* List)
176 List[I_OnUserJoin] = List[I_OnUserPart] = List[I_OnUserQuit] = List[I_OnRehash] = 1;
179 virtual void OnUserJoin(userrec* user, chanrec* channel, bool &silent)
181 if (user->IsModeSet('Q'))
184 /* Because we silenced the event, make sure it reaches the user whos joining (but only them of course) */
185 user->WriteFrom(user, "JOIN %s", channel->name);
186 ServerInstance->WriteOpers("*** \2NOTICE\2: Oper %s has joined %s invisibly (+Q)", user->GetFullHost(), channel->name);
190 virtual void OnRehash(userrec* user, const std::string ¶meter)
193 conf = new ConfigReader(ServerInstance);
196 void OnUserPart(userrec* user, chanrec* channel, const std::string &partmessage, bool &silent)
198 if (user->IsModeSet('Q'))
201 /* Because we silenced the event, make sure it reaches the user whos leaving (but only them of course) */
202 user->WriteFrom(user, "PART %s%s%s", channel->name,
203 partmessage.empty() ? "" : " :",
204 partmessage.empty() ? "" : partmessage.c_str());
208 void OnUserQuit(userrec* user, const std::string &reason, const std::string &oper_message)
210 if (user->IsModeSet('Q'))
212 command_t* parthandler = ServerInstance->Parser->GetHandler("PART");
213 std::vector<std::string> to_leave;
214 const char* parameters[2];
217 for (UCListIter f = user->chans.begin(); f != user->chans.end(); f++)
218 to_leave.push_back(f->first->name);
219 /* We cant do this neatly in one loop, as we are modifying the map we are iterating */
220 for (std::vector<std::string>::iterator n = to_leave.begin(); n != to_leave.end(); n++)
222 parameters[0] = n->c_str();
223 /* This triggers our OnUserPart, above, making the PART silent */
224 parthandler->Handle(parameters, 1, user);
231 class ModuleInvisibleFactory : public ModuleFactory
234 ModuleInvisibleFactory()
238 ~ModuleInvisibleFactory()
242 virtual Module * CreateModule(InspIRCd* Me)
244 return new ModuleInvisible(Me);
249 extern "C" void * init_module( void )
251 return new ModuleInvisibleFactory;