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 * ---------------------------------------------------
17 class DelayJoinMode : public ModeHandler
22 DelayJoinMode(Module* Parent) : ModeHandler(Parent, "delayjoin", 'D', PARAM_NONE, MODETYPE_CHANNEL)
24 levelrequired = OP_VALUE;
27 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding);
30 class ModuleDelayJoin : public Module
35 ModuleDelayJoin() : djm(this), unjoined("delayjoin", this)
37 if (!ServerInstance->Modes->AddMode(&djm))
38 throw ModuleException("Could not add new modes!");
39 Implementation eventlist[] = { I_OnUserJoin, I_OnUserPart, I_OnUserKick, I_OnBuildNeighborList, I_OnNamesListItem, I_OnText, I_OnRawMode };
40 ServerInstance->Modules->Attach(eventlist, this, 7);
44 void OnNamesListItem(User* issuer, Membership*, std::string &prefixes, std::string &nick);
45 void OnUserJoin(Membership*, bool, bool, CUList&);
46 void CleanUser(User* user);
47 void OnUserPart(Membership*, std::string &partmessage, CUList&);
48 void OnUserKick(User* source, Membership*, const std::string &reason, CUList&);
49 void OnBuildNeighborList(User* source, UserChanList &include, std::map<User*,bool> &exception);
50 void OnText(User* user, void* dest, int target_type, const std::string &text, char status, CUList &exempt_list);
51 ModResult OnRawMode(User* user, Channel* channel, const char mode, const std::string ¶m, bool adding, int pcnt);
54 /* $ModDesc: Allows for delay-join channels (+D) where users dont appear to join until they speak */
56 ModeAction DelayJoinMode::OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
59 if (channel->IsModeSet('D') == adding)
60 return MODEACTION_DENY;
65 * Make all users visible, as +D is being removed. If we don't do this,
66 * they remain permanently invisible on this channel!
68 const UserMembList* names = channel->GetUsers();
69 for (UserMembCIter n = names->begin(); n != names->end(); ++n)
70 creator->OnText(n->first, channel, TYPE_CHANNEL, "", 0, empty);
72 channel->SetMode('D', adding);
73 return MODEACTION_ALLOW;
76 ModuleDelayJoin::~ModuleDelayJoin()
80 Version ModuleDelayJoin::GetVersion()
82 return Version("Allows for delay-join channels (+D) where users dont appear to join until they speak", VF_VENDOR);
85 void ModuleDelayJoin::OnNamesListItem(User* issuer, Membership* memb, std::string &prefixes, std::string &nick)
87 /* don't prevent the user from seeing themself */
88 if (issuer == memb->user)
91 /* If the user is hidden by delayed join, hide them from the NAMES list */
92 if (unjoined.get(memb))
96 static void populate(CUList& except, Membership* memb)
98 const UserMembList* users = memb->chan->GetUsers();
99 for(UserMembCIter i = users->begin(); i != users->end(); i++)
101 if (i->first == memb->user || !IS_LOCAL(i->first))
103 except.insert(i->first);
107 void ModuleDelayJoin::OnUserJoin(Membership* memb, bool sync, bool created, CUList& except)
109 if (memb->chan->IsModeSet('D'))
111 unjoined.set(memb, 1);
112 populate(except, memb);
116 void ModuleDelayJoin::OnUserPart(Membership* memb, std::string &partmessage, CUList& except)
118 if (unjoined.set(memb, 0))
119 populate(except, memb);
122 void ModuleDelayJoin::OnUserKick(User* source, Membership* memb, const std::string &reason, CUList& except)
124 if (unjoined.set(memb, 0))
125 populate(except, memb);
128 void ModuleDelayJoin::OnBuildNeighborList(User* source, UserChanList &include, std::map<User*,bool> &exception)
130 UCListIter i = include.begin();
131 while (i != include.end())
134 Membership* memb = c->GetUser(source);
135 if (memb && unjoined.get(memb))
140 void ModuleDelayJoin::OnText(User* user, void* dest, int target_type, const std::string &text, char status, CUList &exempt_list)
146 if (target_type != TYPE_CHANNEL)
149 Channel* channel = static_cast<Channel*>(dest);
151 Membership* memb = channel->GetUser(user);
152 if (!memb || !unjoined.set(memb, 0))
155 /* Display the join to everyone else (the user who joined got it earlier) */
156 channel->WriteAllExceptSender(user, false, 0, "JOIN %s", channel->name.c_str());
158 std::string ms = memb->modes;
159 for(unsigned int i=0; i < memb->modes.length(); i++)
160 ms.append(" ").append(user->nick);
163 channel->WriteAllExceptSender(user, false, 0, "MODE %s +%s", channel->name.c_str(), ms.c_str());
166 /* make the user visible if he receives any mode change */
167 ModResult ModuleDelayJoin::OnRawMode(User* user, Channel* channel, const char mode, const std::string ¶m, bool adding, int pcnt)
169 if (!user || !channel || param.empty())
170 return MOD_RES_PASSTHRU;
174 dest = ServerInstance->FindNickOnly(param);
176 dest = ServerInstance->FindNick(param);
179 return MOD_RES_PASSTHRU;
181 Membership* memb = channel->GetUser(dest);
182 if (memb && unjoined.set(memb, 0))
183 channel->WriteAllExceptSender(dest, false, 0, "JOIN %s", channel->name.c_str());
184 return MOD_RES_PASSTHRU;
187 MODULE_INIT(ModuleDelayJoin)