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 class DelayMsgMode : public ModeHandler
23 DelayMsgMode(InspIRCd* Instance, Module* Parent) : ModeHandler(Instance, 'd', 1, 0, false, MODETYPE_CHANNEL, false, 0, '@'), Creator(Parent) {};
25 ModePair ModeSet(User*, User*, Channel* channel, const std::string ¶meter)
27 std::string climit = channel->GetModeParameter('d');
30 return std::make_pair(true, climit);
34 return std::make_pair(false, parameter);
38 bool CheckTimeStamp(std::string &their_param, const std::string &our_param, Channel*)
40 return (atoi(their_param.c_str()) < atoi(our_param.c_str()));
43 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool);
46 class ModuleDelayMsg : public Module
51 ModuleDelayMsg(InspIRCd* Me) : Module(Me), djm(Me, this)
53 if (!ServerInstance->Modes->AddMode(&djm))
54 throw ModuleException("Could not add new modes!");
55 Implementation eventlist[] = { I_OnUserJoin, I_OnUserPart, I_OnUserKick, I_OnCleanup, I_OnUserPreMessage};
56 ServerInstance->Modules->Attach(eventlist, this, 5);
58 virtual ~ModuleDelayMsg();
59 virtual Version GetVersion();
60 void OnUserJoin(User* user, Channel* channel, bool sync, bool &silent, bool created);
61 void OnUserPart(User* user, Channel* channel, std::string &partmessage, bool &silent);
62 void OnUserKick(User* source, User* user, Channel* chan, const std::string &reason, bool &silent);
63 void OnCleanup(int target_type, void* item);
64 int OnUserPreMessage(User* user, void* dest, int target_type, std::string &text, char status, CUList &exempt_list);
67 /* $ModDesc: Allows for delay-join channels (+D) where users dont appear to join until they speak */
69 ModeAction DelayMsgMode::OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
73 /* Setting a new limit, sanity check */
74 long limit = atoi(parameter.c_str());
76 /* Wrap low values at 32768 */
80 parameter = ConvToStr(limit);
87 CUList* names = channel->GetUsers();
88 for (CUListIter n = names->begin(); n != names->end(); ++n)
89 n->first->Shrink("delaymsg_" + channel->name);
91 channel->SetModeParam('d', adding ? parameter : "");
92 return MODEACTION_ALLOW;
95 ModuleDelayMsg::~ModuleDelayMsg()
97 ServerInstance->Modes->DelMode(&djm);
100 Version ModuleDelayMsg::GetVersion()
102 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
105 void ModuleDelayMsg::OnUserJoin(User* user, Channel* channel, bool sync, bool &silent, bool created)
107 if (channel->IsModeSet('d'))
108 user->Extend("delaymsg_"+channel->name, reinterpret_cast<char*>(ServerInstance->Time()));
111 void ModuleDelayMsg::OnUserPart(User* user, Channel* channel, std::string &partmessage, bool &silent)
113 user->Shrink("delaymsg_"+channel->name);
116 void ModuleDelayMsg::OnUserKick(User* source, User* user, Channel* chan, const std::string &reason, bool &silent)
118 user->Shrink("delaymsg_"+chan->name);
121 void ModuleDelayMsg::OnCleanup(int target_type, void* item)
123 if (target_type == TYPE_USER)
125 User* user = (User*)item;
126 for (UCListIter f = user->chans.begin(); f != user->chans.end(); f++)
128 Channel* chan = f->first;
129 user->Shrink("delaymsg_"+chan->name);
134 int ModuleDelayMsg::OnUserPreMessage(User* user, void* dest, int target_type, std::string &text, char status, CUList &exempt_list)
140 if (target_type != TYPE_CHANNEL)
143 Channel* channel = (Channel*) dest;
145 void* jointime_as_ptr;
147 if (!user->GetExt("delaymsg_"+channel->name, jointime_as_ptr))
150 time_t jointime = reinterpret_cast<time_t>(jointime_as_ptr);
152 std::string len = channel->GetModeParameter('d');
154 if (jointime + atoi(len.c_str()) > ServerInstance->Time())
156 if (channel->GetStatus(user) < STATUS_VOICE)
158 user->WriteNumeric(404, "%s %s :You must wait %s seconds after joining to send to channel (+d)",
159 user->nick.c_str(), channel->name.c_str(), len.c_str());
165 /* Timer has expired, we can stop checking now */
166 user->Shrink("delaymsg_"+channel->name);
171 MODULE_INIT(ModuleDelayMsg)