1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
17 /* $ModDesc: Provides channelmode +d <int>, to deny messages to a channel until <int> seconds. */
19 class DelayMsgMode : public ModeHandler
25 DelayMsgMode(InspIRCd* Instance, Module* Parent) : ModeHandler(Parent, 'd', PARAM_SETONLY, MODETYPE_CHANNEL)
26 , jointime("delaymsg", Parent)
28 levelrequired = OP_VALUE;
31 ModePair ModeSet(User*, User*, Channel* channel, const std::string ¶meter)
33 std::string climit = channel->GetModeParameter('d');
36 return std::make_pair(true, climit);
40 return std::make_pair(false, parameter);
44 bool CheckTimeStamp(std::string &their_param, const std::string &our_param, Channel*)
46 return (atoi(their_param.c_str()) < atoi(our_param.c_str()));
49 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding);
52 class ModuleDelayMsg : public Module
57 ModuleDelayMsg(InspIRCd* Me) : Module(Me), djm(Me, this)
59 if (!ServerInstance->Modes->AddMode(&djm))
60 throw ModuleException("Could not add new modes!");
61 Extensible::Register(&djm.jointime);
62 Implementation eventlist[] = { I_OnUserJoin, I_OnUserPreMessage};
63 ServerInstance->Modules->Attach(eventlist, this, 2);
67 void OnUserJoin(Membership* memb, bool sync, bool created, CUList&);
68 ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string &text, char status, CUList &exempt_list);
71 ModeAction DelayMsgMode::OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
75 /* Setting a new limit, sanity check */
76 long limit = atoi(parameter.c_str());
78 /* Wrap low values at 32768 */
82 parameter = ConvToStr(limit);
89 const UserMembList* names = channel->GetUsers();
90 for (UserMembCIter n = names->begin(); n != names->end(); ++n)
91 jointime.set(n->second, 0);
93 channel->SetModeParam('d', adding ? parameter : "");
94 return MODEACTION_ALLOW;
97 ModuleDelayMsg::~ModuleDelayMsg()
99 ServerInstance->Modes->DelMode(&djm);
102 Version ModuleDelayMsg::GetVersion()
104 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
107 void ModuleDelayMsg::OnUserJoin(Membership* memb, bool sync, bool created, CUList&)
109 if (memb->chan->IsModeSet('d'))
111 djm.jointime.set(memb, ServerInstance->Time());
115 ModResult ModuleDelayMsg::OnUserPreMessage(User* user, void* dest, int target_type, std::string &text, char status, CUList &exempt_list)
119 return MOD_RES_PASSTHRU;
121 if (target_type != TYPE_CHANNEL)
122 return MOD_RES_PASSTHRU;
124 Channel* channel = (Channel*) dest;
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 std::string len = channel->GetModeParameter('d');
137 if (ts + atoi(len.c_str()) > ServerInstance->Time())
139 if (channel->GetPrefixValue(user) < VOICE_VALUE)
141 user->WriteNumeric(404, "%s %s :You must wait %s seconds after joining to send to channel (+d)",
142 user->nick.c_str(), channel->name.c_str(), len.c_str());
148 /* Timer has expired, we can stop checking now */
149 djm.jointime.set(memb, 0);
151 return MOD_RES_PASSTHRU;
154 MODULE_INIT(ModuleDelayMsg)