1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 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, "auditorium", '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(this) == adding)
29 return MODEACTION_DENY;
30 channel->SetMode(this, adding);
31 return MODEACTION_ALLOW;
35 class ModuleAuditorium : public Module
43 ModuleAuditorium() : aum(this)
49 ServerInstance->Modules->AddService(aum);
53 Implementation eventlist[] = { I_OnUserJoin, I_OnUserPart, I_OnUserKick, I_OnBuildNeighborList, I_OnNamesListItem, I_OnRehash };
54 ServerInstance->Modules->Attach(eventlist, this, 6);
61 void OnRehash(User* user)
63 ConfigTag* tag = ServerInstance->Config->ConfValue("auditorium");
64 OpsVisible = tag->getBool("opvisible");
65 OpsCanSee = tag->getBool("opcansee");
66 OperCanSee = tag->getBool("opercansee", true);
71 return Version("Allows for auditorium channels (+u) where nobody can see others joining and parting or the nick list", VF_VENDOR);
74 /* Can they be seen by everyone? */
75 bool IsVisible(Membership* memb)
77 if (!memb->chan->IsModeSet(&aum))
80 ModResult res = ServerInstance->OnCheckExemption(memb->user, memb->chan, "auditorium-vis");
81 return res.check(OpsVisible && memb->getRank() >= OP_VALUE);
84 /* Can they see this specific membership? */
85 bool CanSee(User* issuer, Membership* memb)
87 // If user is oper and operoverride is on, don't touch the list
88 if (OperCanSee && issuer->HasPrivPermission("channels/auspex"))
91 // You can always see yourself
92 if (issuer == memb->user)
95 // Can you see the list by permission?
96 ModResult res = ServerInstance->OnCheckExemption(issuer,memb->chan,"auditorium-see");
97 if (res.check(OpsCanSee && memb->chan->GetPrefixValue(issuer) >= OP_VALUE))
103 void OnNamesListItem(User* issuer, Membership* memb, std::string &prefixes, std::string &nick)
105 // Some module already hid this from being displayed, don't bother
112 if (CanSee(issuer, memb))
118 /** Build CUList for showing this join/part/kick */
119 void BuildExcept(Membership* memb, CUList& excepts)
124 const UserMembList* users = memb->chan->GetUsers();
125 for(UserMembCIter i = users->begin(); i != users->end(); i++)
127 if (IS_LOCAL(i->first) && !CanSee(i->first, memb))
128 excepts.insert(i->first);
132 void OnUserJoin(Membership* memb, bool sync, bool created, CUList& excepts)
134 BuildExcept(memb, excepts);
137 void OnUserPart(Membership* memb, std::string &partmessage, CUList& excepts)
139 BuildExcept(memb, excepts);
142 void OnUserKick(User* source, Membership* memb, const std::string &reason, CUList& excepts)
144 BuildExcept(memb, excepts);
147 void OnBuildNeighborList(User* source, UserChanList &include, std::map<User*,bool> &exception)
149 UCListIter i = include.begin();
150 while (i != include.end())
153 Membership* memb = c->GetUser(source);
154 if (!memb || IsVisible(memb))
156 // this channel should not be considered when listing my neighbors
158 // however, that might hide me from ops that can see me...
159 const UserMembList* users = c->GetUsers();
160 for(UserMembCIter j = users->begin(); j != users->end(); j++)
162 if (IS_LOCAL(j->first) && CanSee(j->first, memb))
163 exception[j->first] = true;
169 MODULE_INIT(ModuleAuditorium)