Anope IRC Services  Version 1.8
bs_info.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_info(User * u);
18 static void send_bot_channels(User * u, BotInfo * bi);
19 static void myBotServHelp(User * u);
20 
27 int AnopeInit(int argc, char **argv)
28 {
29  Command *c;
30 
31  moduleAddAuthor("Anope");
32  moduleAddVersion(VERSION_STRING);
34  c = createCommand("INFO", do_info, NULL, BOT_HELP_INFO, -1, -1, -1,
35  -1);
37 
39 
40  return MOD_CONT;
41 }
42 
46 void AnopeFini(void)
47 {
48 
49 }
50 
51 
52 
57 static void myBotServHelp(User * u)
58 {
59  notice_lang(s_BotServ, u, BOT_HELP_CMD_INFO);
60 }
61 
67 static int do_info(User * u)
68 {
69  BotInfo *bi;
70  ChannelInfo *ci;
71  char *query = strtok(NULL, " ");
72 
73  int need_comma = 0, is_servadmin = is_services_admin(u);
74  char buf[BUFSIZE], *end;
75  const char *commastr = getstring(u->na, COMMA_SPACE);
76 
77  if (!query)
78  syntax_error(s_BotServ, u, "INFO", BOT_INFO_SYNTAX);
79  else if ((bi = findbot(query))) {
80  char buf[BUFSIZE];
81  struct tm *tm;
82 
83  notice_lang(s_BotServ, u, BOT_INFO_BOT_HEADER, bi->nick);
84  notice_lang(s_BotServ, u, BOT_INFO_BOT_MASK, bi->user, bi->host);
85  notice_lang(s_BotServ, u, BOT_INFO_BOT_REALNAME, bi->real);
86  tm = localtime(&bi->created);
87  strftime_lang(buf, sizeof(buf), u, STRFTIME_DATE_TIME_FORMAT, tm);
88  notice_lang(s_BotServ, u, BOT_INFO_BOT_CREATED, buf);
89  notice_lang(s_BotServ, u, BOT_INFO_BOT_OPTIONS,
90  getstring(u->na,
91  (bi->
92  flags & BI_PRIVATE) ? BOT_INFO_OPT_PRIVATE :
93  BOT_INFO_OPT_NONE));
94  notice_lang(s_BotServ, u, BOT_INFO_BOT_USAGE, bi->chancount);
95 
96  if (is_services_admin(u))
97  send_bot_channels(u, bi);
98  } else if ((ci = cs_findchan(query))) {
99  if (!is_servadmin && !is_founder(u, ci)) {
100  notice_lang(s_BotServ, u, PERMISSION_DENIED);
101  return MOD_CONT;
102  }
103  if (ci->flags & CI_VERBOTEN) {
104  notice_lang(s_BotServ, u, CHAN_X_FORBIDDEN, query);
105  return MOD_CONT;
106  }
107 
108  notice_lang(s_BotServ, u, BOT_INFO_CHAN_HEADER, ci->name);
109  if (ci->bi)
110  notice_lang(s_BotServ, u, BOT_INFO_CHAN_BOT, ci->bi->nick);
111  else
112  notice_lang(s_BotServ, u, BOT_INFO_CHAN_BOT_NONE);
113 
114  if (ci->botflags & BS_KICK_BADWORDS) {
115  if (ci->ttb[TTB_BADWORDS])
116  notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_BADWORDS_BAN,
117  getstring(u->na, BOT_INFO_ACTIVE),
118  ci->ttb[TTB_BADWORDS]);
119  else
120  notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_BADWORDS,
121  getstring(u->na, BOT_INFO_ACTIVE));
122  } else
123  notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_BADWORDS,
124  getstring(u->na, BOT_INFO_INACTIVE));
125  if (ci->botflags & BS_KICK_BOLDS) {
126  if (ci->ttb[TTB_BOLDS])
127  notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_BOLDS_BAN,
128  getstring(u->na, BOT_INFO_ACTIVE),
129  ci->ttb[TTB_BOLDS]);
130  else
131  notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_BOLDS,
132  getstring(u->na, BOT_INFO_ACTIVE));
133  } else
134  notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_BOLDS,
135  getstring(u->na, BOT_INFO_INACTIVE));
136  if (ci->botflags & BS_KICK_CAPS) {
137  if (ci->ttb[TTB_CAPS])
138  notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_CAPS_BAN,
139  getstring(u->na, BOT_INFO_ACTIVE),
140  ci->ttb[TTB_CAPS], ci->capsmin,
141  ci->capspercent);
142  else
143  notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_CAPS_ON,
144  getstring(u->na, BOT_INFO_ACTIVE), ci->capsmin,
145  ci->capspercent);
146  } else
147  notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_CAPS_OFF,
148  getstring(u->na, BOT_INFO_INACTIVE));
149  if (ci->botflags & BS_KICK_COLORS) {
150  if (ci->ttb[TTB_COLORS])
151  notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_COLORS_BAN,
152  getstring(u->na, BOT_INFO_ACTIVE),
153  ci->ttb[TTB_COLORS]);
154  else
155  notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_COLORS,
156  getstring(u->na, BOT_INFO_ACTIVE));
157  } else
158  notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_COLORS,
159  getstring(u->na, BOT_INFO_INACTIVE));
160  if (ci->botflags & BS_KICK_FLOOD) {
161  if (ci->ttb[TTB_FLOOD])
162  notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_FLOOD_BAN,
163  getstring(u->na, BOT_INFO_ACTIVE),
164  ci->ttb[TTB_FLOOD], ci->floodlines,
165  ci->floodsecs);
166  else
167  notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_FLOOD_ON,
168  getstring(u->na, BOT_INFO_ACTIVE),
169  ci->floodlines, ci->floodsecs);
170  } else
171  notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_FLOOD_OFF,
172  getstring(u->na, BOT_INFO_INACTIVE));
173  if (ci->botflags & BS_KICK_REPEAT) {
174  if (ci->ttb[TTB_REPEAT])
175  notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_REPEAT_BAN,
176  getstring(u->na, BOT_INFO_ACTIVE),
177  ci->ttb[TTB_REPEAT], ci->repeattimes);
178  else
179  notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_REPEAT_ON,
180  getstring(u->na, BOT_INFO_ACTIVE),
181  ci->repeattimes);
182  } else
183  notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_REPEAT_OFF,
184  getstring(u->na, BOT_INFO_INACTIVE));
185  if (ci->botflags & BS_KICK_REVERSES) {
186  if (ci->ttb[TTB_REVERSES])
187  notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_REVERSES_BAN,
188  getstring(u->na, BOT_INFO_ACTIVE),
189  ci->ttb[TTB_REVERSES]);
190  else
191  notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_REVERSES,
192  getstring(u->na, BOT_INFO_ACTIVE));
193  } else
194  notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_REVERSES,
195  getstring(u->na, BOT_INFO_INACTIVE));
196  if (ci->botflags & BS_KICK_UNDERLINES) {
197  if (ci->ttb[TTB_UNDERLINES])
199  BOT_INFO_CHAN_KICK_UNDERLINES_BAN,
200  getstring(u->na, BOT_INFO_ACTIVE),
201  ci->ttb[TTB_UNDERLINES]);
202  else
203  notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_UNDERLINES,
204  getstring(u->na, BOT_INFO_ACTIVE));
205  } else
206  notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_UNDERLINES,
207  getstring(u->na, BOT_INFO_INACTIVE));
208 
209  end = buf;
210  *end = 0;
211  if (ci->botflags & BS_DONTKICKOPS) {
212  end += snprintf(end, sizeof(buf) - (end - buf), "%s",
213  getstring(u->na, BOT_INFO_OPT_DONTKICKOPS));
214  need_comma = 1;
215  }
216  if (ci->botflags & BS_DONTKICKVOICES) {
217  end += snprintf(end, sizeof(buf) - (end - buf), "%s%s",
218  need_comma ? commastr : "",
219  getstring(u->na, BOT_INFO_OPT_DONTKICKVOICES));
220  need_comma = 1;
221  }
222  if (ci->botflags & BS_FANTASY) {
223  end += snprintf(end, sizeof(buf) - (end - buf), "%s%s",
224  need_comma ? commastr : "",
225  getstring(u->na, BOT_INFO_OPT_FANTASY));
226  need_comma = 1;
227  }
228  if (ci->botflags & BS_GREET) {
229  end += snprintf(end, sizeof(buf) - (end - buf), "%s%s",
230  need_comma ? commastr : "",
231  getstring(u->na, BOT_INFO_OPT_GREET));
232  need_comma = 1;
233  }
234  if (ci->botflags & BS_NOBOT) {
235  end += snprintf(end, sizeof(buf) - (end - buf), "%s%s",
236  need_comma ? commastr : "",
237  getstring(u->na, BOT_INFO_OPT_NOBOT));
238  need_comma = 1;
239  }
240  if (ci->botflags & BS_SYMBIOSIS) {
241  end += snprintf(end, sizeof(buf) - (end - buf), "%s%s",
242  need_comma ? commastr : "",
243  getstring(u->na, BOT_INFO_OPT_SYMBIOSIS));
244  need_comma = 1;
245  }
246  notice_lang(s_BotServ, u, BOT_INFO_CHAN_OPTIONS,
247  *buf ? buf : getstring(u->na, BOT_INFO_OPT_NONE));
248 
249  } else
250  notice_lang(s_BotServ, u, BOT_INFO_NOT_FOUND, query);
251  return MOD_CONT;
252 }
253 
254 static void send_bot_channels(User * u, BotInfo * bi)
255 {
256  int i;
257  ChannelInfo *ci;
258  char buf[307], *end;
259 
260  *buf = 0;
261  end = buf;
262 
263  for (i = 0; i < 256; i++) {
264  for (ci = chanlists[i]; ci; ci = ci->next) {
265  if (ci->bi == bi) {
266  if (strlen(buf) + strlen(ci->name) > 300) {
267  notice_user(s_BotServ, u, "%s", buf);
268  *buf = 0;
269  end = buf;
270  }
271  end +=
272  snprintf(end, sizeof(buf) - (end - buf), " %s ",
273  ci->name);
274  }
275  }
276  }
277 
278  if (*buf)
279  notice_user(s_BotServ, u, "%s", buf);
280  return;
281 }
#define BS_KICK_REPEAT
Definition: services.h:808
#define BS_FANTASY
Definition: services.h:795
#define TTB_FLOOD
Definition: services.h:817
#define TTB_UNDERLINES
Definition: services.h:814
static int do_info(User *u)
Definition: bs_info.c:67
E int snprintf(char *buf, size_t size, const char *fmt,...)
Definition: compat.c:37
uint32 botflags
Definition: services.h:700
int16 capspercent
Definition: services.h:705
E char * s_BotServ
Definition: extern.h:287
void AnopeFini(void)
Definition: bs_info.c:46
#define BS_KICK_CAPS
Definition: services.h:806
#define TTB_REPEAT
Definition: services.h:818
E void E void E void E void notice_user(char *source, User *u, const char *fmt,...) FORMAT(printf
#define CI_VERBOTEN
Definition: services.h:725
int16 chancount
Definition: services.h:579
#define getstring(na, index)
Definition: extern.h:731
#define TTB_BADWORDS
Definition: services.h:815
MDE void moduleAddAuthor(const char *author)
Definition: modules.c:1772
E void syntax_error(char *service, User *u, const char *command, int msgnum)
Definition: language.c:295
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
#define BS_KICK_FLOOD
Definition: services.h:807
E ChannelInfo * chanlists[256]
Definition: extern.h:167
#define BS_KICK_BADWORDS
Definition: services.h:805
#define TTB_COLORS
Definition: services.h:812
#define BS_NOBOT
Definition: services.h:798
uint32 flags
Definition: services.h:669
E BotInfo * findbot(char *nick)
Definition: db-merger.c:1989
#define TTB_CAPS
Definition: services.h:816
#define BS_KICK_BOLDS
Definition: services.h:801
#define BS_KICK_UNDERLINES
Definition: services.h:804
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
Command * c
Definition: ns_recover.c:17
char * real
Definition: services.h:576
#define BOTSERV
Definition: modules.h:57
#define MOD_CONT
Definition: modules.h:54
#define BS_DONTKICKOPS
Definition: services.h:793
#define TTB_REVERSES
Definition: services.h:813
E int is_founder(User *user, ChannelInfo *ci)
Definition: chanserv.c:2255
MDE void moduleSetBotHelp(void(*func)(User *u))
Definition: modules.c:2114
E int is_services_admin(User *u)
Definition: operserv.c:591
int16 floodlines
Definition: services.h:706
int AnopeInit(int argc, char **argv)
Definition: bs_info.c:27
#define BI_PRIVATE
Definition: services.h:1339
time_t created
Definition: services.h:578
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 void send_bot_channels(User *u, BotInfo *bi)
Definition: bs_info.c:254
char * host
Definition: services.h:575
int16 floodsecs
Definition: services.h:706
int16 * ttb
Definition: services.h:701
char * nick
Definition: services.h:573
E ChannelInfo * cs_findchan(const char *chan)
Definition: db-merger.c:2000
int16 capsmin
Definition: services.h:705
#define BS_KICK_REVERSES
Definition: services.h:803
int16 repeattimes
Definition: services.h:707
E int strftime_lang(char *buf, int size, User *u, int format, struct tm *tm)
Definition: language.c:240
BotInfo * bi
Definition: services.h:699
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
#define TTB_BOLDS
Definition: services.h:811
static void myBotServHelp(User *u)
Definition: bs_info.c:57
char * user
Definition: services.h:574
ChannelInfo * next
Definition: services.h:653
#define BS_GREET
Definition: services.h:797
#define BUFSIZE
Definition: config.h:47
#define BS_KICK_COLORS
Definition: services.h:802
#define BS_SYMBIOSIS
Definition: services.h:796
NickAlias * na
Definition: services.h:892
#define MOD_UNIQUE
Definition: module.h:11
#define BS_DONTKICKVOICES
Definition: services.h:794