summaryrefslogtreecommitdiff
path: root/src/botserv.c
diff options
context:
space:
mode:
authorrburchell <rburchell@5417fbe8-f217-4b02-8779-1006273d7864>2008-11-14 20:57:20 +0000
committerrburchell <rburchell@5417fbe8-f217-4b02-8779-1006273d7864>2008-11-14 20:57:20 +0000
commit6c55e0a529c7f1216ff6f63a4fc77ea06a2a3a38 (patch)
tree91b0841faf23087ebe0c74dd4269d181a383f1e7 /src/botserv.c
parent069409cd99cf78ab8bf87a1fe69a833576414fd3 (diff)
Insane commit of doom: s/ \t/g
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@1681 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src/botserv.c')
-rw-r--r--src/botserv.c1648
1 files changed, 824 insertions, 824 deletions
diff --git a/src/botserv.c b/src/botserv.c
index 13d483114..62b19fb1a 100644
--- a/src/botserv.c
+++ b/src/botserv.c
@@ -19,7 +19,7 @@
/*************************************************************************/
-BotInfo *botlists[256]; /* Hash list of bots */
+BotInfo *botlists[256]; /* Hash list of bots */
int nbots = 0;
/*************************************************************************/
@@ -34,7 +34,7 @@ E void moduleAddBotServCmds(void);
/*************************************************************************/
/* *INDENT-OFF* */
void moduleAddBotServCmds(void) {
- ModuleManager::LoadModuleList(BotServCoreNumber, BotServCoreModules);
+ ModuleManager::LoadModuleList(BotServCoreNumber, BotServCoreModules);
}
/* *INDENT-ON* */
/*************************************************************************/
@@ -44,23 +44,23 @@ void moduleAddBotServCmds(void) {
void get_botserv_stats(long *nrec, long *memuse)
{
- long count = 0, mem = 0;
- int i;
- BotInfo *bi;
-
- for (i = 0; i < 256; i++) {
- for (bi = botlists[i]; bi; bi = bi->next) {
- count++;
- mem += sizeof(*bi);
- mem += strlen(bi->nick) + 1;
- mem += strlen(bi->user) + 1;
- mem += strlen(bi->host) + 1;
- mem += strlen(bi->real) + 1;
- }
- }
-
- *nrec = count;
- *memuse = mem;
+ long count = 0, mem = 0;
+ int i;
+ BotInfo *bi;
+
+ for (i = 0; i < 256; i++) {
+ for (bi = botlists[i]; bi; bi = bi->next) {
+ count++;
+ mem += sizeof(*bi);
+ mem += strlen(bi->nick) + 1;
+ mem += strlen(bi->user) + 1;
+ mem += strlen(bi->host) + 1;
+ mem += strlen(bi->real) + 1;
+ }
+ }
+
+ *nrec = count;
+ *memuse = mem;
}
/*************************************************************************/
@@ -70,9 +70,9 @@ void get_botserv_stats(long *nrec, long *memuse)
void bs_init(void)
{
- if (s_BotServ) {
- moduleAddBotServCmds();
- }
+ if (s_BotServ) {
+ moduleAddBotServCmds();
+ }
}
/*************************************************************************/
@@ -81,20 +81,20 @@ void bs_init(void)
void botserv(User * u, char *buf)
{
- char *cmd, *s;
+ char *cmd, *s;
- cmd = strtok(buf, " ");
+ cmd = strtok(buf, " ");
- if (!cmd) {
- return;
- } else if (stricmp(cmd, "\1PING") == 0) {
- if (!(s = strtok(NULL, ""))) {
- *s = 0;
- }
- ircdproto->SendCTCP(findbot(s_BotServ), u->nick, "PING %s", s);
- } else {
- mod_run_cmd(s_BotServ, u, BOTSERV, cmd);
- }
+ if (!cmd) {
+ return;
+ } else if (stricmp(cmd, "\1PING") == 0) {
+ if (!(s = strtok(NULL, ""))) {
+ *s = 0;
+ }
+ ircdproto->SendCTCP(findbot(s_BotServ), u->nick, "PING %s", s);
+ } else {
+ mod_run_cmd(s_BotServ, u, BOTSERV, cmd);
+ }
}
@@ -104,18 +104,18 @@ void botserv(User * u, char *buf)
void botmsgs(User * u, BotInfo * bi, char *buf)
{
- char *cmd = strtok(buf, " ");
- char *s;
-
- if (!cmd || !u)
- return;
-
- if (!stricmp(cmd, "\1PING")) {
- if (!(s = strtok(NULL, ""))) {
- *s = 0;
- }
- ircdproto->SendCTCP(bi, u->nick, "PING %s", s);
- }
+ char *cmd = strtok(buf, " ");
+ char *s;
+
+ if (!cmd || !u)
+ return;
+
+ if (!stricmp(cmd, "\1PING")) {
+ if (!(s = strtok(NULL, ""))) {
+ *s = 0;
+ }
+ ircdproto->SendCTCP(bi, u->nick, "PING %s", s);
+ }
}
/*************************************************************************/
@@ -127,305 +127,305 @@ void botmsgs(User * u, BotInfo * bi, char *buf)
void botchanmsgs(User * u, ChannelInfo * ci, char *buf)
{
- int c;
- int16 cstatus = 0;
- char *cmd;
- UserData *ud;
-
- if (!u || !buf || !ci) {
- return;
- }
-
- /* Answer to ping if needed, without breaking the buffer. */
- if (!strnicmp(buf, "\1PING", 5)) {
- ircdproto->SendCTCP(ci->bi, u->nick, "PING %s", buf);
- }
-
- /* If it's a /me, cut the CTCP part at the beginning (not
- * at the end, because one character just doesn't matter,
- * but the ACTION may create strange behaviours with the
- * caps or badwords kickers */
- if (!strnicmp(buf, "\1ACTION ", 8))
- buf += 8;
-
- /* Now we can make kicker stuff. We try to order the checks
- * from the fastest one to the slowest one, since there's
- * no need to process other kickers if an user is kicked before
- * the last kicker check.
- *
- * But FIRST we check whether the user is protected in any
- * way.
- */
-
- /* We first retrieve the user status on the channel if needed */
- if (ci->botflags & (BS_DONTKICKOPS | BS_DONTKICKVOICES))
- cstatus = chan_get_user_status(ci->c, u);
-
- if (buf && !check_access(u, ci, CA_NOKICK) &&
- (!(ci->botflags & BS_DONTKICKOPS)
- || !(cstatus & (CUS_HALFOP | CUS_OP | CUS_OWNER | CUS_PROTECT)))
-
- && (!(ci->botflags & BS_DONTKICKVOICES) || !(cstatus & CUS_VOICE))) {
- /* Bolds kicker */
- if ((ci->botflags & BS_KICK_BOLDS) && strchr(buf, 2)) {
- check_ban(ci, u, TTB_BOLDS);
- bot_kick(ci, u, BOT_REASON_BOLD);
- return;
- }
-
- /* Color kicker */
- if ((ci->botflags & BS_KICK_COLORS) && strchr(buf, 3)) {
- check_ban(ci, u, TTB_COLORS);
- bot_kick(ci, u, BOT_REASON_COLOR);
- return;
- }
-
- /* Reverses kicker */
- if ((ci->botflags & BS_KICK_REVERSES) && strchr(buf, 22)) {
- check_ban(ci, u, TTB_REVERSES);
- bot_kick(ci, u, BOT_REASON_REVERSE);
- return;
- }
-
- /* Underlines kicker */
- if ((ci->botflags & BS_KICK_UNDERLINES) && strchr(buf, 31)) {
- check_ban(ci, u, TTB_UNDERLINES);
- bot_kick(ci, u, BOT_REASON_UNDERLINE);
- return;
- }
-
- /* Caps kicker */
- if ((ci->botflags & BS_KICK_CAPS)
- && ((c = strlen(buf)) >= ci->capsmin)) {
- int i = 0;
- int l = 0;
- char *s = buf;
-
- do {
- if (isupper(*s))
- i++;
- else if (islower(*s))
- l++;
- } while (*s++);
-
- /* i counts uppercase chars, l counts lowercase chars. Only
- * alphabetic chars (so islower || isupper) qualify for the
- * percentage of caps to kick for; the rest is ignored. -GD
- */
-
- if (i >= ci->capsmin && i * 100 / (i + l) >= ci->capspercent) {
- check_ban(ci, u, TTB_CAPS);
- bot_kick(ci, u, BOT_REASON_CAPS);
- return;
- }
- }
-
- /* Bad words kicker */
- if (ci->botflags & BS_KICK_BADWORDS) {
- int i;
- int mustkick = 0;
- char *nbuf;
- BadWord *bw;
-
- /* Normalize the buffer */
- nbuf = normalizeBuffer(buf);
-
- for (i = 0, bw = ci->badwords; i < ci->bwcount; i++, bw++) {
- if (!bw->in_use)
- continue;
-
- if (bw->type == BW_ANY
- && ((BSCaseSensitive && strstr(nbuf, bw->word))
- || (!BSCaseSensitive && stristr(nbuf, bw->word)))) {
- mustkick = 1;
- } else if (bw->type == BW_SINGLE) {
- int len = strlen(bw->word);
-
- if ((BSCaseSensitive && !strcmp(nbuf, bw->word))
- || (!BSCaseSensitive
- && (!stricmp(nbuf, bw->word)))) {
- mustkick = 1;
- /* two next if are quite odd isn't it? =) */
- } else if ((strchr(nbuf, ' ') == nbuf + len)
- &&
- ((BSCaseSensitive
- && !strcmp(nbuf, bw->word))
- || (!BSCaseSensitive
- && (stristr(nbuf, bw->word) ==
- nbuf)))) {
- mustkick = 1;
- } else {
- if ((strrchr(nbuf, ' ') ==
- nbuf + strlen(nbuf) - len - 1)
- &&
- ((BSCaseSensitive
- && (strstr(nbuf, bw->word) ==
- nbuf + strlen(nbuf) - len))
- || (!BSCaseSensitive
- && (stristr(nbuf, bw->word) ==
- nbuf + strlen(nbuf) - len)))) {
- mustkick = 1;
- } else {
- char *wordbuf = (char *)scalloc(len + 3, 1);
-
- wordbuf[0] = ' ';
- wordbuf[len + 1] = ' ';
- wordbuf[len + 2] = '\0';
- memcpy(wordbuf + 1, bw->word, len);
-
- if ((BSCaseSensitive
- && (strstr(nbuf, wordbuf)))
- || (!BSCaseSensitive
- && (stristr(nbuf, wordbuf)))) {
- mustkick = 1;
- }
-
- /* free previous (sc)allocated memory (#850) */
- free(wordbuf);
- }
- }
- } else if (bw->type == BW_START) {
- int len = strlen(bw->word);
-
- if ((BSCaseSensitive
- && (!strncmp(nbuf, bw->word, len)))
- || (!BSCaseSensitive
- && (!strnicmp(nbuf, bw->word, len)))) {
- mustkick = 1;
- } else {
- char *wordbuf = (char *)scalloc(len + 2, 1);
-
- memcpy(wordbuf + 1, bw->word, len);
- wordbuf[0] = ' ';
- wordbuf[len + 1] = '\0';
-
- if ((BSCaseSensitive && (strstr(nbuf, wordbuf)))
- || (!BSCaseSensitive
- && (stristr(nbuf, wordbuf))))
- mustkick = 1;
-
- free(wordbuf);
- }
- } else if (bw->type == BW_END) {
- int len = strlen(bw->word);
-
- if ((BSCaseSensitive
- &&
- (!strncmp
- (nbuf + strlen(nbuf) - len, bw->word, len)))
- || (!BSCaseSensitive
- &&
- (!strnicmp
- (nbuf + strlen(nbuf) - len, bw->word,
- len)))) {
- mustkick = 1;
- } else {
- char *wordbuf = (char *)scalloc(len + 2, 1);
-
- memcpy(wordbuf, bw->word, len);
- wordbuf[len] = ' ';
- wordbuf[len + 1] = '\0';
-
- if ((BSCaseSensitive && (strstr(nbuf, wordbuf)))
- || (!BSCaseSensitive
- && (stristr(nbuf, wordbuf))))
- mustkick = 1;
-
- free(wordbuf);
- }
- }
-
- if (mustkick) {
- check_ban(ci, u, TTB_BADWORDS);
- if (BSGentleBWReason)
- bot_kick(ci, u, BOT_REASON_BADWORD_GENTLE);
- else
- bot_kick(ci, u, BOT_REASON_BADWORD, bw->word);
-
- /* free the normalized buffer before return (#850) */
- Anope_Free(nbuf);
-
- return;
- }
- }
-
- /* Free the normalized buffer */
- Anope_Free(nbuf);
- }
-
- /* Flood kicker */
- if (ci->botflags & BS_KICK_FLOOD) {
- time_t now = time(NULL);
-
- ud = get_user_data(ci->c, u);
- if (!ud) {
- return;
- }
-
- if (now - ud->last_start > ci->floodsecs) {
- ud->last_start = time(NULL);
- ud->lines = 0;
- }
-
- ud->lines++;
- if (ud->lines >= ci->floodlines) {
- check_ban(ci, u, TTB_FLOOD);
- bot_kick(ci, u, BOT_REASON_FLOOD);
- return;
- }
- }
-
- /* Repeat kicker */
- if (ci->botflags & BS_KICK_REPEAT) {
- ud = get_user_data(ci->c, u);
- if (!ud) {
- return;
- }
- if (ud->lastline && stricmp(ud->lastline, buf)) {
- free(ud->lastline);
- ud->lastline = sstrdup(buf);
- ud->times = 0;
- } else {
- if (!ud->lastline)
- ud->lastline = sstrdup(buf);
- ud->times++;
- }
-
- if (ud->times >= ci->repeattimes) {
- check_ban(ci, u, TTB_REPEAT);
- bot_kick(ci, u, BOT_REASON_REPEAT);
- return;
- }
- }
- }
-
-
- /* return if the user is on the ignore list */
- if (get_ignore(u->nick) != NULL) {
- return;
- }
-
- /* Fantaisist commands */
-
- if (buf && (ci->botflags & BS_FANTASY) && *buf == *BSFantasyCharacter) {
- cmd = strtok(buf, " ");
-
- if (cmd && (cmd[0] == *BSFantasyCharacter)) {
- char *params = strtok(NULL, "");
- const char *event_name = EVENT_BOT_FANTASY_NO_ACCESS;
-
- /* Strip off the fantasy character */
- cmd++;
-
- if (check_access(u, ci, CA_FANTASIA))
- event_name = EVENT_BOT_FANTASY;
-
- if (params)
- send_event(event_name, 4, cmd, u->nick, ci->name, params);
- else
- send_event(event_name, 3, cmd, u->nick, ci->name);
- }
- }
+ int c;
+ int16 cstatus = 0;
+ char *cmd;
+ UserData *ud;
+
+ if (!u || !buf || !ci) {
+ return;
+ }
+
+ /* Answer to ping if needed, without breaking the buffer. */
+ if (!strnicmp(buf, "\1PING", 5)) {
+ ircdproto->SendCTCP(ci->bi, u->nick, "PING %s", buf);
+ }
+
+ /* If it's a /me, cut the CTCP part at the beginning (not
+ * at the end, because one character just doesn't matter,
+ * but the ACTION may create strange behaviours with the
+ * caps or badwords kickers */
+ if (!strnicmp(buf, "\1ACTION ", 8))
+ buf += 8;
+
+ /* Now we can make kicker stuff. We try to order the checks
+ * from the fastest one to the slowest one, since there's
+ * no need to process other kickers if an user is kicked before
+ * the last kicker check.
+ *
+ * But FIRST we check whether the user is protected in any
+ * way.
+ */
+
+ /* We first retrieve the user status on the channel if needed */
+ if (ci->botflags & (BS_DONTKICKOPS | BS_DONTKICKVOICES))
+ cstatus = chan_get_user_status(ci->c, u);
+
+ if (buf && !check_access(u, ci, CA_NOKICK) &&
+ (!(ci->botflags & BS_DONTKICKOPS)
+ || !(cstatus & (CUS_HALFOP | CUS_OP | CUS_OWNER | CUS_PROTECT)))
+
+ && (!(ci->botflags & BS_DONTKICKVOICES) || !(cstatus & CUS_VOICE))) {
+ /* Bolds kicker */
+ if ((ci->botflags & BS_KICK_BOLDS) && strchr(buf, 2)) {
+ check_ban(ci, u, TTB_BOLDS);
+ bot_kick(ci, u, BOT_REASON_BOLD);
+ return;
+ }
+
+ /* Color kicker */
+ if ((ci->botflags & BS_KICK_COLORS) && strchr(buf, 3)) {
+ check_ban(ci, u, TTB_COLORS);
+ bot_kick(ci, u, BOT_REASON_COLOR);
+ return;
+ }
+
+ /* Reverses kicker */
+ if ((ci->botflags & BS_KICK_REVERSES) && strchr(buf, 22)) {
+ check_ban(ci, u, TTB_REVERSES);
+ bot_kick(ci, u, BOT_REASON_REVERSE);
+ return;
+ }
+
+ /* Underlines kicker */
+ if ((ci->botflags & BS_KICK_UNDERLINES) && strchr(buf, 31)) {
+ check_ban(ci, u, TTB_UNDERLINES);
+ bot_kick(ci, u, BOT_REASON_UNDERLINE);
+ return;
+ }
+
+ /* Caps kicker */
+ if ((ci->botflags & BS_KICK_CAPS)
+ && ((c = strlen(buf)) >= ci->capsmin)) {
+ int i = 0;
+ int l = 0;
+ char *s = buf;
+
+ do {
+ if (isupper(*s))
+ i++;
+ else if (islower(*s))
+ l++;
+ } while (*s++);
+
+ /* i counts uppercase chars, l counts lowercase chars. Only
+ * alphabetic chars (so islower || isupper) qualify for the
+ * percentage of caps to kick for; the rest is ignored. -GD
+ */
+
+ if (i >= ci->capsmin && i * 100 / (i + l) >= ci->capspercent) {
+ check_ban(ci, u, TTB_CAPS);
+ bot_kick(ci, u, BOT_REASON_CAPS);
+ return;
+ }
+ }
+
+ /* Bad words kicker */
+ if (ci->botflags & BS_KICK_BADWORDS) {
+ int i;
+ int mustkick = 0;
+ char *nbuf;
+ BadWord *bw;
+
+ /* Normalize the buffer */
+ nbuf = normalizeBuffer(buf);
+
+ for (i = 0, bw = ci->badwords; i < ci->bwcount; i++, bw++) {
+ if (!bw->in_use)
+ continue;
+
+ if (bw->type == BW_ANY
+ && ((BSCaseSensitive && strstr(nbuf, bw->word))
+ || (!BSCaseSensitive && stristr(nbuf, bw->word)))) {
+ mustkick = 1;
+ } else if (bw->type == BW_SINGLE) {
+ int len = strlen(bw->word);
+
+ if ((BSCaseSensitive && !strcmp(nbuf, bw->word))
+ || (!BSCaseSensitive
+ && (!stricmp(nbuf, bw->word)))) {
+ mustkick = 1;
+ /* two next if are quite odd isn't it? =) */
+ } else if ((strchr(nbuf, ' ') == nbuf + len)
+ &&
+ ((BSCaseSensitive
+ && !strcmp(nbuf, bw->word))
+ || (!BSCaseSensitive
+ && (stristr(nbuf, bw->word) ==
+ nbuf)))) {
+ mustkick = 1;
+ } else {
+ if ((strrchr(nbuf, ' ') ==
+ nbuf + strlen(nbuf) - len - 1)
+ &&
+ ((BSCaseSensitive
+ && (strstr(nbuf, bw->word) ==
+ nbuf + strlen(nbuf) - len))
+ || (!BSCaseSensitive
+ && (stristr(nbuf, bw->word) ==
+ nbuf + strlen(nbuf) - len)))) {
+ mustkick = 1;
+ } else {
+ char *wordbuf = (char *)scalloc(len + 3, 1);
+
+ wordbuf[0] = ' ';
+ wordbuf[len + 1] = ' ';
+ wordbuf[len + 2] = '\0';
+ memcpy(wordbuf + 1, bw->word, len);
+
+ if ((BSCaseSensitive
+ && (strstr(nbuf, wordbuf)))
+ || (!BSCaseSensitive
+ && (stristr(nbuf, wordbuf)))) {
+ mustkick = 1;
+ }
+
+ /* free previous (sc)allocated memory (#850) */
+ free(wordbuf);
+ }
+ }
+ } else if (bw->type == BW_START) {
+ int len = strlen(bw->word);
+
+ if ((BSCaseSensitive
+ && (!strncmp(nbuf, bw->word, len)))
+ || (!BSCaseSensitive
+ && (!strnicmp(nbuf, bw->word, len)))) {
+ mustkick = 1;
+ } else {
+ char *wordbuf = (char *)scalloc(len + 2, 1);
+
+ memcpy(wordbuf + 1, bw->word, len);
+ wordbuf[0] = ' ';
+ wordbuf[len + 1] = '\0';
+
+ if ((BSCaseSensitive && (strstr(nbuf, wordbuf)))
+ || (!BSCaseSensitive
+ && (stristr(nbuf, wordbuf))))
+ mustkick = 1;
+
+ free(wordbuf);
+ }
+ } else if (bw->type == BW_END) {
+ int len = strlen(bw->word);
+
+ if ((BSCaseSensitive
+ &&
+ (!strncmp
+ (nbuf + strlen(nbuf) - len, bw->word, len)))
+ || (!BSCaseSensitive
+ &&
+ (!strnicmp
+ (nbuf + strlen(nbuf) - len, bw->word,
+ len)))) {
+ mustkick = 1;
+ } else {
+ char *wordbuf = (char *)scalloc(len + 2, 1);
+
+ memcpy(wordbuf, bw->word, len);
+ wordbuf[len] = ' ';
+ wordbuf[len + 1] = '\0';
+
+ if ((BSCaseSensitive && (strstr(nbuf, wordbuf)))
+ || (!BSCaseSensitive
+ && (stristr(nbuf, wordbuf))))
+ mustkick = 1;
+
+ free(wordbuf);
+ }
+ }
+
+ if (mustkick) {
+ check_ban(ci, u, TTB_BADWORDS);
+ if (BSGentleBWReason)
+ bot_kick(ci, u, BOT_REASON_BADWORD_GENTLE);
+ else
+ bot_kick(ci, u, BOT_REASON_BADWORD, bw->word);
+
+ /* free the normalized buffer before return (#850) */
+ Anope_Free(nbuf);
+
+ return;
+ }
+ }
+
+ /* Free the normalized buffer */
+ Anope_Free(nbuf);
+ }
+
+ /* Flood kicker */
+ if (ci->botflags & BS_KICK_FLOOD) {
+ time_t now = time(NULL);
+
+ ud = get_user_data(ci->c, u);
+ if (!ud) {
+ return;
+ }
+
+ if (now - ud->last_start > ci->floodsecs) {
+ ud->last_start = time(NULL);
+ ud->lines = 0;
+ }
+
+ ud->lines++;
+ if (ud->lines >= ci->floodlines) {
+ check_ban(ci, u, TTB_FLOOD);
+ bot_kick(ci, u, BOT_REASON_FLOOD);
+ return;
+ }
+ }
+
+ /* Repeat kicker */
+ if (ci->botflags & BS_KICK_REPEAT) {
+ ud = get_user_data(ci->c, u);
+ if (!ud) {
+ return;
+ }
+ if (ud->lastline && stricmp(ud->lastline, buf)) {
+ free(ud->lastline);
+ ud->lastline = sstrdup(buf);
+ ud->times = 0;
+ } else {
+ if (!ud->lastline)
+ ud->lastline = sstrdup(buf);
+ ud->times++;
+ }
+
+ if (ud->times >= ci->repeattimes) {
+ check_ban(ci, u, TTB_REPEAT);
+ bot_kick(ci, u, BOT_REASON_REPEAT);
+ return;
+ }
+ }
+ }
+
+
+ /* return if the user is on the ignore list */
+ if (get_ignore(u->nick) != NULL) {
+ return;
+ }
+
+ /* Fantaisist commands */
+
+ if (buf && (ci->botflags & BS_FANTASY) && *buf == *BSFantasyCharacter) {
+ cmd = strtok(buf, " ");
+
+ if (cmd && (cmd[0] == *BSFantasyCharacter)) {
+ char *params = strtok(NULL, "");
+ const char *event_name = EVENT_BOT_FANTASY_NO_ACCESS;
+
+ /* Strip off the fantasy character */
+ cmd++;
+
+ if (check_access(u, ci, CA_FANTASIA))
+ event_name = EVENT_BOT_FANTASY;
+
+ if (params)
+ send_event(event_name, 4, cmd, u->nick, ci->name, params);
+ else
+ send_event(event_name, 3, cmd, u->nick, ci->name);
+ }
+ }
}
/*************************************************************************/
@@ -434,51 +434,51 @@ void botchanmsgs(User * u, ChannelInfo * ci, char *buf)
#define SAFE(x) do { \
- if ((x) < 0) { \
+ if ((x) < 0) { \
if (!forceload) \
- fatal("Read error on %s", BotDBName); \
+ fatal("Read error on %s", BotDBName); \
failed = 1; \
break; \
- } \
+ } \
} while (0)
void load_bs_dbase(void)
{
- dbFILE *f;
- int c, ver;
- uint16 tmp16;
- uint32 tmp32;
- BotInfo *bi;
- int failed = 0;
-
- if (!(f = open_db(s_BotServ, BotDBName, "r", BOT_VERSION)))
- return;
-
- ver = get_file_version(f);
-
- while (!failed && (c = getc_db(f)) != 0) {
- char *s;
-
- if (c != 1)
- fatal("Invalid format in %s %d", BotDBName, c);
-
- SAFE(read_string(&s, f));
- bi = new BotInfo(s);
- free(s);
- SAFE(read_string(&bi->user, f));
- SAFE(read_string(&bi->host, f));
- SAFE(read_string(&bi->real, f));
- if (ver >= 10) {
- SAFE(read_int16(&tmp16, f));
- bi->flags = tmp16;
- }
- SAFE(read_int32(&tmp32, f));
- bi->created = tmp32;
- SAFE(read_int16(&tmp16, f));
- bi->chancount = tmp16;
- }
-
- close_db(f);
+ dbFILE *f;
+ int c, ver;
+ uint16 tmp16;
+ uint32 tmp32;
+ BotInfo *bi;
+ int failed = 0;
+
+ if (!(f = open_db(s_BotServ, BotDBName, "r", BOT_VERSION)))
+ return;
+
+ ver = get_file_version(f);
+
+ while (!failed && (c = getc_db(f)) != 0) {
+ char *s;
+
+ if (c != 1)
+ fatal("Invalid format in %s %d", BotDBName, c);
+
+ SAFE(read_string(&s, f));
+ bi = new BotInfo(s);
+ free(s);
+ SAFE(read_string(&bi->user, f));
+ SAFE(read_string(&bi->host, f));
+ SAFE(read_string(&bi->real, f));
+ if (ver >= 10) {
+ SAFE(read_int16(&tmp16, f));
+ bi->flags = tmp16;
+ }
+ SAFE(read_int32(&tmp32, f));
+ bi->created = tmp32;
+ SAFE(read_int16(&tmp16, f));
+ bi->chancount = tmp16;
+ }
+
+ close_db(f);
}
#undef SAFE
@@ -486,43 +486,43 @@ void load_bs_dbase(void)
/*************************************************************************/
#define SAFE(x) do { \
- if ((x) < 0) { \
+ if ((x) < 0) { \
restore_db(f); \
log_perror("Write error on %s", BotDBName); \
if (time(NULL) - lastwarn > WarningTimeout) { \
- ircdproto->SendGlobops(NULL, "Write error on %s: %s", BotDBName, \
+ ircdproto->SendGlobops(NULL, "Write error on %s: %s", BotDBName, \
strerror(errno)); \
- lastwarn = time(NULL); \
+ lastwarn = time(NULL); \
} \
return; \
- } \
+ } \
} while (0)
void save_bs_dbase(void)
{
- dbFILE *f;
- BotInfo *bi;
- static time_t lastwarn = 0;
- int i;
-
- if (!(f = open_db(s_BotServ, BotDBName, "w", BOT_VERSION)))
- return;
-
- for (i = 0; i < 256; i++) {
- for (bi = botlists[i]; bi; bi = bi->next) {
- SAFE(write_int8(1, f));
- SAFE(write_string(bi->nick, f));
- SAFE(write_string(bi->user, f));
- SAFE(write_string(bi->host, f));
- SAFE(write_string(bi->real, f));
- SAFE(write_int16(bi->flags, f));
- SAFE(write_int32(bi->created, f));
- SAFE(write_int16(bi->chancount, f));
- }
- }
- SAFE(write_int8(0, f));
-
- close_db(f);
+ dbFILE *f;
+ BotInfo *bi;
+ static time_t lastwarn = 0;
+ int i;
+
+ if (!(f = open_db(s_BotServ, BotDBName, "w", BOT_VERSION)))
+ return;
+
+ for (i = 0; i < 256; i++) {
+ for (bi = botlists[i]; bi; bi = bi->next) {
+ SAFE(write_int8(1, f));
+ SAFE(write_string(bi->nick, f));
+ SAFE(write_string(bi->user, f));
+ SAFE(write_string(bi->host, f));
+ SAFE(write_string(bi->real, f));
+ SAFE(write_int16(bi->flags, f));
+ SAFE(write_int32(bi->created, f));
+ SAFE(write_int16(bi->chancount, f));
+ }
+ }
+ SAFE(write_int8(0, f));
+
+ close_db(f);
}
@@ -534,19 +534,19 @@ void save_bs_dbase(void)
void insert_bot(BotInfo * bi)
{
- BotInfo *ptr, *prev;
-
- for (prev = NULL, ptr = botlists[tolower(*bi->nick)];
- ptr != NULL && stricmp(ptr->nick, bi->nick) < 0;
- prev = ptr, ptr = ptr->next);
- bi->prev = prev;
- bi->next = ptr;
- if (!prev)
- botlists[tolower(*bi->nick)] = bi;
- else
- prev->next = bi;
- if (ptr)
- ptr->prev = bi;
+ BotInfo *ptr, *prev;
+
+ for (prev = NULL, ptr = botlists[tolower(*bi->nick)];
+ ptr != NULL && stricmp(ptr->nick, bi->nick) < 0;
+ prev = ptr, ptr = ptr->next);
+ bi->prev = prev;
+ bi->next = ptr;
+ if (!prev)
+ botlists[tolower(*bi->nick)] = bi;
+ else
+ prev->next = bi;
+ if (ptr)
+ ptr->prev = bi;
}
/*************************************************************************/
@@ -585,49 +585,49 @@ BotInfo *findbot(const char *nick)
static BanData *get_ban_data(Channel * c, User * u)
{
- char mask[BUFSIZE];
- BanData *bd, *next;
- time_t now = time(NULL);
-
- if (!c || !u)
- return NULL;
-
- snprintf(mask, sizeof(mask), "%s@%s", u->username,
- common_get_vhost(u));
-
- for (bd = c->bd; bd; bd = next) {
- if (now - bd->last_use > BSKeepData) {
- if (bd->next)
- bd->next->prev = bd->prev;
- if (bd->prev)
- bd->prev->next = bd->next;
- else
- c->bd = bd->next;
- if (bd->mask)
- free(bd->mask);
- next = bd->next;
- free(bd);
- continue;
- }
- if (!stricmp(bd->mask, mask)) {
- bd->last_use = now;
- return bd;
- }
- next = bd->next;
- }
-
- /* If we fall here it is that we haven't found the record */
- bd = (BanData *)scalloc(sizeof(BanData), 1);
- bd->mask = sstrdup(mask);
- bd->last_use = now;
-
- bd->prev = NULL;
- bd->next = c->bd;
- if (bd->next)
- bd->next->prev = bd;
- c->bd = bd;
-
- return bd;
+ char mask[BUFSIZE];
+ BanData *bd, *next;
+ time_t now = time(NULL);
+
+ if (!c || !u)
+ return NULL;
+
+ snprintf(mask, sizeof(mask), "%s@%s", u->username,
+ common_get_vhost(u));
+
+ for (bd = c->bd; bd; bd = next) {
+ if (now - bd->last_use > BSKeepData) {
+ if (bd->next)
+ bd->next->prev = bd->prev;
+ if (bd->prev)
+ bd->prev->next = bd->next;
+ else
+ c->bd = bd->next;
+ if (bd->mask)
+ free(bd->mask);
+ next = bd->next;
+ free(bd);
+ continue;
+ }
+ if (!stricmp(bd->mask, mask)) {
+ bd->last_use = now;
+ return bd;
+ }
+ next = bd->next;
+ }
+
+ /* If we fall here it is that we haven't found the record */
+ bd = (BanData *)scalloc(sizeof(BanData), 1);
+ bd->mask = sstrdup(mask);
+ bd->last_use = now;
+
+ bd->prev = NULL;
+ bd->next = c->bd;
+ if (bd->next)
+ bd->next->prev = bd;
+ c->bd = bd;
+
+ return bd;
}
/*************************************************************************/
@@ -638,36 +638,36 @@ static BanData *get_ban_data(Channel * c, User * u)
static UserData *get_user_data(Channel * c, User * u)
{
- struct c_userlist *user;
-
- if (!c || !u)
- return NULL;
-
- for (user = c->users; user; user = user->next) {
- if (user->user == u) {
- if (user->ud) {
- time_t now = time(NULL);
-
- /* Checks whether data is obsolete */
- if (now - user->ud->last_use > BSKeepData) {
- if (user->ud->lastline)
- free(user->ud->lastline);
- /* We should not free and realloc, but reset to 0
- instead. */
- memset(user->ud, 0, sizeof(UserData));
- user->ud->last_use = now;
- }
-
- return user->ud;
- } else {
- user->ud = (UserData *)scalloc(sizeof(UserData), 1);
- user->ud->last_use = time(NULL);
- return user->ud;
- }
- }
- }
-
- return NULL;
+ struct c_userlist *user;
+
+ if (!c || !u)
+ return NULL;
+
+ for (user = c->users; user; user = user->next) {
+ if (user->user == u) {
+ if (user->ud) {
+ time_t now = time(NULL);
+
+ /* Checks whether data is obsolete */
+ if (now - user->ud->last_use > BSKeepData) {
+ if (user->ud->lastline)
+ free(user->ud->lastline);
+ /* We should not free and realloc, but reset to 0
+ instead. */
+ memset(user->ud, 0, sizeof(UserData));
+ user->ud->last_use = now;
+ }
+
+ return user->ud;
+ } else {
+ user->ud = (UserData *)scalloc(sizeof(UserData), 1);
+ user->ud->last_use = time(NULL);
+ return user->ud;
+ }
+ }
+ }
+
+ return NULL;
}
/*************************************************************************/
@@ -676,55 +676,55 @@ static UserData *get_user_data(Channel * c, User * u)
void bot_join(ChannelInfo * ci)
{
- if (!ci || !ci->c || !ci->bi)
- return;
-
- if (BSSmartJoin) {
- /* We check for bans */
- if (ci->c->bans && ci->c->bans->count) {
- char buf[BUFSIZE];
- const char *av[4];
- Entry *ban, *next;
- int ac;
-
- if (ircdcap->tsmode) {
- snprintf(buf, BUFSIZE - 1, "%ld", (long int) time(NULL));
- av[0] = ci->c->name;
- av[1] = buf;
- av[2] = "-b";
- ac = 4;
- } else {
- av[0] = ci->c->name;
- av[1] = "-b";
- ac = 3;
- }
-
- for (ban = ci->c->bans->entries; ban; ban = next) {
- next = ban->next;
- if (entry_match
- (ban, ci->bi->nick, ci->bi->user, ci->bi->host, 0)) {
- ircdproto->SendMode(whosends(ci), ci->name, "-b %s",
-