1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 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)
25 if (channel->IsModeSet('u') != adding)
27 if (IS_LOCAL(source) && (channel->GetStatus(source) < STATUS_OP))
29 source->WriteServ("482 %s %s :Only channel operators may %sset channel mode +u", source->nick, channel->name, adding ? "" : "un");
30 return MODEACTION_DENY;
34 channel->SetMode('u', adding);
35 return MODEACTION_ALLOW;
40 return MODEACTION_DENY;
45 class ModuleAuditorium : public Module
53 ModuleAuditorium(InspIRCd* Me)
56 aum = new AuditoriumMode(ServerInstance);
57 if (!ServerInstance->Modes->AddMode(aum))
60 throw ModuleException("Could not add new modes!");
65 Implementation eventlist[] = { I_OnUserJoin, I_OnUserPart, I_OnUserKick, I_OnUserQuit, I_OnUserList, I_OnRehash };
66 Me->Modules->Attach(eventlist, this, 6);
70 virtual ~ModuleAuditorium()
72 ServerInstance->Modes->DelMode(aum);
78 Module* namesx = ServerInstance->Modules->Find("m_namesx.so");
79 ServerInstance->Modules->SetPriority(this, I_OnUserList, PRIO_BEFORE, &namesx);
82 virtual void OnRehash(User* user, const std::string ¶meter)
84 ConfigReader conf(ServerInstance);
85 ShowOps = conf.ReadFlag("auditorium", "showops", 0);
88 virtual Version GetVersion()
90 return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
93 virtual int OnUserList(User* user, Channel* Ptr, CUList* &nameslist)
95 if (Ptr->IsModeSet('u'))
99 /* Leave the names list alone, theyre an op
100 * doing /names on the channel after joining it
102 if (Ptr->GetStatus(user) >= STATUS_OP)
104 nameslist = Ptr->GetUsers();
108 /* Show all the opped users */
109 nl = *(Ptr->GetOppedUsers());
110 nl[user] = user->nick;
116 /* HELLOOO, IS ANYBODY THERE? -- nope, just us. */
117 user->WriteServ("353 %s %c %s :%s", user->nick, Ptr->IsModeSet('s') ? '@' : Ptr->IsModeSet('p') ? '*' : '=', Ptr->name, user->nick);
118 user->WriteServ("366 %s %s :End of /NAMES list.", user->nick, Ptr->name);
125 virtual void OnUserJoin(User* user, Channel* channel, bool sync, bool &silent)
127 if (channel->IsModeSet('u'))
130 /* Because we silenced the event, make sure it reaches the user whos joining (but only them of course) */
131 user->WriteFrom(user, "JOIN %s", channel->name);
133 channel->WriteAllExcept(user, false, channel->GetStatus(user) >= STATUS_OP ? 0 : '@', except_list, "JOIN %s", channel->name);
137 void OnUserPart(User* user, Channel* channel, const std::string &partmessage, bool &silent)
139 if (channel->IsModeSet('u'))
142 /* Because we silenced the event, make sure it reaches the user whos leaving (but only them of course) */
143 user->WriteFrom(user, "PART %s%s%s", channel->name,
144 partmessage.empty() ? "" : " :",
145 partmessage.empty() ? "" : partmessage.c_str());
148 channel->WriteAllExcept(user, false, channel->GetStatus(user) >= STATUS_OP ? 0 : '@', except_list, "PART %s%s%s", channel->name, partmessage.empty() ? "" : " :",
149 partmessage.empty() ? "" : partmessage.c_str());
154 void OnUserKick(User* source, User* user, Channel* chan, const std::string &reason, bool &silent)
156 if (chan->IsModeSet('u'))
159 /* Send silenced event only to the user being kicked and the user doing the kick */
160 source->WriteFrom(source, "KICK %s %s %s", chan->name, user->nick, reason.c_str());
162 chan->WriteAllExcept(source, false, chan->GetStatus(source) >= STATUS_OP ? 0 : '@', except_list, "KICK %s %s %s", chan->name, user->nick, reason.c_str());
164 user->WriteFrom(source, "KICK %s %s %s", chan->name, user->nick, reason.c_str());
168 void OnUserQuit(User* user, const std::string &reason, const std::string &oper_message)
170 Command* parthandler = ServerInstance->Parser->GetHandler("PART");
171 std::vector<std::string> to_leave;
172 const char* parameters[2];
175 for (UCListIter f = user->chans.begin(); f != user->chans.end(); f++)
177 if (f->first->IsModeSet('u'))
178 to_leave.push_back(f->first->name);
180 /* We cant do this neatly in one loop, as we are modifying the map we are iterating */
181 for (std::vector<std::string>::iterator n = to_leave.begin(); n != to_leave.end(); n++)
183 parameters[0] = n->c_str();
184 /* This triggers our OnUserPart, above, making the PART silent */
185 parthandler->Handle(parameters, 1, user);
191 MODULE_INIT(ModuleAuditorium)