summaryrefslogtreecommitdiff
path: root/src/botserv.c
diff options
context:
space:
mode:
authorrob rob@31f1291d-b8d6-0310-a050-a5561fc1590b <rob rob@31f1291d-b8d6-0310-a050-a5561fc1590b@5417fbe8-f217-4b02-8779-1006273d7864>2005-05-02 19:02:12 +0000
committerrob rob@31f1291d-b8d6-0310-a050-a5561fc1590b <rob rob@31f1291d-b8d6-0310-a050-a5561fc1590b@5417fbe8-f217-4b02-8779-1006273d7864>2005-05-02 19:02:12 +0000
commite0583918834a3f8683e430adf3923ea89d2a449a (patch)
treeff36ada734c3874d3be1a806e3a2b994386b54ed /src/botserv.c
parent49491770383e66f1b8074d8b0f80026e3086e9d8 (diff)
BUILD : 1.7.8 (753) BUGS : N/a NOTES : Merged anope-dev with trunk
git-svn-id: svn://svn.anope.org/anope/trunk@753 31f1291d-b8d6-0310-a050-a5561fc1590b git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@516 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src/botserv.c')
-rw-r--r--src/botserv.c1575
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));