Anope IRC Services  Version 1.8
bs_set.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_set(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 
34  c = createCommand("SET", do_set, NULL, BOT_HELP_SET, -1, -1,
35  BOT_SERVADMIN_HELP_SET, BOT_SERVADMIN_HELP_SET);
37  c = createCommand("SET DONTKICKOPS", NULL, NULL,
38  BOT_HELP_SET_DONTKICKOPS, -1, -1, -1, -1);
40  c = createCommand("SET DONTKICKVOICES", NULL, NULL,
41  BOT_HELP_SET_DONTKICKVOICES, -1, -1, -1, -1);
43  c = createCommand("SET FANTASY", NULL, NULL, BOT_HELP_SET_FANTASY, -1,
44  -1, -1, -1);
46  c = createCommand("SET GREET", NULL, NULL, BOT_HELP_SET_GREET, -1, -1,
47  -1, -1);
49  c = createCommand("SET SYMBIOSIS", NULL, NULL, BOT_HELP_SET_SYMBIOSIS,
50  -1, -1, -1, -1);
53  c = createCommand("SET NOBOT", NULL, NULL, -1, -1, -1,
54  BOT_SERVADMIN_HELP_SET_NOBOT,
55  BOT_SERVADMIN_HELP_SET_NOBOT);
57  c = createCommand("SET PRIVATE", NULL, NULL, -1, -1, -1,
58  BOT_SERVADMIN_HELP_SET_PRIVATE,
59  BOT_SERVADMIN_HELP_SET_PRIVATE);
61 
62 
64 
65  return MOD_CONT;
66 }
67 
71 void AnopeFini(void)
72 {
73 
74 }
75 
76 
77 
82 static void myBotServHelp(User * u)
83 {
84  notice_lang(s_BotServ, u, BOT_HELP_CMD_SET);
85 }
86 
92 static int do_set(User * u)
93 {
94  char *chan = strtok(NULL, " ");
95  char *option = strtok(NULL, " ");
96  char *value = strtok(NULL, " ");
97  int is_servadmin = is_services_admin(u);
98 
99  ChannelInfo *ci;
100 
101  if (readonly)
102  notice_lang(s_BotServ, u, BOT_SET_DISABLED);
103  else if (!chan || !option || !value)
104  syntax_error(s_BotServ, u, "SET", BOT_SET_SYNTAX);
105  else if (is_servadmin && !stricmp(option, "PRIVATE")) {
106  BotInfo *bi;
107 
108  if ((bi = findbot(chan))) {
109  if (!stricmp(value, "ON")) {
110  bi->flags |= BI_PRIVATE;
111  alog("%s: %s!%s@%s set PRIVATE on bot %s",
112  s_BotServ, u->nick, u->username, u->host, bi->nick);
113  notice_lang(s_BotServ, u, BOT_SET_PRIVATE_ON, bi->nick);
114  } else if (!stricmp(value, "OFF")) {
115  bi->flags &= ~BI_PRIVATE;
116  alog("%s: %s!%s@%s unset PRIVATE on bot %s",
117  s_BotServ, u->nick, u->username, u->host, bi->nick);
118  notice_lang(s_BotServ, u, BOT_SET_PRIVATE_OFF, bi->nick);
119  } else {
120  syntax_error(s_BotServ, u, "SET PRIVATE",
121  BOT_SET_PRIVATE_SYNTAX);
122  }
123  } else {
124  notice_lang(s_BotServ, u, BOT_DOES_NOT_EXIST, chan);
125  }
126  return MOD_CONT;
127  } else if (!(ci = cs_findchan(chan)))
128  notice_lang(s_BotServ, u, CHAN_X_NOT_REGISTERED, chan);
129  else if (ci->flags & CI_VERBOTEN)
130  notice_lang(s_BotServ, u, CHAN_X_FORBIDDEN, chan);
131  else if (!is_servadmin && !check_access(u, ci, CA_SET))
132  notice_lang(s_BotServ, u, ACCESS_DENIED);
133  else {
134  if (!stricmp(option, "DONTKICKOPS")) {
135  if (!stricmp(value, "ON")) {
136  ci->botflags |= BS_DONTKICKOPS;
137  alog("%s: %s!%s@%s set DONTKICKOPS on %s",
138  s_BotServ, u->nick, u->username, u->host, ci->name);
139  notice_lang(s_BotServ, u, BOT_SET_DONTKICKOPS_ON,
140  ci->name);
141  } else if (!stricmp(value, "OFF")) {
142  ci->botflags &= ~BS_DONTKICKOPS;
143  alog("%s: %s!%s@%s unset DONTKICKOPS on %s",
144  s_BotServ, u->nick, u->username, u->host, ci->name);
145  notice_lang(s_BotServ, u, BOT_SET_DONTKICKOPS_OFF,
146  ci->name);
147  } else {
148  syntax_error(s_BotServ, u, "SET DONTKICKOPS",
149  BOT_SET_DONTKICKOPS_SYNTAX);
150  }
151  } else if (!stricmp(option, "DONTKICKVOICES")) {
152  if (!stricmp(value, "ON")) {
154  alog("%s: %s!%s@%s set DONTKICKVOICES on %s",
155  s_BotServ, u->nick, u->username, u->host, ci->name);
156  notice_lang(s_BotServ, u, BOT_SET_DONTKICKVOICES_ON,
157  ci->name);
158  } else if (!stricmp(value, "OFF")) {
159  ci->botflags &= ~BS_DONTKICKVOICES;
160  alog("%s: %s!%s@%s unset DONTKICKVOICES on %s",
161  s_BotServ, u->nick, u->username, u->host, ci->name);
162  notice_lang(s_BotServ, u, BOT_SET_DONTKICKVOICES_OFF,
163  ci->name);
164  } else {
165  syntax_error(s_BotServ, u, "SET DONTKICKVOICES",
166  BOT_SET_DONTKICKVOICES_SYNTAX);
167  }
168  } else if (!stricmp(option, "FANTASY")) {
169  if (!stricmp(value, "ON")) {
170  ci->botflags |= BS_FANTASY;
171  alog("%s: %s!%s@%s set FANTASY on %s",
172  s_BotServ, u->nick, u->username, u->host, ci->name);
173  notice_lang(s_BotServ, u, BOT_SET_FANTASY_ON, ci->name);
174  } else if (!stricmp(value, "OFF")) {
175  ci->botflags &= ~BS_FANTASY;
176  alog("%s: %s!%s@%s unset FANTASY on %s",
177  s_BotServ, u->nick, u->username, u->host, ci->name);
178  notice_lang(s_BotServ, u, BOT_SET_FANTASY_OFF, ci->name);
179  } else {
180  syntax_error(s_BotServ, u, "SET FANTASY",
181  BOT_SET_FANTASY_SYNTAX);
182  }
183  } else if (!stricmp(option, "GREET")) {
184  if (!stricmp(value, "ON")) {
185  ci->botflags |= BS_GREET;
186  alog("%s: %s!%s@%s set GREET on %s",
187  s_BotServ, u->nick, u->username, u->host, ci->name);
188  notice_lang(s_BotServ, u, BOT_SET_GREET_ON, ci->name);
189  } else if (!stricmp(value, "OFF")) {
190  ci->botflags &= ~BS_GREET;
191  alog("%s: %s!%s@%s unset GREET on %s",
192  s_BotServ, u->nick, u->username, u->host, ci->name);
193  notice_lang(s_BotServ, u, BOT_SET_GREET_OFF, ci->name);
194  } else {
195  syntax_error(s_BotServ, u, "SET GREET",
196  BOT_SET_GREET_SYNTAX);
197  }
198  } else if (is_servadmin && !stricmp(option, "NOBOT")) {
199  if (!stricmp(value, "ON")) {
200  ci->botflags |= BS_NOBOT;
201  if (ci->bi)
202  unassign(u, ci);
203  alog("%s: %s!%s@%s set NOBOT on %s",
204  s_BotServ, u->nick, u->username, u->host, ci->name);
205  notice_lang(s_BotServ, u, BOT_SET_NOBOT_ON, ci->name);
206  } else if (!stricmp(value, "OFF")) {
207  ci->botflags &= ~BS_NOBOT;
208  alog("%s: %s!%s@%s unset NOBOT on %s",
209  s_BotServ, u->nick, u->username, u->host, ci->name);
210  notice_lang(s_BotServ, u, BOT_SET_NOBOT_OFF, ci->name);
211  } else {
212  syntax_error(s_BotServ, u, "SET NOBOT",
213  BOT_SET_NOBOT_SYNTAX);
214  }
215  } else if (!stricmp(option, "SYMBIOSIS")) {
216  if (!stricmp(value, "ON")) {
217  ci->botflags |= BS_SYMBIOSIS;
218  alog("%s: %s!%s@%s set SYMBIOSIS on %s",
219  s_BotServ, u->nick, u->username, u->host, ci->name);
220  notice_lang(s_BotServ, u, BOT_SET_SYMBIOSIS_ON, ci->name);
221  } else if (!stricmp(value, "OFF")) {
222  ci->botflags &= ~BS_SYMBIOSIS;
223  alog("%s: %s!%s@%s unset SYMBIOSIS on %s",
224  s_BotServ, u->nick, u->username, u->host, ci->name);
225  notice_lang(s_BotServ, u, BOT_SET_SYMBIOSIS_OFF, ci->name);
226  } else {
227  syntax_error(s_BotServ, u, "SET SYMBIOSIS",
228  BOT_SET_SYMBIOSIS_SYNTAX);
229  }
230  } else {
231  notice_help(s_BotServ, u, BOT_SET_UNKNOWN, option);
232  }
233  }
234  return MOD_CONT;
235 }
#define BS_FANTASY
Definition: services.h:795
E int readonly
Definition: extern.h:776
void AnopeFini(void)
Definition: bs_set.c:71
char nick[NICKMAX]
Definition: services.h:875
uint32 botflags
Definition: services.h:700
E char * s_BotServ
Definition: extern.h:287
E int check_access(User *user, ChannelInfo *ci, int what)
Definition: chanserv.c:1974
static void myBotServHelp(User *u)
Definition: bs_set.c:82
E int stricmp(const char *s1, const char *s2)
Definition: compat.c:58
#define CI_VERBOTEN
Definition: services.h:725
char * host
Definition: services.h:878
E void unassign(User *u, ChannelInfo *ci)
Definition: botserv.c:637
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
char * help_param1
Definition: modules.h:187
#define BS_NOBOT
Definition: services.h:798
uint32 flags
Definition: services.h:669
int16 flags
Definition: services.h:577
E BotInfo * findbot(char *nick)
Definition: db-merger.c:1989
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
Command * c
Definition: ns_recover.c:17
#define BOTSERV
Definition: modules.h:57
E void notice_help(char *source, User *dest, int message,...)
Definition: send.c:220
E void alog(const char *fmt,...) FORMAT(printf
#define MOD_CONT
Definition: modules.h:54
#define BS_DONTKICKOPS
Definition: services.h:793
static int do_set(User *u)
Definition: bs_set.c:92
MDE void moduleSetBotHelp(void(*func)(User *u))
Definition: modules.c:2114
E int is_services_admin(User *u)
Definition: operserv.c:591
char * username
Definition: services.h:877
#define BI_PRIVATE
Definition: services.h:1339
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 * nick
Definition: services.h:573
E ChannelInfo * cs_findchan(const char *chan)
Definition: db-merger.c:2000
int AnopeInit(int argc, char **argv)
Definition: bs_set.c:26
E char * s_ChanServ
Definition: extern.h:285
BotInfo * bi
Definition: services.h:699
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
#define BS_GREET
Definition: services.h:797
#define CA_SET
Definition: services.h:751
#define BS_SYMBIOSIS
Definition: services.h:796
#define MOD_UNIQUE
Definition: module.h:11
#define BS_DONTKICKVOICES
Definition: services.h:794