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/>.
21 #include "modules/ctctags.h"
23 class DelayMsgMode : public ParamMode<DelayMsgMode, LocalIntExt>
27 DelayMsgMode(Module* Parent)
28 : ParamMode<DelayMsgMode, LocalIntExt>(Parent, "delaymsg", 'd')
29 , jointime("delaymsg", ExtensionItem::EXT_MEMBERSHIP, Parent)
31 ranktoset = ranktounset = OP_VALUE;
34 bool ResolveModeConflict(std::string& their_param, const std::string& our_param, Channel*) CXX11_OVERRIDE
36 return (atoi(their_param.c_str()) < atoi(our_param.c_str()));
39 ModeAction OnSet(User* source, Channel* chan, std::string& parameter) CXX11_OVERRIDE;
40 void OnUnset(User* source, Channel* chan) CXX11_OVERRIDE;
42 void SerializeParam(Channel* chan, intptr_t n, std::string& out)
50 , public CTCTags::EventListener
55 ModResult HandleMessage(User* user, const MessageTarget& target, bool notice);
59 : CTCTags::EventListener(this)
64 Version GetVersion() CXX11_OVERRIDE;
65 void OnUserJoin(Membership* memb, bool sync, bool created, CUList&) CXX11_OVERRIDE;
66 ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE;
67 ModResult OnUserPreTagMessage(User* user, const MessageTarget& target, CTCTags::TagMessageDetails& details) CXX11_OVERRIDE;
68 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE;
71 ModeAction DelayMsgMode::OnSet(User* source, Channel* chan, std::string& parameter)
73 // Setting a new limit, sanity check
74 intptr_t limit = ConvToNum<intptr_t>(parameter);
79 return MODEACTION_ALLOW;
82 void DelayMsgMode::OnUnset(User* source, Channel* chan)
87 const Channel::MemberMap& users = chan->GetUsers();
88 for (Channel::MemberMap::const_iterator n = users.begin(); n != users.end(); ++n)
89 jointime.set(n->second, 0);
92 Version ModuleDelayMsg::GetVersion()
94 return Version("Provides channel mode +d <int>, to deny messages to a channel until <int> seconds have passed", VF_VENDOR);
97 void ModuleDelayMsg::OnUserJoin(Membership* memb, bool sync, bool created, CUList&)
99 if ((IS_LOCAL(memb->user)) && (memb->chan->IsModeSet(djm)))
101 djm.jointime.set(memb, ServerInstance->Time());
105 ModResult ModuleDelayMsg::OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details)
107 return HandleMessage(user, target, details.type == MSG_NOTICE);
110 ModResult ModuleDelayMsg::OnUserPreTagMessage(User* user, const MessageTarget& target, CTCTags::TagMessageDetails& details)
112 return HandleMessage(user, target, false);
115 ModResult ModuleDelayMsg::HandleMessage(User* user, const MessageTarget& target, bool notice)
118 return MOD_RES_PASSTHRU;
120 if ((target.type != MessageTarget::TYPE_CHANNEL) || ((!allownotice) && (notice)))
121 return MOD_RES_PASSTHRU;
123 Channel* channel = target.Get<Channel>();
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 int len = djm.ext.get(channel);
136 if ((ts + len) > ServerInstance->Time())
138 if (channel->GetPrefixValue(user) < VOICE_VALUE)
140 user->WriteNumeric(ERR_CANNOTSENDTOCHAN, channel->name, InspIRCd::Format("You must wait %d seconds after joining to send to the channel (+d is set)", len));
146 /* Timer has expired, we can stop checking now */
147 djm.jointime.set(memb, 0);
149 return MOD_RES_PASSTHRU;
152 void ModuleDelayMsg::ReadConfig(ConfigStatus& status)
154 ConfigTag* tag = ServerInstance->Config->ConfValue("delaymsg");
155 allownotice = tag->getBool("allownotice", true);
158 MODULE_INIT(ModuleDelayMsg)