]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/cmd_ison.cpp
Extra Dry! Shame it's not in Hereford right now :p
[user/henk/code/inspircd.git] / src / cmd_ison.cpp
index f630194271d3c5d7fb80c98774546c72a34fd6e3..0cee160c7f8e39c657328c6b9601594b9ab9d934 100644 (file)
@@ -1 +1,86 @@
-/*       +------------------------------------+\r *       | Inspire Internet Relay Chat Daemon |\r *       +------------------------------------+\r *\r *  InspIRCd: (C) 2002-2007 InspIRCd Development Team\r * See: http://www.inspircd.org/wiki/index.php/Credits\r *\r * This program is free but copyrighted software; see\r *            the file COPYING for details.\r *\r * ---------------------------------------------------\r */\r\r#include "inspircd.h"\r#include "users.h"\r#include "commands/cmd_ison.h"\r\rextern "C" DllExport command_t* init_command(InspIRCd* Instance)\r{\r       return new cmd_ison(Instance);\r}\r\r/** Handle /ISON\r */\rCmdResult cmd_ison::Handle (const char** parameters, int pcnt, userrec *user)\r{\r std::map<userrec*,userrec*> ison_already;\r      userrec *u;\r    std::string reply = std::string("303 ") + user->nick + " :";\r\r  for (int i = 0; i < pcnt; i++)\r {\r              u = ServerInstance->FindNick(parameters[i]);\r           if (ison_already.find(u) != ison_already.end())\r                        continue;\r\r             if (u)\r         {\r                      reply.append(u->nick).append(" ");\r                     if (reply.length() > 450)\r                      {\r                              user->WriteServ(reply);\r                                reply = std::string("303 ") + user->nick + " :";\r                       }\r                      ison_already[u] = u;\r           }\r              else\r           {\r                      if ((i == pcnt-1) && (strchr(parameters[i],' ')))\r                      {\r                              /* Its a space seperated list of nicks (RFC1459 says to support this)\r                           */\r                            irc::spacesepstream list(parameters[i]);\r                               std::string item("*");\r                         while (((item = list.GetToken()) != ""))\r                               {\r                                      u = ServerInstance->FindNick(item);\r                                    if (ison_already.find(u) != ison_already.end())\r                                                continue;\r\r                                     if (u)\r                                 {\r                                              if (u->Visibility && !u->Visibility->VisibleTo(user))\r                                                  continue;\r\r                                             reply.append(u->nick).append(" ");\r                                             if (reply.length() > 450)\r                                              {\r                                                      user->WriteServ(reply);\r                                                        reply = std::string("303 ") + user->nick + " :";\r                                               }\r                                              ison_already[u] = u;\r                                   }\r                              }\r                      }\r                      /* There will only be one of these, we can bail after. */\r                      break;\r         }\r      }\r\r     if (!reply.empty())\r            user->WriteServ(reply);\r\r       return CMD_SUCCESS;\r}\r\r
\ No newline at end of file
+/*       +------------------------------------+
+ *       | Inspire Internet Relay Chat Daemon |
+ *       +------------------------------------+
+ *
+ *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ * See: http://www.inspircd.org/wiki/index.php/Credits
+ *
+ * This program is free but copyrighted software; see
+ *            the file COPYING for details.
+ *
+ * ---------------------------------------------------
+ */
+
+#include "inspircd.h"
+#include "users.h"
+#include "commands/cmd_ison.h"
+
+extern "C" DllExport command_t* init_command(InspIRCd* Instance)
+{
+       return new cmd_ison(Instance);
+}
+
+/** Handle /ISON
+ */
+CmdResult cmd_ison::Handle (const char** parameters, int pcnt, userrec *user)
+{
+       std::map<userrec*,userrec*> ison_already;
+       userrec *u;
+       std::string reply = std::string("303 ") + user->nick + " :";
+
+       for (int i = 0; i < pcnt; i++)
+       {
+               u = ServerInstance->FindNick(parameters[i]);
+               if (ison_already.find(u) != ison_already.end())
+                       continue;
+
+               if (u)
+               {
+                       reply.append(u->nick).append(" ");
+                       if (reply.length() > 450)
+                       {
+                               user->WriteServ(reply);
+                               reply = std::string("303 ") + user->nick + " :";
+                       }
+                       ison_already[u] = u;
+               }
+               else
+               {
+                       if ((i == pcnt-1) && (strchr(parameters[i],' ')))
+                       {
+                               /* Its a space seperated list of nicks (RFC1459 says to support this)
+                                */
+                               irc::spacesepstream list(parameters[i]);
+                               std::string item("*");
+                               while (((item = list.GetToken()) != ""))
+                               {
+                                       u = ServerInstance->FindNick(item);
+                                       if (ison_already.find(u) != ison_already.end())
+                                               continue;
+
+                                       if (u)
+                                       {
+                                               if (u->Visibility && !u->Visibility->VisibleTo(user))
+                                                       continue;
+
+                                               reply.append(u->nick).append(" ");
+                                               if (reply.length() > 450)
+                                               {
+                                                       user->WriteServ(reply);
+                                                       reply = std::string("303 ") + user->nick + " :";
+                                               }
+                                               ison_already[u] = u;
+                                       }
+                               }
+                       }
+                       /* There will only be one of these, we can bail after. */
+                       break;
+               }
+       }
+
+       if (!reply.empty())
+               user->WriteServ(reply);
+
+       return CMD_SUCCESS;
+}
+