]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_check.cpp
Rewrite clone counting to use one map instead of two
[user/henk/code/inspircd.git] / src / modules / m_check.cpp
index fda211cf80eb03061972ab36471cd3a51817439a..ad0e2394d45864497bf6c308ef3e71154b0b884f 100644 (file)
@@ -20,8 +20,6 @@
  */
 
 
-/* $ModDesc: Provides the /CHECK command to retrieve information on a user, channel, hostname or IP address */
-
 #include "inspircd.h"
 #include "listmode.h"
 
  */
 class CommandCheck : public Command
 {
-       ModeReference ban;
+       UserModeReference snomaskmode;
+
+       std::string GetSnomasks(User* user)
+       {
+               std::string ret;
+               if (snomaskmode)
+                       ret = snomaskmode->GetUserParameter(user);
+
+               if (ret.empty())
+                       ret = "+";
+               return ret;
+       }
+
+       static void dumpListMode(User* user, const std::string& checkstr, const ListModeBase::ModeList* list)
+       {
+               if (!list)
+                       return;
+
+               std::string buf = checkstr + " modelist";
+               const std::string::size_type headlen = buf.length();
+               const size_t maxline = ServerInstance->Config->Limits.MaxLine;
+               for (ListModeBase::ModeList::const_iterator i = list->begin(); i != list->end(); ++i)
+               {
+                       if (buf.size() + i->mask.size() + 1 > maxline)
+                       {
+                               user->SendText(buf);
+                               buf.erase(headlen);
+                       }
+                       buf.append(" ").append(i->mask);
+               }
+               if (buf.length() > headlen)
+                       user->SendText(buf);
+       }
+
  public:
        CommandCheck(Module* parent)
                : Command(parent,"CHECK", 1)
-               , ban(parent, "ban")
+               , snomaskmode(parent, "snomask")
        {
                flags_needed = 'o'; syntax = "<nickname>|<ip>|<hostmask>|<channel> <server>";
        }
@@ -94,8 +125,8 @@ class CommandCheck : public Command
                        user->SendText(checkstr + " realnuh " + targuser->GetFullRealHost());
                        user->SendText(checkstr + " realname " + targuser->fullname);
                        user->SendText(checkstr + " modes +" + targuser->FormatModes());
-                       user->SendText(checkstr + " snomasks +" + targuser->FormatNoticeMasks());
-                       user->SendText(checkstr + " server " + targuser->server);
+                       user->SendText(checkstr + " snomasks " + GetSnomasks(targuser));
+                       user->SendText(checkstr + " server " + targuser->server->GetName());
                        user->SendText(checkstr + " uid " + targuser->uuid);
                        user->SendText(checkstr + " signon " + timestring(targuser->signon));
                        user->SendText(checkstr + " nickts " + timestring(targuser->age));
@@ -149,8 +180,8 @@ class CommandCheck : public Command
 
                        if (loctarg)
                        {
-                               user->SendText(checkstr + " clientaddr " + irc::sockets::satouser(loctarg->client_sa));
-                               user->SendText(checkstr + " serveraddr " + irc::sockets::satouser(loctarg->server_sa));
+                               user->SendText(checkstr + " clientaddr " + loctarg->client_sa.str());
+                               user->SendText(checkstr + " serveraddr " + loctarg->server_sa.str());
 
                                std::string classname = loctarg->GetClass()->name;
                                if (!classname.empty())
@@ -161,8 +192,10 @@ class CommandCheck : public Command
 
                        for (UCListIter i = targuser->chans.begin(); i != targuser->chans.end(); i++)
                        {
-                               Channel* c = *i;
-                               chliststr.append(c->GetPrefixChar(targuser)).append(c->name).append(" ");
+                               Membership* memb = *i;
+                               Channel* c = memb->chan;
+                               chliststr.push_back(memb->GetPrefixChar());
+                               chliststr.append(c->name).push_back(' ');
                        }
 
                        std::stringstream dump(chliststr);
@@ -194,20 +227,20 @@ class CommandCheck : public Command
                        /* note that unlike /names, we do NOT check +i vs in the channel */
                        for (UserMembCIter i = ulist->begin(); i != ulist->end(); i++)
                        {
-                               char tmpbuf[MAXBUF];
                                /*
-                                * Unlike Asuka, I define a clone as coming from the same host. --w00t
-                                */
-                               snprintf(tmpbuf, MAXBUF, "%-3lu %s%s (%s@%s) %s ", ServerInstance->Users->GlobalCloneCount(i->first), targchan->GetAllPrefixChars(i->first), i->first->nick.c_str(), i->first->ident.c_str(), i->first->dhost.c_str(), i->first->fullname.c_str());
-                               user->SendText(checkstr + " member " + tmpbuf);
+                                * Unlike Asuka, I define a clone as coming from the same host. --w00t
+                                */
+                               const UserManager::CloneCounts& clonecount = ServerInstance->Users->GetCloneCounts(i->first);
+                               user->SendText("%s member %-3u %s%s (%s@%s) %s ",
+                                       checkstr.c_str(), clonecount.global,
+                                       i->second->GetAllPrefixChars(), i->first->nick.c_str(),
+                                       i->first->ident.c_str(), i->first->dhost.c_str(), i->first->fullname.c_str());
                        }
 
-                       // We know that the mode handler for bans is in the core and is derived from ListModeBase
-                       ListModeBase* banlm = static_cast<ListModeBase*>(*ban);
-                       banlm->DoSyncChannel(targchan, creator, user);
+                       const ModeParser::ListModeList& listmodes = ServerInstance->Modes->GetListModes();
+                       for (ModeParser::ListModeList::const_iterator i = listmodes.begin(); i != listmodes.end(); ++i)
+                               dumpListMode(user, checkstr, (*i)->GetList(targchan));
 
-                       // Show other listmodes as well
-                       FOREACH_MOD(I_OnSyncChannel,OnSyncChannel(targchan,creator,user));
                        dumpExt(user, checkstr, targchan);
                }
                else
@@ -216,7 +249,8 @@ class CommandCheck : public Command
                        long x = 0;
 
                        /* hostname or other */
-                       for (user_hash::const_iterator a = ServerInstance->Users->clientlist->begin(); a != ServerInstance->Users->clientlist->end(); a++)
+                       const user_hash& users = ServerInstance->Users->GetUsers();
+                       for (user_hash::const_iterator a = users.begin(); a != users.end(); ++a)
                        {
                                if (InspIRCd::Match(a->second->host, parameters[0], ascii_case_insensitive_map) || InspIRCd::Match(a->second->dhost, parameters[0], ascii_case_insensitive_map))
                                {
@@ -255,27 +289,6 @@ class ModuleCheck : public Module
        {
        }
 
-       void init() CXX11_OVERRIDE
-       {
-               ServerInstance->Modules->AddService(mycommand);
-       }
-
-       void ProtoSendMode(void* uv, TargetTypeFlags, void*, const std::vector<std::string>& result, const std::vector<TranslateType>&)
-       {
-               User* user = (User*)uv;
-               std::string checkstr(":");
-               checkstr.append(ServerInstance->Config->ServerName);
-               checkstr.append(" 304 ");
-               checkstr.append(user->nick);
-               checkstr.append(" :CHECK modelist");
-               for(unsigned int i=0; i < result.size(); i++)
-               {
-                       checkstr.append(" ");
-                       checkstr.append(result[i]);
-               }
-               user->SendText(checkstr);
-       }
-
        Version GetVersion() CXX11_OVERRIDE
        {
                return Version("CHECK command, view user, channel, IP address or hostname information", VF_VENDOR|VF_OPTCOMMON);