Anope IRC Services  Version 1.8
bs_botlist.c
Go to the documentation of this file.
1 /* BotServ 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_botlist(User * u);
18 static void myBotServHelp(User * u);
19 
26 int AnopeInit(int argc, char **argv)
27 {
28  Command *c;
29 
30  moduleAddAuthor("Anope");
31  moduleAddVersion(VERSION_STRING);
33  c = createCommand("BOTLIST", do_botlist, NULL, BOT_HELP_BOTLIST, -1,
34  -1, -1, -1);
36 
38 
39  return MOD_CONT;
40 }
41 
45 void AnopeFini(void)
46 {
47 
48 }
49 
50 
51 
56 static void myBotServHelp(User * u)
57 {
58  notice_lang(s_BotServ, u, BOT_HELP_CMD_BOTLIST);
59 }
60 
66 static int do_botlist(User * u)
67 {
68  int i, count = 0;
69  BotInfo *bi;
70 
71  if (!nbots) {
72  notice_lang(s_BotServ, u, BOT_BOTLIST_EMPTY);
73  return MOD_CONT;
74  }
75 
76  for (i = 0; i < 256; i++) {
77  for (bi = botlists[i]; bi; bi = bi->next) {
78  if (!(bi->flags & BI_PRIVATE)) {
79  if (!count)
80  notice_lang(s_BotServ, u, BOT_BOTLIST_HEADER);
81  count++;
82  notice_user(s_BotServ, u, " %-15s (%s@%s)", bi->nick,
83  bi->user, bi->host);
84  }
85  }
86  }
87 
88  if (is_oper(u) && count < nbots) {
89  notice_lang(s_BotServ, u, BOT_BOTLIST_PRIVATE_HEADER);
90 
91  for (i = 0; i < 256; i++) {
92  for (bi = botlists[i]; bi; bi = bi->next) {
93  if (bi->flags & BI_PRIVATE) {
94  notice_user(s_BotServ, u, " %-15s (%s@%s)",
95  bi->nick, bi->user, bi->host);
96  count++;
97  }
98  }
99  }
100  }
101 
102  if (!count)
103  notice_lang(s_BotServ, u, BOT_BOTLIST_EMPTY);
104  else
105  notice_lang(s_BotServ, u, BOT_BOTLIST_FOOTER, count);
106  return MOD_CONT;
107 }
E int is_oper(User *user)
Definition: users.c:937
void AnopeFini(void)
Definition: bs_botlist.c:45
E char * s_BotServ
Definition: extern.h:287
E void E void E void E void notice_user(char *source, User *u, const char *fmt,...) FORMAT(printf
static int do_botlist(User *u)
Definition: bs_botlist.c:66
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
static void myBotServHelp(User *u)
Definition: bs_botlist.c:56
int16 flags
Definition: services.h:577
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
Command * c
Definition: ns_recover.c:17
#define BOTSERV
Definition: modules.h:57
#define MOD_CONT
Definition: modules.h:54
MDE void moduleSetBotHelp(void(*func)(User *u))
Definition: modules.c:2114
#define BI_PRIVATE
Definition: services.h:1339
int AnopeInit(int argc, char **argv)
Definition: bs_botlist.c:26
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 * host
Definition: services.h:575
E int nbots
Definition: extern.h:65
BotInfo * next
Definition: services.h:571
char * nick
Definition: services.h:573
E BotInfo * botlists[256]
Definition: extern.h:64
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
char * user
Definition: services.h:574
#define MOD_UNIQUE
Definition: module.h:11