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);
64 void OnRehash(User* user)
67 ShowOps = conf.ReadFlag("auditorium", "showops", 0);
68 OperOverride = conf.ReadFlag("auditorium", "operoverride", 0);
73 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);
76 void OnNamesListItem(User* issuer, Membership* memb, std::string &prefixes, std::string &nick)
78 if (!memb->chan->IsModeSet('u'))
81 /* Some module hid this from being displayed, dont bother */
85 /* If user is oper and operoverride is on, don't touch the list */
86 if (OperOverride && issuer->HasPrivPermission("channels/auspex"))
89 if (ShowOps && (issuer != memb->user) && (memb->getRank() < OP_VALUE))
91 /* Showops is set, hide all non-ops from the user, except themselves */
96 if (!ShowOps && (issuer != memb->user))
98 /* ShowOps is not set, hide everyone except the user whos requesting NAMES */
104 void BuildExcept(Membership* memb, CUList& excepts)
106 if (!memb->chan->IsModeSet('u'))
108 if (ShowOps && memb->getRank() >= OP_VALUE)
111 const UserMembList* users = memb->chan->GetUsers();
112 for(UserMembCIter i = users->begin(); i != users->end(); i++)
114 if (i->first == memb->user || !IS_LOCAL(i->first))
116 if (ShowOps && i->second->getRank() >= OP_VALUE)
118 if (OperOverride && i->first->HasPrivPermission("channels/auspex"))
120 // This is a different user in the channel, local, and not op/oper
121 // so, hide the join from them
122 excepts.insert(i->first);
125 void OnUserJoin(Membership* memb, bool sync, bool created, CUList& excepts)
127 BuildExcept(memb, excepts);
130 void OnUserPart(Membership* memb, std::string &partmessage, CUList& excepts)
132 BuildExcept(memb, excepts);
135 void OnUserKick(User* source, Membership* memb, const std::string &reason, CUList& excepts)
137 BuildExcept(memb, excepts);
140 ModResult OnHostCycle(User* user)
142 for (UCListIter f = user->chans.begin(); f != user->chans.end(); f++)
143 if ((*f)->IsModeSet('u'))
146 return MOD_RES_PASSTHRU;
149 void OnUserQuit(User* user, const std::string &reason, const std::string &oper_message)
151 Command* parthandler = ServerInstance->Parser->GetHandler("PART");
152 std::vector<std::string> to_leave;
155 for (UCListIter f = user->chans.begin(); f != user->chans.end(); f++)
157 if ((*f)->IsModeSet('u'))
158 to_leave.push_back((*f)->name);
160 /* We cant do this neatly in one loop, as we are modifying the map we are iterating */
161 for (std::vector<std::string>::iterator n = to_leave.begin(); n != to_leave.end(); n++)
163 std::vector<std::string> parameters;
164 parameters.push_back(*n);
165 /* This triggers our OnUserPart, above, making the PART silent */
166 parthandler->Handle(parameters, user);
172 MODULE_INIT(ModuleAuditorium)