diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile | 8 | ||||
-rw-r--r-- | src/bots.cpp | 47 | ||||
-rw-r--r-- | src/botserv.c | 45 | ||||
-rw-r--r-- | src/core/bs_bot.c | 22 | ||||
-rw-r--r-- | src/makefile.win32 | 9 | ||||
-rw-r--r-- | src/messages.c | 2 |
6 files changed, 65 insertions, 68 deletions
diff --git a/src/Makefile b/src/Makefile index cbfe40fda..851c68d08 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,11 +1,11 @@ MYSQL_OBJ = $(MYSQL:.c=.o) RDB_OBJ = $(RDB:.c=.o) -OBJS = actions.o base64.o botserv.o channels.o chanserv.o commands.o compat.o \ +OBJS = actions.o base64.o bots.o botserv.o channels.o chanserv.o commands.o compat.o \ config.o datafiles.o encrypt.o events.o helpserv.o hostserv.o init.o ircd.o language.o log.o mail.o main.o \ memory.o memoserv.o messages.o misc.o modules.o news.o nickserv.o operserv.o \ process.o send.o servers.o sessions.o slist.o sockutil.o timeout.o users.o \ $(RDB_OBJ) $(MYSQL_OBJ) -SRCS = actions.c base64.c botserv.c channels.c chanserv.c commands.c compat.c \ +SRCS = actions.c base64.c bots.cpp botserv.c channels.c chanserv.c commands.c compat.c \ config.c datafiles.c encrypt.c events.c helpserv.c hostserv.c init.c ircd.c language.c log.c mail.c main.c \ memory.c memoserv.c messages.c misc.c modules.c news.c nickserv.c operserv.c \ process.c send.c servers.c sessions.c s sockutil.c timeout.c users.c \ @@ -27,6 +27,9 @@ MAKEARGS = 'CFLAGS=${CFLAGS}' 'CC=${CC}' 'ANOPELIBS=${ANOPELIBS}' \ .c.o: $(CC) $(CFLAGS) -I../include/ -c $< +.cpp.o: + $(CC) $(CFLAGS) -I../include/ -c $< + all: services distclean: spotless @@ -38,6 +41,7 @@ services: $(OBJS) mod_version $(OBJS): Makefile actions.o: actions.c $(INCLUDES) base64.o: base64.c $(INCLUDES) +bots.o: bots.cpp $(INCLUDES) botserv.o: botserv.c $(INCLUDES) channels.o: channels.c $(INCLUDES) chanserv.o: chanserv.c $(INCLUDES) diff --git a/src/bots.cpp b/src/bots.cpp new file mode 100644 index 000000000..487cc6dc7 --- /dev/null +++ b/src/bots.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2008 Robin Burchell <w00t@inspircd.org> + * Copyright (C) 2008 Anope Team <info@anope.org> + * + * Please read COPYING and README for further details. + * + * + * $Id$ + * + */ + +#include "services.h" + +BotInfo::BotInfo(const char *nnick) +{ + this->nick = sstrdup(nnick); + this->lastmsg = time(NULL); + insert_bot(this); // XXX, this is ugly, but it needs to stay until hashing of bots is redone in STL. + nbots++; +} + +void BotInfo::ChangeNick(const char *newnick) +{ + if (this->next) + this->next->prev = this->prev; + if (this->prev) + this->prev->next = this->next; + else + botlists[tolower(*this->nick)] = this->next; + + if (this->nick) + free(this->nick); + this->nick = sstrdup(newnick); + + insert_bot(this); +} + +void BotInfo::RejoinAll() +{ + int i; + ChannelInfo *ci; + + for (i = 0; i < 256; i++) + for (ci = chanlists[i]; ci; ci = ci->next) + if (ci->bi == this && ci->c && (ci->c->usercount >= BSMinUsers)) + bot_join(ci); +} diff --git a/src/botserv.c b/src/botserv.c index 19fff43e7..7fd029153 100644 --- a/src/botserv.c +++ b/src/botserv.c @@ -464,7 +464,7 @@ void load_bs_dbase(void) fatal("Invalid format in %s %d", BotDBName, c); SAFE(read_string(&s, f)); - bi = makebot(s); + bi = new BotInfo(s); free(s); SAFE(read_string(&bi->user, f)); SAFE(read_string(&bi->host, f)); @@ -585,32 +585,6 @@ void insert_bot(BotInfo * bi) } /*************************************************************************/ - -BotInfo *makebot(char *nick) -{ - BotInfo *bi; - - if (!nick) { - if (debug) { - alog("debug: makebot called with NULL values"); - } - return NULL; - } - - bi = (BotInfo *)scalloc(sizeof(BotInfo), 1); - bi->nick = sstrdup(nick); - bi->lastmsg = time(NULL); - insert_bot(bi); - nbots++; - return bi; -} - -/*************************************************************************/ - - -/*************************************************************************/ - - /*************************************************************************/ BotInfo *findbot(const char *nick) @@ -808,23 +782,6 @@ void bot_join(ChannelInfo * ci) /*************************************************************************/ -/* This makes the bot rejoin all channel he is on when he gets killed - * or changed. - */ - -void bot_rejoin_all(BotInfo * bi) -{ - int i; - ChannelInfo *ci; - - for (i = 0; i < 256; i++) - for (ci = chanlists[i]; ci; ci = ci->next) - if (ci->bi == bi && ci->c && (ci->c->usercount >= BSMinUsers)) - bot_join(ci); -} - -/*************************************************************************/ - /* This makes a ban if the user has to have one. In every cases it increments the kick count for the user. */ diff --git a/src/core/bs_bot.c b/src/core/bs_bot.c index f35e55152..17f237be6 100644 --- a/src/core/bs_bot.c +++ b/src/core/bs_bot.c @@ -18,7 +18,6 @@ int do_bot(User * u); int delbot(BotInfo * bi); void myBotServHelp(User * u); -void change_bot_nick(BotInfo * bi, char *newnick); /** * Create the command, and tell anope about it. @@ -150,7 +149,7 @@ int do_bot(User * u) return MOD_CONT; } - bi = makebot(nick); + bi = new BotInfo(nick); if (!bi) { notice_lang(s_BotServ, u, BOT_BOT_CREATION_FAILED); return MOD_CONT; @@ -277,7 +276,7 @@ int do_bot(User * u) } if (strcmp(nick, bi->nick)) - change_bot_nick(bi, nick); + bi->ChangeNick(nick); if (user && strcmp(user, bi->user)) { free(bi->user); @@ -303,7 +302,7 @@ int do_bot(User * u) anope_cmd_bot_nick(bi->nick, bi->user, bi->host, bi->real, ircd->botserv_bot_mode); - bot_rejoin_all(bi); + bi->RejoinAll(); } notice_lang(s_BotServ, u, BOT_BOT_CHANGED, oldnick, bi->nick, @@ -361,18 +360,3 @@ int delbot(BotInfo * bi) return 1; } -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); -} diff --git a/src/makefile.win32 b/src/makefile.win32 index 271db56d1..09f05acbe 100644 --- a/src/makefile.win32 +++ b/src/makefile.win32 @@ -17,14 +17,14 @@ include ../Makefile.inc.win32 ########################################################################### -OBJS = actions.obj base64.obj botserv.obj channels.obj chanserv.obj commands.obj compat.obj \ +OBJS = actions.obj base64.obj bots.obj botserv.obj channels.obj chanserv.obj commands.obj compat.obj \ config.obj datafiles.obj encrypt.obj events.obj helpserv.obj hostserv.obj \ init.obj ircd.obj language.obj list.obj log.obj mail.obj main.obj memory.obj \ memoserv.obj messages.obj misc.obj modules.obj mod_version.obj news.obj nickserv.obj operserv.obj \ process.obj send.obj servers.obj sessions.obj slist.obj sockutil.obj \ timeout.obj users.obj $(RDB_O) $(MYSQL_O) -SRCS = actions.c base64.c botserv.c channels.c chanserv.c commands.c compat.c \ +SRCS = actions.c base64.c botserv.c bots.cpp channels.c chanserv.c commands.c compat.c \ config.c datafiles.c encrypt.c events.c helpserv.c hostserv.c init.c ircd.c \ language.c list.c log.c mail.c main.c memory.c memoserv.c messages.c misc.c \ modules.c mod_version.c news.c nickserv.c operserv.c process.c send.c servers.obj sessions.c \ @@ -35,6 +35,10 @@ SRCS = actions.c base64.c botserv.c channels.c chanserv.c commands.c compat.c \ .c.obj: $(CC) $(CFLAGS) -c $< +.cpp.obj: + $(CC) $(CFLAGS) -c $< + + all: $(PROGRAM) $(PROGRAM): $(OBJS) win32.res @@ -60,6 +64,7 @@ $(OBJS): actions.obj: actions.c ..\include\services.h base64.obj: base64.c ..\include\services.h +bots.obj: bots.cpp ..\include\services.h botserv.obj: botserv.c ..\include\services.h ..\include\pseudo.h ..\include\language.h channels.obj: channels.c ..\include\services.h chanserv.obj: chanserv.c ..\include\services.h ..\include\pseudo.h diff --git a/src/messages.c b/src/messages.c index eca2d07ca..169cb8ec6 100644 --- a/src/messages.c +++ b/src/messages.c @@ -49,7 +49,7 @@ int m_kill(const char *nick, const char *msg) introduce_user(nick); } else if (s_BotServ && (bi = findbot(nick))) { introduce_user(nick); - bot_rejoin_all(bi); + bi->RejoinAll(); } else { do_kill(nick, msg); } |