1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/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(Module* Creator) : ModeHandler(Creator, 'u', PARAM_NONE, MODETYPE_CHANNEL)
23 levelrequired = OP_VALUE;
26 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
28 if (channel->IsModeSet('u') != adding)
30 channel->SetMode('u', adding);
31 return MODEACTION_ALLOW;
35 return MODEACTION_DENY;
40 class ModuleAuditorium : public Module
50 if (!ServerInstance->Modes->AddMode(&aum))
51 throw ModuleException("Could not add new modes!");
55 Implementation eventlist[] = { I_OnUserJoin, I_OnUserPart, I_OnUserKick, I_OnUserQuit, I_OnNamesListItem, I_OnRehash, I_OnHostCycle };
56 ServerInstance->Modules->Attach(eventlist, this, 7);
62 ServerInstance->Modes->DelMode(&aum);
65 void OnRehash(User* user)
68 ShowOps = conf.ReadFlag("auditorium", "showops", 0);
69 OperOverride = conf.ReadFlag("auditorium", "operoverride", 0);
74 return Version("Allows for auditorium channels (+u) where nobody can see others joining and parting or the nick list", VF_COMMON | VF_VENDOR, API_VERSION);
77 void OnNamesListItem(User* issuer, Membership* memb, std::string &prefixes, std::string &nick)
79 if (!memb->chan->IsModeSet('u'))
82 /* Some module hid this from being displayed, dont bother */
86 /* If user is oper and operoverride is on, don't touch the list */
87 if (OperOverride && issuer->HasPrivPermission("channels/auspex"))
90 if (ShowOps && (issuer != memb->user) && (memb->getRank() < OP_VALUE))
92 /* Showops is set, hide all non-ops from the user, except themselves */
97 if (!ShowOps && (issuer != memb->user))
99 /* ShowOps is not set, hide everyone except the user whos requesting NAMES */
105 void BuildExcept(Membership* memb, CUList& excepts)
107 if (!memb->chan->IsModeSet('u'))
109 if (ShowOps && memb->getRank() >= OP_VALUE)
112 const UserMembList* users = memb->chan->GetUsers();
113 for(UserMembCIter i = users->begin(); i != users->end(); i++)
115 if (i->first == memb->user || !IS_LOCAL(i->first))
117 if (ShowOps && i->second->getRank() >= OP_VALUE)
119 if (OperOverride && i->first->HasPrivPermission("channels/auspex"))
121 // This is a different user in the channel, local, and not op/oper
122 // so, hide the join from them
123 excepts.insert(i->first);
126 void OnUserJoin(Membership* memb, bool sync, bool created, CUList& excepts)
128 BuildExcept(memb, excepts);
131 void OnUserPart(Membership* memb, std::string &partmessage, CUList& excepts)
133 BuildExcept(memb, excepts);
136 void OnUserKick(User* source, Membership* memb, const std::string &reason, CUList& excepts)
138 BuildExcept(memb, excepts);
141 ModResult OnHostCycle(User* user)
143 for (UCListIter f = user->chans.begin(); f != user->chans.end(); f++)
144 if ((*f)->IsModeSet('u'))
147 return MOD_RES_PASSTHRU;
150 void OnUserQuit(User* user, const std::string &reason, const std::string &oper_message)
152 Command* parthandler = ServerInstance->Parser->GetHandler("PART");
153 std::vector<std::string> to_leave;
156 for (UCListIter f = user->chans.begin(); f != user->chans.end(); f++)
158 if ((*f)->IsModeSet('u'))
159 to_leave.push_back((*f)->name);
161 /* We cant do this neatly in one loop, as we are modifying the map we are iterating */
162 for (std::vector<std::string>::iterator n = to_leave.begin(); n != to_leave.end(); n++)
164 std::vector<std::string> parameters;
165 parameters.push_back(*n);
166 /* This triggers our OnUserPart, above, making the PART silent */
167 parthandler->Handle(parameters, user);
173 MODULE_INIT(ModuleAuditorium)