Anope IRC Services  Version 1.8
bs_assign.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_assign(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("ASSIGN", do_assign, NULL, BOT_HELP_ASSIGN, -1, -1,
34  -1, -1);
36 
38 
39  return MOD_CONT;
40 }
41 
45 void AnopeFini(void)
46 {
47 
48 }
49 
50 
55 static void myBotServHelp(User * u)
56 {
57  notice_lang(s_BotServ, u, BOT_HELP_CMD_ASSIGN);
58 }
59 
65 static int do_assign(User * u)
66 {
67  char *chan = strtok(NULL, " ");
68  char *nick = strtok(NULL, " ");
69  BotInfo *bi;
70  ChannelInfo *ci;
71 
72  if (readonly)
73  notice_lang(s_BotServ, u, BOT_ASSIGN_READONLY);
74  else if (!chan || !nick)
75  syntax_error(s_BotServ, u, "ASSIGN", BOT_ASSIGN_SYNTAX);
76  else if (!(bi = findbot(nick)))
77  notice_lang(s_BotServ, u, BOT_DOES_NOT_EXIST, nick);
78  else if (bi->flags & BI_PRIVATE && !is_oper(u))
79  notice_lang(s_BotServ, u, PERMISSION_DENIED);
80  else if (!(ci = cs_findchan(chan)))
81  notice_lang(s_BotServ, u, CHAN_X_NOT_REGISTERED, chan);
82  else if ((ci->botflags & BS_NOBOT)
83  || (!check_access(u, ci, CA_ASSIGN) && !is_services_admin(u)))
84  notice_lang(s_BotServ, u, PERMISSION_DENIED);
85  else if (ci->flags & CI_VERBOTEN)
86  notice_lang(s_BotServ, u, CHAN_X_FORBIDDEN, chan);
87  else if ((ci->bi) && (stricmp(ci->bi->nick, nick) == 0))
88  notice_lang(s_BotServ, u, BOT_ASSIGN_ALREADY, ci->bi->nick, chan);
89  else {
90  if (ci->bi)
91  unassign(u, ci);
92  ci->bi = bi;
93  bi->chancount++;
94  if (ci->c && ci->c->usercount >= BSMinUsers) {
95  bot_join(ci);
96  }
97  alog("%s: %s!%s@%s assigned bot %s to %s", s_BotServ, u->nick, u->username,
98  u->host, bi->nick, ci->name);
99  notice_lang(s_BotServ, u, BOT_ASSIGN_ASSIGNED, bi->nick, ci->name);
100  send_event(EVENT_BOT_ASSIGN, 2, ci->name, bi->nick);
101  }
102  return MOD_CONT;
103 }
E int is_oper(User *user)
Definition: users.c:937
int16 usercount
Definition: services.h:1020
E int readonly
Definition: extern.h:776
char nick[NICKMAX]
Definition: services.h:875
uint32 botflags
Definition: services.h:700
int AnopeInit(int argc, char **argv)
Definition: bs_assign.c:26
E char * s_BotServ
Definition: extern.h:287
E int check_access(User *user, ChannelInfo *ci, int what)
Definition: chanserv.c:1974
E void send_event(const char *name, int argc,...)
Definition: events.c:37
E int stricmp(const char *s1, const char *s2)
Definition: compat.c:58
#define EVENT_BOT_ASSIGN
Definition: events.h:27
#define CI_VERBOTEN
Definition: services.h:725
int16 chancount
Definition: services.h:579
E int BSMinUsers
Definition: extern.h:422
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
static void myBotServHelp(User *u)
Definition: bs_assign.c:55
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_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
struct channel_ * c
Definition: services.h:692
Command * c
Definition: ns_recover.c:17
#define BOTSERV
Definition: modules.h:57
E void alog(const char *fmt,...) FORMAT(printf
#define MOD_CONT
Definition: modules.h:54
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
E void bot_join(ChannelInfo *ci)
Definition: botserv.c:745
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_assign(User *u)
Definition: bs_assign.c:65
char * nick
Definition: services.h:573
E ChannelInfo * cs_findchan(const char *chan)
Definition: db-merger.c:2000
BotInfo * bi
Definition: services.h:699
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
#define CA_ASSIGN
Definition: services.h:762
#define MOD_UNIQUE
Definition: module.h:11
void AnopeFini(void)
Definition: bs_assign.c:45