]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_check.cpp
Sync helpop chmodes s and p with docs
[user/henk/code/inspircd.git] / src / modules / m_check.cpp
index 65cccec5b8d1a8f5f7405f0069836ef92b84c9c0..714f0bddd86b073575231226c417396d1d20577d 100644 (file)
@@ -1,10 +1,15 @@
 /*
  * InspIRCd -- Internet Relay Chat Daemon
  *
+ *   Copyright (C) 2020 Matt Schatz <genius3000@g3k.solutions>
+ *   Copyright (C) 2013-2016 Attila Molnar <attilamolnar@hush.com>
+ *   Copyright (C) 2013, 2017-2021 Sadie Powell <sadie@witchery.services>
+ *   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
+ *   Copyright (C) 2010 Craig Edwards <brain@inspircd.org>
  *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
+ *   Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
- *   Copyright (C) 2006-2007 Robin Burchell <robin+git@viroteck.net>
- *   Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
+ *   Copyright (C) 2006-2008 Robin Burchell <robin+git@viroteck.net>
  *
  * This file is part of InspIRCd.  InspIRCd is free software: you can
  * redistribute it and/or modify it under the terms of the GNU General Public
@@ -67,16 +72,21 @@ class CheckContext
 
        User* GetUser() const { return user; }
 
-       void DumpListMode(const ListModeBase::ModeList* list)
+       void DumpListMode(ListModeBase* mode, Channel* chan)
        {
+               const ListModeBase::ModeList* list = mode->GetList(chan);
                if (!list)
                        return;
 
-               CheckContext::List modelist(*this, "modelist");
                for (ListModeBase::ModeList::const_iterator i = list->begin(); i != list->end(); ++i)
-                       modelist.Add(i->mask);
-
-               modelist.Flush();
+               {
+                       CheckContext::List listmode(*this, "listmode");
+                       listmode.Add(ConvToStr(mode->GetModeChar()));
+                       listmode.Add(i->mask);
+                       listmode.Add(i->setter);
+                       listmode.Add(FormatTime(i->time));
+                       listmode.Flush();
+               }
        }
 
        void DumpExt(Extensible* ext)
@@ -85,7 +95,7 @@ class CheckContext
                for(Extensible::ExtensibleStore::const_iterator i = ext->GetExtList().begin(); i != ext->GetExtList().end(); ++i)
                {
                        ExtensionItem* item = i->first;
-                       std::string value = item->serialize(FORMAT_USER, ext, i->second);
+                       std::string value = item->ToHuman(ext, i->second);
                        if (!value.empty())
                                Write("meta:" + item->name, value);
                        else if (!item->name.empty())
@@ -136,12 +146,22 @@ class CommandCheck : public Command
                return ret;
        }
 
+       static std::string GetAllowedOperOnlySnomasks(LocalUser* user)
+       {
+               std::string ret;
+               for (unsigned char sno = 'A'; sno <= 'z'; ++sno)
+                       if (ServerInstance->SNO->IsSnomaskUsable(sno) && user->HasSnomaskPermission(sno))
+                               ret.push_back(sno);
+               return ret;
+       }
+
  public:
        CommandCheck(Module* parent)
                : Command(parent,"CHECK", 1)
                , snomaskmode(parent, "snomask")
        {
-               flags_needed = 'o'; syntax = "<nickname>|<ip>|<hostmask>|<channel> <server>";
+               flags_needed = 'o';
+               syntax = "<nick>|<ipmask>|<hostmask>|<channel> [<servername>]";
        }
 
        CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
@@ -151,7 +171,6 @@ class CommandCheck : public Command
 
                User *targuser;
                Channel *targchan;
-               std::string chliststr;
 
                targuser = ServerInstance->FindNick(parameters[0]);
                targchan = ServerInstance->FindChan(parameters[0]);
@@ -198,6 +217,7 @@ class CommandCheck : public Command
                                {
                                        context.Write("chanmodeperms", GetAllowedOperOnlyModes(loctarg, MODETYPE_CHANNEL));
                                        context.Write("usermodeperms", GetAllowedOperOnlyModes(loctarg, MODETYPE_USER));
+                                       context.Write("snomaskperms", GetAllowedOperOnlySnomasks(loctarg));
                                        context.Write("commandperms", oper->AllowedOperCommands.ToString());
                                        context.Write("permissions", oper->AllowedPrivs.ToString());
                                }
@@ -211,6 +231,8 @@ class CommandCheck : public Command
                                std::string classname = loctarg->GetClass()->name;
                                if (!classname.empty())
                                        context.Write("connectclass", classname);
+
+                               context.Write("exempt", loctarg->exempt ? "yes" : "no");
                        }
                        else
                                context.Write("onip", targuser->GetIPString());
@@ -219,13 +241,7 @@ class CommandCheck : public Command
                        for (User::ChanList::iterator i = targuser->chans.begin(); i != targuser->chans.end(); i++)
                        {
                                Membership* memb = *i;
-                               Channel* c = memb->chan;
-                               char prefix = memb->GetPrefixChar();
-                               if (prefix)
-                                       chliststr.push_back(prefix);
-                               chliststr.append(c->name);
-                               chanlist.Add(chliststr);
-                               chliststr.clear();
+                               chanlist.Add(memb->GetAllPrefixChars() + memb->chan->name);
                        }
 
                        chanlist.Flush();
@@ -256,8 +272,8 @@ class CommandCheck : public Command
                        for (Channel::MemberMap::const_iterator i = ulist.begin(); i != ulist.end(); ++i)
                        {
                                /*
-                                * Unlike Asuka, I define a clone as coming from the same host. --w00t
-                                */
+                                * Unlike Asuka, I define a clone as coming from the same host. --w00t
+                                */
                                const UserManager::CloneCounts& clonecount = ServerInstance->Users->GetCloneCounts(i->first);
                                context.Write("member", InspIRCd::Format("%u %s%s (%s)", clonecount.global,
                                        i->second->GetAllPrefixChars().c_str(), i->first->GetFullHost().c_str(),
@@ -266,7 +282,7 @@ class CommandCheck : public Command
 
                        const ModeParser::ListModeList& listmodes = ServerInstance->Modes->GetListModes();
                        for (ModeParser::ListModeList::const_iterator i = listmodes.begin(); i != listmodes.end(); ++i)
-                               context.DumpListMode((*i)->GetList(targchan));
+                               context.DumpListMode(*i, targchan);
 
                        context.DumpExt(targchan);
                }
@@ -317,7 +333,7 @@ class ModuleCheck : public Module
 
        Version GetVersion() CXX11_OVERRIDE
        {
-               return Version("CHECK command, view user, channel, IP address or hostname information", VF_VENDOR|VF_OPTCOMMON);
+               return Version("Adds the /CHECK command which allows server operators to look up details about a channel, user, IP address, or hostname.", VF_VENDOR|VF_OPTCOMMON);
        }
 };