Anope IRC Services  Version 2.0
cs_sync.cpp
Go to the documentation of this file.
1 /*
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 CommandCSSync : public Command
15 {
16  public:
17  CommandCSSync(Module *creator) : Command(creator, "chanserv/sync", 1, 1)
18  {
19  this->SetDesc(_("Sync users channel modes"));
20  this->SetSyntax(_("\037channel\037"));
21  }
22 
23  void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
24  {
25  ChannelInfo *ci = ChannelInfo::Find(params[0]);
26 
27  if (ci == NULL)
28  source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str());
29  else if (ci->c == NULL)
30  source.Reply(CHAN_X_NOT_IN_USE, params[0].c_str());
31  else if (!source.AccessFor(ci).HasPriv("ACCESS_CHANGE") && !source.HasPriv("chanserv/administration"))
32  source.Reply(ACCESS_DENIED);
33  else
34  {
35  bool override = !source.AccessFor(ci).HasPriv("ACCESS_CHANGE") && source.HasPriv("chanserv/administration");
36  Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci);
37 
38  for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it)
39  ci->c->SetCorrectModes(it->second->user, true);
40 
41  source.Reply(_("All user modes on \002%s\002 have been synced."), ci->name.c_str());
42  }
43  }
44 
45  bool OnHelp(CommandSource &source, const Anope::string &params) anope_override
46  {
47  this->SendSyntax(source);
48  source.Reply(" ");
49  source.Reply(_("Syncs all modes set on users on the channel with the modes\n"
50  "they should have based on their access."));
51  return true;
52  }
53 };
54 
55 class CSSync : public Module
56 {
58  public:
59  CSSync(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
60  commandcssync(this)
61  {
62 
63  }
64 };
65 
CommandCSSync commandcssync
Definition: cs_sync.cpp:57
Definition: hashcomp.h:84
Anope::string name
Definition: regchannel.h:63
#define CHAN_X_NOT_IN_USE
Definition: language.h:85
#define ACCESS_DENIED
Definition: language.h:73
void Execute(CommandSource &source, const std::vector< Anope::string > &params) anope_override
Definition: cs_sync.cpp:23
void SetDesc(const Anope::string &d)
Definition: command.cpp:130
CSSync(const Anope::string &modname, const Anope::string &creator)
Definition: cs_sync.cpp:59
static ChannelInfo * Find(const Anope::string &name)
Definition: regchannel.cpp:630
Channel * c
Definition: regchannel.h:79
CommandCSSync(Module *creator)
Definition: cs_sync.cpp:17
#define anope_override
Definition: services.h:56
void SetCorrectModes(User *u, bool give_modes)
Definition: channels.cpp:816
#define MODULE_INIT(x)
Definition: modules.h:45
ChanUserList users
Definition: channels.h:56
void SetSyntax(const Anope::string &s)
Definition: command.cpp:140
#define CHAN_X_NOT_REGISTERED
Definition: language.h:84
void SendSyntax(CommandSource &)
Definition: command.cpp:145
const char * c_str() const
Definition: anope.h:117
Definition: logger.h:53
#define _(x)
Definition: services.h:50
bool OnHelp(CommandSource &source, const Anope::string &params) anope_override
Definition: cs_sync.cpp:45