1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 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(InspIRCd* Instance, Module* Parent) : ModeHandler(Instance, Parent, 'D', 0, 0, false, MODETYPE_CHANNEL, false, 0, '@') {};
24 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding);
27 class ModuleDelayJoin : public Module
32 ModuleDelayJoin(InspIRCd* Me) : Module(Me), djm(Me, this), unjoined("delayjoin", this)
34 if (!ServerInstance->Modes->AddMode(&djm))
35 throw ModuleException("Could not add new modes!");
36 Implementation eventlist[] = { I_OnUserJoin, I_OnUserPart, I_OnUserKick, I_OnUserQuit, I_OnNamesListItem, I_OnText, I_OnHostCycle };
37 ServerInstance->Modules->Attach(eventlist, this, 7);
41 void OnNamesListItem(User* issuer, Membership*, std::string &prefixes, std::string &nick);
42 void OnUserJoin(Membership*, bool, bool, CUList&);
43 void CleanUser(User* user);
44 ModResult OnHostCycle(User* user);
45 void OnUserPart(Membership*, std::string &partmessage, CUList&);
46 void OnUserKick(User* source, Membership*, const std::string &reason, CUList&);
47 void OnUserQuit(User* user, const std::string &reason, const std::string &oper_message);
48 void OnText(User* user, void* dest, int target_type, const std::string &text, char status, CUList &exempt_list);
51 /* $ModDesc: Allows for delay-join channels (+D) where users dont appear to join until they speak */
53 ModeAction DelayJoinMode::OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
56 if (channel->IsModeSet('D') == adding)
57 return MODEACTION_DENY;
62 * Make all users visible, as +D is being removed. If we don't do this,
63 * they remain permanently invisible on this channel!
65 const UserMembList* names = channel->GetUsers();
66 for (UserMembCIter n = names->begin(); n != names->end(); ++n)
67 creator->OnText(n->first, channel, TYPE_CHANNEL, "", 0, empty);
69 channel->SetMode('D', adding);
70 return MODEACTION_ALLOW;
73 ModuleDelayJoin::~ModuleDelayJoin()
75 ServerInstance->Modes->DelMode(&djm);
78 Version ModuleDelayJoin::GetVersion()
80 return Version("$Id$", VF_COMMON | VF_VENDOR);
83 void ModuleDelayJoin::OnNamesListItem(User* issuer, Membership* memb, std::string &prefixes, std::string &nick)
85 /* don't prevent the user from seeing themself */
86 if (issuer == memb->user)
89 /* If the user is hidden by delayed join, hide them from the NAMES list */
90 if (unjoined.get(memb))
94 static void populate(CUList& except, Membership* memb)
96 const UserMembList* users = memb->chan->GetUsers();
97 for(UserMembCIter i = users->begin(); i != users->end(); i++)
99 if (i->first == memb->user || !IS_LOCAL(i->first))
101 except.insert(i->first);
105 void ModuleDelayJoin::OnUserJoin(Membership* memb, bool sync, bool created, CUList& except)
107 if (memb->chan->IsModeSet('D'))
109 unjoined.set(memb, 1);
110 populate(except, memb);
114 void ModuleDelayJoin::OnUserPart(Membership* memb, std::string &partmessage, CUList& except)
116 if (unjoined.set(memb, 0))
117 populate(except, memb);
120 void ModuleDelayJoin::OnUserKick(User* source, Membership* memb, const std::string &reason, CUList& except)
122 if (unjoined.set(memb, 0))
123 populate(except, memb);
126 ModResult ModuleDelayJoin::OnHostCycle(User* user)
132 void ModuleDelayJoin::OnUserQuit(User* user, const std::string &reason, const std::string &oper_message)
134 Command* parthandler = ServerInstance->Parser->GetHandler("PART");
137 for (UCListIter f = user->chans.begin(); f != user->chans.end(); f++)
140 Membership* memb = chan->GetUser(user);
141 if (memb && unjoined.get(memb))
143 std::vector<std::string> parameters;
144 parameters.push_back(chan->name);
145 /* Send a fake PART from the channel, which will be silent */
146 parthandler->Handle(parameters, user);
151 void ModuleDelayJoin::OnText(User* user, void* dest, int target_type, const std::string &text, char status, CUList &exempt_list)
157 if (target_type != TYPE_CHANNEL)
160 Channel* channel = (Channel*) dest;
162 Membership* memb = channel->GetUser(user);
163 if (!memb || !unjoined.set(memb, 0))
166 /* Display the join to everyone else (the user who joined got it earlier) */
167 channel->WriteAllExceptSender(user, false, 0, "JOIN %s", channel->name.c_str());
169 std::string n = this->ServerInstance->Modes->ModeString(user, channel);
171 channel->WriteAllExceptSender(user, false, 0, "MODE %s +%s", channel->name.c_str(), n.c_str());
174 MODULE_INIT(ModuleDelayJoin)