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;
35 bool ResolveModeConflict(std::string& their_param, const std::string& our_param, Channel*) CXX11_OVERRIDE
37 return ConvToNum<intptr_t>(their_param) < ConvToNum<intptr_t>(our_param);
40 ModeAction OnSet(User* source, Channel* chan, std::string& parameter) CXX11_OVERRIDE;
41 void OnUnset(User* source, Channel* chan) CXX11_OVERRIDE;
43 void SerializeParam(Channel* chan, intptr_t n, std::string& out)
51 , public CTCTags::EventListener
56 ModResult HandleMessage(User* user, const MessageTarget& target, bool notice);
60 : CTCTags::EventListener(this)
65 Version GetVersion() CXX11_OVERRIDE;
66 void OnUserJoin(Membership* memb, bool sync, bool created, CUList&) CXX11_OVERRIDE;
67 ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE;
68 ModResult OnUserPreTagMessage(User* user, const MessageTarget& target, CTCTags::TagMessageDetails& details) CXX11_OVERRIDE;
69 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE;
72 ModeAction DelayMsgMode::OnSet(User* source, Channel* chan, std::string& parameter)
74 // Setting a new limit, sanity check
75 intptr_t limit = ConvToNum<intptr_t>(parameter);
80 return MODEACTION_ALLOW;
83 void DelayMsgMode::OnUnset(User* source, Channel* chan)
88 const Channel::MemberMap& users = chan->GetUsers();
89 for (Channel::MemberMap::const_iterator n = users.begin(); n != users.end(); ++n)
90 jointime.set(n->second, 0);
93 Version ModuleDelayMsg::GetVersion()
95 return Version("Provides channel mode +d <int>, to deny messages to a channel until <int> seconds have passed", VF_VENDOR);
98 void ModuleDelayMsg::OnUserJoin(Membership* memb, bool sync, bool created, CUList&)
100 if ((IS_LOCAL(memb->user)) && (memb->chan->IsModeSet(djm)))
102 djm.jointime.set(memb, ServerInstance->Time());
106 ModResult ModuleDelayMsg::OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details)
108 return HandleMessage(user, target, details.type == MSG_NOTICE);
111 ModResult ModuleDelayMsg::OnUserPreTagMessage(User* user, const MessageTarget& target, CTCTags::TagMessageDetails& details)
113 return HandleMessage(user, target, false);
116 ModResult ModuleDelayMsg::HandleMessage(User* user, const MessageTarget& target, bool notice)
119 return MOD_RES_PASSTHRU;
121 if ((target.type != MessageTarget::TYPE_CHANNEL) || ((!allownotice) && (notice)))
122 return MOD_RES_PASSTHRU;
124 Channel* channel = target.Get<Channel>();
125 Membership* memb = channel->GetUser(user);
128 return MOD_RES_PASSTHRU;
130 time_t ts = djm.jointime.get(memb);
133 return MOD_RES_PASSTHRU;
135 int len = djm.ext.get(channel);
137 if ((ts + len) > ServerInstance->Time())
139 if (channel->GetPrefixValue(user) < VOICE_VALUE)
141 user->WriteNumeric(ERR_CANNOTSENDTOCHAN, channel->name, InspIRCd::Format("You must wait %d seconds after joining to send to the channel (+d is set)", len));
147 /* Timer has expired, we can stop checking now */
148 djm.jointime.set(memb, 0);
150 return MOD_RES_PASSTHRU;
153 void ModuleDelayMsg::ReadConfig(ConfigStatus& status)
155 ConfigTag* tag = ServerInstance->Config->ConfValue("delaymsg");
156 allownotice = tag->getBool("allownotice", true);
159 MODULE_INIT(ModuleDelayMsg)