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(Instance, Parent, 'd', 1, 0, false, MODETYPE_CHANNEL, false, 0, '@'), jointime("delaymsg", Parent) {};
27 ModePair ModeSet(User*, User*, Channel* channel, const std::string ¶meter)
29 std::string climit = channel->GetModeParameter('d');
32 return std::make_pair(true, climit);
36 return std::make_pair(false, parameter);
40 bool CheckTimeStamp(std::string &their_param, const std::string &our_param, Channel*)
42 return (atoi(their_param.c_str()) < atoi(our_param.c_str()));
45 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding);
48 class ModuleDelayMsg : public Module
53 ModuleDelayMsg(InspIRCd* Me) : Module(Me), djm(Me, this)
55 if (!ServerInstance->Modes->AddMode(&djm))
56 throw ModuleException("Could not add new modes!");
57 Extensible::Register(&djm.jointime);
58 Implementation eventlist[] = { I_OnUserJoin, I_OnUserPreMessage};
59 ServerInstance->Modules->Attach(eventlist, this, 2);
63 void OnUserJoin(User* user, Channel* channel, bool sync, bool &silent, bool created);
64 void OnUserPart(User* user, Channel* channel, std::string &partmessage, bool &silent);
65 void OnUserKick(User* source, User* user, Channel* chan, const std::string &reason, bool &silent);
66 void OnCleanup(int target_type, void* item);
67 ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string &text, char status, CUList &exempt_list);
70 ModeAction DelayMsgMode::OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
74 /* Setting a new limit, sanity check */
75 long limit = atoi(parameter.c_str());
77 /* Wrap low values at 32768 */
81 parameter = ConvToStr(limit);
88 const UserMembList* names = channel->GetUsers();
89 for (UserMembCIter n = names->begin(); n != names->end(); ++n)
90 jointime.set(n->second, 0);
92 channel->SetModeParam('d', adding ? parameter : "");
93 return MODEACTION_ALLOW;
96 ModuleDelayMsg::~ModuleDelayMsg()
98 ServerInstance->Modes->DelMode(&djm);
101 Version ModuleDelayMsg::GetVersion()
103 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
106 void ModuleDelayMsg::OnUserJoin(User* user, Channel* channel, bool sync, bool &silent, bool created)
108 if (channel->IsModeSet('d'))
110 Membership* memb = channel->GetUser(user);
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)