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 /* $ModDesc: Provides channelmode +d <int>, to deny messages to a channel until <int> seconds. */
19 class DelayMsgMode : public ModeHandler
25 DelayMsgMode(Module* Parent) : ModeHandler(Parent, "delaymsg", 'd', PARAM_SETONLY, MODETYPE_CHANNEL)
26 , jointime("delaymsg", Parent)
28 levelrequired = OP_VALUE;
31 bool ResolveModeConflict(std::string &their_param, const std::string &our_param, Channel*)
33 return (atoi(their_param.c_str()) < atoi(our_param.c_str()));
36 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding);
39 class ModuleDelayMsg : public Module
44 ModuleDelayMsg() : djm(this)
46 if (!ServerInstance->Modes->AddMode(&djm))
47 throw ModuleException("Could not add new modes!");
48 ServerInstance->Extensions.Register(&djm.jointime);
49 Implementation eventlist[] = { I_OnUserJoin, I_OnUserPreMessage};
50 ServerInstance->Modules->Attach(eventlist, this, 2);
54 void OnUserJoin(Membership* memb, bool sync, bool created, CUList&);
55 ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string &text, char status, CUList &exempt_list);
58 ModeAction DelayMsgMode::OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
62 /* Setting a new limit, sanity check */
63 long limit = atoi(parameter.c_str());
65 /* Wrap low values at 32768 */
69 parameter = ConvToStr(limit);
76 const UserMembList* names = channel->GetUsers();
77 for (UserMembCIter n = names->begin(); n != names->end(); ++n)
78 jointime.set(n->second, 0);
80 channel->SetModeParam('d', adding ? parameter : "");
81 return MODEACTION_ALLOW;
84 ModuleDelayMsg::~ModuleDelayMsg()
88 Version ModuleDelayMsg::GetVersion()
90 return Version("Provides channelmode +d <int>, to deny messages to a channel until <int> seconds.", VF_VENDOR);
93 void ModuleDelayMsg::OnUserJoin(Membership* memb, bool sync, bool created, CUList&)
95 if (memb->chan->IsModeSet('d'))
97 djm.jointime.set(memb, ServerInstance->Time());
101 ModResult ModuleDelayMsg::OnUserPreMessage(User* user, void* dest, int target_type, std::string &text, char status, CUList &exempt_list)
105 return MOD_RES_PASSTHRU;
107 if (target_type != TYPE_CHANNEL)
108 return MOD_RES_PASSTHRU;
110 Channel* channel = (Channel*) dest;
111 Membership* memb = channel->GetUser(user);
114 return MOD_RES_PASSTHRU;
116 time_t ts = djm.jointime.get(memb);
119 return MOD_RES_PASSTHRU;
121 std::string len = channel->GetModeParameter('d');
123 if (ts + atoi(len.c_str()) > ServerInstance->Time())
125 if (channel->GetPrefixValue(user) < VOICE_VALUE)
127 user->WriteNumeric(404, "%s %s :You must wait %s seconds after joining to send to channel (+d)",
128 user->nick.c_str(), channel->name.c_str(), len.c_str());
134 /* Timer has expired, we can stop checking now */
135 djm.jointime.set(memb, 0);
137 return MOD_RES_PASSTHRU;
140 MODULE_INIT(ModuleDelayMsg)