anope

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

cs_register.cpp (4141B)

      1 /* ChanServ 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 CommandCSRegister : public Command
     15 {
     16  public:
     17 	CommandCSRegister(Module *creator) : Command(creator, "chanserv/register", 1, 2)
     18 	{
     19 		this->SetDesc(_("Register a channel"));
     20 		this->SetSyntax(_("\037channel\037 [\037description\037]"));
     21 	}
     22 
     23 	void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
     24 	{
     25 		const Anope::string &chan = params[0];
     26 		const Anope::string &chdesc = params.size() > 1 ? params[1] : "";
     27 		unsigned maxregistered = Config->GetModule("chanserv")->Get<unsigned>("maxregistered");
     28 
     29 		User *u = source.GetUser();
     30 		NickCore *nc = source.nc;
     31 		Channel *c = Channel::Find(params[0]);
     32 		ChannelInfo *ci = ChannelInfo::Find(params[0]);
     33 
     34 		if (Anope::ReadOnly)
     35 			source.Reply(_("Sorry, channel registration is temporarily disabled."));
     36 		else if (nc->HasExt("UNCONFIRMED"))
     37 			source.Reply(_("You must confirm your account before you can register a channel."));
     38 		else if (chan[0] == '&')
     39 			source.Reply(_("Local channels cannot be registered."));
     40 		else if (chan[0] != '#')
     41 			source.Reply(CHAN_SYMBOL_REQUIRED);
     42 		else if (!IRCD->IsChannelValid(chan))
     43 			source.Reply(CHAN_X_INVALID, chan.c_str());
     44 		else if (!c && u)
     45 			source.Reply(CHAN_X_NOT_IN_USE, chan.c_str());
     46 		else if (ci)
     47 			source.Reply(_("Channel \002%s\002 is already registered!"), chan.c_str());
     48 		else if (c && u && !c->HasUserStatus(u, "OP"))
     49 			source.Reply(_("You must be a channel operator to register the channel."));
     50 		else if (maxregistered && nc->channelcount >= maxregistered && !source.HasPriv("chanserv/no-register-limit"))
     51 			source.Reply(nc->channelcount > maxregistered ? CHAN_EXCEEDED_CHANNEL_LIMIT : CHAN_REACHED_CHANNEL_LIMIT, maxregistered);
     52 		else
     53 		{
     54 			ci = new ChannelInfo(chan);
     55 			ci->SetFounder(nc);
     56 			ci->desc = chdesc;
     57 
     58 			if (c && !c->topic.empty())
     59 			{
     60 				ci->last_topic = c->topic;
     61 				ci->last_topic_setter = c->topic_setter;
     62 				ci->last_topic_time = c->topic_time;
     63 			}
     64 			else
     65 				ci->last_topic_setter = source.service->nick;
     66 
     67 			Log(LOG_COMMAND, source, this, ci);
     68 			source.Reply(_("Channel \002%s\002 registered under your account: %s"), chan.c_str(), nc->display.c_str());
     69 
     70 			FOREACH_MOD(OnChanRegistered, (ci));
     71 
     72 			/* Implement new mode lock */
     73 			if (c)
     74 			{
     75 				c->CheckModes();
     76 				if (u)
     77 					c->SetCorrectModes(u, true);
     78 			}
     79 		}
     80 	}
     81 
     82 	bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
     83 	{
     84 		this->SendSyntax(source);
     85 		source.Reply(" ");
     86 		source.Reply(_("Registers a channel in the %s database.  In order\n"
     87 			"to use this command, you must first be a channel operator\n"
     88 			"on the channel you're trying to register.\n"
     89 			"The description, which is optional, is a\n"
     90 			"general description of the channel's purpose.\n"
     91 			" \n"
     92 			"When you register a channel, you are recorded as the\n"
     93 			"\"founder\" of the channel. The channel founder is allowed\n"
     94 			"to change all of the channel settings for the channel;\n"
     95 			"%s will also automatically give the founder\n"
     96 			"channel-operator privileges when s/he enters the channel."),
     97 				source.service->nick.c_str(), source.service->nick.c_str());
     98 		BotInfo *bi;
     99 		Anope::string cmd;
    100 		if (Command::FindCommandFromService("chanserv/access", bi, cmd))
    101 			source.Reply(_(" \n"
    102 				"See the \002%s\002 command (\002%s%s HELP ACCESS\002) for\n"
    103 				"information on giving a subset of these privileges to\n"
    104 				"other channel users.\n"), cmd.c_str(), Config->StrictPrivmsg.c_str(), bi->nick.c_str());
    105 		source.Reply(_(" \n"
    106 			"NOTICE: In order to register a channel, you must have\n"
    107 			"first registered your nickname."));
    108 		return true;
    109 	}
    110 };
    111 
    112 
    113 class CSRegister : public Module
    114 {
    115 	CommandCSRegister commandcsregister;
    116 
    117  public:
    118 	CSRegister(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
    119 		commandcsregister(this)
    120 	{
    121 	}
    122 };
    123 
    124 MODULE_INIT(CSRegister)