Anope IRC Services  Version 2.0
cs_register.cpp
Go to the documentation of this file.
1 /* ChanServ core functions
2  *
3  * (C) 2003-2014 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 && !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;
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  /* Implement new mode lock */
71  if (c)
72  {
73  c->CheckModes();
74  if (u)
75  c->SetCorrectModes(u, true);
76  }
77 
78  FOREACH_MOD(OnChanRegistered, (ci));
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 {
116 
117  public:
118  CSRegister(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
119  commandcsregister(this)
120  {
121  }
122 };
123 
Definition: bots.h:24
#define CHAN_X_INVALID
Definition: language.h:102
CoreExport bool ReadOnly
Definition: main.cpp:28
CommandCSRegister(Module *creator)
Definition: cs_register.cpp:17
#define CHAN_REACHED_CHANNEL_LIMIT
Definition: language.h:103
Definition: hashcomp.h:84
CommandCSRegister commandcsregister
#define CHAN_X_NOT_IN_USE
Definition: language.h:85
Anope::string desc
Definition: regchannel.h:64
static bool FindCommandFromService(const Anope::string &command_service, BotInfo *&bi, Anope::string &name)
Definition: command.cpp:287
time_t last_topic_time
Definition: regchannel.h:71
Definition: users.h:34
Anope::string topic_setter
Definition: channels.h:61
void SetDesc(const Anope::string &d)
Definition: command.cpp:130
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
Definition: cs_register.cpp:82
uint16_t channelcount
Definition: account.h:136
Anope::string topic
Definition: channels.h:59
bool HasUserStatus(User *u, ChannelModeStatus *cms)
Definition: channels.cpp:181
#define FOREACH_MOD(ename, args)
Definition: modules.h:62
static ChannelInfo * Find(const Anope::string &name)
Definition: regchannel.cpp:630
void CheckModes()
Definition: channels.cpp:105
Definition: Config.cs:26
CSRegister(const Anope::string &modname, const Anope::string &creator)
Anope::string display
Definition: account.h:113
void SetFounder(NickCore *nc)
Definition: regchannel.cpp:347
#define anope_override
Definition: services.h:56
bool empty() const
Definition: anope.h:126
Anope::string last_topic_setter
Definition: regchannel.h:70
void SetCorrectModes(User *u, bool give_modes)
Definition: channels.cpp:816
time_t topic_time
Definition: channels.h:68
CoreExport IRCDProto * IRCD
Definition: protocol.cpp:23
#define MODULE_INIT(x)
Definition: modules.h:45
void SetSyntax(const Anope::string &s)
Definition: command.cpp:140
Anope::string last_topic
Definition: regchannel.h:69
#define CHAN_EXCEEDED_CHANNEL_LIMIT
Definition: language.h:104
Anope::string nick
Definition: users.h:62
virtual bool IsChannelValid(const Anope::string &)
Definition: protocol.cpp:372
static Channel * Find(const Anope::string &name)
Definition: channels.cpp:920
void SendSyntax(CommandSource &)
Definition: command.cpp:145
const char * c_str() const
Definition: anope.h:117
Definition: logger.h:53
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: cs_register.cpp:23
#define _(x)
Definition: services.h:50
bool HasExt(const Anope::string &name) const
Definition: extensible.cpp:31
#define CHAN_SYMBOL_REQUIRED
Definition: language.h:105