2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
6 * This file is part of InspIRCd. InspIRCd is free software: you can
7 * redistribute it and/or modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation, version 2.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 class DelayMsgMode : public ModeHandler
26 DelayMsgMode(Module* Parent) : ModeHandler(Parent, "delaymsg", 'd', PARAM_SETONLY, MODETYPE_CHANNEL)
27 , jointime("delaymsg", Parent)
29 levelrequired = OP_VALUE;
32 bool ResolveModeConflict(std::string &their_param, const std::string &our_param, Channel*)
34 return (atoi(their_param.c_str()) < atoi(our_param.c_str()));
37 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding);
40 class ModuleDelayMsg : public Module
44 ModuleDelayMsg() : djm(this)
48 void init() CXX11_OVERRIDE
50 ServerInstance->Modules->AddService(djm);
51 ServerInstance->Modules->AddService(djm.jointime);
53 Version GetVersion() CXX11_OVERRIDE;
54 void OnUserJoin(Membership* memb, bool sync, bool created, CUList&) CXX11_OVERRIDE;
55 ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE;
58 ModeAction DelayMsgMode::OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
62 if ((channel->IsModeSet(this)) && (channel->GetModeParameter(this) == parameter))
63 return MODEACTION_DENY;
65 /* Setting a new limit, sanity check */
66 long limit = atoi(parameter.c_str());
68 /* Wrap low values at 32768 */
72 parameter = ConvToStr(limit);
76 if (!channel->IsModeSet(this))
77 return MODEACTION_DENY;
82 const UserMembList* names = channel->GetUsers();
83 for (UserMembCIter n = names->begin(); n != names->end(); ++n)
84 jointime.set(n->second, 0);
86 return MODEACTION_ALLOW;
89 Version ModuleDelayMsg::GetVersion()
91 return Version("Provides channelmode +d <int>, to deny messages to a channel until <int> seconds.", VF_VENDOR);
94 void ModuleDelayMsg::OnUserJoin(Membership* memb, bool sync, bool created, CUList&)
96 if ((IS_LOCAL(memb->user)) && (memb->chan->IsModeSet(djm)))
98 djm.jointime.set(memb, ServerInstance->Time());
102 ModResult ModuleDelayMsg::OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype)
105 if ((!user) || (!IS_LOCAL(user)))
106 return MOD_RES_PASSTHRU;
108 if ((target_type != TYPE_CHANNEL) || (msgtype != MSG_PRIVMSG))
109 return MOD_RES_PASSTHRU;
111 Channel* channel = (Channel*) dest;
112 Membership* memb = channel->GetUser(user);
115 return MOD_RES_PASSTHRU;
117 time_t ts = djm.jointime.get(memb);
120 return MOD_RES_PASSTHRU;
122 std::string len = channel->GetModeParameter(&djm);
124 if (ts + atoi(len.c_str()) > ServerInstance->Time())
126 if (channel->GetPrefixValue(user) < VOICE_VALUE)
128 user->WriteNumeric(404, "%s %s :You must wait %s seconds after joining to send to channel (+d)",
129 user->nick.c_str(), channel->name.c_str(), len.c_str());
135 /* Timer has expired, we can stop checking now */
136 djm.jointime.set(memb, 0);
138 return MOD_RES_PASSTHRU;
141 MODULE_INIT(ModuleDelayMsg)