Anope IRC Services  Version 1.8
os_userlist.c
Go to the documentation of this file.
1 /* OperServ core functions
2  *
3  * (C) 2003-2014 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  */
13 /*************************************************************************/
14 
15 #include "module.h"
16 
17 #ifdef _WIN32
18 extern MDE int anope_get_invite_mode();
19 extern MDE int anope_get_invis_mode();
20 #endif
21 
22 static int do_userlist(User * u);
23 static void myOperServHelp(User * u);
24 
31 int AnopeInit(int argc, char **argv)
32 {
33  Command *c;
34 
35  moduleAddAuthor("Anope");
36  moduleAddVersion(VERSION_STRING);
38 
39  c = createCommand("USERLIST", do_userlist, NULL,
40  OPER_HELP_USERLIST, -1, -1, -1, -1);
42 
44 
45  return MOD_CONT;
46 }
47 
51 void AnopeFini(void)
52 {
53 
54 }
55 
56 
61 static void myOperServHelp(User * u)
62 {
63  notice_lang(s_OperServ, u, OPER_HELP_CMD_USERLIST);
64 }
65 
72 static int do_userlist(User * u)
73 {
74  char *pattern = strtok(NULL, " ");
75  char *opt = strtok(NULL, " ");
76 
77  Channel *c;
78  int modes = 0;
79 
80  if (opt && !stricmp(opt, "INVISIBLE"))
81  modes |= anope_get_invis_mode();
82 
83  if (pattern && (c = findchan(pattern))) {
84  struct c_userlist *cu;
85 
86  notice_lang(s_OperServ, u, OPER_USERLIST_HEADER_CHAN, pattern);
87 
88  for (cu = c->users; cu; cu = cu->next) {
89  if (modes && !(cu->user->mode & modes))
90  continue;
91  notice_lang(s_OperServ, u, OPER_USERLIST_RECORD,
92  cu->user->nick, common_get_vident(cu->user),
93  common_get_vhost(cu->user));
94  }
95  } else {
96  char mask[BUFSIZE];
97  int i;
98  User *u2;
99 
100  notice_lang(s_OperServ, u, OPER_USERLIST_HEADER);
101 
102  for (i = 0; i < 1024; i++) {
103  for (u2 = userlist[i]; u2; u2 = u2->next) {
104  if (pattern) {
105  snprintf(mask, sizeof(mask), "%s!%s@%s", u2->nick,
107  if (!match_wild_nocase(pattern, mask))
108  continue;
109  if (modes && !(u2->mode & modes))
110  continue;
111  }
112  notice_lang(s_OperServ, u, OPER_USERLIST_RECORD, u2->nick,
114  }
115  }
116  }
117 
118  notice_lang(s_OperServ, u, OPER_USERLIST_END);
119  return MOD_CONT;
120 }
E int match_wild_nocase(const char *pattern, const char *str)
Definition: misc.c:268
static int do_userlist(User *u)
Definition: os_userlist.c:72
char nick[NICKMAX]
Definition: services.h:875
E int snprintf(char *buf, size_t size, const char *fmt,...)
Definition: compat.c:37
E int stricmp(const char *s1, const char *s2)
Definition: compat.c:58
#define MDE
Definition: modules.h:89
MDE void moduleAddAuthor(const char *author)
Definition: modules.c:1772
E void notice_lang(char *source, User *dest, int message,...)
Definition: send.c:169
MDE void moduleSetType(MODType type)
Definition: modules.c:818
E Channel * findchan(const char *chan)
Definition: channels.c:394
static void myOperServHelp(User *u)
Definition: os_userlist.c:61
#define OPERSERV
Definition: modules.h:62
E char * s_OperServ
Definition: extern.h:289
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
Command * c
Definition: ns_recover.c:17
User * next
Definition: services.h:873
MDE void moduleSetOperHelp(void(*func)(User *u))
Definition: modules.c:2126
#define MOD_CONT
Definition: modules.h:54
struct c_userlist * next
Definition: services.h:1016
Definition: modules.h:99
MDE Command * createCommand(const char *name, int(*func)(User *u), int(*has_priv)(User *u), int help_all, int help_reg, int help_oper, int help_admin, int help_root)
Definition: modules.c:987
uint32 mode
Definition: services.h:889
int AnopeInit(int argc, char **argv)
Definition: os_userlist.c:31
E User * userlist[1024]
Definition: extern.h:1138
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
E int anope_get_invis_mode()
Definition: ircd.c:1211
E char * common_get_vhost(User *u)
Definition: actions.c:251
void AnopeFini(void)
Definition: os_userlist.c:51
#define BUFSIZE
Definition: config.h:47
E int anope_get_invite_mode()
Definition: ircd.c:1221
E char * common_get_vident(User *u)
Definition: actions.c:272
#define MOD_UNIQUE
Definition: module.h:11
struct channel_::c_userlist * users