1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 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 * ---------------------------------------------------
19 /* $ModDesc: Allows for auditorium channels (+u) where nobody can see others joining and parting or the nick list */
21 class AuditoriumMode : public ModeHandler
24 AuditoriumMode(InspIRCd* Instance) : ModeHandler(Instance, 'u', 0, 0, false, MODETYPE_CHANNEL, false) { }
26 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
28 if (channel->IsModeSet('u') != adding)
30 if (IS_LOCAL(source) && (channel->GetStatus(source) < STATUS_OP))
32 source->WriteServ("482 %s %s :Only channel operators may %sset channel mode +u", source->nick, channel->name, adding ? "" : "un");
33 return MODEACTION_DENY;
37 channel->SetMode('u', adding);
38 return MODEACTION_ALLOW;
43 return MODEACTION_DENY;
48 class ModuleAuditorium : public Module
53 ModuleAuditorium(InspIRCd* Me)
56 aum = new AuditoriumMode(ServerInstance);
57 if (!ServerInstance->AddMode(aum, 'u'))
58 throw ModuleException("Could not add new modes!");
61 virtual ~ModuleAuditorium()
63 ServerInstance->Modes->DelMode(aum);
69 /* To ensure that we get priority over namesx for names list generation on +u channels */
70 return (Priority)ServerInstance->PriorityBefore("m_namesx.so");
73 virtual Version GetVersion()
75 return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
78 void Implements(char* List)
80 List[I_OnUserJoin] = List[I_OnUserPart] = List[I_OnUserKick] = List[I_OnUserQuit] = List[I_OnUserList] = 1;
83 virtual int OnUserList(userrec* user, chanrec* Ptr)
85 if (Ptr->IsModeSet('u'))
87 /* HELLOOO, IS ANYBODY THERE? -- nope, just us. */
88 user->WriteServ("353 %s = %s :%s", user->nick, Ptr->name, user->nick);
89 user->WriteServ("366 %s %s :End of /NAMES list.", user->nick, Ptr->name);
95 virtual void OnUserJoin(userrec* user, chanrec* channel, bool &silent)
97 if (channel->IsModeSet('u'))
100 /* Because we silenced the event, make sure it reaches the user whos joining (but only them of course) */
101 user->WriteFrom(user, "JOIN %s", channel->name);
105 void OnUserPart(userrec* user, chanrec* channel, const std::string &partmessage, bool &silent)
107 if (channel->IsModeSet('u'))
110 /* Because we silenced the event, make sure it reaches the user whos leaving (but only them of course) */
111 user->WriteFrom(user, "PART %s%s%s", channel->name,
112 partmessage.empty() ? "" : " :",
113 partmessage.empty() ? "" : partmessage.c_str());
117 void OnUserKick(userrec* source, userrec* user, chanrec* chan, const std::string &reason, bool &silent)
119 if (chan->IsModeSet('u'))
122 /* Send silenced event only to the user being kicked and the user doing the kick */
123 source->WriteFrom(source, "KICK %s %s %s", channel->name, user->nick, reason.c_str());
124 user->WriteFrom(source, "KICK %s %s %s", channel->name, user->nick, reason.c_str());
128 void OnUserQuit(userrec* user, const std::string &reason, const std::string &oper_message)
130 command_t* parthandler = ServerInstance->Parser->GetHandler("PART");
131 std::vector<std::string> to_leave;
132 const char* parameters[2];
135 for (UCListIter f = user->chans.begin(); f != user->chans.end(); f++)
137 if (f->first->IsModeSet('u'))
138 to_leave.push_back(f->first->name);
140 /* We cant do this neatly in one loop, as we are modifying the map we are iterating */
141 for (std::vector<std::string>::iterator n = to_leave.begin(); n != to_leave.end(); n++)
143 parameters[0] = n->c_str();
144 /* This triggers our OnUserPart, above, making the PART silent */
145 parthandler->Handle(parameters, 1, user);
151 class ModuleAuditoriumFactory : public ModuleFactory
154 ModuleAuditoriumFactory()
158 ~ModuleAuditoriumFactory()
162 virtual Module * CreateModule(InspIRCd* Me)
164 return new ModuleAuditorium(Me);
169 extern "C" void * init_module( void )
171 return new ModuleAuditoriumFactory;