1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 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(Module* parent) : Command(parent,"OJOIN", 1)
48 flags_needed = 'o'; Penalty = 0; syntax = "<channel>";
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(user, parameters[0].c_str(), false, "", false);
68 ServerInstance->SNO->WriteGlobalSno('a', std::string(user->nick)+" used OJOIN to join "+channel->name);
72 channel = ServerInstance->FindChan(parameters[0]);
73 channel->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "NOTICE %s :%s joined on official network business.",
74 parameters[0].c_str(), user->nick.c_str());
75 ServerInstance->PI->SendChannelNotice(channel, 0, std::string(user->nick) + " joined on official network business.");
80 ServerInstance->SNO->WriteGlobalSno('a', std::string(user->nick)+" used OJOIN in "+parameters[0]);
81 // they're already in the channel
82 std::vector<std::string> modes;
83 modes.push_back(parameters[0]);
84 modes.push_back("+Y");
85 modes.push_back(user->nick);
86 ServerInstance->SendGlobalMode(modes, ServerInstance->FakeClient);
94 class NetworkPrefix : public ModeHandler
97 NetworkPrefix(Module* parent) : ModeHandler(parent, "official-join", 'Y', PARAM_ALWAYS, MODETYPE_CHANNEL)
101 levelrequired = INT_MAX;
102 m_paramtype = TR_NICK;
105 void RemoveMode(Channel* channel, irc::modestacker* stack)
107 const UserMembList* cl = channel->GetUsers();
108 std::vector<std::string> mode_junk;
109 mode_junk.push_back(channel->name);
110 irc::modestacker modestack(false);
111 std::deque<std::string> stackresult;
113 for (UserMembCIter i = cl->begin(); i != cl->end(); i++)
115 if (i->second->hasMode('Y'))
118 stack->Push(this->GetModeChar(), i->first->nick);
120 modestack.Push(this->GetModeChar(), i->first->nick);
127 while (modestack.GetStackedLine(stackresult))
129 mode_junk.insert(mode_junk.end(), stackresult.begin(), stackresult.end());
130 ServerInstance->SendMode(mode_junk, ServerInstance->FakeClient);
131 mode_junk.erase(mode_junk.begin() + 1, mode_junk.end());
135 unsigned int GetPrefixRank()
137 return NETWORK_VALUE;
140 void RemoveMode(User* user, irc::modestacker* stack)
144 ModResult AccessCheck(User* source, Channel* channel, std::string ¶meter, bool adding)
146 User* theuser = ServerInstance->FindNick(parameter);
148 if (source == theuser && !adding)
149 return MOD_RES_ALLOW;
151 return MOD_RES_PASSTHRU;
154 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
156 return MODEACTION_ALLOW;
161 class ModuleOjoin : public Module
164 CommandOjoin mycommand;
169 : np(NULL), mycommand(this)
175 /* Load config stuff */
178 /* Initialise module variables */
179 np = new NetworkPrefix(this);
181 ServerInstance->Modules->AddService(*np);
182 ServerInstance->Modules->AddService(mycommand);
184 Implementation eventlist[] = { I_OnUserPreJoin, I_OnUserPreKick, I_OnRehash };
185 ServerInstance->Modules->Attach(eventlist, this, 3);
188 ModResult OnUserPreJoin(User *user, Channel *chan, const char *cname, std::string &privs, const std::string &keygiven)
190 if (mycommand.active)
195 return MOD_RES_ALLOW;
198 return MOD_RES_PASSTHRU;
201 void OnRehash(User* user)
203 ConfigTag* Conf = ServerInstance->Config->ConfValue("ojoin");
207 // This is done on module load only
208 std::string npre = Conf->getString("prefix");
209 NPrefix = npre.empty() ? 0 : npre[0];
211 if (NPrefix && ServerInstance->Modes->FindPrefix(NPrefix))
212 throw ModuleException("Looks like the +Y prefix you picked for m_ojoin is already in use. Pick another.");
215 notice = Conf->getBool("notice", true);
216 op = Conf->getBool("op", true);
219 ModResult OnUserPreKick(User* source, Membership* memb, const std::string &reason)
221 // Don't do anything if they're not +Y
222 if (!memb->hasMode('Y'))
223 return MOD_RES_PASSTHRU;
225 // Let them do whatever they want to themselves.
226 if (source == memb->user)
227 return MOD_RES_PASSTHRU;
229 source->WriteNumeric(484, source->nick+" "+memb->chan->name+" :Can't kick "+memb->user->nick+" as they're on official network business.");
240 ServerInstance->Modules->SetPriority(this, I_OnUserPreJoin, PRIORITY_FIRST);
245 return Version("Network Buisness Join", VF_VENDOR);
249 MODULE_INIT(ModuleOjoin)