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 ParamMode<DelayMsgMode, LocalIntExt>
26 DelayMsgMode(Module* Parent)
27 : ParamMode<DelayMsgMode, LocalIntExt>(Parent, "delaymsg", 'd')
28 , jointime("delaymsg", Parent)
30 levelrequired = OP_VALUE;
33 bool ResolveModeConflict(std::string &their_param, const std::string &our_param, Channel*)
35 return (atoi(their_param.c_str()) < atoi(our_param.c_str()));
38 ModeAction OnSet(User* source, Channel* chan, std::string& parameter);
39 void OnUnset(User* source, Channel* chan);
41 void SerializeParam(Channel* chan, int n, std::string& out)
47 class ModuleDelayMsg : public Module
51 ModuleDelayMsg() : djm(this)
55 Version GetVersion() CXX11_OVERRIDE;
56 void OnUserJoin(Membership* memb, bool sync, bool created, CUList&) CXX11_OVERRIDE;
57 ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE;
60 ModeAction DelayMsgMode::OnSet(User* source, Channel* chan, std::string& parameter)
62 // Setting a new limit, sanity check
63 unsigned int limit = ConvToInt(parameter);
68 return MODEACTION_ALLOW;
71 void DelayMsgMode::OnUnset(User* source, Channel* chan)
76 const Channel::MemberMap& users = chan->GetUsers();
77 for (Channel::MemberMap::const_iterator n = users.begin(); n != users.end(); ++n)
78 jointime.set(n->second, 0);
81 Version ModuleDelayMsg::GetVersion()
83 return Version("Provides channelmode +d <int>, to deny messages to a channel until <int> seconds.", VF_VENDOR);
86 void ModuleDelayMsg::OnUserJoin(Membership* memb, bool sync, bool created, CUList&)
88 if ((IS_LOCAL(memb->user)) && (memb->chan->IsModeSet(djm)))
90 djm.jointime.set(memb, ServerInstance->Time());
94 ModResult ModuleDelayMsg::OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype)
97 if ((!user) || (!IS_LOCAL(user)))
98 return MOD_RES_PASSTHRU;
100 if ((target_type != TYPE_CHANNEL) || (msgtype != MSG_PRIVMSG))
101 return MOD_RES_PASSTHRU;
103 Channel* channel = (Channel*) dest;
104 Membership* memb = channel->GetUser(user);
107 return MOD_RES_PASSTHRU;
109 time_t ts = djm.jointime.get(memb);
112 return MOD_RES_PASSTHRU;
114 int len = djm.ext.get(channel);
116 if ((ts + len) > ServerInstance->Time())
118 if (channel->GetPrefixValue(user) < VOICE_VALUE)
120 user->WriteNumeric(ERR_CANNOTSENDTOCHAN, "%s :You must wait %d seconds after joining to send to channel (+d)",
121 channel->name.c_str(), len);
127 /* Timer has expired, we can stop checking now */
128 djm.jointime.set(memb, 0);
130 return MOD_RES_PASSTHRU;
133 MODULE_INIT(ModuleDelayMsg)