2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2010 Jens Voss <DukePyrolator@anope.org>
5 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
6 * Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
7 * Copyright (C) 2007-2008 Craig Edwards <craigedwards@brainbox.cc>
9 * This file is part of InspIRCd. InspIRCd is free software: you can
10 * redistribute it and/or modify it under the terms of the GNU General Public
11 * License as published by the Free Software Foundation, version 2.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 /* $ModDesc: Allows for delay-join channels (+D) where users don't appear to join until they speak */
28 class DelayJoinMode : public ModeHandler
33 DelayJoinMode(Module* Parent) : ModeHandler(Parent, "delayjoin", 'D', PARAM_NONE, MODETYPE_CHANNEL)
35 levelrequired = OP_VALUE;
38 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding);
41 class ModuleDelayJoin : public Module
46 ModuleDelayJoin() : djm(this), unjoined("delayjoin", this)
52 ServerInstance->Modules->AddService(djm);
53 Implementation eventlist[] = { I_OnUserJoin, I_OnUserPart, I_OnUserKick, I_OnBuildNeighborList, I_OnNamesListItem, I_OnText, I_OnRawMode };
54 ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
58 void OnNamesListItem(User* issuer, Membership*, std::string &prefixes, std::string &nick);
59 void OnUserJoin(Membership*, bool, bool, CUList&);
60 void CleanUser(User* user);
61 void OnUserPart(Membership*, std::string &partmessage, CUList&);
62 void OnUserKick(User* source, Membership*, const std::string &reason, CUList&);
63 void OnBuildNeighborList(User* source, UserChanList &include, std::map<User*,bool> &exception);
64 void OnText(User* user, void* dest, int target_type, const std::string &text, char status, CUList &exempt_list);
65 ModResult OnRawMode(User* user, Channel* channel, const char mode, const std::string ¶m, bool adding, int pcnt);
68 ModeAction DelayJoinMode::OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
71 if (channel->IsModeSet('D') == adding)
72 return MODEACTION_DENY;
77 * Make all users visible, as +D is being removed. If we don't do this,
78 * they remain permanently invisible on this channel!
80 const UserMembList* names = channel->GetUsers();
81 for (UserMembCIter n = names->begin(); n != names->end(); ++n)
82 creator->OnText(n->first, channel, TYPE_CHANNEL, "", 0, empty);
84 channel->SetMode('D', adding);
85 return MODEACTION_ALLOW;
88 ModuleDelayJoin::~ModuleDelayJoin()
92 Version ModuleDelayJoin::GetVersion()
94 return Version("Allows for delay-join channels (+D) where users don't appear to join until they speak", VF_VENDOR);
97 void ModuleDelayJoin::OnNamesListItem(User* issuer, Membership* memb, std::string &prefixes, std::string &nick)
99 /* don't prevent the user from seeing themself */
100 if (issuer == memb->user)
103 /* If the user is hidden by delayed join, hide them from the NAMES list */
104 if (unjoined.get(memb))
108 static void populate(CUList& except, Membership* memb)
110 const UserMembList* users = memb->chan->GetUsers();
111 for(UserMembCIter i = users->begin(); i != users->end(); i++)
113 if (i->first == memb->user || !IS_LOCAL(i->first))
115 except.insert(i->first);
119 void ModuleDelayJoin::OnUserJoin(Membership* memb, bool sync, bool created, CUList& except)
121 if (memb->chan->IsModeSet('D'))
123 unjoined.set(memb, 1);
124 populate(except, memb);
128 void ModuleDelayJoin::OnUserPart(Membership* memb, std::string &partmessage, CUList& except)
130 if (unjoined.set(memb, 0))
131 populate(except, memb);
134 void ModuleDelayJoin::OnUserKick(User* source, Membership* memb, const std::string &reason, CUList& except)
136 if (unjoined.set(memb, 0))
137 populate(except, memb);
140 void ModuleDelayJoin::OnBuildNeighborList(User* source, UserChanList &include, std::map<User*,bool> &exception)
142 UCListIter i = include.begin();
143 while (i != include.end())
146 Membership* memb = c->GetUser(source);
147 if (memb && unjoined.get(memb))
152 void ModuleDelayJoin::OnText(User* user, void* dest, int target_type, const std::string &text, char status, CUList &exempt_list)
158 if (target_type != TYPE_CHANNEL)
161 Channel* channel = static_cast<Channel*>(dest);
163 Membership* memb = channel->GetUser(user);
164 if (!memb || !unjoined.set(memb, 0))
167 /* Display the join to everyone else (the user who joined got it earlier) */
168 channel->WriteAllExceptSender(user, false, 0, "JOIN %s", channel->name.c_str());
170 std::string ms = memb->modes;
171 for(unsigned int i=0; i < memb->modes.length(); i++)
172 ms.append(" ").append(user->nick);
175 channel->WriteAllExceptSender(user, false, 0, "MODE %s +%s", channel->name.c_str(), ms.c_str());
178 /* make the user visible if he receives any mode change */
179 ModResult ModuleDelayJoin::OnRawMode(User* user, Channel* channel, const char mode, const std::string ¶m, bool adding, int pcnt)
181 if (!user || !channel || param.empty())
182 return MOD_RES_PASSTHRU;
186 dest = ServerInstance->FindNickOnly(param);
188 dest = ServerInstance->FindNick(param);
191 return MOD_RES_PASSTHRU;
193 Membership* memb = channel->GetUser(dest);
194 if (memb && unjoined.set(memb, 0))
195 channel->WriteAllExceptSender(dest, false, 0, "JOIN %s", channel->name.c_str());
196 return MOD_RES_PASSTHRU;
199 MODULE_INIT(ModuleDelayJoin)