1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 /* $ModDesc: Provides channel mode +L (limit redirection) */
18 /** Handle channel mode +L
20 class Redirect : public ModeHandler
23 Redirect(InspIRCd* Instance) : ModeHandler(Instance, 'L', 1, 0, false, MODETYPE_CHANNEL, false) { }
25 ModePair ModeSet(User* source, User* dest, Channel* channel, const std::string ¶meter)
27 if (channel->IsModeSet('L'))
28 return std::make_pair(true, channel->GetModeParameter('L'));
30 return std::make_pair(false, parameter);
33 bool CheckTimeStamp(time_t theirs, time_t ours, const std::string &their_param, const std::string &our_param, Channel* channel)
35 /* When TS is equal, the alphabetically later one wins */
36 return (their_param < our_param);
39 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
45 if (!ServerInstance->IsChannel(parameter.c_str()))
47 source->WriteServ("403 %s %s :Invalid channel name",source->nick, parameter.c_str());
49 return MODEACTION_DENY;
52 c = ServerInstance->FindChan(parameter);
55 /* Fix by brain: Dont let a channel be linked to *itself* either */
58 if ((c == channel) || (c->IsModeSet('L')))
60 source->WriteServ("690 %s :Circular or chained +L to %s not allowed (Channel already has +L). Pack of wild dogs has been unleashed.",source->nick,parameter.c_str());
62 return MODEACTION_DENY;
66 for (chan_hash::const_iterator i = ServerInstance->chanlist->begin(); i != ServerInstance->chanlist->end(); i++)
68 if ((i->second != channel) && (i->second->IsModeSet('L')) && (irc::string(i->second->GetModeParameter('L').c_str()) == irc::string(channel->name)))
70 source->WriteServ("690 %s :Circular or chained +L to %s not allowed (Already forwarded here from %s). Angry monkeys dispatched.",source->nick,parameter.c_str(),i->second->name);
71 return MODEACTION_DENY;
78 channel->SetMode('L', true);
79 channel->SetModeParam('L', parameter.c_str(), true);
80 return MODEACTION_ALLOW;
84 if (channel->IsModeSet('L'))
86 channel->SetMode('L', false);
87 return MODEACTION_ALLOW;
91 return MODEACTION_DENY;
96 class ModuleRedirect : public Module
103 ModuleRedirect(InspIRCd* Me)
107 re = new Redirect(ServerInstance);
108 if (!ServerInstance->Modes->AddMode(re))
109 throw ModuleException("Could not add new modes!");
110 Implementation eventlist[] = { I_OnUserPreJoin };
111 ServerInstance->Modules->Attach(eventlist, this, 1);
115 virtual int OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs)
119 if (chan->IsModeSet('L') && chan->limit)
121 if (chan->GetUserCounter() >= chan->limit)
123 std::string channel = chan->GetModeParameter('L');
125 /* sometimes broken ulines can make circular or chained +L, avoid this */
126 Channel* destchan = NULL;
127 destchan = ServerInstance->FindChan(channel);
128 if (destchan && destchan->IsModeSet('L'))
130 user->WriteServ("470 %s :%s is full, but has a circular redirect (+L), not following redirection to %s", user->nick, cname, channel.c_str());
134 user->WriteServ("470 %s :%s has become full, so you are automatically being transferred to the linked channel %s", user->nick, cname, channel.c_str());
135 Channel::JoinUser(ServerInstance, user, channel.c_str(), false, "", false, ServerInstance->Time(true));
143 virtual ~ModuleRedirect()
145 ServerInstance->Modes->DelMode(re);
149 virtual Version GetVersion()
151 return Version(1, 1, 0, 0, VF_COMMON | VF_VENDOR, API_VERSION);
155 MODULE_INIT(ModuleRedirect)