anope

- supernets anope source code & configuration
git clone git://git.acid.vegas/anope.git
Log | Files | Refs | Archive | README

os_svs.cpp (5663B)

      1 /* OperServ core functions
      2  *
      3  * (C) 2003-2022 Anope Team
      4  * Contact us at team@anope.org
      5  *
      6  * Please read COPYING and README for further details.
      7  *
      8  * Based on the original code of Epona by Lara.
      9  * Based on the original code of Services by Andy Church.
     10  */
     11 
     12 #include "module.h"
     13 
     14 class CommandOSSVSNick : public Command
     15 {
     16  public:
     17 	CommandOSSVSNick(Module *creator) : Command(creator, "operserv/svsnick", 2, 2)
     18 	{
     19 		this->SetDesc(_("Forcefully change a user's nickname"));
     20 		this->SetSyntax(_("\037nick\037 \037newnick\037"));
     21 	}
     22 
     23 	void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
     24 	{
     25 		const Anope::string &nick = params[0];
     26 		Anope::string newnick = params[1];
     27 		User *u2;
     28 
     29 		if (!IRCD->CanSVSNick)
     30 		{
     31 			source.Reply(_("Your IRCd does not support SVSNICK."));
     32 			return;
     33 		}
     34 
     35 		/* Truncate long nicknames to nicklen characters */
     36 		unsigned nicklen = Config->GetBlock("networkinfo")->Get<unsigned>("nicklen");
     37 		if (newnick.length() > nicklen)
     38 		{
     39 			source.Reply(_("Nick \002%s\002 was truncated to %d characters."), newnick.c_str(), nicklen, newnick.c_str());
     40 			newnick = params[1].substr(0, nicklen);
     41 		}
     42 
     43 		/* Check for valid characters */
     44 		if (!IRCD->IsNickValid(newnick))
     45 		{
     46 			source.Reply(_("Nick \002%s\002 is an illegal nickname and cannot be used."), newnick.c_str());
     47 			return;
     48 		}
     49 
     50 		/* Check for a nick in use or a forbidden/suspended nick */
     51 		if (!(u2 = User::Find(nick, true)))
     52 			source.Reply(NICK_X_NOT_IN_USE, nick.c_str());
     53 		else if (!nick.equals_ci(newnick) && User::Find(newnick))
     54 			source.Reply(_("Nick \002%s\002 is currently in use."), newnick.c_str());
     55 		else
     56 		{
     57 			source.Reply(_("The nick \002%s\002 is now being changed to \002%s\002."), nick.c_str(), newnick.c_str());
     58 			Log(LOG_ADMIN, source, this) << "to change " << nick << " to " << newnick;
     59 			IRCD->SendForceNickChange(u2, newnick, Anope::CurTime);
     60 		}
     61 		return;
     62 	}
     63 
     64 	bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
     65 	{
     66 		this->SendSyntax(source);
     67 		source.Reply(" ");
     68 		source.Reply(_("Forcefully changes a user's nickname from \037nick\037 to \037newnick\037."));
     69 		return true;
     70 	}
     71 };
     72 
     73 class CommandOSSVSJoin : public Command
     74 {
     75  public:
     76 	CommandOSSVSJoin(Module *creator) : Command(creator, "operserv/svsjoin", 2, 2)
     77 	{
     78 		this->SetDesc(_("Forcefully join a user to a channel"));
     79 		this->SetSyntax(_("\037nick\037 \037channel\037"));
     80 	}
     81 
     82 	void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
     83 	{
     84 		if (!IRCD->CanSVSJoin)
     85 		{
     86 			source.Reply(_("Your IRCd does not support SVSJOIN."));
     87 			return;
     88 		}
     89 
     90 		User *target = User::Find(params[0], true);
     91 		Channel *c = Channel::Find(params[1]);
     92 		if (target == NULL)
     93 			source.Reply(NICK_X_NOT_IN_USE, params[0].c_str());
     94 		else if (source.GetUser() != target && (target->IsProtected() || target->server == Me))
     95 			source.Reply(ACCESS_DENIED);
     96 		else if (!IRCD->IsChannelValid(params[1]))
     97 			source.Reply(CHAN_X_INVALID, params[1].c_str());
     98 		else if (c && c->FindUser(target))
     99 			source.Reply(_("\002%s\002 is already in \002%s\002."), target->nick.c_str(), c->name.c_str());
    100 		else
    101 		{
    102 			IRCD->SendSVSJoin(*source.service, target, params[1], "");
    103 			Log(LOG_ADMIN, source, this) << "to force " << target->nick << " to join " << params[1];
    104 			source.Reply(_("\002%s\002 has been joined to \002%s\002."), target->nick.c_str(), params[1].c_str());
    105 		}
    106 	}
    107 
    108 	bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
    109 	{
    110 		this->SendSyntax(source);
    111 		source.Reply(" ");
    112 		source.Reply(_("Forcefully join a user to a channel."));
    113 		return true;
    114 	}
    115 };
    116 
    117 class CommandOSSVSPart : public Command
    118 {
    119  public:
    120 	CommandOSSVSPart(Module *creator) : Command(creator, "operserv/svspart", 2, 3)
    121 	{
    122 		this->SetDesc(_("Forcefully part a user from a channel"));
    123 		this->SetSyntax(_("\037nick\037 \037channel\037 [\037reason\037]"));
    124 	}
    125 
    126 	void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
    127 	{
    128 		if (!IRCD->CanSVSJoin)
    129 		{
    130 			source.Reply(_("Your IRCd does not support SVSPART."));
    131 			return;
    132 		}
    133 
    134 		User *target = User::Find(params[0], true);
    135 		Channel *c = Channel::Find(params[1]);
    136 		const Anope::string &reason = params.size() > 2 ? params[2] : "";
    137 		if (target == NULL)
    138 			source.Reply(NICK_X_NOT_IN_USE, params[0].c_str());
    139 		else if (source.GetUser() != target && (target->IsProtected() || target->server == Me))
    140 			source.Reply(ACCESS_DENIED);
    141 		else if (!c)
    142 			source.Reply(CHAN_X_NOT_IN_USE, params[1].c_str());
    143 		else if (!c->FindUser(target))
    144 			source.Reply(_("\002%s\002 is not in \002%s\002."), target->nick.c_str(), c->name.c_str());
    145 		else
    146 		{
    147 			IRCD->SendSVSPart(*source.service, target, params[1], reason);
    148 			if (!reason.empty())
    149 				Log(LOG_ADMIN, source, this) << "to force " << target->nick << " to part " << c->name << " with reason " << reason;
    150 			else
    151 				Log(LOG_ADMIN, source, this) << "to force " << target->nick << " to part " << c->name;
    152 			source.Reply(_("\002%s\002 has been parted from \002%s\002."), target->nick.c_str(), c->name.c_str());
    153 		}
    154 	}
    155 
    156 	bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
    157 	{
    158 		this->SendSyntax(source);
    159 		source.Reply(" ");
    160 		source.Reply(_("Forcefully part a user from a channel."));
    161 		return true;
    162 	}
    163 };
    164 
    165 class OSSVS : public Module
    166 {
    167 	CommandOSSVSNick commandossvsnick;
    168 	CommandOSSVSJoin commandossvsjoin;
    169 	CommandOSSVSPart commandossvspart;
    170 
    171  public:
    172 	OSSVS(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
    173 		commandossvsnick(this), commandossvsjoin(this), commandossvspart(this)
    174 	{
    175 	}
    176 };
    177 
    178 MODULE_INIT(OSSVS)