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 * ---------------------------------------------------
15 * Written for InspIRCd-1.2 by Taros on the Tel'Laerad M&D Team
16 * <http://tellaerad.net>
21 /* $ModConfig: <ojoin prefix="!" notice="yes" op="yes">
22 * Specify the prefix that +Y will grant here, it should be unused.
23 * Leave prefix empty if you do not wish +Y to grant a prefix
24 * If notice is set to on, upon ojoin, the server will notice
25 * the channel saying that the oper is joining on network business
26 * If op is set to on, it will give them +o along with +Y */
27 /* $ModDesc: Provides the /ojoin command, which joins a user to a channel on network business, and gives them +Y, which makes them immune to kick / deop and so on. */
28 /* $ModAuthor: Taros */
29 /* $ModAuthorMail: taros34@hotmail.com */
31 /* A note: This will not protect against kicks from services,
32 * ulines, or operoverride. */
34 #define NETWORK_VALUE 9000000
42 class CommandOjoin : public Command
46 CommandOjoin (InspIRCd* Instance, Module* parent) : Command(Instance,parent,"OJOIN", "o", 1, false, 0)
50 TRANSLATE3(TR_NICK, TR_TEXT, TR_END);
53 CmdResult Handle (const std::vector<std::string>& parameters, User *user)
55 // Make sure the channel name is allowable.
56 if (!ServerInstance->IsChannel(parameters[0].c_str(), ServerInstance->Config->Limits.ChanMax))
58 user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Invalid characters in channel name or name too long");
63 Channel* channel = Channel::JoinUser(ServerInstance, user, parameters[0].c_str(), false, "", false);
68 ServerInstance->SNO->WriteGlobalSno('a', std::string(user->nick)+" used OJOIN to join "+channel->name);
72 std::vector<std::string> modes;
73 modes.push_back(parameters[0]);
74 modes.push_back("+Y");
75 modes.push_back(user->nick);
76 ServerInstance->SendMode(modes, ServerInstance->FakeClient);
77 ServerInstance->PI->SendMode(channel->name, ServerInstance->Modes->GetLastParseParams(), ServerInstance->Modes->GetLastParseTranslate());
82 channel = ServerInstance->FindChan(parameters[0]);
83 channel->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s joined on official network business.",
84 parameters[0].c_str(), user->nick.c_str());
85 ServerInstance->PI->SendChannelNotice(channel, 0, std::string(user->nick) + " joined on official network business.");
92 user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Could not join "+parameters[0]);
97 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
99 return ROUTE_BROADCAST;
103 /** Abstraction of NetworkPrefixBase for channel mode +Y
105 class NetworkPrefix : public ModeHandler
108 NetworkPrefix(InspIRCd* Instance, Module* parent)
109 : ModeHandler(Instance, parent, 'Y', 1, 1, true, MODETYPE_CHANNEL, false, NPrefix, 0, TR_NICK)
110 // NetworkPrefixBase(Instance,"cm_network_","official user", 388, 389) { }
111 // NetworkPrefixBase(InspIRCd* Instance, const std::string &ext, const std::string &mtype, int l, int e) :
112 // extend(ext), type(mtype), list(l), end(e)
116 ModePair ModeSet(User* source, User* dest, Channel* channel, const std::string ¶meter)
118 User* x = ServerInstance->FindNick(parameter);
121 if (!channel->HasUser(x))
123 return std::make_pair(false, parameter);
127 std::string item = "cm_network_"+std::string(channel->name);
130 return std::make_pair(true, x->nick);
134 return std::make_pair(false, parameter);
138 return std::make_pair(false, parameter);
141 void RemoveMode(Channel* channel, irc::modestacker* stack)
143 CUList* cl = channel->GetUsers();
144 std::string item = "cm_network_" + std::string(channel->name);
145 std::vector<std::string> mode_junk;
146 mode_junk.push_back(channel->name);
147 irc::modestacker modestack(ServerInstance, false);
148 std::deque<std::string> stackresult;
150 for (CUList::iterator i = cl->begin(); i != cl->end(); i++)
152 if (i->first->GetExt(item))
155 stack->Push(this->GetModeChar(), i->first->nick);
157 modestack.Push(this->GetModeChar(), i->first->nick);
164 while (modestack.GetStackedLine(stackresult))
166 mode_junk.insert(mode_junk.end(), stackresult.begin(), stackresult.end());
167 ServerInstance->SendMode(mode_junk, ServerInstance->FakeClient);
168 mode_junk.erase(mode_junk.begin() + 1, mode_junk.end());
172 User* FindAndVerify(std::string ¶meter, Channel* channel)
174 User* theuser = ServerInstance->FindNick(parameter);
175 if ((!theuser) || (!channel->HasUser(theuser)))
183 ModeAction HandleChange(User* source, User* theuser, bool adding, Channel* channel, std::string ¶meter)
185 std::string item = "cm_network_" + std::string(channel->name);
189 if (!theuser->GetExt(item))
191 theuser->Extend(item);
192 parameter = theuser->nick;
193 return MODEACTION_ALLOW;
198 if (theuser->GetExt(item))
200 theuser->Shrink(item);
201 parameter = theuser->nick;
202 return MODEACTION_ALLOW;
205 return MODEACTION_DENY;
208 unsigned int GetPrefixRank()
210 return NETWORK_VALUE;
213 void RemoveMode(User* user, irc::modestacker* stack)
217 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
219 User* theuser = FindAndVerify(parameter, channel);
222 return MODEACTION_DENY;
224 // source is a server, or ulined, we'll let them +-Y the user.
225 if (source == ServerInstance->FakeClient ||
226 ((source == theuser) && (!adding)) ||
227 (ServerInstance->ULine(source->nick.c_str())) ||
228 (ServerInstance->ULine(source->server)) ||
229 (!*source->server) ||
233 return HandleChange(source, theuser, adding, channel, parameter);
237 // bzzzt, wrong answer!
238 source->WriteNumeric(482, "%s %s :Only servers may change this mode.", source->nick.c_str(), channel->name.c_str());
239 return MODEACTION_DENY;
245 class ModuleOjoin : public Module
248 CommandOjoin mycommand;
252 ModuleOjoin(InspIRCd* Me)
253 : Module(Me), np(NULL), mycommand(Me, this)
255 /* Load config stuff */
258 /* Initialise module variables */
259 np = new NetworkPrefix(ServerInstance, this);
261 if (!ServerInstance->Modes->AddMode(np))
264 throw ModuleException("Could not add new mode!");
267 ServerInstance->AddCommand(&mycommand);
269 Implementation eventlist[] = { I_OnUserPreJoin, I_OnUserKick, I_OnUserPart, I_OnAccessCheck, I_OnRehash };
270 ServerInstance->Modules->Attach(eventlist, this, 5);
273 ModResult OnUserPreJoin(User *user, Channel *chan, const char *cname, std::string &privs, const std::string &keygiven)
275 if (mycommand.active)
279 if (op && privs.find('@') == std::string::npos)
281 return MOD_RES_ALLOW;
284 return MOD_RES_PASSTHRU;
287 void OnUserKick(User* source, User* user, Channel* chan, const std::string &reason, bool &silent)
289 user->Shrink("cm_network_"+std::string(chan->name));
292 void OnUserPart(User* user, Channel* channel, std::string &partreason, bool &silent)
294 user->Shrink("cm_network_"+std::string(channel->name));
297 void OnRehash(User* user)
299 ConfigReader Conf(ServerInstance);
303 // This is done on module load only
304 std::string npre = Conf.ReadValue("ojoin", "prefix", 0);
305 NPrefix = npre.empty() ? 0 : npre[0];
307 if (NPrefix && ServerInstance->Modes->FindPrefix(NPrefix))
308 throw ModuleException("Looks like the +Y prefix you picked for m_ojoin is already in use. Pick another.");
311 notice = Conf.ReadFlag("ojoin", "notice", "yes", 0);
312 op = Conf.ReadFlag("ojoin", "op", "yes", 0);
315 ModResult OnAccessCheck(User* source,User* dest,Channel* channel,int access_type)
317 // Here's where we preform access checks, and disallow any kicking/deopping
320 // If there's no dest, it's not for us.
321 if (!dest || !channel)
322 return MOD_RES_PASSTHRU;
324 // If a ulined nickname, or a server is setting the mode, let it
325 // do whatever it wants.
326 if ((ServerInstance->ULine(source->nick.c_str())) || (ServerInstance->ULine(source->server)) || (!*source->server))
327 return MOD_RES_ALLOW;
329 std::string network("cm_network_"+channel->name);
331 // Don't do anything if they're not +Y
332 if (!dest->GetExt(network))
333 return MOD_RES_PASSTHRU;
335 // Let them do whatever they want to themselves.
337 return MOD_RES_PASSTHRU;
341 // Disallow deopping of +Y users.
343 source->WriteNumeric(484, source->nick+" "+channel->name+" :Can't deop "+dest->nick+" as they're on official network business.");
347 // Kicking people who are here on network business is a no no.
349 source->WriteNumeric(484, source->nick+" "+channel->name+" :Can't kick "+dest->nick+" as they're on official network business.");
353 // Yes, they're immune to dehalfopping too.
355 source->WriteNumeric(484, source->nick+" "+channel->name+" :Can't de-halfop "+dest->nick+" as they're on official network business.");
359 // same with devoice.
361 source->WriteNumeric(484, source->nick+" "+channel->name+" :Can't devoice "+dest->nick+" as they're on official network business.");
366 // Some other access check that doesn't fall into the above. Let it through.
367 return MOD_RES_PASSTHRU;
372 ServerInstance->Modes->DelMode(np);
378 ServerInstance->Modules->SetPriority(this, I_OnUserPreJoin, PRIORITY_FIRST);
383 return Version("Network Buisness Join", VF_COMMON | VF_VENDOR);
387 MODULE_INIT(ModuleOjoin)