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(InspIRCd* Instance, Module* Creator) : ModeHandler(Instance, Creator, 'u', 0, 0, false, MODETYPE_CHANNEL, false, 0, '@') { }
23 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
25 if (channel->IsModeSet('u') != adding)
27 channel->SetMode('u', adding);
28 return MODEACTION_ALLOW;
32 return MODEACTION_DENY;
37 class ModuleAuditorium : public Module
44 ModuleAuditorium(InspIRCd* Me)
45 : Module(Me), aum(Me, this)
47 if (!ServerInstance->Modes->AddMode(&aum))
48 throw ModuleException("Could not add new modes!");
52 Implementation eventlist[] = { I_OnUserJoin, I_OnUserPart, I_OnUserKick, I_OnUserQuit, I_OnNamesListItem, I_OnRehash, I_OnHostCycle };
53 Me->Modules->Attach(eventlist, this, 7);
59 ServerInstance->Modes->DelMode(&aum);
62 void OnRehash(User* user)
64 ConfigReader conf(ServerInstance);
65 ShowOps = conf.ReadFlag("auditorium", "showops", 0);
66 OperOverride = conf.ReadFlag("auditorium", "operoverride", 0);
71 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
74 void OnNamesListItem(User* issuer, Membership* memb, std::string &prefixes, std::string &nick)
76 if (!memb->chan->IsModeSet('u'))
79 /* Some module hid this from being displayed, dont bother */
83 /* If user is oper and operoverride is on, don't touch the list */
84 if (OperOverride && issuer->HasPrivPermission("channels/auspex"))
87 if (ShowOps && (issuer != memb->user) && (memb->getRank() < OP_VALUE))
89 /* Showops is set, hide all non-ops from the user, except themselves */
94 if (!ShowOps && (issuer != memb->user))
96 /* ShowOps is not set, hide everyone except the user whos requesting NAMES */
102 void BuildExcept(Membership* memb, CUList& excepts)
104 if (!memb->chan->IsModeSet('u'))
106 if (ShowOps && memb->getRank() >= OP_VALUE)
109 const UserMembList* users = memb->chan->GetUsers();
110 for(UserMembCIter i = users->begin(); i != users->end(); i++)
112 if (i->first == memb->user || !IS_LOCAL(i->first))
114 if (ShowOps && i->second->getRank() >= OP_VALUE)
116 if (OperOverride && i->first->HasPrivPermission("channels/auspex"))
118 // This is a different user in the channel, local, and not op/oper
119 // so, hide the join from them
120 excepts.insert(i->first);
123 void OnUserJoin(Membership* memb, bool sync, bool created, CUList& excepts)
125 BuildExcept(memb, excepts);
128 void OnUserPart(Membership* memb, std::string &partmessage, CUList& excepts)
130 BuildExcept(memb, excepts);
133 void OnUserKick(User* source, Membership* memb, const std::string &reason, CUList& excepts)
135 BuildExcept(memb, excepts);
138 ModResult OnHostCycle(User* user)
140 for (UCListIter f = user->chans.begin(); f != user->chans.end(); f++)
141 if ((*f)->IsModeSet('u'))
144 return MOD_RES_PASSTHRU;
147 void OnUserQuit(User* user, const std::string &reason, const std::string &oper_message)
149 Command* parthandler = ServerInstance->Parser->GetHandler("PART");
150 std::vector<std::string> to_leave;
153 for (UCListIter f = user->chans.begin(); f != user->chans.end(); f++)
155 if ((*f)->IsModeSet('u'))
156 to_leave.push_back((*f)->name);
158 /* We cant do this neatly in one loop, as we are modifying the map we are iterating */
159 for (std::vector<std::string>::iterator n = to_leave.begin(); n != to_leave.end(); n++)
161 std::vector<std::string> parameters;
162 parameters.push_back(*n);
163 /* This triggers our OnUserPart, above, making the PART silent */
164 parthandler->Handle(parameters, user);
170 MODULE_INIT(ModuleAuditorium)