1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 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 * ---------------------------------------------------
16 /* $ModDesc: Allows for auditorium channels (+u) where nobody can see others joining and parting or the nick list */
18 class AuditoriumMode : public ModeHandler
21 AuditoriumMode(InspIRCd* Instance) : ModeHandler(Instance, 'u', 0, 0, false, MODETYPE_CHANNEL, false) { }
23 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
25 if (channel->IsModeSet('u') != adding)
27 if (IS_LOCAL(source) && (channel->GetStatus(source) < STATUS_OP))
29 source->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :Only channel operators may %sset channel mode +u", source->nick.c_str(), channel->name.c_str(), adding ? "" : "un");
30 return MODEACTION_DENY;
34 channel->SetMode('u', adding);
35 return MODEACTION_ALLOW;
40 return MODEACTION_DENY;
45 class ModuleAuditorium : public Module
52 ModuleAuditorium(InspIRCd* Me)
55 aum = new AuditoriumMode(ServerInstance);
56 if (!ServerInstance->Modes->AddMode(aum))
59 throw ModuleException("Could not add new modes!");
64 Implementation eventlist[] = { I_OnUserJoin, I_OnUserPart, I_OnUserKick, I_OnUserQuit, I_OnNamesListItem, I_OnRehash, I_OnHostCycle };
65 Me->Modules->Attach(eventlist, this, 7);
69 virtual ~ModuleAuditorium()
71 ServerInstance->Modes->DelMode(aum);
75 virtual void OnRehash(User* user, const std::string ¶meter)
77 ConfigReader conf(ServerInstance);
78 ShowOps = conf.ReadFlag("auditorium", "showops", 0);
79 OperOverride = conf.ReadFlag("auditorium", "operoverride", 0);
82 virtual Version GetVersion()
84 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
87 virtual void OnNamesListItem(User* issuer, User* user, Channel* channel, std::string &prefixes, std::string &nick)
89 if (!channel->IsModeSet('u'))
92 /* Some module hid this from being displayed, dont bother */
96 /* If user is oper and operoverride is on, don't touch the list */
97 if (OperOverride && user->HasPrivPermission("channels/auspex"))
100 if (ShowOps && (issuer != user) && (channel->GetStatus(user) < STATUS_OP))
102 /* Showops is set, hide all non-ops from the user, except themselves */
107 if (!ShowOps && (issuer != user))
109 /* ShowOps is not set, hide everyone except the user whos requesting NAMES */
115 virtual void OnUserJoin(User* user, Channel* channel, bool sync, bool &silent)
117 if (channel->IsModeSet('u'))
120 /* Because we silenced the event, make sure it reaches the user whos joining (but only them of course) */
121 user->WriteFrom(user, "JOIN %s", channel->name.c_str());
123 channel->WriteAllExceptSender(user, false, channel->GetStatus(user) >= STATUS_OP ? 0 : '@', "JOIN %s", channel->name.c_str());
127 void OnUserPart(User* user, Channel* channel, std::string &partmessage, bool &silent)
129 if (channel->IsModeSet('u'))
132 /* Because we silenced the event, make sure it reaches the user whos leaving (but only them of course) */
133 user->WriteFrom(user, "PART %s%s%s", channel->name.c_str(),
134 partmessage.empty() ? "" : " :",
135 partmessage.empty() ? "" : partmessage.c_str());
138 channel->WriteAllExceptSender(user, false, channel->GetStatus(user) >= STATUS_OP ? 0 : '@', "PART %s%s%s", channel->name.c_str(), partmessage.empty() ? "" : " :",
139 partmessage.empty() ? "" : partmessage.c_str());
144 void OnUserKick(User* source, User* user, Channel* chan, const std::string &reason, bool &silent)
146 if (chan->IsModeSet('u'))
149 /* Send silenced event only to the user being kicked and the user doing the kick */
150 source->WriteFrom(source, "KICK %s %s %s", chan->name.c_str(), user->nick.c_str(), reason.c_str());
152 chan->WriteAllExceptSender(source, false, chan->GetStatus(user) >= STATUS_OP ? 0 : '@', "KICK %s %s %s", chan->name.c_str(), user->nick.c_str(), reason.c_str());
153 if ((!ShowOps) || (chan->GetStatus(user) < STATUS_OP)) /* make sure the target gets the event */
154 user->WriteFrom(source, "KICK %s %s %s", chan->name.c_str(), user->nick.c_str(), reason.c_str());
158 bool OnHostCycle(User* user)
160 for (UCListIter f = user->chans.begin(); f != user->chans.end(); f++)
161 if (f->first->IsModeSet('u'))
167 void OnUserQuit(User* user, const std::string &reason, const std::string &oper_message)
169 Command* parthandler = ServerInstance->Parser->GetHandler("PART");
170 std::vector<std::string> to_leave;
173 for (UCListIter f = user->chans.begin(); f != user->chans.end(); f++)
175 if (f->first->IsModeSet('u'))
176 to_leave.push_back(f->first->name);
178 /* We cant do this neatly in one loop, as we are modifying the map we are iterating */
179 for (std::vector<std::string>::iterator n = to_leave.begin(); n != to_leave.end(); n++)
181 std::vector<std::string> parameters;
182 parameters.push_back(*n);
183 /* This triggers our OnUserPart, above, making the PART silent */
184 parthandler->Handle(parameters, user);
190 MODULE_INIT(ModuleAuditorium)