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 /* $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 ModePair ModeSet(User*, User*, Channel* channel, const std::string ¶meter)
33 std::string climit = channel->GetModeParameter('d');
36 return std::make_pair(true, climit);
40 return std::make_pair(false, parameter);
44 bool ResolveModeConflict(std::string &their_param, const std::string &our_param, Channel*)
46 return (atoi(their_param.c_str()) < atoi(our_param.c_str()));
49 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding);
52 class ModuleDelayMsg : public Module
57 ModuleDelayMsg() : djm(this)
59 if (!ServerInstance->Modes->AddMode(&djm))
60 throw ModuleException("Could not add new modes!");
61 ServerInstance->Extensions.Register(&djm.jointime);
62 Implementation eventlist[] = { I_OnUserJoin, I_OnUserPreMessage};
63 ServerInstance->Modules->Attach(eventlist, this, 2);
67 void OnUserJoin(Membership* memb, bool sync, bool created, CUList&);
68 ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string &text, char status, CUList &exempt_list);
71 ModeAction DelayMsgMode::OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
75 /* Setting a new limit, sanity check */
76 long limit = atoi(parameter.c_str());
78 /* Wrap low values at 32768 */
82 parameter = ConvToStr(limit);
89 const UserMembList* names = channel->GetUsers();
90 for (UserMembCIter n = names->begin(); n != names->end(); ++n)
91 jointime.set(n->second, 0);
93 channel->SetModeParam('d', adding ? parameter : "");
94 return MODEACTION_ALLOW;
97 ModuleDelayMsg::~ModuleDelayMsg()
101 Version ModuleDelayMsg::GetVersion()
103 return Version("Provides channelmode +d <int>, to deny messages to a channel until <int> seconds.", VF_COMMON | VF_VENDOR);
106 void ModuleDelayMsg::OnUserJoin(Membership* memb, bool sync, bool created, CUList&)
108 if (memb->chan->IsModeSet('d'))
110 djm.jointime.set(memb, ServerInstance->Time());
114 ModResult ModuleDelayMsg::OnUserPreMessage(User* user, void* dest, int target_type, std::string &text, char status, CUList &exempt_list)
118 return MOD_RES_PASSTHRU;
120 if (target_type != TYPE_CHANNEL)
121 return MOD_RES_PASSTHRU;
123 Channel* channel = (Channel*) dest;
124 Membership* memb = channel->GetUser(user);
127 return MOD_RES_PASSTHRU;
129 time_t ts = djm.jointime.get(memb);
132 return MOD_RES_PASSTHRU;
134 std::string len = channel->GetModeParameter('d');
136 if (ts + atoi(len.c_str()) > ServerInstance->Time())
138 if (channel->GetPrefixValue(user) < VOICE_VALUE)
140 user->WriteNumeric(404, "%s %s :You must wait %s seconds after joining to send to channel (+d)",
141 user->nick.c_str(), channel->name.c_str(), len.c_str());
147 /* Timer has expired, we can stop checking now */
148 djm.jointime.set(memb, 0);
150 return MOD_RES_PASSTHRU;
153 MODULE_INIT(ModuleDelayMsg)