Anope IRC Services  Version 1.8
ns_alist.c
Go to the documentation of this file.
1 /* NickServ 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 static int do_alist(User * u);
18 static void myNickServHelp(User * u);
19 
26 int AnopeInit(int argc, char **argv)
27 {
28  Command *c;
29 
30  moduleAddAuthor("Anope");
31  moduleAddVersion(VERSION_STRING);
33 
34  c = createCommand("ALIST", do_alist, NULL, -1, NICK_HELP_ALIST, -1,
35  NICK_SERVADMIN_HELP_ALIST,
36  NICK_SERVADMIN_HELP_ALIST);
38 
40 
41  return MOD_CONT;
42 }
43 
47 void AnopeFini(void)
48 {
49 
50 }
51 
52 
53 
58 static void myNickServHelp(User * u)
59 {
60  notice_lang(s_NickServ, u, NICK_HELP_CMD_ALIST);
61 }
62 
68 static int do_alist(User * u)
69 {
70 
71 /*
72  * List the channels that the given nickname has access on
73  *
74  * /ns ALIST [level]
75  * /ns ALIST [nickname] [level]
76  *
77  * -jester
78  */
79 
80  char *nick = NULL;
81  char *lev = NULL;
82 
83  NickAlias *na;
84 
85  int min_level = 0;
86  int is_servadmin = is_services_admin(u);
87 
88  if (!is_servadmin) {
89  /* Non service admins can only see their own levels */
90  na = u->na;
91  } else {
92  /* Services admins can request ALIST on nicks.
93  * The first argument for service admins must
94  * always be a nickname.
95  */
96  nick = strtok(NULL, " ");
97 
98  /* If an argument was passed, use it as the nick to see levels
99  * for, else check levels for the user calling the command */
100  if (nick) {
101  na = findnick(nick);
102  } else {
103  na = u->na;
104  }
105  }
106 
107  /* If available, get level from arguments */
108  lev = strtok(NULL, " ");
109 
110  /* if a level was given, make sure it's an int for later */
111  if (lev) {
112  if (stricmp(lev, "FOUNDER") == 0) {
113  min_level = ACCESS_FOUNDER;
114  } else if (stricmp(lev, "SOP") == 0) {
115  min_level = ACCESS_SOP;
116  } else if (stricmp(lev, "AOP") == 0) {
117  min_level = ACCESS_AOP;
118  } else if (stricmp(lev, "HOP") == 0) {
119  min_level = ACCESS_HOP;
120  } else if (stricmp(lev, "VOP") == 0) {
121  min_level = ACCESS_VOP;
122  } else {
123  min_level = atoi(lev);
124  }
125  }
126 
127  if (!nick_identified(u)) {
128  notice_lang(s_NickServ, u, NICK_IDENTIFY_REQUIRED, s_NickServ);
129  } else if (is_servadmin && nick && !na) {
130  notice_lang(s_NickServ, u, NICK_X_NOT_REGISTERED, nick);
131  } else if (na->status & NS_VERBOTEN) {
132  notice_lang(s_NickServ, u, NICK_X_FORBIDDEN, na->nick);
133  } else if (min_level <= ACCESS_INVALID || min_level > ACCESS_FOUNDER) {
134  notice_lang(s_NickServ, u, CHAN_ACCESS_LEVEL_RANGE,
135  ACCESS_INVALID + 1, ACCESS_FOUNDER - 1);
136  } else {
137  int i, level;
138  int chan_count = 0;
139  int match_count = 0;
140  ChannelInfo *ci;
141 
142  notice_lang(s_NickServ, u, (is_servadmin ? NICK_ALIST_HEADER_X :
143  NICK_ALIST_HEADER), na->nick);
144 
145  for (i = 0; i < 256; i++) {
146  for ((ci = chanlists[i]); ci; (ci = ci->next)) {
147 
148  if ((level = get_access_level(ci, na))) {
149  chan_count++;
150 
151  if (min_level > level) {
152  continue;
153  }
154 
155  match_count++;
156 
157  if ((ci->flags & CI_XOP) || (level == ACCESS_FOUNDER)) {
158  const char *xop;
159 
160  xop = get_xop_level(level);
161 
162  notice_lang(s_NickServ, u, NICK_ALIST_XOP_FORMAT,
163  match_count,
164  ((ci->
165  flags & CI_NO_EXPIRE) ? '!' : ' '),
166  ci->name, xop,
167  (ci->desc ? ci->desc : ""));
168  } else {
170  NICK_ALIST_ACCESS_FORMAT, match_count,
171  ((ci->
172  flags & CI_NO_EXPIRE) ? '!' : ' '),
173  ci->name, level,
174  (ci->desc ? ci->desc : ""));
175 
176  }
177  }
178  }
179  }
180 
181  notice_lang(s_NickServ, u, NICK_ALIST_FOOTER, match_count,
182  chan_count);
183  }
184  return MOD_CONT;
185 }
static void myNickServHelp(User *u)
Definition: ns_alist.c:58
int AnopeInit(int argc, char **argv)
Definition: ns_alist.c:26
E int get_access_level(ChannelInfo *ci, NickAlias *na)
Definition: chanserv.c:2601
E NickAlias * findnick(const char *nick)
Definition: db-merger.c:1857
#define CI_NO_EXPIRE
Definition: services.h:729
E int nick_identified(User *u)
Definition: nickserv.c:1111
E int stricmp(const char *s1, const char *s2)
Definition: compat.c:58
static int do_alist(User *u)
Definition: ns_alist.c:68
#define NS_VERBOTEN
Definition: services.h:1273
#define ACCESS_VOP
Definition: services.h:614
MDE void moduleAddAuthor(const char *author)
Definition: modules.c:1772
char name[CHANMAX]
Definition: services.h:654
E void notice_lang(char *source, User *dest, int message,...)
Definition: send.c:169
MDE void moduleSetType(MODType type)
Definition: modules.c:818
E ChannelInfo * chanlists[256]
Definition: extern.h:167
#define ACCESS_SOP
Definition: services.h:617
#define ACCESS_FOUNDER
Definition: services.h:604
#define ACCESS_INVALID
Definition: services.h:605
uint32 flags
Definition: services.h:669
uint16 status
Definition: services.h:532
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
Command * c
Definition: ns_recover.c:17
#define CI_XOP
Definition: services.h:741
#define MOD_CONT
Definition: modules.h:54
E int is_services_admin(User *u)
Definition: operserv.c:591
void AnopeFini(void)
Definition: ns_alist.c:47
#define ACCESS_HOP
Definition: services.h:615
char * nick
Definition: services.h:526
MDE void moduleSetNickHelp(void(*func)(User *u))
Definition: modules.c:2078
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
char * desc
Definition: services.h:659
E char * s_NickServ
Definition: extern.h:284
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
E const char * get_xop_level(int level)
Definition: chanserv.c:2628
ChannelInfo * next
Definition: services.h:653
#define ACCESS_AOP
Definition: services.h:616
#define NICKSERV
Definition: modules.h:59
NickAlias * na
Definition: services.h:892
#define MOD_UNIQUE
Definition: module.h:11