Anope IRC Services  Version 1.8
os_chanlist.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 static int do_chanlist(User * u);
18 static void myOperServHelp(User * u);
19 #ifdef _WIN32
20 extern MDE int anope_get_private_mode();
21 #endif
22 
29 int AnopeInit(int argc, char **argv)
30 {
31  Command *c;
32 
33  moduleAddAuthor("Anope");
34  moduleAddVersion(VERSION_STRING);
36 
38  OPER_HELP_CHANLIST, -1, -1, -1, -1);
40 
42 
43  return MOD_CONT;
44 }
45 
46 
50 void AnopeFini(void)
51 {
52 
53 }
54 
55 
60 static void myOperServHelp(User * u)
61 {
62  notice_lang(s_OperServ, u, OPER_HELP_CMD_CHANLIST);
63 }
64 
70 static int do_chanlist(User * u)
71 {
72  char *pattern = strtok(NULL, " ");
73  char *opt = strtok(NULL, " ");
74 
75  int modes = 0;
76  User *u2;
77 
78  if (opt && !stricmp(opt, "SECRET"))
80 
81  if (pattern && (u2 = finduser(pattern))) {
82  struct u_chanlist *uc;
83 
84  notice_lang(s_OperServ, u, OPER_CHANLIST_HEADER_USER, u2->nick);
85 
86  for (uc = u2->chans; uc; uc = uc->next) {
87  if (modes && !(uc->chan->mode & modes))
88  continue;
89  notice_lang(s_OperServ, u, OPER_CHANLIST_RECORD,
90  uc->chan->name, uc->chan->usercount,
91  chan_get_modes(uc->chan, 1, 1),
92  (uc->chan->topic ? uc->chan->topic : ""));
93  }
94  } else {
95  int i;
96  Channel *c;
97 
98  notice_lang(s_OperServ, u, OPER_CHANLIST_HEADER);
99 
100  for (i = 0; i < 1024; i++) {
101  for (c = chanlist[i]; c; c = c->next) {
102  if (pattern && !match_wild_nocase(pattern, c->name))
103  continue;
104  if (modes && !(c->mode & modes))
105  continue;
106  notice_lang(s_OperServ, u, OPER_CHANLIST_RECORD, c->name,
107  c->usercount, chan_get_modes(c, 1, 1),
108  (c->topic ? c->topic : ""));
109  }
110  }
111  }
112 
113  notice_lang(s_OperServ, u, OPER_CHANLIST_END);
114  return MOD_CONT;
115 }
int16 usercount
Definition: services.h:1020
E int match_wild_nocase(const char *pattern, const char *str)
Definition: misc.c:268
char nick[NICKMAX]
Definition: services.h:875
struct u_chanlist * next
Definition: services.h:899
E int stricmp(const char *s1, const char *s2)
Definition: compat.c:58
Channel * next
Definition: services.h:999
#define MDE
Definition: modules.h:89
E int anope_get_private_mode()
Definition: ircd.c:1231
struct user_::u_chanlist * chans
MDE void moduleAddAuthor(const char *author)
Definition: modules.c:1772
E int anope_get_secret_mode()
Definition: ircd.c:1226
E void notice_lang(char *source, User *dest, int message,...)
Definition: send.c:169
MDE void moduleSetType(MODType type)
Definition: modules.c:818
E char * chan_get_modes(Channel *chan, int complete, int plus)
Definition: channels.c:68
#define OPERSERV
Definition: modules.h:62
E char * s_OperServ
Definition: extern.h:289
uint32 mode
Definition: services.h:1006
E User * finduser(const char *nick)
Definition: users.c:323
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
Command * c
Definition: ns_recover.c:17
MDE void moduleSetOperHelp(void(*func)(User *u))
Definition: modules.c:2126
#define MOD_CONT
Definition: modules.h:54
static void myOperServHelp(User *u)
Definition: os_chanlist.c:60
char * topic
Definition: services.h:1003
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
static int do_chanlist(User *u)
Definition: os_chanlist.c:70
char name[CHANMAX]
Definition: services.h:1000
E int is_services_oper(User *u)
Definition: operserv.c:606
int AnopeInit(int argc, char **argv)
Definition: os_chanlist.c:29
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
#define MOD_UNIQUE
Definition: module.h:11
E Channel * chanlist[1024]
Definition: extern.h:88
void AnopeFini(void)
Definition: os_chanlist.c:50