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 auditorium channels (+u) where nobody can see others joining and parting or the nick list */
21 class AuditoriumMode : public ModeHandler
24 AuditoriumMode(InspIRCd* Instance) : ModeHandler(Instance, 'u', 0, 0, false, MODETYPE_CHANNEL, false) { }
26 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
28 if (channel->IsModeSet('u') != adding)
30 if (IS_LOCAL(source) && (channel->GetStatus(source) < STATUS_OP))
32 source->WriteServ("482 %s %s :Only channel operators may %sset channel mode +u", source->nick, channel->name, adding ? "" : "un");
33 return MODEACTION_DENY;
37 channel->SetMode('u', adding);
38 return MODEACTION_ALLOW;
43 return MODEACTION_DENY;
48 class ModuleAuditorium : public Module
56 ModuleAuditorium(InspIRCd* Me)
59 aum = new AuditoriumMode(ServerInstance);
60 if (!ServerInstance->AddMode(aum, 'u'))
61 throw ModuleException("Could not add new modes!");
65 virtual ~ModuleAuditorium()
67 ServerInstance->Modes->DelMode(aum);
71 virtual void OnRehash(userrec* user, const std::string ¶meter)
73 ConfigReader conf(ServerInstance);
74 ShowOps = conf.ReadFlag("auditorium", "showops", 0);
79 /* To ensure that we get priority over namesx for names list generation on +u channels */
80 return (Priority)ServerInstance->PriorityBefore("m_namesx.so");
83 virtual Version GetVersion()
85 return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
88 void Implements(char* List)
90 List[I_OnUserJoin] = List[I_OnUserPart] = List[I_OnUserKick] = List[I_OnUserQuit] = List[I_OnUserList] = List[I_OnRehash] = 1;
93 virtual int OnUserList(userrec* user, chanrec* Ptr, CUList* &nameslist)
95 if (Ptr->IsModeSet('u'))
99 /* Show all the opped users */
100 nl = *(Ptr->GetOppedUsers());
107 /* HELLOOO, IS ANYBODY THERE? -- nope, just us. */
108 user->WriteServ("353 %s = %s :%s", user->nick, Ptr->name, user->nick);
109 user->WriteServ("366 %s %s :End of /NAMES list.", user->nick, Ptr->name);
116 virtual void OnUserJoin(userrec* user, chanrec* channel, bool &silent)
118 if (channel->IsModeSet('u'))
121 /* Because we silenced the event, make sure it reaches the user whos joining (but only them of course) */
122 user->WriteFrom(user, "JOIN %s", channel->name);
124 channel->WriteAllExcept(user, false, '@', except_list, "JOIN %s", channel->name);
128 void OnUserPart(userrec* user, chanrec* channel, const std::string &partmessage, bool &silent)
130 if (channel->IsModeSet('u'))
133 /* Because we silenced the event, make sure it reaches the user whos leaving (but only them of course) */
134 user->WriteFrom(user, "PART %s%s%s", channel->name,
135 partmessage.empty() ? "" : " :",
136 partmessage.empty() ? "" : partmessage.c_str());
138 channel->WriteAllExcept(user, false, '@', except_list, "PART %s%s%s", channel->name, partmessage.empty() ? "" : " :",
139 partmessage.empty() ? "" : partmessage.c_str());
143 void OnUserKick(userrec* source, userrec* user, chanrec* chan, const std::string &reason, bool &silent)
145 if (chan->IsModeSet('u'))
148 /* Send silenced event only to the user being kicked and the user doing the kick */
149 source->WriteFrom(source, "KICK %s %s %s", chan->name, user->nick, reason.c_str());
151 chan->WriteAllExcept(source, false, '@', except_list, "KICK %s %s %s", chan->name, user->nick, reason.c_str());
153 user->WriteFrom(source, "KICK %s %s %s", chan->name, user->nick, reason.c_str());
157 void OnUserQuit(userrec* user, const std::string &reason, const std::string &oper_message)
159 command_t* parthandler = ServerInstance->Parser->GetHandler("PART");
160 std::vector<std::string> to_leave;
161 const char* parameters[2];
164 for (UCListIter f = user->chans.begin(); f != user->chans.end(); f++)
166 if (f->first->IsModeSet('u'))
167 to_leave.push_back(f->first->name);
169 /* We cant do this neatly in one loop, as we are modifying the map we are iterating */
170 for (std::vector<std::string>::iterator n = to_leave.begin(); n != to_leave.end(); n++)
172 parameters[0] = n->c_str();
173 /* This triggers our OnUserPart, above, making the PART silent */
174 parthandler->Handle(parameters, 1, user);
180 class ModuleAuditoriumFactory : public ModuleFactory
183 ModuleAuditoriumFactory()
187 ~ModuleAuditoriumFactory()
191 virtual Module * CreateModule(InspIRCd* Me)
193 return new ModuleAuditorium(Me);
198 extern "C" void * init_module( void )
200 return new ModuleAuditoriumFactory;