anope

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

cs_status.cpp (3717B)

      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 CommandCSStatus : public Command
     15 {
     16 public:
     17 	CommandCSStatus(Module *creator) : Command(creator, "chanserv/status", 1, 2)
     18 	{
     19 		this->SetDesc(_("Find a user's status on a channel"));
     20 		this->SetSyntax(_("\037channel\037 [\037user\037]"));
     21 	}
     22 
     23 	void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
     24 	{
     25 		const Anope::string &channel = params[0];
     26 
     27 		ChannelInfo *ci = ChannelInfo::Find(channel);
     28 		if (ci == NULL)
     29 			source.Reply(CHAN_X_NOT_REGISTERED, channel.c_str());
     30 		else if (!source.AccessFor(ci).HasPriv("ACCESS_CHANGE") && !source.HasPriv("chanserv/auspex"))
     31 			source.Reply(ACCESS_DENIED);
     32 		else
     33 		{
     34 			Anope::string nick = source.GetNick();
     35 			if (params.size() > 1)
     36 				nick = params[1];
     37 
     38 			AccessGroup ag;
     39 			User *u = User::Find(nick, true);
     40 			NickAlias *na = NULL;
     41 			if (u != NULL)
     42 				ag = ci->AccessFor(u);
     43 			else
     44 			{
     45 				na = NickAlias::Find(nick);
     46 				if (na != NULL)
     47 					ag = ci->AccessFor(na->nc);
     48 			}
     49 
     50 			if (ag.super_admin)
     51 				source.Reply(_("\002%s\002 is a super administrator."), nick.c_str());
     52 			else if (ag.founder)
     53 				source.Reply(_("\002%s\002 is the founder of \002%s\002."), nick.c_str(), ci->name.c_str());
     54 			else  if (ag.empty())
     55 				source.Reply(_("\002%s\002 has no access on \002%s\002."), nick.c_str(), ci->name.c_str());
     56 			else
     57 			{
     58 				source.Reply(_("Access for \002%s\002 on \002%s\002:"), nick.c_str(), ci->name.c_str());
     59 
     60 				for (unsigned i = 0; i < ag.paths.size(); ++i)
     61 				{
     62 					ChanAccess::Path &p = ag.paths[i];
     63 
     64 					if (p.empty())
     65 						continue;
     66 
     67 					if (p.size() == 1)
     68 					{
     69 						ChanAccess *acc = p[0];
     70 
     71 						source.Reply(_("\002%s\002 matches access entry %s, which has privilege %s."), nick.c_str(), acc->Mask().c_str(), acc->AccessSerialize().c_str());
     72 					}
     73 					else
     74 					{
     75 						ChanAccess *first = p[0];
     76 						ChanAccess *acc = p[p.size() - 1];
     77 
     78 						source.Reply(_("\002%s\002 matches access entry %s (from entry %s), which has privilege %s."), nick.c_str(), acc->Mask().c_str(), first->Mask().c_str(), acc->AccessSerialize().c_str());
     79 					}
     80 				}
     81 			}
     82 
     83 			for (unsigned j = 0, end = ci->GetAkickCount(); j < end; ++j)
     84 			{
     85 				AutoKick *autokick = ci->GetAkick(j);
     86 
     87 				if (autokick->nc)
     88 				{
     89 					if (na && *autokick->nc == na->nc)
     90 						source.Reply(_("\002%s\002 is on the auto kick list of \002%s\002 (%s)."), na->nc->display.c_str(), ci->name.c_str(), autokick->reason.c_str());
     91 				}
     92 				else if (u != NULL)
     93 				{
     94 					Entry akick_mask("", autokick->mask);
     95 					if (akick_mask.Matches(u))
     96 						source.Reply(_("\002%s\002 matches auto kick entry %s on \002%s\002 (%s)."), u->nick.c_str(), autokick->mask.c_str(), ci->name.c_str(), autokick->reason.c_str());
     97 				}
     98 			}
     99 		}
    100 	}
    101 
    102 	bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
    103 	{
    104 		this->SendSyntax(source);
    105 		source.Reply(" ");
    106 		source.Reply(_("This command tells you what a users access is on a channel\n"
    107 				"and what access entries, if any, they match. Additionally it\n"
    108 				"will tell you of any auto kick entries they match. Usage of\n"
    109 				"this command is limited to users who have the ability to modify\n"
    110 				"access entries on the channel."));
    111 		return true;
    112 	}
    113 };
    114 
    115 class CSStatus : public Module
    116 {
    117 	CommandCSStatus commandcsstatus;
    118 
    119  public:
    120 	CSStatus(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), commandcsstatus(this)
    121 	{
    122 	}
    123 };
    124 
    125 MODULE_INIT(CSStatus)