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 * ---------------------------------------------------
16 /* $ModDesc: Allows for delay-join channels (+D) where users dont appear to join until they speak */
18 class DelayJoinMode : public ModeHandler
21 DelayJoinMode(InspIRCd* Instance) : ModeHandler(Instance, 'D', 0, 0, false, MODETYPE_CHANNEL, false) { }
23 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
25 if (channel->IsModeSet('D') != adding)
27 if (IS_LOCAL(source) && (channel->GetStatus(source) < STATUS_OP))
29 source->WriteServ("482 %s %s :Only channel operators may %sset channel mode +D", source->nick, channel->name, adding ? "" : "un");
30 return MODEACTION_DENY;
34 channel->SetMode('D', adding);
35 return MODEACTION_ALLOW;
40 return MODEACTION_DENY;
45 class ModuleDelayJoin : public Module
51 ModuleDelayJoin(InspIRCd* Me)
54 djm = new DelayJoinMode(ServerInstance);
55 if (!ServerInstance->AddMode(djm))
56 throw ModuleException("Could not add new modes!");
59 virtual ~ModuleDelayJoin()
61 ServerInstance->Modes->DelMode(djm);
67 /* To ensure that we get priority over namesx for names list generation on +u channels */
68 return (Priority)ServerInstance->Modules->PriorityBefore("m_namesx.so");
71 virtual Version GetVersion()
73 return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
76 void Implements(char* List)
78 List[I_OnUserJoin] = List[I_OnUserPart] = List[I_OnUserKick] = List[I_OnUserQuit] = List[I_OnUserList] = List[I_OnText] = 1;
81 virtual int OnUserList(User* user, Channel* Ptr, CUList* &nameslist)
83 CUList* newlist = nameslist ? nameslist : Ptr->GetUsers();
87 /* For +D channels ... */
88 if (Ptr->IsModeSet('D'))
90 std::string key("delayjoin_");
91 key.append(Ptr->name);
92 ServerInstance->Log(DEBUG,"Key: %s", key.c_str());
93 /* Modify the names list, erasing users with the delay join metadata
94 * for this channel (havent spoken yet)
96 for (CUListIter n = newlist->begin(); n != newlist->end(); ++n)
98 ServerInstance->Log(DEBUG,"Item: %s", n->first->nick);
99 if (!n->first->GetExt(key))
102 ServerInstance->Log(DEBUG,"Spoken: %s", n->first->nick);
105 ServerInstance->Log(DEBUG,"Insert self");
106 nl[user] = user->nick;
112 virtual void OnUserJoin(User* user, Channel* channel, bool &silent)
114 if (channel->IsModeSet('D'))
117 /* Because we silenced the event, make sure it reaches the user whos joining (but only them of course) */
118 user->WriteFrom(user, "JOIN %s", channel->name);
120 /* This metadata tells the module the user is delayed join on this specific channel */
121 user->Extend(std::string("delayjoin_")+channel->name);
123 /* This metadata tells the module the user is delayed join on at least one (or more) channels.
124 * It is only cleared when the user is no longer on ANY +D channels.
126 if (!user->GetExt("delayjoin"))
127 user->Extend("delayjoin");
131 void OnUserPart(User* user, Channel* channel, const std::string &partmessage, bool &silent)
133 if (channel->IsModeSet('D'))
135 if (user->GetExt(std::string("delayjoin_")+channel->name))
138 /* Because we silenced the event, make sure it reaches the user whos leaving (but only them of course) */
139 user->WriteFrom(user, "PART %s%s%s", channel->name, partmessage.empty() ? "" : " :", partmessage.empty() ? "" : partmessage.c_str());
144 void OnUserKick(User* source, User* user, Channel* chan, const std::string &reason, bool &silent)
146 if (chan->IsModeSet('D'))
148 /* Send silenced event only to the user being kicked and the user doing the kick */
149 if (user->GetExt(std::string("delayjoin_")+chan->name))
152 user->WriteFrom(source, "KICK %s %s %s", chan->name, user->nick, reason.c_str());
157 void OnUserQuit(User* user, const std::string &reason, const std::string &oper_message)
159 Command* parthandler = ServerInstance->Parser->GetHandler("PART");
160 const char* parameters[2];
161 if (parthandler && user->GetExt("delayjoin"))
163 for (UCListIter f = user->chans.begin(); f != user->chans.end(); f++)
165 parameters[0] = f->first->name;
166 /* This triggers our OnUserPart, above, making the PART silent */
167 parthandler->Handle(parameters, 1, user);
172 void OnText(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
174 if (target_type != TYPE_CHANNEL)
177 Channel* channel = (Channel*) dest;
179 if (!user->GetExt(std::string("delayjoin_")+channel->name))
182 /* Display the join to everyone else (the user who joined got it earlier) */
183 channel->WriteAllExcept(user, false, 0, exempt_list, "JOIN %s", channel->name);
185 /* Shrink off the neccessary metadata for a specific channel */
186 user->Shrink(std::string("delayjoin_")+channel->name);
188 /* Check if the user is left on any other +D channels, if so don't take away the
189 * metadata that says theyre on one or more channels
191 for (UCListIter f = user->chans.begin(); f != user->chans.end(); f++)
192 if (f->first->IsModeSet('D'))
195 user->Shrink("delayjoin");
199 MODULE_INIT(ModuleDelayJoin)