diff options
Diffstat (limited to 'src/botserv.c')
-rw-r--r-- | src/botserv.c | 1575 |
1 files changed, 24 insertions, 1551 deletions
diff --git a/src/botserv.c b/src/botserv.c index 0eec8f8d9..961f07cee 100644 --- a/src/botserv.c +++ b/src/botserv.c @@ -17,15 +17,6 @@ #include "services.h" #include "pseudo.h" -/** - * RFC: defination of a valid nick - * nickname = ( letter / special ) *8( letter / digit / special / "-" ) - * letter = %x41-5A / %x61-7A ; A-Z / a-z - * digit = %x30-39 ; 0-9 - * special = %x5B-60 / %x7B-7D ; "[", "]", "\", "`", "_", "^", "{", "|", "}" - **/ -#define isvalidnick(c) ( isalnum(c) || ((c) >='\x5B' && (c) <='\x60') || ((c) >='\x7B' && (c) <='\x7D') || (c)=='-' ) - /*************************************************************************/ @@ -36,62 +27,17 @@ int nbots = 0; BotInfo *makebot(char *nick); static UserData *get_user_data(Channel * c, User * u); -static void unassign(User * u, ChannelInfo * ci); +E void unassign(User * u, ChannelInfo * ci); static void check_ban(ChannelInfo * ci, User * u, int ttbtype); static void bot_kick(ChannelInfo * ci, User * u, int message, ...); -static void bot_raw_ban(User * requester, ChannelInfo * ci, char *nick, - char *reason); -static void bot_raw_kick(User * requester, ChannelInfo * ci, char *nick, - char *reason); -static void bot_raw_mode(User * requester, ChannelInfo * ci, char *mode, - char *nick); - -static int do_help(User * u); -static int do_bot(User * u); -static int do_botlist(User * u); -static int do_assign(User * u); -static int do_unassign(User * u); -static int do_info(User * u); -static int do_set(User * u); -static int do_kickcmd(User * u); -static int do_badwords(User * u); -static int do_say(User * u); -static int do_act(User * u); -void moduleAddBotServCmds(void); + +E void moduleAddBotServCmds(void); /*************************************************************************/ /* *INDENT-OFF* */ void moduleAddBotServCmds(void) { - Command *c; - c = createCommand("HELP",do_help,NULL, -1,-1,-1,-1,-1); addCoreCommand(BOTSERV,c); - c = createCommand("BOTLIST", do_botlist, NULL, BOT_HELP_BOTLIST, -1,-1,-1,-1); addCoreCommand(BOTSERV,c); - c = createCommand("ASSIGN", do_assign, NULL, BOT_HELP_ASSIGN, -1,-1,-1,-1); addCoreCommand(BOTSERV,c); - c = createCommand("UNASSIGN", do_unassign, NULL, BOT_HELP_UNASSIGN, -1,-1,-1,-1); addCoreCommand(BOTSERV,c); - c = createCommand("INFO", do_info, NULL, BOT_HELP_INFO, -1,-1,-1,-1); addCoreCommand(BOTSERV,c); - c = createCommand("SET", do_set, NULL, BOT_HELP_SET, -1,-1,BOT_SERVADMIN_HELP_SET, BOT_SERVADMIN_HELP_SET); addCoreCommand(BOTSERV,c); - c = createCommand("SET DONTKICKOPS", NULL, NULL, BOT_HELP_SET_DONTKICKOPS, -1,-1,-1,-1); addCoreCommand(BOTSERV,c); - c = createCommand("SET DONTKICKVOICES", NULL, NULL, BOT_HELP_SET_DONTKICKVOICES, -1,-1,-1,-1); addCoreCommand(BOTSERV,c); - c = createCommand("SET FANTASY", NULL, NULL, BOT_HELP_SET_FANTASY, -1,-1,-1,-1); addCoreCommand(BOTSERV,c); - c = createCommand("SET GREET", NULL, NULL, BOT_HELP_SET_GREET, -1,-1,-1,-1); addCoreCommand(BOTSERV,c); - c = createCommand("SET SYMBIOSIS", NULL, NULL, BOT_HELP_SET_SYMBIOSIS, -1,-1,-1,-1); addCoreCommand(BOTSERV,c); - c = createCommand("KICK", do_kickcmd, NULL, BOT_HELP_KICK, -1,-1,-1,-1); addCoreCommand(BOTSERV,c); - c = createCommand("KICK BADWORDS", NULL, NULL, BOT_HELP_KICK_BADWORDS, -1,-1,-1,-1); addCoreCommand(BOTSERV,c); - c = createCommand("KICK BOLDS", NULL, NULL, BOT_HELP_KICK_BOLDS, -1,-1,-1,-1); addCoreCommand(BOTSERV,c); - c = createCommand("KICK CAPS", NULL, NULL, BOT_HELP_KICK_CAPS, -1,-1,-1,-1); addCoreCommand(BOTSERV,c); - c = createCommand("KICK COLORS", NULL, NULL, BOT_HELP_KICK_COLORS, -1,-1,-1,-1); addCoreCommand(BOTSERV,c); - c = createCommand("KICK FLOOD", NULL, NULL, BOT_HELP_KICK_FLOOD, -1,-1,-1,-1); addCoreCommand(BOTSERV,c); - c = createCommand("KICK REPEAT", NULL, NULL, BOT_HELP_KICK_REPEAT, -1,-1,-1,-1); addCoreCommand(BOTSERV,c); - c = createCommand("KICK REVERSES", NULL, NULL, BOT_HELP_KICK_REVERSES, -1,-1,-1,-1); addCoreCommand(BOTSERV,c); - c = createCommand("KICK UNDERLINES", NULL, NULL, BOT_HELP_KICK_UNDERLINES, -1,-1,-1,-1); addCoreCommand(BOTSERV,c); - c = createCommand("BADWORDS", do_badwords, NULL, BOT_HELP_BADWORDS, -1,-1,-1,-1); addCoreCommand(BOTSERV,c); - c = createCommand("SAY", do_say, NULL, BOT_HELP_SAY, -1,-1,-1,-1); addCoreCommand(BOTSERV,c); - c = createCommand("ACT", do_act, NULL, BOT_HELP_ACT, -1,-1,-1,-1); addCoreCommand(BOTSERV,c); - - /* Services admins commands */ - c = createCommand("BOT", do_bot, is_services_admin, -1,-1, -1,BOT_SERVADMIN_HELP_BOT, BOT_SERVADMIN_HELP_BOT); addCoreCommand(BOTSERV,c); - c = createCommand("SET NOBOT", NULL, NULL, -1,-1, -1,BOT_SERVADMIN_HELP_SET_NOBOT, BOT_SERVADMIN_HELP_SET_NOBOT); addCoreCommand(BOTSERV,c); - c = createCommand("SET PRIVATE", NULL, NULL, -1,-1, -1,BOT_SERVADMIN_HELP_SET_PRIVATE, BOT_SERVADMIN_HELP_SET_PRIVATE); addCoreCommand(BOTSERV,c); + modules_core_init(BotServCoreNumber, BotServCoreModules); } /* *INDENT-ON* */ /*************************************************************************/ @@ -192,6 +138,7 @@ void botchanmsgs(User * u, ChannelInfo * ci, char *buf) int16 cstatus = 0; char *cmd; UserData *ud; + int found = 0; if (!u || !buf || !ci) { @@ -459,149 +406,13 @@ void botchanmsgs(User * u, ChannelInfo * ci, char *buf) && check_access(u, ci, CA_FANTASIA)) { cmd = strtok(buf, " "); - if (cmd) { - if (!stricmp(cmd, "!deowner") && ircd->owner) { - if (is_founder(u, ci)) - bot_raw_mode(u, ci, ircd->ownerunset, u->nick); - } else if (!stricmp(cmd, "!kb")) { - char *target = strtok(NULL, " "); - char *reason = strtok(NULL, ""); - - if (!target && check_access(u, ci, CA_BANME)) { - bot_raw_ban(u, ci, u->nick, "Requested"); - } else if (target && check_access(u, ci, CA_BAN)) { - if (!stricmp(target, ci->bi->nick)) { - bot_raw_ban(u, ci, u->nick, "Oops!"); - } else { - if (!reason) - bot_raw_ban(u, ci, target, "Requested"); - else - bot_raw_ban(u, ci, target, reason); - } - } - } else if ((!stricmp(cmd, "!kick")) || (!stricmp(cmd, "!k"))) { - char *target = strtok(NULL, " "); - char *reason = strtok(NULL, ""); - - if (!target && check_access(u, ci, CA_KICKME)) { - bot_raw_kick(u, ci, u->nick, "Requested"); - } else if (target && check_access(u, ci, CA_KICK)) { - if (!stricmp(target, ci->bi->nick)) - bot_raw_kick(u, ci, u->nick, "Oops!"); - else if (!reason) - bot_raw_kick(u, ci, target, "Requested"); - else - bot_raw_kick(u, ci, target, reason); - } - } else if (!stricmp(cmd, "!owner") && ircd->owner) { - if (is_founder(u, ci)) - bot_raw_mode(u, ci, ircd->ownerset, u->nick); - } else if (!stricmp(cmd, "!seen")) { - char *target = strtok(NULL, " "); - char buf[BUFSIZE]; - - if (target) { - User *u2; - NickAlias *na; - ChanAccess *access; - - if (!stricmp(ci->bi->nick, target)) { - /* If we look for the bot */ - snprintf(buf, sizeof(buf), - getstring(u->na, BOT_SEEN_BOT), u->nick); - anope_cmd_privmsg(ci->bi->nick, ci->name, "%s", - buf); - } else if (!(na = findnick(target)) - || (na->status & NS_VERBOTEN)) { - /* If the nick is not registered or forbidden */ - snprintf(buf, sizeof(buf), - getstring(u->na, BOT_SEEN_UNKNOWN), - target); - anope_cmd_privmsg(ci->bi->nick, ci->name, "%s", - buf); - } else if ((u2 = nc_on_chan(ci->c, na->nc))) { - /* If the nick we're looking for is on the channel, - * there are three possibilities: it's yourself, - * it's the nick we look for, it's an alias of the - * nick we look for. - */ - if (u == u2 || (u->na && u->na->nc == na->nc)) - snprintf(buf, sizeof(buf), - getstring(u->na, BOT_SEEN_YOU), - u->nick); - else if (!stricmp(u2->nick, target)) - snprintf(buf, sizeof(buf), - getstring(u->na, BOT_SEEN_ON_CHANNEL), - u2->nick); - else - snprintf(buf, sizeof(buf), - getstring(u->na, - BOT_SEEN_ON_CHANNEL_AS), - target, u2->nick); - anope_cmd_privmsg(ci->bi->nick, ci->name, "%s", - buf); - } else if ((access = get_access_entry(na->nc, ci))) { - /* User is on the access list but not present actually. - Special case: if access->last_seen is 0 it's that we - never seen the user. - */ - if (access->last_seen) { - char durastr[192]; - duration(u->na, durastr, sizeof(durastr), - time(NULL) - access->last_seen); - snprintf(buf, sizeof(buf), - getstring(u->na, BOT_SEEN_ON), target, - durastr); - } else { - snprintf(buf, sizeof(buf), - getstring(u->na, BOT_SEEN_NEVER), - target); - } - anope_cmd_privmsg(ci->bi->nick, ci->name, "%s", - buf); - } else if (na->nc == ci->founder) { - /* User is the founder of the channel */ - char durastr[192]; - duration(u->na, durastr, sizeof(durastr), - time(NULL) - na->last_seen); - snprintf(buf, sizeof(buf), - getstring(u->na, BOT_SEEN_ON), target, - durastr); - anope_cmd_privmsg(ci->bi->nick, ci->name, "%s", - buf); - } else { - /* All other cases */ - snprintf(buf, sizeof(buf), - getstring(u->na, BOT_SEEN_UNKNOWN), - target); - anope_cmd_privmsg(ci->bi->nick, ci->name, "%s", - buf); - } - } - } else if (!stricmp(cmd, "!unban") - && check_access(u, ci, CA_UNBAN)) { - char *target = strtok(NULL, " "); - - if (!target) - common_unban(ci, u->nick); - else - common_unban(ci, target); - } else { - CSModeUtil *util = csmodeutils; - - do { - if (!stricmp(cmd, util->bsname)) { - char *target = strtok(NULL, " "); - - if (!target - && check_access(u, ci, util->levelself)) - bot_raw_mode(u, ci, util->mode, u->nick); - else if (target - && check_access(u, ci, util->level)) - bot_raw_mode(u, ci, util->mode, target); - } - } while ((++util)->name != NULL); - } + if (cmd && (cmd[0] == '!')) { + char *params = strtok(NULL, ""); + if (params) + send_event(EVENT_BOT_FANTASY, 4, cmd, u->nick, ci->name, + params); + else + send_event(EVENT_BOT_FANTASY, 3, cmd, u->nick, ci->name); } } } @@ -732,7 +543,7 @@ void save_bs_rdb_dbase(void) /* Inserts a bot in the bot list. I can't be much explicit mh? */ -static void insert_bot(BotInfo * bi) +void insert_bot(BotInfo * bi) { BotInfo *ptr, *prev; @@ -772,46 +583,9 @@ BotInfo *makebot(char *nick) /*************************************************************************/ -static void change_bot_nick(BotInfo * bi, char *newnick) -{ - if (bi->next) - bi->next->prev = bi->prev; - if (bi->prev) - bi->prev->next = bi->next; - else - botlists[tolower(*bi->nick)] = bi->next; - - if (bi->nick) - free(bi->nick); - bi->nick = sstrdup(newnick); - - insert_bot(bi); -} /*************************************************************************/ -static int delbot(BotInfo * bi) -{ - cs_remove_bot(bi); - - if (bi->next) - bi->next->prev = bi->prev; - if (bi->prev) - bi->prev->next = bi->next; - else - botlists[tolower(*bi->nick)] = bi->next; - - nbots--; - - free(bi->nick); - free(bi->user); - free(bi->host); - free(bi->real); - - free(bi); - - return 1; -} /*************************************************************************/ @@ -847,9 +621,9 @@ BotInfo *findbot(char *nick) /* Unassign a bot from a channel. Assumes u, ci and ci->bi are not NULL */ -static void unassign(User * u, ChannelInfo * ci) +void unassign(User * u, ChannelInfo * ci) { - send_event(EVENT_BOT_UNASSIGN, ci->name); + send_event(EVENT_BOT_UNASSIGN, 2, ci->name, ci->bi->nick); if (ci->c && ci->c->usercount >= BSMinUsers) { anope_cmd_part(ci->bi->nick, ci->name, "UNASSIGN from %s", @@ -989,7 +763,7 @@ void bot_join(ChannelInfo * ci) } /* Should we be invited? */ - if ((ci->c->mode & CMODE_i) + if ((ci->c->mode & anope_get_invite_mode()) || (ci->c->limit && ci->c->usercount >= ci->c->limit)) anope_cmd_notice_ops(NULL, ci->c->name, "%s invited %s into the channel.", @@ -997,7 +771,7 @@ void bot_join(ChannelInfo * ci) } anope_cmd_join(ci->bi->nick, ci->c->name, ci->c->creation_time); anope_cmd_bot_chan_mode(ci->bi->nick, ci->c->name); - send_event(EVENT_BOT_JOIN, ci->name); + send_event(EVENT_BOT_JOIN, 2, ci->name, ci->bi->nick); } /*************************************************************************/ @@ -1078,8 +852,8 @@ static void bot_kick(ChannelInfo * ci, User * u, int message, ...) /* Makes a simple ban and kicks the target */ -static void bot_raw_ban(User * requester, ChannelInfo * ci, char *nick, - char *reason) +void bot_raw_ban(User * requester, ChannelInfo * ci, char *nick, + char *reason) { int ac; char *av[4]; @@ -1154,8 +928,8 @@ static void bot_raw_ban(User * requester, ChannelInfo * ci, char *nick, /* Makes a kick with a "dynamic" reason ;) */ -static void bot_raw_kick(User * requester, ChannelInfo * ci, char *nick, - char *reason) +void bot_raw_kick(User * requester, ChannelInfo * ci, char *nick, + char *reason) { char *av[3]; User *u = finduser(nick); @@ -1194,8 +968,8 @@ static void bot_raw_kick(User * requester, ChannelInfo * ci, char *nick, /* Makes a mode operation on a channel for a nick */ -static void bot_raw_mode(User * requester, ChannelInfo * ci, char *mode, - char *nick) +void bot_raw_mode(User * requester, ChannelInfo * ci, char *mode, + char *nick) { char *av[4]; int ac; @@ -1242,1307 +1016,6 @@ static void bot_raw_mode(User * requester, ChannelInfo * ci, char *mode, } /*************************************************************************/ - -static int do_help(User * u) -{ - char *cmd = strtok(NULL, ""); - - if (!cmd) { - notice_help(s_BotServ, u, BOT_HELP, BSMinUsers); - if (is_services_oper(u)) - notice_help(s_BotServ, u, BOT_SERVADMIN_HELP); - moduleDisplayHelp(4, u); - } else { - mod_help_cmd(s_BotServ, u, BOTSERV, cmd); - } - return MOD_CONT; -} - -/*************************************************************************/ - -static int do_bot(User * u) -{ - BotInfo *bi; - char *cmd = strtok(NULL, " "); - char *ch = NULL; - - if (!cmd) - syntax_error(s_BotServ, u, "BOT", BOT_BOT_SYNTAX); - else if (!stricmp(cmd, "ADD")) { - char *nick = strtok(NULL, " "); - char *user = strtok(NULL, " "); - char *host = strtok(NULL, " "); - char *real = strtok(NULL, ""); - - if (!nick || !user || !host || !real) - syntax_error(s_BotServ, u, "BOT", BOT_BOT_SYNTAX); - else if (readonly) - notice_lang(s_BotServ, u, BOT_BOT_READONLY); - else if (findbot(nick)) - notice_lang(s_BotServ, u, BOT_BOT_ALREADY_EXISTS, nick); - else { - NickAlias *na; - - /** - * Check the nick is valid re RFC 2812 - **/ - if (isdigit(nick[0]) || nick[0] == '-') { - notice_lang(s_BotServ, u, BOT_BAD_NICK); - return MOD_CONT; - } - for (ch = nick; *ch && (ch - nick) < NICKMAX; ch++) { - if (!isvalidnick(*ch)) { - notice_lang(s_BotServ, u, BOT_BAD_NICK); - return MOD_CONT; - } - } - - /* check for hardcored ircd forbidden nicks */ - if (!anope_valid_nick(nick)) { - notice_lang(s_BotServ, u, BOT_BAD_NICK); - return MOD_CONT; - } - - if (!isValidHost(host, 3)) { - notice_lang(s_BotServ, u, BOT_BAD_HOST); - return MOD_CONT; - } - for (ch = user; *ch && (ch - user) < USERMAX; ch++) { - if (!isalnum(*ch)) { - notice_lang(s_BotServ, u, BOT_BAD_IDENT); - return MOD_CONT; - } - } - - /** - * Check the host is valid re RFC 2812 - **/ - - /* Check whether it's a services client's nick and return if so - Certus */ - /* use nickIsServices reduce the total number lines of code - TSL */ - - if (nickIsServices(nick, 0)) { - notice_lang(s_BotServ, u, BOT_BOT_CREATION_FAILED); - return MOD_CONT; - } - - /* We check whether the nick is registered, and inform the user - * if so. You need to drop the nick manually before you can use - * it as a bot nick from now on -GD - */ - if ((na = findnick(nick))) { - notice_lang(s_BotServ, u, NICK_ALREADY_REGISTERED, nick); - return MOD_CONT; - } - - bi = makebot(nick); - if (!bi) { - notice_lang(s_BotServ, u, BOT_BOT_CREATION_FAILED); - return MOD_CONT; - } - - bi->user = sstrdup(user); - bi->host = sstrdup(host); - bi->real = sstrdup(real); - bi->created = time(NULL); - bi->chancount = 0; - - /* We check whether user with this nick is online, and kill it if so */ - EnforceQlinedNick(nick, s_BotServ); - - /* We make the bot online, ready to serve */ - anope_cmd_bot_nick(bi->nick, bi->user, bi->host, bi->real, - ircd->botserv_bot_mode); - - notice_lang(s_BotServ, u, BOT_BOT_ADDED, bi->nick, bi->user, - bi->host, bi->real); - - send_event(EVENT_BOT_CREATE, bi->nick); - } - } else if (!stricmp(cmd, "CHANGE")) { - char *oldnick = strtok(NULL, " "); - char *nick = strtok(NULL, " "); - char *user = strtok(NULL, " "); - char *host = strtok(NULL, " "); - char *real = strtok(NULL, ""); - - if (!oldnick || !nick) - syntax_error(s_BotServ, u, "BOT", BOT_BOT_SYNTAX); - else if (readonly) - notice_lang(s_BotServ, u, BOT_BOT_READONLY); - else if (!(bi = findbot(oldnick))) - notice_lang(s_BotServ, u, BOT_DOES_NOT_EXIST, oldnick); - else { - NickAlias *na; - - /* Checks whether there *are* changes. - * Case sensitive because we may want to change just the case. - * And we must finally check that the nick is not already - * taken by another bot. - */ - if (!strcmp(bi->nick, nick) - && ((user) ? !strcmp(bi->user, user) : 1) - && ((host) ? !strcmp(bi->host, host) : 1) - && ((real) ? !strcmp(bi->real, real) : 1)) { - notice_lang(s_BotServ, u, BOT_BOT_ANY_CHANGES); - return MOD_CONT; - } - - /* Check whether it's a services client's nick and return if so - Certus */ - /* use nickIsServices() to reduce the number of lines of code - TSL */ - if (nickIsServices(nick, 0)) { - notice_lang(s_BotServ, u, BOT_BOT_CREATION_FAILED); - return MOD_CONT; - } - - /** - * Check the nick is valid re RFC 2812 - **/ - if (isdigit(nick[0]) || nick[0] == '-') { - notice_lang(s_BotServ, u, BOT_BAD_NICK); - return MOD_CONT; - } - for (ch = nick; *ch && (ch - nick) < NICKMAX; ch++) { - if (!isvalidnick(*ch)) { - notice_lang(s_BotServ, u, BOT_BAD_NICK); - return MOD_CONT; - } - } - - /* check for hardcored ircd forbidden nicks */ - if (!anope_valid_nick(nick)) { - notice_lang(s_BotServ, u, BOT_BAD_NICK); - return MOD_CONT; - } - - if (!isValidHost(host, 3)) { - notice_lang(s_BotServ, u, BOT_BAD_HOST); - return MOD_CONT; - } - - for (ch = user; *ch && (ch - user) < USERMAX; ch++) { - if (!isalnum(*ch)) { - notice_lang(s_BotServ, u, BOT_BAD_IDENT); - return MOD_CONT; - } - } - - if (stricmp(bi->nick, nick) && findbot(nick)) { - notice_lang(s_BotServ, u, BOT_BOT_ALREADY_EXISTS, nick); - return MOD_CONT; - } - - if (stricmp(bi->nick, nick)) { - /* We check whether the nick is registered, and inform the user - * if so. You need to drop the nick manually before you can use - * it as a bot nick from now on -GD - */ - if ((na = findnick(nick))) { - notice_lang(s_BotServ, u, NICK_ALREADY_REGISTERED, - nick); - return MOD_CONT; - } - - /* The new nick is really different, so we remove the Q line for - the old nick. */ - if (ircd->sqline) { - anope_cmd_unsqline(bi->nick); - } - - /* We check whether user with this nick is online, and kill it if so */ - EnforceQlinedNick(nick, s_BotServ); - } - - if (strcmp(nick, bi->nick)) - change_bot_nick(bi, nick); - - if (user && strcmp(user, bi->user)) { - free(bi->user); - bi->user = sstrdup(user); - } - if (host && strcmp(host, bi->host)) { - free(bi->host); - bi->host = sstrdup(host); - } - if (real && strcmp(real, bi->real)) { - free(bi->real); - bi->real = sstrdup(real); - } - - /* If only the nick changes, we just make the bot change his nick, - else we must make it quit and rejoin. */ - if (!user) - anope_cmd_chg_nick(oldnick, bi->nick); - else { - anope_cmd_quit(oldnick, "Quit: Be right back"); - - anope_cmd_bot_nick(bi->nick, bi->user, bi->host, bi->real, - ircd->botserv_bot_mode); - bot_rejoin_all(bi); - } - - notice_lang(s_BotServ, u, BOT_BOT_CHANGED, oldnick, bi->nick, - bi->user, bi->host, bi->real); - - send_event(EVENT_BOT_CHANGE, bi->nick); - } - } else if (!stricmp(cmd, "DEL")) { - char *nick = strtok(NULL, " "); - - if (!nick) - syntax_error(s_BotServ, u, "BOT", BOT_BOT_SYNTAX); - else if (readonly) - notice_lang(s_BotServ, u, BOT_BOT_READONLY); - else if (!(bi = findbot(nick))) - notice_lang(s_BotServ, u, BOT_DOES_NOT_EXIST, nick); - else { - send_event(EVENT_BOT_DEL, bi->nick); - anope_cmd_quit(bi->nick, - "Quit: Help! I'm being deleted by %s!", - u->nick); - if (ircd->sqline) { - anope_cmd_unsqline(bi->nick); - } - delbot(bi); - - notice_lang(s_BotServ, u, BOT_BOT_DELETED, nick); - } - } else if (!stricmp(cmd, "LIST")) - do_botlist(u); - else - syntax_error(s_BotServ, u, "BOT", BOT_BOT_SYNTAX); - - return MOD_CONT; -} - -/*************************************************************************/ - -static int do_botlist(User * u) -{ - int i, count = 0; - BotInfo *bi; - - if (!nbots) { - notice_lang(s_BotServ, u, BOT_BOTLIST_EMPTY); - return MOD_CONT; - } - - for (i = 0; i < 256; i++) { - for (bi = botlists[i]; bi; bi = bi->next) { - if (!(bi->flags & BI_PRIVATE)) { - if (!count) - notice_lang(s_BotServ, u, BOT_BOTLIST_HEADER); - count++; - notice_user(s_BotServ, u, " %-15s (%s@%s)", bi->nick, - bi->user, bi->host); - } - } - } - - if (is_oper(u) && count < nbots) { - notice_lang(s_BotServ, u, BOT_BOTLIST_PRIVATE_HEADER); - - for (i = 0; i < 256; i++) { - for (bi = botlists[i]; bi; bi = bi->next) { - if (bi->flags & BI_PRIVATE) { - notice_user(s_BotServ, u, " %-15s (%s@%s)", - bi->nick, bi->user, bi->host); - count++; - } - } - } - } - - if (!count) - notice_lang(s_BotServ, u, BOT_BOTLIST_EMPTY); - else - notice_lang(s_BotServ, u, BOT_BOTLIST_FOOTER, count); - return MOD_CONT; -} - -/*************************************************************************/ - -static int do_assign(User * u) -{ - char *chan = strtok(NULL, " "); - char *nick = strtok(NULL, " "); - BotInfo *bi; - ChannelInfo *ci; - - if (readonly) - notice_lang(s_BotServ, u, BOT_ASSIGN_READONLY); - else if (!chan || !nick) - syntax_error(s_BotServ, u, "ASSIGN", BOT_ASSIGN_SYNTAX); - else if (!(bi = findbot(nick))) - notice_lang(s_BotServ, u, BOT_DOES_NOT_EXIST, nick); - else if (bi->flags & BI_PRIVATE && !is_oper(u)) - notice_lang(s_BotServ, u, PERMISSION_DENIED); - else if (!(ci = cs_findchan(chan))) - notice_lang(s_BotServ, u, CHAN_X_NOT_REGISTERED, chan); - else if (ci->flags & CI_VERBOTEN) - notice_lang(s_BotServ, u, CHAN_X_FORBIDDEN, chan); - else if ((ci->bi) && (stricmp(ci->bi->nick, nick) == 0)) - notice_lang(s_BotServ, u, BOT_ASSIGN_ALREADY, ci->bi->nick, chan); - else if ((ci->botflags & BS_NOBOT) - || (!check_access(u, ci, CA_ASSIGN) && !is_services_admin(u))) - notice_lang(s_BotServ, u, PERMISSION_DENIED); - else { - if (ci->bi) - unassign(u, ci); - ci->bi = bi; - bi->chancount++; - if (ci->c && ci->c->usercount >= BSMinUsers) { - bot_join(ci); - } - notice_lang(s_BotServ, u, BOT_ASSIGN_ASSIGNED, bi->nick, ci->name); - send_event(EVENT_BOT_ASSIGN, ci->name); - } - return MOD_CONT; -} - -/*************************************************************************/ - -static int do_unassign(User * u) -{ - char *chan = strtok(NULL, " "); - ChannelInfo *ci; - - if (readonly) - notice_lang(s_BotServ, u, BOT_ASSIGN_READONLY); - else if (!chan) - syntax_error(s_BotServ, u, "UNASSIGN", BOT_UNASSIGN_SYNTAX); - else if (!(ci = cs_findchan(chan))) - notice_lang(s_BotServ, u, CHAN_X_NOT_REGISTERED, chan); - else if (ci->flags & CI_VERBOTEN) - notice_lang(s_BotServ, u, CHAN_X_FORBIDDEN, chan); - else if (!is_services_admin(u) && !check_access(u, ci, CA_ASSIGN)) - notice_lang(s_BotServ, u, ACCESS_DENIED); - else { - if (ci->bi) - unassign(u, ci); - notice_lang(s_BotServ, u, BOT_UNASSIGN_UNASSIGNED, ci->name); - } - return MOD_CONT; -} - -/*************************************************************************/ - -static void send_bot_channels(User * u, BotInfo * bi) -{ - int i; - ChannelInfo *ci; - char buf[307], *end; - - *buf = 0; - end = buf; - - for (i = 0; i < 256; i++) { - for (ci = chanlists[i]; ci; ci = ci->next) { - if (ci->bi == bi) { - if (strlen(buf) + strlen(ci->name) > 300) { - notice_user(s_BotServ, u, buf); - *buf = 0; - end = buf; - } - end += - snprintf(end, sizeof(buf) - (end - buf), " %s ", - ci->name); - } - } - } - - if (*buf) - notice_user(s_BotServ, u, buf); - return; -} - -static int do_info(User * u) -{ - BotInfo *bi; - ChannelInfo *ci; - char *query = strtok(NULL, " "); - - int need_comma = 0, is_servadmin = is_services_admin(u); - char buf[BUFSIZE], *end; - const char *commastr = getstring(u->na, COMMA_SPACE); - - if (!query) - syntax_error(s_BotServ, u, "INFO", BOT_INFO_SYNTAX); - else if ((bi = findbot(query))) { - char buf[BUFSIZE]; - struct tm *tm; - - notice_lang(s_BotServ, u, BOT_INFO_BOT_HEADER, bi->nick); - notice_lang(s_BotServ, u, BOT_INFO_BOT_MASK, bi->user, bi->host); - notice_lang(s_BotServ, u, BOT_INFO_BOT_REALNAME, bi->real); - tm = localtime(&bi->created); - strftime_lang(buf, sizeof(buf), u, STRFTIME_DATE_TIME_FORMAT, tm); - notice_lang(s_BotServ, u, BOT_INFO_BOT_CREATED, buf); - notice_lang(s_BotServ, u, BOT_INFO_BOT_OPTIONS, - getstring(u->na, - (bi-> - flags & BI_PRIVATE) ? BOT_INFO_OPT_PRIVATE : - BOT_INFO_OPT_NONE)); - notice_lang(s_BotServ, u, BOT_INFO_BOT_USAGE, bi->chancount); - - if (is_services_admin(u)) - send_bot_channels(u, bi); - } else if ((ci = cs_findchan(query))) { - if (!is_servadmin && !is_founder(u, ci)) { - notice_lang(s_BotServ, u, PERMISSION_DENIED); - return MOD_CONT; - } - if (ci->flags & CI_VERBOTEN) { - notice_lang(s_BotServ, u, CHAN_X_FORBIDDEN, query); - return MOD_CONT; - } - - notice_lang(s_BotServ, u, BOT_INFO_CHAN_HEADER, ci->name); - if (ci->bi) - notice_lang(s_BotServ, u, BOT_INFO_CHAN_BOT, ci->bi->nick); - else - notice_lang(s_BotServ, u, BOT_INFO_CHAN_BOT_NONE); - - if (ci->botflags & BS_KICK_BADWORDS) { - if (ci->ttb[TTB_BADWORDS]) - notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_BADWORDS_BAN, - getstring(u->na, BOT_INFO_ACTIVE), - ci->ttb[TTB_BADWORDS]); - else - notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_BADWORDS, - getstring(u->na, BOT_INFO_ACTIVE)); - } else - notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_BADWORDS, - getstring(u->na, BOT_INFO_INACTIVE)); - if (ci->botflags & BS_KICK_BOLDS) { - if (ci->ttb[TTB_BOLDS]) - notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_BOLDS_BAN, - getstring(u->na, BOT_INFO_ACTIVE), - ci->ttb[TTB_BOLDS]); - else - notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_BOLDS, - getstring(u->na, BOT_INFO_ACTIVE)); - } else - notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_BOLDS, - getstring(u->na, BOT_INFO_INACTIVE)); - if (ci->botflags & BS_KICK_CAPS) { - if (ci->ttb[TTB_CAPS]) - notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_CAPS_BAN, - getstring(u->na, BOT_INFO_ACTIVE), - ci->ttb[TTB_CAPS], ci->capsmin, - ci->capspercent); - else - notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_CAPS_ON, - getstring(u->na, BOT_INFO_ACTIVE), ci->capsmin, - ci->capspercent); - } else - notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_CAPS_OFF, - getstring(u->na, BOT_INFO_INACTIVE)); - if (ci->botflags & BS_KICK_COLORS) { - if (ci->ttb[TTB_COLORS]) - notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_COLORS_BAN, - getstring(u->na, BOT_INFO_ACTIVE), - ci->ttb[TTB_COLORS]); - else - notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_COLORS, - getstring(u->na, BOT_INFO_ACTIVE)); - } else - notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_COLORS, - getstring(u->na, BOT_INFO_INACTIVE)); - if (ci->botflags & BS_KICK_FLOOD) { - if (ci->ttb[TTB_FLOOD]) - notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_FLOOD_BAN, - getstring(u->na, BOT_INFO_ACTIVE), - ci->ttb[TTB_FLOOD], ci->floodlines, - ci->floodsecs); - else - notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_FLOOD_ON, - getstring(u->na, BOT_INFO_ACTIVE), - ci->floodlines, ci->floodsecs); - } else - notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_FLOOD_OFF, - getstring(u->na, BOT_INFO_INACTIVE)); - if (ci->botflags & BS_KICK_REPEAT) { - if (ci->ttb[TTB_REPEAT]) - notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_REPEAT_BAN, - getstring(u->na, BOT_INFO_ACTIVE), - ci->ttb[TTB_REPEAT], ci->repeattimes); - else - notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_REPEAT_ON, - getstring(u->na, BOT_INFO_ACTIVE), - ci->repeattimes); - } else - notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_REPEAT_OFF, - getstring(u->na, BOT_INFO_INACTIVE)); - if (ci->botflags & BS_KICK_REVERSES) { - if (ci->ttb[TTB_REVERSES]) - notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_REVERSES_BAN, - getstring(u->na, BOT_INFO_ACTIVE), - ci->ttb[TTB_REVERSES]); - else - notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_REVERSES, - getstring(u->na, BOT_INFO_ACTIVE)); - } else - notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_REVERSES, - getstring(u->na, BOT_INFO_INACTIVE)); - if (ci->botflags & BS_KICK_UNDERLINES) { - if (ci->ttb[TTB_UNDERLINES]) - notice_lang(s_BotServ, u, - BOT_INFO_CHAN_KICK_UNDERLINES_BAN, - getstring(u->na, BOT_INFO_ACTIVE), - ci->ttb[TTB_UNDERLINES]); - else - notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_UNDERLINES, - getstring(u->na, BOT_INFO_ACTIVE)); - } else - notice_lang(s_BotServ, u, BOT_INFO_CHAN_KICK_UNDERLINES, - getstring(u->na, BOT_INFO_INACTIVE)); - - end = buf; - *end = 0; - if (ci->botflags & BS_DONTKICKOPS) { - end += snprintf(end, sizeof(buf) - (end - buf), "%s", - getstring(u->na, BOT_INFO_OPT_DONTKICKOPS)); - need_comma = 1; - } - if (ci->botflags & BS_DONTKICKVOICES) { - end += snprintf(end, sizeof(buf) - (end - buf), "%s%s", - need_comma ? commastr : "", - getstring(u->na, BOT_INFO_OPT_DONTKICKVOICES)); - need_comma = 1; - } - if (ci->botflags & BS_FANTASY) { - end += snprintf(end, sizeof(buf) - (end - buf), "%s%s", - need_comma ? commastr : "", - getstring(u->na, BOT_INFO_OPT_FANTASY)); - need_comma = 1; - } - if (ci->botflags & BS_GREET) { - end += snprintf(end, sizeof(buf) - (end - buf), "%s%s", - need_comma ? commastr : "", - getstring(u->na, BOT_INFO_OPT_GREET)); - need_comma = 1; - } - if (ci->botflags & BS_NOBOT) { - end += snprintf(end, sizeof(buf) - (end - buf), "%s%s", - need_comma ? commastr : "", - getstring(u->na, BOT_INFO_OPT_NOBOT)); - need_comma = 1; - } - if (ci->botflags & BS_SYMBIOSIS) { - end += snprintf(end, sizeof(buf) - (end - buf), "%s%s", - need_comma ? commastr : "", - getstring(u->na, BOT_INFO_OPT_SYMBIOSIS)); - need_comma = 1; - } - notice_lang(s_BotServ, u, BOT_INFO_CHAN_OPTIONS, - *buf ? buf : getstring(u->na, BOT_INFO_OPT_NONE)); - - } else - notice_lang(s_BotServ, u, BOT_INFO_NOT_FOUND, query); - return MOD_CONT; -} - -/*************************************************************************/ - -static int do_set(User * u) -{ - char *chan = strtok(NULL, " "); - char *option = strtok(NULL, " "); - char *value = strtok(NULL, " "); - int is_servadmin = is_services_admin(u); - - ChannelInfo *ci; - - if (readonly) - notice_lang(s_BotServ, u, BOT_SET_DISABLED); - else if (!chan || !option || !value) - syntax_error(s_BotServ, u, "SET", BOT_SET_SYNTAX); - else if (is_servadmin && !stricmp(option, "PRIVATE")) { - BotInfo *bi; - - if ((bi = findbot(chan))) { - if (!stricmp(value, "ON")) { - bi->flags |= BI_PRIVATE; - notice_lang(s_BotServ, u, BOT_SET_PRIVATE_ON, bi->nick); - } else if (!stricmp(value, "OFF")) { - bi->flags &= ~BI_PRIVATE; - notice_lang(s_BotServ, u, BOT_SET_PRIVATE_OFF, bi->nick); - } else { - syntax_error(s_BotServ, u, "SET PRIVATE", - BOT_SET_PRIVATE_SYNTAX); - } - } else { - notice_lang(s_BotServ, u, BOT_DOES_NOT_EXIST, chan); - } - return MOD_CONT; - } else if (!(ci = cs_findchan(chan))) - notice_lang(s_BotServ, u, CHAN_X_NOT_REGISTERED, chan); - else if (ci->flags & CI_VERBOTEN) - notice_lang(s_BotServ, u, CHAN_X_FORBIDDEN, chan); - else if (!is_servadmin && !check_access(u, ci, CA_SET)) - notice_lang(s_BotServ, u, ACCESS_DENIED); - else { - if (!stricmp(option, "DONTKICKOPS")) { - if (!stricmp(value, "ON")) { - ci->botflags |= BS_DONTKICKOPS; - notice_lang(s_BotServ, u, BOT_SET_DONTKICKOPS_ON, - ci->name); - } else if (!stricmp(value, "OFF")) { - ci->botflags &= ~BS_DONTKICKOPS; - notice_lang(s_BotServ, u, BOT_SET_DONTKICKOPS_OFF, - ci->name); - } else { - syntax_error(s_BotServ, u, "SET DONTKICKOPS", - BOT_SET_DONTKICKOPS_SYNTAX); - } - } else if (!stricmp(option, "DONTKICKVOICES")) { - if (!stricmp(value, "ON")) { - ci->botflags |= BS_DONTKICKVOICES; - notice_lang(s_BotServ, u, BOT_SET_DONTKICKVOICES_ON, - ci->name); - } else if (!stricmp(value, "OFF")) { - ci->botflags &= ~BS_DONTKICKVOICES; - notice_lang(s_BotServ, u, BOT_SET_DONTKICKVOICES_OFF, - ci->name); - } else { - syntax_error(s_BotServ, u, "SET DONTKICKVOICES", - BOT_SET_DONTKICKVOICES_SYNTAX); - } - } else if (!stricmp(option, "FANTASY")) { - if (!stricmp(value, "ON")) { - ci->botflags |= BS_FANTASY; - notice_lang(s_BotServ, u, BOT_SET_FANTASY_ON, ci->name); - } else if (!stricmp(value, "OFF")) { - ci->botflags &= ~BS_FANTASY; - notice_lang(s_BotServ, u, BOT_SET_FANTASY_OFF, ci->name); - } else { - syntax_error(s_BotServ, u, "SET FANTASY", - BOT_SET_FANTASY_SYNTAX); - } - } else if (!stricmp(option, "GREET")) { - if (!stricmp(value, "ON")) { - ci->botflags |= BS_GREET; - notice_lang(s_BotServ, u, BOT_SET_GREET_ON, ci->name); - } else if (!stricmp(value, "OFF")) { - ci->botflags &= ~BS_GREET; - notice_lang(s_BotServ, u, BOT_SET_GREET_OFF, ci->name); - } else { - syntax_error(s_BotServ, u, "SET GREET", - BOT_SET_GREET_SYNTAX); - } - } else if (is_servadmin && !stricmp(option, "NOBOT")) { - if (!stricmp(value, "ON")) { - ci->botflags |= BS_NOBOT; - if (ci->bi) - unassign(u, ci); - notice_lang(s_BotServ, u, BOT_SET_NOBOT_ON, ci->name); - } else if (!stricmp(value, "OFF")) { - ci->botflags &= ~BS_NOBOT; - notice_lang(s_BotServ, u, BOT_SET_NOBOT_OFF, ci->name); - } else { - syntax_error(s_BotServ, u, "SET NOBOT", - BOT_SET_NOBOT_SYNTAX); - } - } else if (!stricmp(option, "SYMBIOSIS")) { - if (!stricmp(value, "ON")) { - ci->botflags |= BS_SYMBIOSIS; - notice_lang(s_BotServ, u, BOT_SET_SYMBIOSIS_ON, ci->name); - } else if (!stricmp(value, "OFF")) { - ci->botflags &= ~BS_SYMBIOSIS; - notice_lang(s_BotServ, u, BOT_SET_SYMBIOSIS_OFF, ci->name); - } else { - syntax_error(s_BotServ, u, "SET SYMBIOSIS", - BOT_SET_SYMBIOSIS_SYNTAX); - } - } else { - notice_help(s_BotServ, u, BOT_SET_UNKNOWN, option); - } - } - return MOD_CONT; -} - -/*************************************************************************/ - -static int do_kickcmd(User * u) -{ - char *chan = strtok(NULL, " "); - char *option = strtok(NULL, " "); - char *value = strtok(NULL, " "); - char *ttb = strtok(NULL, " "); - - ChannelInfo *ci; - - if (readonly) - notice_lang(s_BotServ, u, BOT_KICK_DISABLED); - else if (!chan || !option || !value) - syntax_error(s_BotServ, u, "KICK", BOT_KICK_SYNTAX); - else if (stricmp(value, "ON") && stricmp(value, "OFF")) - syntax_error(s_BotServ, u, "KICK", BOT_KICK_SYNTAX); - else if (!(ci = cs_findchan(chan))) - notice_lang(s_BotServ, u, CHAN_X_NOT_REGISTERED, chan); - else if (ci->flags & CI_VERBOTEN) - notice_lang(s_BotServ, u, CHAN_X_FORBIDDEN, chan); - else if (!is_services_admin(u) && !check_access(u, ci, CA_SET)) - notice_lang(s_BotServ, u, ACCESS_DENIED); - else { - if (!stricmp(option, "BADWORDS")) { - if (!stricmp(value, "ON")) { - if (ttb) { - ci->ttb[TTB_BADWORDS] = - strtol(ttb, (char **) NULL, 10); - /* Only error if errno returns ERANGE or EINVAL or we are less then 0 - TSL */ - if (errno == ERANGE || errno == EINVAL - || ci->ttb[TTB_BADWORDS] < 0) { - /* leaving the debug behind since we might want to know what these are */ - if (debug) { - alog("debug: errno is %d ERANGE %d EINVAL %d ttb %d", errno, ERANGE, EINVAL, ci->ttb[TTB_BADWORDS]); - } - /* reset the value back to 0 - TSL */ - ci->ttb[TTB_BADWORDS] = 0; - notice_lang(s_BotServ, u, BOT_KICK_BAD_TTB, ttb); - return MOD_CONT; - } - } else { - ci->ttb[TTB_BADWORDS] = 0; - } - ci->botflags |= BS_KICK_BADWORDS; - if (ci->ttb[TTB_BADWORDS]) - notice_lang(s_BotServ, u, BOT_KICK_BADWORDS_ON_BAN, - ci->ttb[TTB_BADWORDS]); - else - notice_lang(s_BotServ, u, BOT_KICK_BADWORDS_ON); - } else { - ci->botflags &= ~BS_KICK_BADWORDS; - notice_lang(s_BotServ, u, BOT_KICK_BADWORDS_OFF); - } - } else if (!stricmp(option, "BOLDS")) { - if (!stricmp(value, "ON")) { - if (ttb) { - ci->ttb[TTB_BOLDS] = strtol(ttb, (char **) NULL, 10); - if (errno == ERANGE || errno == EINVAL - || ci->ttb[TTB_BOLDS] < 0) { - if (debug) { - alog("debug: errno is %d ERANGE %d EINVAL %d ttb %d", errno, ERANGE, EINVAL, ci->ttb[TTB_BOLDS]); - } - ci->ttb[TTB_BOLDS] = 0; - notice_lang(s_BotServ, u, BOT_KICK_BAD_TTB, ttb); - return MOD_CONT; - } - } else - ci->ttb[TTB_BOLDS] = 0; - ci->botflags |= BS_KICK_BOLDS; - if (ci->ttb[TTB_BOLDS]) - notice_lang(s_BotServ, u, BOT_KICK_BOLDS_ON_BAN, - ci->ttb[TTB_BOLDS]); - else - notice_lang(s_BotServ, u, BOT_KICK_BOLDS_ON); - } else { - ci->botflags &= ~BS_KICK_BOLDS; - notice_lang(s_BotServ, u, BOT_KICK_BOLDS_OFF); - } - } else if (!stricmp(option, "CAPS")) { - if (!stricmp(value, "ON")) { - char *min = strtok(NULL, " "); - char *percent = strtok(NULL, " "); - - if (ttb) { - ci->ttb[TTB_CAPS] = strtol(ttb, (char **) NULL, 10); - if (errno == ERANGE || errno == EINVAL - || ci->ttb[TTB_CAPS] < 0) { - if (debug) { - alog("debug: errno is %d ERANGE %d EINVAL %d ttb %d", errno, ERANGE, EINVAL, ci->ttb[TTB_CAPS]); - } - ci->ttb[TTB_CAPS] = 0; - notice_lang(s_BotServ, u, BOT_KICK_BAD_TTB, ttb); - return MOD_CONT; - } - } else - ci->ttb[TTB_CAPS] = 0; - - if (!min) - ci->capsmin = 10; - else - ci->capsmin = atol(min); - if (ci->capsmin < 1) - ci->capsmin = 10; - - if (!percent) - ci->capspercent = 25; - else - ci->capspercent = atol(percent); - if (ci->capspercent < 1 || ci->capspercent > 100) - ci->capspercent = 25; - - ci->botflags |= BS_KICK_CAPS; - if (ci->ttb[TTB_CAPS]) - notice_lang(s_BotServ, u, BOT_KICK_CAPS_ON_BAN, - ci->capsmin, ci->capspercent, - ci->ttb[TTB_CAPS]); - else - notice_lang(s_BotServ, u, BOT_KICK_CAPS_ON, - ci->capsmin, ci->capspercent); - } else { - ci->botflags &= ~BS_KICK_CAPS; - notice_lang(s_BotServ, u, BOT_KICK_CAPS_OFF); - } - } else if (!stricmp(option, "COLORS")) { - if (!stricmp(value, "ON")) { - if (ttb) { - ci->ttb[TTB_COLORS] = strtol(ttb, (char **) NULL, 10); - if (errno == ERANGE || errno == EINVAL - || ci->ttb[TTB_COLORS] < 0) { - if (debug) { - alog("debug: errno is %d ERANGE %d EINVAL %d ttb %d", errno, ERANGE, EINVAL, ci->ttb[TTB_COLORS]); - } - ci->ttb[TTB_COLORS] = 0; - notice_lang(s_BotServ, u, BOT_KICK_BAD_TTB, ttb); - return MOD_CONT; - } - } else - ci->ttb[TTB_COLORS] = 0; - ci->botflags |= BS_KICK_COLORS; - if (ci->ttb[TTB_COLORS]) - notice_lang(s_BotServ, u, BOT_KICK_COLORS_ON_BAN, - ci->ttb[TTB_COLORS]); - else - notice_lang(s_BotServ, u, BOT_KICK_COLORS_ON); - } else { - ci->botflags &= ~BS_KICK_COLORS; - notice_lang(s_BotServ, u, BOT_KICK_COLORS_OFF); - } - } else if (!stricmp(option, "FLOOD")) { - if (!stricmp(value, "ON")) { - char *lines = strtok(NULL, " "); - char *secs = strtok(NULL, " "); - - if (ttb) { - ci->ttb[TTB_FLOOD] = strtol(ttb, (char **) NULL, 10); - if (errno == ERANGE || errno == EINVAL - || ci->ttb[TTB_FLOOD] < 0) { - if (debug) { - alog("debug: errno is %d ERANGE %d EINVAL %d ttb %d", errno, ERANGE, EINVAL, ci->ttb[TTB_FLOOD]); - } - ci->ttb[TTB_FLOOD] = 0; - notice_lang(s_BotServ, u, BOT_KICK_BAD_TTB, ttb); - return MOD_CONT; - } - } else - ci->ttb[TTB_FLOOD] = 0; - - if (!lines) - ci->floodlines = 6; - else - ci->floodlines = atol(lines); - if (ci->floodlines < 2) - ci->floodlines = 6; - - if (!secs) - ci->floodsecs = 10; - else - ci->floodsecs = atol(secs); - if (ci->floodsecs < 1 || ci->floodsecs > BSKeepData) - ci->floodsecs = 10; - - ci->botflags |= BS_KICK_FLOOD; - if (ci->ttb[TTB_FLOOD]) - notice_lang(s_BotServ, u, BOT_KICK_FLOOD_ON_BAN, - ci->floodlines, ci->floodsecs, - ci->ttb[TTB_FLOOD]); - else - notice_lang(s_BotServ, u, BOT_KICK_FLOOD_ON, - ci->floodlines, ci->floodsecs); - } else { - ci->botflags &= ~BS_KICK_FLOOD; - notice_lang(s_BotServ, u, BOT_KICK_FLOOD_OFF); - } - } else if (!stricmp(option, "REPEAT")) { - if (!stricmp(value, "ON")) { - char *times = strtok(NULL, " "); - - if (ttb) { - ci->ttb[TTB_REPEAT] = strtol(ttb, (char **) NULL, 10); - if (errno == ERANGE || errno == EINVAL - || ci->ttb[TTB_REPEAT] < 0) { - if (debug) { - alog("debug: errno is %d ERANGE %d EINVAL %d ttb %d", errno, ERANGE, EINVAL, ci->ttb[TTB_REPEAT]); - } - ci->ttb[TTB_REPEAT] = 0; - notice_lang(s_BotServ, u, BOT_KICK_BAD_TTB, ttb); - return MOD_CONT; - } - } else - ci->ttb[TTB_REPEAT] = 0; - - if (!times) - ci->repeattimes = 3; - else - ci->repeattimes = atol(times); - if (ci->repeattimes < 2) - ci->repeattimes = 3; - - ci->botflags |= BS_KICK_REPEAT; - if (ci->ttb[TTB_REPEAT]) - notice_lang(s_BotServ, u, BOT_KICK_REPEAT_ON_BAN, - ci->repeattimes, ci->ttb[TTB_REPEAT]); - else - notice_lang(s_BotServ, u, BOT_KICK_REPEAT_ON, - ci->repeattimes); - } else { - ci->botflags &= ~BS_KICK_REPEAT; - notice_lang(s_BotServ, u, BOT_KICK_REPEAT_OFF); - } - } else if (!stricmp(option, "REVERSES")) { - if (!stricmp(value, "ON")) { - if (ttb) { - ci->ttb[TTB_REVERSES] = - strtol(ttb, (char **) NULL, 10); - if (errno == ERANGE || errno == EINVAL - || ci->ttb[TTB_REVERSES] < 0) { - if (debug) { - alog("debug: errno is %d ERANGE %d EINVAL %d ttb %d", errno, ERANGE, EINVAL, ci->ttb[TTB_REVERSES]); - } - ci->ttb[TTB_REVERSES] = 0; - notice_lang(s_BotServ, u, BOT_KICK_BAD_TTB, ttb); - return MOD_CONT; - } - } else - ci->ttb[TTB_REVERSES] = 0; - ci->botflags |= BS_KICK_REVERSES; - if (ci->ttb[TTB_REVERSES]) - notice_lang(s_BotServ, u, BOT_KICK_REVERSES_ON_BAN, - ci->ttb[TTB_REVERSES]); - else - notice_lang(s_BotServ, u, BOT_KICK_REVERSES_ON); - } else { - ci->botflags &= ~BS_KICK_REVERSES; - notice_lang(s_BotServ, u, BOT_KICK_REVERSES_OFF); - } - } else if (!stricmp(option, "UNDERLINES")) { - if (!stricmp(value, "ON")) { - if (ttb) { - ci->ttb[TTB_UNDERLINES] = - strtol(ttb, (char **) NULL, 10); - if (errno == ERANGE || errno == EINVAL - || ci->ttb[TTB_UNDERLINES] < 0) { - if (debug) { - alog("debug: errno is %d ERANGE %d EINVAL %d ttb %d", errno, ERANGE, EINVAL, ci->ttb[TTB_UNDERLINES]); - } - ci->ttb[TTB_UNDERLINES] = 0; - notice_lang(s_BotServ, u, BOT_KICK_BAD_TTB, ttb); - return MOD_CONT; - } - } else - ci->ttb[TTB_UNDERLINES] = 0; - ci->botflags |= BS_KICK_UNDERLINES; - if (ci->ttb[TTB_UNDERLINES]) - notice_lang(s_BotServ, u, BOT_KICK_UNDERLINES_ON_BAN, - ci->ttb[TTB_UNDERLINES]); - else - notice_lang(s_BotServ, u, BOT_KICK_UNDERLINES_ON); - } else { - ci->botflags &= ~BS_KICK_UNDERLINES; - notice_lang(s_BotServ, u, BOT_KICK_UNDERLINES_OFF); - } - } else - notice_help(s_BotServ, u, BOT_KICK_UNKNOWN, option); - } - return MOD_CONT; -} - -/*************************************************************************/ - -static int badwords_del_callback(User * u, int num, va_list args) -{ - BadWord *bw; - ChannelInfo *ci = va_arg(args, ChannelInfo *); - int *last = va_arg(args, int *); - if (num < 1 || num > ci->bwcount) - return 0; - *last = num; - - bw = &ci->badwords[num - 1]; - if (bw->word) - free(bw->word); - bw->word = NULL; - bw->in_use = 0; - - return 1; -} - -static int badwords_list(User * u, int index, ChannelInfo * ci, - int *sent_header) -{ - BadWord *bw = &ci->badwords[index]; - - if (!bw->in_use) - return 0; - if (!*sent_header) { - notice_lang(s_BotServ, u, BOT_BADWORDS_LIST_HEADER, ci->name); - *sent_header = 1; - } - - notice_lang(s_BotServ, u, BOT_BADWORDS_LIST_FORMAT, index + 1, - bw->word, - ((bw->type == - BW_SINGLE) ? "(SINGLE)" : ((bw->type == - BW_START) ? "(START)" - : ((bw->type == - BW_END) ? "(END)" : ""))) - ); - return 1; -} - -static int badwords_list_callback(User * u, int num, va_list args) -{ - ChannelInfo *ci = va_arg(args, ChannelInfo *); - int *sent_header = va_arg(args, int *); - if (num < 1 || num > ci->bwcount) - return 0; - return badwords_list(u, num - 1, ci, sent_header); -} - -static int do_badwords(User * u) -{ - char *chan = strtok(NULL, " "); - char *cmd = strtok(NULL, " "); - char *word = strtok(NULL, ""); - ChannelInfo *ci; - BadWord *bw; - - int i; - int need_args = (cmd - && (!stricmp(cmd, "LIST") || !stricmp(cmd, "CLEAR"))); - - if (!cmd || (need_args ? 0 : !word)) { - syntax_error(s_BotServ, u, "BADWORDS", BOT_BADWORDS_SYNTAX); - } else if (!(ci = cs_findchan(chan))) { - notice_lang(s_BotServ, u, CHAN_X_NOT_REGISTERED, chan); - } else if (ci->flags & CI_VERBOTEN) { - notice_lang(s_BotServ, u, CHAN_X_FORBIDDEN, chan); - } else if (!check_access(u, ci, CA_BADWORDS) - && (!need_args || !is_services_admin(u))) { - notice_lang(s_BotServ, u, ACCESS_DENIED); - } else if (stricmp(cmd, "ADD") == 0) { - - char *opt, *pos; - int type = BW_ANY; - - if (readonly) { - notice_lang(s_BotServ, u, BOT_BADWORDS_DISABLED); - return MOD_CONT; - } - - pos = strrchr(word, ' '); - if (pos) { - opt = pos + 1; - if (*opt) { - if (!stricmp(opt, "SINGLE")) - type = BW_SINGLE; - else if (!stricmp(opt, "START")) - type = BW_START; - else if (!stricmp(opt, "END")) - type = BW_END; - if (type != BW_ANY) - *pos = 0; - } - } - - for (bw = ci->badwords, i = 0; i < ci->bwcount; bw++, i++) { - if (bw->word && ((BSCaseSensitive && (!strcmp(bw->word, word))) - || (!BSCaseSensitive - && (!stricmp(bw->word, word))))) { - notice_lang(s_BotServ, u, BOT_BADWORDS_ALREADY_EXISTS, - bw->word, ci->name); - return MOD_CONT; - } - } - - for (i = 0; i < ci->bwcount; i++) { - if (!ci->badwords[i].in_use) - break; - } - if (i == ci->bwcount) { - if (i < BSBadWordsMax) { - ci->bwcount++; - ci->badwords = - srealloc(ci->badwords, sizeof(BadWord) * ci->bwcount); - } else { - notice_lang(s_BotServ, u, BOT_BADWORDS_REACHED_LIMIT, - BSBadWordsMax); - return MOD_CONT; - } - } - bw = &ci->badwords[i]; - bw->in_use = 1; - bw->word = sstrdup(word); - bw->type = type; - - notice_lang(s_BotServ, u, BOT_BADWORDS_ADDED, bw->word, ci->name); - - } else if (stricmp(cmd, "DEL") == 0) { - - if (readonly) { - notice_lang(s_BotServ, u, BOT_BADWORDS_DISABLED); - return MOD_CONT; - } - - /* Special case: is it a number/list? Only do search if it isn't. */ - if (isdigit(*word) && strspn(word, "1234567890,-") == strlen(word)) { - int count, deleted, last = -1; - deleted = - process_numlist(word, &count, badwords_del_callback, u, ci, - &last); - if (!deleted) { - if (count == 1) { - notice_lang(s_BotServ, u, BOT_BADWORDS_NO_SUCH_ENTRY, - last, ci->name); - } else { - notice_lang(s_BotServ, u, BOT_BADWORDS_NO_MATCH, - ci->name); - } - } else if (deleted == 1) { - notice_lang(s_BotServ, u, BOT_BADWORDS_DELETED_ONE, - ci->name); - } else { - notice_lang(s_BotServ, u, BOT_BADWORDS_DELETED_SEVERAL, - deleted, ci->name); - } - } else { - for (i = 0; i < ci->bwcount; i++) { - if (ci->badwords[i].in_use - && !stricmp(ci->badwords[i].word, word)) - break; - } - if (i == ci->bwcount) { - notice_lang(s_BotServ, u, BOT_BADWORDS_NOT_FOUND, word, - chan); - return MOD_CONT; - } - bw = &ci->badwords[i]; - notice_lang(s_BotServ, u, BOT_BADWORDS_DELETED, bw->word, - ci->name); - if (bw->word) - free(bw->word); - bw->word = NULL; - bw->in_use = 0; - } - - } else if (stricmp(cmd, "LIST") == 0) { - int sent_header = 0; - - if (ci->bwcount == 0) { - notice_lang(s_BotServ, u, BOT_BADWORDS_LIST_EMPTY, chan); - return MOD_CONT; - } - if (word && strspn(word, "1234567890,-") == strlen(word)) { - process_numlist(word, NULL, badwords_list_callback, u, ci, - &sent_header); - } else { - for (i = 0; i < ci->bwcount; i++) { - if (!(ci->badwords[i].in_use)) - continue; - if (word && ci->badwords[i].word - && !match_wild_nocase(word, ci->badwords[i].word)) - continue; - badwords_list(u, i, ci, &sent_header); - } - } - if (!sent_header) - notice_lang(s_BotServ, u, BOT_BADWORDS_NO_MATCH, chan); - - } else if (stricmp(cmd, "CLEAR") == 0) { - - if (readonly) { - notice_lang(s_BotServ, u, BOT_BADWORDS_DISABLED); - return MOD_CONT; - } - - for (i = 0; i < ci->bwcount; i++) - if (ci->badwords[i].word) - free(ci->badwords[i].word); - - free(ci->badwords); - ci->badwords = NULL; - ci->bwcount = 0; - - notice_lang(s_BotServ, u, BOT_BADWORDS_CLEAR); - - } else { - syntax_error(s_BotServ, u, "BADWORDS", BOT_BADWORDS_SYNTAX); - } - return MOD_CONT; -} - -/*************************************************************************/ - -static int do_say(User * u) -{ - ChannelInfo *ci; - - char *chan = strtok(NULL, " "); - char *text = strtok(NULL, ""); - - if (!chan || !text) - syntax_error(s_BotServ, u, "SAY", BOT_SAY_SYNTAX); - else if (!(ci = cs_findchan(chan))) - notice_lang(s_BotServ, u, CHAN_X_NOT_REGISTERED, chan); - else if (ci->flags & CI_VERBOTEN) - notice_lang(s_BotServ, u, CHAN_X_FORBIDDEN, chan); - else if (!ci->bi) - notice_help(s_BotServ, u, BOT_NOT_ASSIGNED); - else if (!ci->c || ci->c->usercount < BSMinUsers) - notice_lang(s_BotServ, u, BOT_NOT_ON_CHANNEL, ci->name); - else if (!check_access(u, ci, CA_SAY)) - notice_lang(s_BotServ, u, ACCESS_DENIED); - else { - if (text[0] != '\001') { - anope_cmd_privmsg(ci->bi->nick, ci->name, "%s", text); - ci->bi->lastmsg = time(NULL); - if (logchan && LogBot) - anope_cmd_privmsg(ci->bi->nick, LogChannel, - "SAY %s %s %s", u->nick, ci->name, text); - } else { - syntax_error(s_BotServ, u, "SAY", BOT_SAY_SYNTAX); - } - } - return MOD_CONT; -} - -/*************************************************************************/ - -static int do_act(User * u) -{ - ChannelInfo *ci; - - char *chan = strtok(NULL, " "); - char *text = strtok(NULL, ""); - - if (!chan || !text) - syntax_error(s_BotServ, u, "ACT", BOT_ACT_SYNTAX); - else if (!(ci = cs_findchan(chan))) - notice_lang(s_BotServ, u, CHAN_X_NOT_REGISTERED, chan); - else if (ci->flags & CI_VERBOTEN) - notice_lang(s_BotServ, u, CHAN_X_FORBIDDEN, chan); - else if (!ci->bi) - notice_help(s_BotServ, u, BOT_NOT_ASSIGNED); - else if (!ci->c || ci->c->usercount < BSMinUsers) - notice_lang(s_BotServ, u, BOT_NOT_ON_CHANNEL, ci->name); - else if (!check_access(u, ci, CA_SAY)) - notice_lang(s_BotServ, u, ACCESS_DENIED); - else { - strnrepl(text, BUFSIZE, "\001", ""); - anope_cmd_privmsg(ci->bi->nick, ci->name, "%cACTION %s %c", 1, - text, 1); - ci->bi->lastmsg = time(NULL); - if (logchan && LogBot) - anope_cmd_privmsg(ci->bi->nick, LogChannel, "ACT %s %s %s", - u->nick, ci->name, text); - } - return MOD_CONT; -} - -/*************************************************************************/ /** * Normalize buffer stripping control characters and colors * @param A string to be parsed for control and color codes @@ -2554,7 +1027,7 @@ char *normalizeBuffer(char *buf) int i, len, j = 0; len = strlen(buf); - newbuf = (char *) malloc(sizeof(char) * len + 1); + newbuf = (char *) smalloc(sizeof(char) * len + 1); for (i = 0; i < len; i++) { switch (buf[i]) { |