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", ExtensionItem::EXT_MEMBERSHIP, Parent)
30 ranktoset = ranktounset = OP_VALUE;
33 bool ResolveModeConflict(std::string& their_param, const std::string& our_param, Channel*) CXX11_OVERRIDE
35 return (atoi(their_param.c_str()) < atoi(our_param.c_str()));
38 ModeAction OnSet(User* source, Channel* chan, std::string& parameter) CXX11_OVERRIDE;
39 void OnUnset(User* source, Channel* chan);
41 void SerializeParam(Channel* chan, int n, std::string& out)
47 class ModuleDelayMsg : public Module
52 ModuleDelayMsg() : djm(this)
56 Version GetVersion() CXX11_OVERRIDE;
57 void OnUserJoin(Membership* memb, bool sync, bool created, CUList&) CXX11_OVERRIDE;
58 ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE;
59 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE;
62 ModeAction DelayMsgMode::OnSet(User* source, Channel* chan, std::string& parameter)
64 // Setting a new limit, sanity check
65 unsigned int limit = ConvToInt(parameter);
70 return MODEACTION_ALLOW;
73 void DelayMsgMode::OnUnset(User* source, Channel* chan)
78 const Channel::MemberMap& users = chan->GetUsers();
79 for (Channel::MemberMap::const_iterator n = users.begin(); n != users.end(); ++n)
80 jointime.set(n->second, 0);
83 Version ModuleDelayMsg::GetVersion()
85 return Version("Provides channelmode +d <int>, to deny messages to a channel until <int> seconds.", VF_VENDOR);
88 void ModuleDelayMsg::OnUserJoin(Membership* memb, bool sync, bool created, CUList&)
90 if ((IS_LOCAL(memb->user)) && (memb->chan->IsModeSet(djm)))
92 djm.jointime.set(memb, ServerInstance->Time());
96 ModResult ModuleDelayMsg::OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype)
99 return MOD_RES_PASSTHRU;
101 if ((target_type != TYPE_CHANNEL) || ((!allownotice) && (msgtype == MSG_NOTICE)))
102 return MOD_RES_PASSTHRU;
104 Channel* channel = (Channel*) dest;
105 Membership* memb = channel->GetUser(user);
108 return MOD_RES_PASSTHRU;
110 time_t ts = djm.jointime.get(memb);
113 return MOD_RES_PASSTHRU;
115 int len = djm.ext.get(channel);
117 if ((ts + len) > ServerInstance->Time())
119 if (channel->GetPrefixValue(user) < VOICE_VALUE)
121 user->WriteNumeric(ERR_CANNOTSENDTOCHAN, channel->name, InspIRCd::Format("You must wait %d seconds after joining to send to channel (+d)", len));
127 /* Timer has expired, we can stop checking now */
128 djm.jointime.set(memb, 0);
130 return MOD_RES_PASSTHRU;
133 void ModuleDelayMsg::ReadConfig(ConfigStatus& status)
135 ConfigTag* tag = ServerInstance->Config->ConfValue("delaymsg");
136 allownotice = tag->getBool("allownotice", true);
139 MODULE_INIT(ModuleDelayMsg)