os_userlist.c

Go to the documentation of this file.
00001 /* OperServ core functions
00002  *
00003  * (C) 2003-2013 Anope Team
00004  * Contact us at team@anope.org
00005  *
00006  * Please read COPYING and README for further details.
00007  *
00008  * Based on the original code of Epona by Lara.
00009  * Based on the original code of Services by Andy Church. 
00010  * 
00011  *
00012  */
00013 /*************************************************************************/
00014 
00015 #include "module.h"
00016 
00017 #ifdef _WIN32
00018 extern MDE int anope_get_invite_mode();
00019 extern MDE int anope_get_invis_mode();
00020 #endif
00021 
00022 static int do_userlist(User * u);
00023 static void myOperServHelp(User * u);
00024 
00031 int AnopeInit(int argc, char **argv)
00032 {
00033     Command *c;
00034 
00035     moduleAddAuthor("Anope");
00036     moduleAddVersion(VERSION_STRING);
00037     moduleSetType(CORE);
00038 
00039     c = createCommand("USERLIST", do_userlist, NULL,
00040                       OPER_HELP_USERLIST, -1, -1, -1, -1);
00041     moduleAddCommand(OPERSERV, c, MOD_UNIQUE);
00042 
00043     moduleSetOperHelp(myOperServHelp);
00044 
00045     return MOD_CONT;
00046 }
00047 
00051 void AnopeFini(void)
00052 {
00053 
00054 }
00055 
00056 
00061 static void myOperServHelp(User * u)
00062 {
00063     notice_lang(s_OperServ, u, OPER_HELP_CMD_USERLIST);
00064 }
00065 
00072 static int do_userlist(User * u)
00073 {
00074     char *pattern = strtok(NULL, " ");
00075     char *opt = strtok(NULL, " ");
00076 
00077     Channel *c;
00078     int modes = 0;
00079 
00080     if (opt && !stricmp(opt, "INVISIBLE"))
00081         modes |= anope_get_invis_mode();
00082 
00083     if (pattern && (c = findchan(pattern))) {
00084         struct c_userlist *cu;
00085 
00086         notice_lang(s_OperServ, u, OPER_USERLIST_HEADER_CHAN, pattern);
00087 
00088         for (cu = c->users; cu; cu = cu->next) {
00089             if (modes && !(cu->user->mode & modes))
00090                 continue;
00091             notice_lang(s_OperServ, u, OPER_USERLIST_RECORD,
00092                         cu->user->nick, common_get_vident(cu->user),
00093                         common_get_vhost(cu->user));
00094         }
00095     } else {
00096         char mask[BUFSIZE];
00097         int i;
00098         User *u2;
00099 
00100         notice_lang(s_OperServ, u, OPER_USERLIST_HEADER);
00101 
00102         for (i = 0; i < 1024; i++) {
00103             for (u2 = userlist[i]; u2; u2 = u2->next) {
00104                 if (pattern) {
00105                     snprintf(mask, sizeof(mask), "%s!%s@%s", u2->nick,
00106                              common_get_vident(u2), common_get_vhost(u2));
00107                     if (!match_wild_nocase(pattern, mask))
00108                         continue;
00109                     if (modes && !(u2->mode & modes))
00110                         continue;
00111                 }
00112                 notice_lang(s_OperServ, u, OPER_USERLIST_RECORD, u2->nick,
00113                             common_get_vident(u2), common_get_vhost(u2));
00114             }
00115         }
00116     }
00117 
00118     notice_lang(s_OperServ, u, OPER_USERLIST_END);
00119     return MOD_CONT;
00120 }