From c777c8d9aa7cd5c2e9a399727a7fa9985a77fb1c Mon Sep 17 00:00:00 2001 From: sjaz Date: Thu, 1 Jan 2009 12:00:20 +0000 Subject: Anope Stable Branch git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/stable@1902 5417fbe8-f217-4b02-8779-1006273d7864 --- src/core/Makefile | 45 +++ src/core/Makefile.sub | 29 ++ src/core/Makefile.win32 | 24 ++ src/core/bs_act.c | 92 +++++ src/core/bs_assign.c | 102 +++++ src/core/bs_badwords.c | 326 ++++++++++++++++ src/core/bs_bot.c | 378 +++++++++++++++++++ src/core/bs_botlist.c | 108 ++++++ src/core/bs_fantasy.c | 89 +++++ src/core/bs_fantasy_kick.c | 98 +++++ src/core/bs_fantasy_kickban.c | 99 +++++ src/core/bs_fantasy_owner.c | 88 +++++ src/core/bs_fantasy_seen.c | 139 +++++++ src/core/bs_help.c | 67 ++++ src/core/bs_info.c | 282 ++++++++++++++ src/core/bs_kick.c | 379 +++++++++++++++++++ src/core/bs_say.c | 97 +++++ src/core/bs_set.c | 208 +++++++++++ src/core/bs_unassign.c | 89 +++++ src/core/configure | 53 +++ src/core/cs_access.c | 543 +++++++++++++++++++++++++++ src/core/cs_akick.c | 668 +++++++++++++++++++++++++++++++++ src/core/cs_ban.c | 227 ++++++++++++ src/core/cs_clear.c | 402 ++++++++++++++++++++ src/core/cs_drop.c | 128 +++++++ src/core/cs_forbid.c | 139 +++++++ src/core/cs_getkey.c | 88 +++++ src/core/cs_getpass.c | 102 +++++ src/core/cs_help.c | 84 +++++ src/core/cs_identify.c | 117 ++++++ src/core/cs_info.c | 249 +++++++++++++ src/core/cs_invite.c | 90 +++++ src/core/cs_kick.c | 152 ++++++++ src/core/cs_list.c | 199 ++++++++++ src/core/cs_logout.c | 131 +++++++ src/core/cs_modes.c | 392 ++++++++++++++++++++ src/core/cs_register.c | 192 ++++++++++ src/core/cs_sendpass.c | 125 +++++++ src/core/cs_set.c | 837 ++++++++++++++++++++++++++++++++++++++++++ src/core/cs_status.c | 102 +++++ src/core/cs_suspend.c | 211 +++++++++++ src/core/cs_topic.c | 119 ++++++ src/core/cs_xop.c | 509 +++++++++++++++++++++++++ src/core/dummy/Makefile | 6 + src/core/enc_md5.c | 427 +++++++++++++++++++++ src/core/enc_none.c | 78 ++++ src/core/enc_old.c | 451 +++++++++++++++++++++++ src/core/enc_sha1.c | 275 ++++++++++++++ src/core/he_help.c | 76 ++++ src/core/hs_del.c | 91 +++++ src/core/hs_delall.c | 96 +++++ src/core/hs_group.c | 124 +++++++ src/core/hs_help.c | 66 ++++ src/core/hs_list.c | 187 ++++++++++ src/core/hs_off.c | 87 +++++ src/core/hs_on.c | 102 +++++ src/core/hs_set.c | 178 +++++++++ src/core/hs_setall.c | 180 +++++++++ src/core/ms_cancel.c | 105 ++++++ src/core/ms_check.c | 118 ++++++ src/core/ms_del.c | 202 ++++++++++ src/core/ms_help.c | 66 ++++ src/core/ms_info.c | 231 ++++++++++++ src/core/ms_list.c | 197 ++++++++++ src/core/ms_read.c | 203 ++++++++++ src/core/ms_rsend.c | 120 ++++++ src/core/ms_send.c | 74 ++++ src/core/ms_sendall.c | 96 +++++ src/core/ms_set.c | 266 ++++++++++++++ src/core/ms_staff.c | 93 +++++ src/core/ns_access.c | 189 ++++++++++ src/core/ns_alist.c | 186 ++++++++++ src/core/ns_drop.c | 156 ++++++++ src/core/ns_forbid.c | 155 ++++++++ src/core/ns_getemail.c | 102 +++++ src/core/ns_getpass.c | 112 ++++++ src/core/ns_ghost.c | 118 ++++++ src/core/ns_group.c | 337 +++++++++++++++++ src/core/ns_help.c | 79 ++++ src/core/ns_identify.c | 171 +++++++++ src/core/ns_info.c | 284 ++++++++++++++ src/core/ns_list.c | 247 +++++++++++++ src/core/ns_logout.c | 128 +++++++ src/core/ns_recover.c | 137 +++++++ src/core/ns_register.c | 490 +++++++++++++++++++++++++ src/core/ns_release.c | 127 +++++++ src/core/ns_saset.c | 533 +++++++++++++++++++++++++++ src/core/ns_sendpass.c | 122 ++++++ src/core/ns_set.c | 475 ++++++++++++++++++++++++ src/core/ns_status.c | 94 +++++ src/core/ns_suspend.c | 193 ++++++++++ src/core/ns_update.c | 90 +++++ src/core/os_admin.c | 249 +++++++++++++ src/core/os_akill.c | 386 +++++++++++++++++++ src/core/os_chankill.c | 134 +++++++ src/core/os_chanlist.c | 116 ++++++ src/core/os_clearmodes.c | 328 +++++++++++++++++ src/core/os_defcon.c | 169 +++++++++ src/core/os_global.c | 82 +++++ src/core/os_help.c | 66 ++++ src/core/os_ignore.c | 146 ++++++++ src/core/os_jupe.c | 88 +++++ src/core/os_kick.c | 100 +++++ src/core/os_logonnews.c | 98 +++++ src/core/os_mode.c | 102 +++++ src/core/os_modinfo.c | 139 +++++++ src/core/os_modlist.c | 195 ++++++++++ src/core/os_modload.c | 83 +++++ src/core/os_modunload.c | 85 +++++ src/core/os_noop.c | 106 ++++++ src/core/os_oline.c | 108 ++++++ src/core/os_oper.c | 252 +++++++++++++ src/core/os_opernews.c | 97 +++++ src/core/os_quit.c | 82 +++++ src/core/os_randomnews.c | 66 ++++ src/core/os_raw.c | 78 ++++ src/core/os_reload.c | 84 +++++ src/core/os_restart.c | 91 +++++ src/core/os_session.c | 68 ++++ src/core/os_set.c | 264 +++++++++++++ src/core/os_sgline.c | 362 ++++++++++++++++++ src/core/os_shutdown.c | 83 +++++ src/core/os_sqline.c | 355 ++++++++++++++++++ src/core/os_staff.c | 156 ++++++++ src/core/os_stats.c | 453 +++++++++++++++++++++++ src/core/os_svsnick.c | 125 +++++++ src/core/os_szline.c | 350 ++++++++++++++++++ src/core/os_umode.c | 116 ++++++ src/core/os_update.c | 74 ++++ src/core/os_userlist.c | 121 ++++++ 130 files changed, 23375 insertions(+) create mode 100644 src/core/Makefile create mode 100644 src/core/Makefile.sub create mode 100644 src/core/Makefile.win32 create mode 100644 src/core/bs_act.c create mode 100644 src/core/bs_assign.c create mode 100644 src/core/bs_badwords.c create mode 100644 src/core/bs_bot.c create mode 100644 src/core/bs_botlist.c create mode 100644 src/core/bs_fantasy.c create mode 100644 src/core/bs_fantasy_kick.c create mode 100644 src/core/bs_fantasy_kickban.c create mode 100644 src/core/bs_fantasy_owner.c create mode 100644 src/core/bs_fantasy_seen.c create mode 100644 src/core/bs_help.c create mode 100644 src/core/bs_info.c create mode 100644 src/core/bs_kick.c create mode 100644 src/core/bs_say.c create mode 100644 src/core/bs_set.c create mode 100644 src/core/bs_unassign.c create mode 100755 src/core/configure create mode 100644 src/core/cs_access.c create mode 100644 src/core/cs_akick.c create mode 100644 src/core/cs_ban.c create mode 100644 src/core/cs_clear.c create mode 100644 src/core/cs_drop.c create mode 100644 src/core/cs_forbid.c create mode 100644 src/core/cs_getkey.c create mode 100644 src/core/cs_getpass.c create mode 100644 src/core/cs_help.c create mode 100644 src/core/cs_identify.c create mode 100644 src/core/cs_info.c create mode 100644 src/core/cs_invite.c create mode 100644 src/core/cs_kick.c create mode 100644 src/core/cs_list.c create mode 100644 src/core/cs_logout.c create mode 100644 src/core/cs_modes.c create mode 100644 src/core/cs_register.c create mode 100644 src/core/cs_sendpass.c create mode 100644 src/core/cs_set.c create mode 100644 src/core/cs_status.c create mode 100644 src/core/cs_suspend.c create mode 100644 src/core/cs_topic.c create mode 100644 src/core/cs_xop.c create mode 100644 src/core/dummy/Makefile create mode 100644 src/core/enc_md5.c create mode 100644 src/core/enc_none.c create mode 100644 src/core/enc_old.c create mode 100644 src/core/enc_sha1.c create mode 100644 src/core/he_help.c create mode 100644 src/core/hs_del.c create mode 100644 src/core/hs_delall.c create mode 100644 src/core/hs_group.c create mode 100644 src/core/hs_help.c create mode 100644 src/core/hs_list.c create mode 100644 src/core/hs_off.c create mode 100644 src/core/hs_on.c create mode 100644 src/core/hs_set.c create mode 100644 src/core/hs_setall.c create mode 100644 src/core/ms_cancel.c create mode 100644 src/core/ms_check.c create mode 100644 src/core/ms_del.c create mode 100644 src/core/ms_help.c create mode 100644 src/core/ms_info.c create mode 100644 src/core/ms_list.c create mode 100644 src/core/ms_read.c create mode 100644 src/core/ms_rsend.c create mode 100644 src/core/ms_send.c create mode 100644 src/core/ms_sendall.c create mode 100644 src/core/ms_set.c create mode 100644 src/core/ms_staff.c create mode 100644 src/core/ns_access.c create mode 100644 src/core/ns_alist.c create mode 100644 src/core/ns_drop.c create mode 100644 src/core/ns_forbid.c create mode 100644 src/core/ns_getemail.c create mode 100644 src/core/ns_getpass.c create mode 100644 src/core/ns_ghost.c create mode 100644 src/core/ns_group.c create mode 100644 src/core/ns_help.c create mode 100644 src/core/ns_identify.c create mode 100644 src/core/ns_info.c create mode 100644 src/core/ns_list.c create mode 100644 src/core/ns_logout.c create mode 100644 src/core/ns_recover.c create mode 100644 src/core/ns_register.c create mode 100644 src/core/ns_release.c create mode 100644 src/core/ns_saset.c create mode 100644 src/core/ns_sendpass.c create mode 100644 src/core/ns_set.c create mode 100644 src/core/ns_status.c create mode 100644 src/core/ns_suspend.c create mode 100644 src/core/ns_update.c create mode 100644 src/core/os_admin.c create mode 100644 src/core/os_akill.c create mode 100644 src/core/os_chankill.c create mode 100644 src/core/os_chanlist.c create mode 100644 src/core/os_clearmodes.c create mode 100644 src/core/os_defcon.c create mode 100644 src/core/os_global.c create mode 100644 src/core/os_help.c create mode 100644 src/core/os_ignore.c create mode 100644 src/core/os_jupe.c create mode 100644 src/core/os_kick.c create mode 100644 src/core/os_logonnews.c create mode 100644 src/core/os_mode.c create mode 100644 src/core/os_modinfo.c create mode 100644 src/core/os_modlist.c create mode 100644 src/core/os_modload.c create mode 100644 src/core/os_modunload.c create mode 100644 src/core/os_noop.c create mode 100644 src/core/os_oline.c create mode 100644 src/core/os_oper.c create mode 100644 src/core/os_opernews.c create mode 100644 src/core/os_quit.c create mode 100644 src/core/os_randomnews.c create mode 100644 src/core/os_raw.c create mode 100644 src/core/os_reload.c create mode 100644 src/core/os_restart.c create mode 100644 src/core/os_session.c create mode 100644 src/core/os_set.c create mode 100644 src/core/os_sgline.c create mode 100644 src/core/os_shutdown.c create mode 100644 src/core/os_sqline.c create mode 100644 src/core/os_staff.c create mode 100644 src/core/os_stats.c create mode 100644 src/core/os_svsnick.c create mode 100644 src/core/os_szline.c create mode 100644 src/core/os_umode.c create mode 100644 src/core/os_update.c create mode 100644 src/core/os_userlist.c (limited to 'src/core') diff --git a/src/core/Makefile b/src/core/Makefile new file mode 100644 index 000000000..4ec275430 --- /dev/null +++ b/src/core/Makefile @@ -0,0 +1,45 @@ +include ./Makefile.inc + +MAKEARGS = 'CFLAGS=${CFLAGS}' 'CC=${CC}' 'ANOPELIBS=${ANOPELIBS}' \ + 'LDFLAGS=${LDFLAGS}' 'BINDEST=${BINDEST}' 'INSTALL=${INSTALL}' \ + 'INCLUDEDIR=${INCLUDEDIR}' 'RM=${RM}' 'CP=${CP}' \ + 'TOUCH=${TOUCH}' 'SHELL=${SHELL}' 'DATDEST=${DATDEST}' \ + 'RUNGROUP=${RUNGROUP}' 'MODULE_PATH=${MODULE_PATH}' \ + 'PROFILE=${PROFILE}' 'SHARED=${SHARED}' 'MODULEFLAGS=${MODULEFLAGS}' + +OBJECTS= $(SRCS:.c=.o) +SO_FILES=$(OBJECTS:.o=.s) +CDEFS= -rdynamic -Wall + +all: modules subs + +modules: $(OBJECTS) $(SO_FILES) + +install: + $(CP) ./*.so $(MODULE_PATH) + +distclean: spotless + +.c.o: + $(CC) ${CFLAGS} ${CDEFS} ${MODULEFLAGS} -I../${INCLUDEDIR} -c $< + +.o.s: + $(CC) ${SHARED} ../mod_version.o $< -o $*.so ${PROFILE} + @$(TOUCH) $*.s + +subs: + @for i in $(SUBS); do \ + echo "make all in $$i..."; \ + (cd $$i; $(MAKE) $(MAKEARGS) all); done + +subs_clean: + @for i in $(SUBS); do \ + echo "cleaning in $$i..."; \ + (cd $$i; $(MAKE) clean); done + +clean: subs_clean + rm -f *.o *.s *.so *.c~ core + +spotless: subs_clean + rm -f *.o *.s *.so *.c~ core Makefile.inc + diff --git a/src/core/Makefile.sub b/src/core/Makefile.sub new file mode 100644 index 000000000..9fbadf3b0 --- /dev/null +++ b/src/core/Makefile.sub @@ -0,0 +1,29 @@ +MAKEARGS = 'CFLAGS=${CFLAGS}' 'CC=${CC}' 'ANOPELIBS=${ANOPELIBS}' \ + 'LDFLAGS=${LDFLAGS}' 'BINDEST=${BINDEST}' 'INSTALL=${INSTALL}' \ + 'INCLUDEDIR=${INCLUDEDIR}' 'RM=${RM}' 'CP=${CP}' \ + 'TOUCH=${TOUCH}' 'SHELL=${SHELL}' 'DATDEST=${DATDEST}' \ + 'RUNGROUP=${RUNGROUP}' 'MODULE_PATH=${MODULE_PATH}' \ + 'PROFILE=${PROFILE}' 'SHARED=${SHARED}' 'MODULEFLAGS=${MODULEFLAGS}' + +OBJECTS= $(SRCS:.c=.o) +SO_FILES=$(OBJECTS:.o=.s) +CDEFS= -rdynamic -Wall + +all: module + +module: $(OBJECTS) so + +distclean: spotless + +.c.o: + $(CC) $(CC) ${CFLAGS} ${CDEFS} ${MODULEFLAGS} -I../ -I../../${INCLUDEDIR} -c $< + +so: + $(CC) ${SHARED} $(OBJECTS) -o ../$(TARGET).so ${PROFILE} + +clean: + rm -f *.o *.so *.c~ core + +spotless: clean + rm -f *~ *.o *.so *.c~ core + diff --git a/src/core/Makefile.win32 b/src/core/Makefile.win32 new file mode 100644 index 000000000..1c05bb42b --- /dev/null +++ b/src/core/Makefile.win32 @@ -0,0 +1,24 @@ +include ../../Makefile.inc.win32 + +SRCS=bs_act.c bs_assign.c bs_badwords.c bs_bot.c bs_botlist.c bs_fantasy.c bs_fantasy_kick.c bs_fantasy_kickban.c bs_fantasy_owner.c bs_fantasy_seen.c bs_help.c bs_info.c bs_kick.c bs_say.c bs_set.c bs_unassign.c cs_access.c cs_akick.c cs_ban.c cs_clear.c cs_drop.c cs_forbid.c cs_getkey.c cs_getpass.c cs_help.c cs_identify.c cs_info.c cs_invite.c cs_kick.c cs_list.c cs_logout.c cs_modes.c cs_register.c cs_sendpass.c cs_set.c cs_status.c cs_suspend.c cs_topic.c cs_xop.c enc_none.c enc_md5.c enc_old.c enc_sha1.c he_help.c hs_del.c hs_delall.c hs_group.c hs_help.c hs_list.c hs_off.c hs_on.c hs_set.c hs_setall.c ms_cancel.c ms_check.c ms_del.c ms_help.c ms_info.c ms_list.c ms_read.c ms_rsend.c ms_send.c ms_sendall.c ms_set.c ms_staff.c ns_access.c ns_alist.c ns_drop.c ns_forbid.c ns_getemail.c ns_getpass.c ns_ghost.c ns_group.c ns_help.c ns_identify.c ns_info.c ns_list.c ns_logout.c ns_recover.c ns_register.c ns_release.c ns_sendpass.c ns_set.c ns_saset.c ns_status.c ns_suspend.c ns_update.c os_admin.c os_akill.c os_chankill.c os_chanlist.c os_clearmodes.c os_defcon.c os_global.c os_help.c os_ignore.c os_jupe.c os_kick.c os_logonnews.c os_mode.c os_modinfo.c os_modlist.c os_modload.c os_modunload.c os_noop.c os_oline.c os_oper.c os_opernews.c os_quit.c os_randomnews.c os_raw.c os_reload.c os_restart.c os_session.c os_set.c os_sgline.c os_shutdown.c os_sqline.c os_staff.c os_stats.c os_svsnick.c os_szline.c os_umode.c os_update.c os_userlist.c +OBJECTS= $(SRCS:.c=.dll) +CFLAGS=/LD /MD /D MODULE_COMPILE $(CFLAGS) /I"../../include" +LFLAGS=/link ../anope.lib wsock32.lib $(LIBS) $(LFLAGS) $(MYSQL_LIB_PATH) /export:AnopeInit /export:AnopeFini /VERSION:$(VERSION) + +all: $(OBJECTS) + +distclean: clean spotless + +.c.dll: + $(CC) $(CFLAGS) $< ..\mod_version.c $(LFLAGS) + +clean: + -@del *.obj + +spotless: clean + -@del *.dll *.lib *.exp *.manifest + +install: + -@mkdir ..\..\$(DATDEST)\modules + -@mkdir ..\..\$(DATDEST)\modules\runtime + -@copy *.dll ..\..\$(DATDEST)\modules diff --git a/src/core/bs_act.c b/src/core/bs_act.c new file mode 100644 index 000000000..1f92b7e42 --- /dev/null +++ b/src/core/bs_act.c @@ -0,0 +1,92 @@ +/* BotServ core functions + * + * (C) 2003-2008 Anope Team + * Contact us at info@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + * $Id$ + * + */ +/*************************************************************************/ + +#include "module.h" + +int do_act(User * u); +void myBotServHelp(User * u); + +/** + * Create the command, and tell anope about it. + * @param argc Argument count + * @param argv Argument list + * @return MOD_CONT to allow the module, MOD_STOP to stop it + **/ +int AnopeInit(int argc, char **argv) +{ + Command *c; + + moduleAddAuthor("Anope"); + moduleAddVersion("$Id$"); + moduleSetType(CORE); + c = createCommand("ACT", do_act, NULL, BOT_HELP_ACT, -1, -1, -1, -1); + moduleAddCommand(BOTSERV, c, MOD_UNIQUE); + + moduleSetBotHelp(myBotServHelp); + + return MOD_CONT; +} + +/** + * Unload the module + **/ +void AnopeFini(void) +{ + +} + +/** + * Add the help response to Anopes /bs help output. + * @param u The user who is requesting help + **/ +void myBotServHelp(User * u) +{ + notice_lang(s_BotServ, u, BOT_HELP_CMD_ACT); +} + +/** + * The /bs act command. + * @param u The user who issued the command + * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing. + **/ +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_action(ci->bi->nick, ci->name, "%s", text); + ci->bi->lastmsg = time(NULL); + if (LogBot && LogChannel && logchan && !debug && findchan(LogChannel)) + anope_cmd_privmsg(ci->bi->nick, LogChannel, "ACT %s %s %s", + u->nick, ci->name, text); + } + return MOD_CONT; +} diff --git a/src/core/bs_assign.c b/src/core/bs_assign.c new file mode 100644 index 000000000..e34ca7d81 --- /dev/null +++ b/src/core/bs_assign.c @@ -0,0 +1,102 @@ +/* BotServ core functions + * + * (C) 2003-2008 Anope Team + * Contact us at info@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + * $Id$ + * + */ +/*************************************************************************/ + +#include "module.h" + +int do_assign(User * u); +void myBotServHelp(User * u); + +/** + * Create the command, and tell anope about it. + * @param argc Argument count + * @param argv Argument list + * @return MOD_CONT to allow the module, MOD_STOP to stop it + **/ +int AnopeInit(int argc, char **argv) +{ + Command *c; + + moduleAddAuthor("Anope"); + moduleAddVersion("$Id$"); + moduleSetType(CORE); + c = createCommand("ASSIGN", do_assign, NULL, BOT_HELP_ASSIGN, -1, -1, + -1, -1); + moduleAddCommand(BOTSERV, c, MOD_UNIQUE); + + moduleSetBotHelp(myBotServHelp); + + return MOD_CONT; +} + +/** + * Unload the module + **/ +void AnopeFini(void) +{ + +} + + +/** + * Add the help response to Anopes /bs help output. + * @param u The user who is requesting help + **/ +void myBotServHelp(User * u) +{ + notice_lang(s_BotServ, u, BOT_HELP_CMD_ASSIGN); +} + +/** + * The /bs assign command. + * @param u The user who issued the command + * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing. + **/ +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, 2, ci->name, bi->nick); + } + return MOD_CONT; +} diff --git a/src/core/bs_badwords.c b/src/core/bs_badwords.c new file mode 100644 index 000000000..3b5733f42 --- /dev/null +++ b/src/core/bs_badwords.c @@ -0,0 +1,326 @@ +/* BotServ core functions + * + * (C) 2003-2008 Anope Team + * Contact us at info@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + * $Id$ + * + */ +/*************************************************************************/ + +#include "module.h" + +int do_badwords(User * u); +void myBotServHelp(User * u); +int badwords_del_callback(User * u, int num, va_list args); +int badwords_list(User * u, int index, ChannelInfo * ci, int *sent_header); +int badwords_list_callback(User * u, int num, va_list args); + +/** + * Create the command, and tell anope about it. + * @param argc Argument count + * @param argv Argument list + * @return MOD_CONT to allow the module, MOD_STOP to stop it + **/ +int AnopeInit(int argc, char **argv) +{ + Command *c; + + moduleAddAuthor("Anope"); + moduleAddVersion("$Id$"); + moduleSetType(CORE); + + c = createCommand("BADWORDS", do_badwords, NULL, BOT_HELP_BADWORDS, -1, + -1, -1, -1); + moduleAddCommand(BOTSERV, c, MOD_UNIQUE); + + moduleSetBotHelp(myBotServHelp); + + return MOD_CONT; +} + +/** + * Unload the module + **/ +void AnopeFini(void) +{ + +} + + + +/** + * Add the help response to Anopes /bs help output. + * @param u The user who is requesting help + **/ +void myBotServHelp(User * u) +{ + notice_lang(s_BotServ, u, BOT_HELP_CMD_BADWORDS); +} + +/** + * The /bs badwords command. + * @param u The user who issued the command + * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing. + **/ +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) { + int deleted = 0, a, b; + + 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, 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; + deleted = 1; + } + + if (deleted) { + /* Reordering - DrStein */ + for (b = 0; b < ci->bwcount; b++) { + if (ci->badwords[b].in_use) { + for (a = 0; a < ci->bwcount; a++) { + if (a > b) + break; + if (!(ci->badwords[a].in_use)) { + ci->badwords[a].in_use = ci->badwords[b].in_use; + ci->badwords[a].type = ci->badwords[b].type; + if (ci->badwords[b].word) { + ci->badwords[a].word = sstrdup(ci->badwords[b].word); + free(ci->badwords[b].word); + } + ci->badwords[b].word = NULL; + ci->badwords[b].in_use = 0; + break; + } + } + } + } + /* After reordering only the entries at the end could still be empty. + * We ll free the places no longer in use... - Viper */ + for (i = ci->bwcount - 1; i >= 0; i--) { + if (ci->badwords[i].in_use) + break; + ci->bwcount--; + } + ci->badwords = + srealloc(ci->badwords,sizeof(BadWord) * ci->bwcount); + } + + } 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; +} + +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 *); + + *last = num; + + if (num < 1 || num > ci->bwcount) + return 0; + + bw = &ci->badwords[num - 1]; + if (bw->word) + free(bw->word); + bw->word = NULL; + bw->in_use = 0; + + return 1; +} + +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; +} + +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); +} diff --git a/src/core/bs_bot.c b/src/core/bs_bot.c new file mode 100644 index 000000000..f35e55152 --- /dev/null +++ b/src/core/bs_bot.c @@ -0,0 +1,378 @@ +/* BotServ core functions + * + * (C) 2003-2008 Anope Team + * Contact us at info@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + * $Id$ + * + */ +/*************************************************************************/ + +#include "module.h" + +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. + * @param argc Argument count + * @param argv Argument list + * @return MOD_CONT to allow the module, MOD_STOP to stop it + **/ +int AnopeInit(int argc, char **argv) +{ + Command *c; + + moduleAddAuthor("Anope"); + moduleAddVersion("$Id$"); + moduleSetType(CORE); + + c = createCommand("BOT", do_bot, is_services_admin, -1, -1, -1, + BOT_SERVADMIN_HELP_BOT, BOT_SERVADMIN_HELP_BOT); + moduleAddCommand(BOTSERV, c, MOD_UNIQUE); + + moduleSetBotHelp(myBotServHelp); + + return MOD_CONT; +} + +/** + * Unload the module + **/ +void AnopeFini(void) +{ + +} + + + +/** + * Add the help response to Anopes /bs help output. + * @param u The user who is requesting help + **/ +void myBotServHelp(User * u) +{ + if (is_services_admin(u)) { + notice_lang(s_BotServ, u, BOT_HELP_CMD_BOT); + } +} + +/** + * The /bs bot command. + * @param u The user who issued the command + * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing. + **/ +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 if (strlen(nick) > NickLen) + notice_lang(s_BotServ, u, BOT_BAD_NICK); + else if (strlen(user) >= USERMAX) + notice_lang(s_BotServ, u, BOT_LONG_IDENT, USERMAX - 1); + else if (strlen(user) > HOSTMAX) + notice_lang(s_BotServ, u, BOT_LONG_HOST, HOSTMAX); + 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_LONG_IDENT, USERMAX - 1); + 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, 1, 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 if (strlen(nick) > NickLen) + notice_lang(s_BotServ, u, BOT_BAD_NICK); + else if (user && strlen(user) >= USERMAX) + notice_lang(s_BotServ, u, BOT_LONG_IDENT, USERMAX - 1); + else if (host && strlen(host) > HOSTMAX) + notice_lang(s_BotServ, u, BOT_LONG_HOST, HOSTMAX); + 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 (host && !isValidHost(host, 3)) { + notice_lang(s_BotServ, u, BOT_BAD_HOST); + return MOD_CONT; + } + + if (user) { + for (ch = user; *ch && (ch - user) < USERMAX; ch++) { + if (!isalnum(*ch)) { + notice_lang(s_BotServ, u, BOT_LONG_IDENT, USERMAX - 1); + 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. We must not forget to set + the Q:Line either (it's otherwise set in anope_cmd_bot_nick) */ + if (!user) { + anope_cmd_chg_nick(oldnick, bi->nick); + anope_cmd_sqline(bi->nick, "Reserved for services"); + } 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, 1, 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, 1, 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 + syntax_error(s_BotServ, u, "BOT", BOT_BOT_SYNTAX); + + return MOD_CONT; +} + +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; +} + +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/core/bs_botlist.c b/src/core/bs_botlist.c new file mode 100644 index 000000000..9e0fb9d45 --- /dev/null +++ b/src/core/bs_botlist.c @@ -0,0 +1,108 @@ +/* BotServ core functions + * + * (C) 2003-2008 Anope Team + * Contact us at info@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + * $Id$ + * + */ +/*************************************************************************/ + +#include "module.h" + +int do_botlist(User * u); +void myBotServHelp(User * u); + +/** + * Create the botlist command, and tell anope about it. + * @param argc Argument count + * @param argv Argument list + * @return MOD_CONT to allow the module, MOD_STOP to stop it + **/ +int AnopeInit(int argc, char **argv) +{ + Command *c; + + moduleAddAuthor("Anope"); + moduleAddVersion("$Id$"); + moduleSetType(CORE); + c = createCommand("BOTLIST", do_botlist, NULL, BOT_HELP_BOTLIST, -1, + -1, -1, -1); + moduleAddCommand(BOTSERV, c, MOD_UNIQUE); + + moduleSetBotHelp(myBotServHelp); + + return MOD_CONT; +} + +/** + * Unload the module + **/ +void AnopeFini(void) +{ + +} + + + +/** + * Add the help response to Anopes /bs help output. + * @param u The user who is requesting help + **/ +void myBotServHelp(User * u) +{ + notice_lang(s_BotServ, u, BOT_HELP_CMD_BOTLIST); +} + +/** + * The /bs botlist command. + * @param u The user who issued the command + * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing. + **/ +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; +} diff --git a/src/core/bs_fantasy.c b/src/core/bs_fantasy.c new file mode 100644 index 000000000..c63d139b1 --- /dev/null +++ b/src/core/bs_fantasy.c @@ -0,0 +1,89 @@ +/* BotServ core fantasy functions + * + * (C) 2003-2008 Anope Team + * Contact us at info@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + * $Id$ + * + */ +/*************************************************************************/ + +#include "module.h" + +int do_fantasy(int argc, char **argv); + +/** + * Create the hook, and tell anope about it. + * @param argc Argument count + * @param argv Argument list + * @return MOD_CONT to allow the module, MOD_STOP to stop it + **/ +int AnopeInit(int argc, char **argv) +{ + EvtHook *hook; + + moduleAddAuthor("Anope"); + moduleAddVersion("$Id$"); + moduleSetType(CORE); + hook = createEventHook(EVENT_BOT_FANTASY, do_fantasy); + moduleAddEventHook(hook); + + return MOD_CONT; +} + +/** + * Unload the module + **/ +void AnopeFini(void) +{ + +} + +/** + * Handle all csmodeutils fantasy commands. + * @param argc Argument count + * @param argv Argument list + * @return MOD_CONT or MOD_STOP + **/ +int do_fantasy(int argc, char **argv) +{ + User *u; + ChannelInfo *ci; + CSModeUtil *util = csmodeutils; + char *target; + + if (argc < 3) + return MOD_CONT; + + do { + if (stricmp(argv[0], util->bsname) == 0) { + /* This could have been moved to its own module + however it would require more coding to handle the pass holders + similar to how PROTECT is done + */ + if (!ircd->halfop) { + if (!stricmp(argv[0], "halfop") || !stricmp(argv[0], "dehalfop")) { + return MOD_CONT; + } + } + u = finduser(argv[1]); + ci = cs_findchan(argv[2]); + if (!u || !ci) + return MOD_CONT; + + target = ((argc == 4) ? argv[3] : 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); + + return MOD_CONT; +} diff --git a/src/core/bs_fantasy_kick.c b/src/core/bs_fantasy_kick.c new file mode 100644 index 000000000..d8f272e8a --- /dev/null +++ b/src/core/bs_fantasy_kick.c @@ -0,0 +1,98 @@ +/* BotServ core fantasy functions + * + * (C) 2003-2008 Anope Team + * Contact us at info@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + * $Id$ + * + */ +/*************************************************************************/ + +#include "module.h" + +int do_fantasy(int argc, char **argv); + +/** + * Create the hook, and tell anope about it. + * @param argc Argument count + * @param argv Argument list + * @return MOD_CONT to allow the module, MOD_STOP to stop it + **/ +int AnopeInit(int argc, char **argv) +{ + EvtHook *hook; + + moduleAddAuthor("Anope"); + moduleAddVersion + ("$Id$"); + moduleSetType(CORE); + + hook = createEventHook(EVENT_BOT_FANTASY, do_fantasy); + moduleAddEventHook(hook); + + return MOD_CONT; +} + +/** + * Unload the module + **/ +void AnopeFini(void) +{ + +} + +/** + * Handle kick/k fantasy commands. + * @param argc Argument count + * @param argv Argument list + * @return MOD_CONT or MOD_STOP + **/ +int do_fantasy(int argc, char **argv) +{ + User *u, *u2; + ChannelInfo *ci; + char *target = NULL; + char *reason = NULL; + + if (argc < 3) + return MOD_CONT; + + if ((stricmp(argv[0], "kick") == 0) || (stricmp(argv[0], "k") == 0)) { + u = finduser(argv[1]); + ci = cs_findchan(argv[2]); + if (!u || !ci) + return MOD_CONT; + + if (argc >= 4) { + target = myStrGetToken(argv[3], ' ', 0); + reason = myStrGetTokenRemainder(argv[3], ' ', 1); + } + 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 { + u2 = finduser(target); + if (u2 && ci->c && is_on_chan(ci->c, u2)) { + if (!reason && !is_protected(u2)) + bot_raw_kick(u, ci, target, "Requested"); + else if (!is_protected(u2)) + bot_raw_kick(u, ci, target, reason); + } + } + } + } + + if (target) + free(target); + if (reason) + free(reason); + + return MOD_CONT; +} diff --git a/src/core/bs_fantasy_kickban.c b/src/core/bs_fantasy_kickban.c new file mode 100644 index 000000000..4cb64f116 --- /dev/null +++ b/src/core/bs_fantasy_kickban.c @@ -0,0 +1,99 @@ +/* BotServ core fantasy functions + * + * (C) 2003-2008 Anope Team + * Contact us at info@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + * $Id$ + * + */ +/*************************************************************************/ + +#include "module.h" + +int do_fantasy(int argc, char **argv); + +/** + * Create the hook, and tell anope about it. + * @param argc Argument count + * @param argv Argument list + * @return MOD_CONT to allow the module, MOD_STOP to stop it + **/ +int AnopeInit(int argc, char **argv) +{ + EvtHook *hook; + + moduleAddAuthor("Anope"); + moduleAddVersion + ("$Id$"); + moduleSetType(CORE); + + hook = createEventHook(EVENT_BOT_FANTASY, do_fantasy); + moduleAddEventHook(hook); + + return MOD_CONT; +} + +/** + * Unload the module + **/ +void AnopeFini(void) +{ + +} + +/** + * Handle kickban/kb fantasy commands. + * @param argc Argument count + * @param argv Argument list + * @return MOD_CONT or MOD_STOP + **/ +int do_fantasy(int argc, char **argv) +{ + User *u, *u2; + ChannelInfo *ci; + char *target = NULL; + char *reason = NULL; + + if (argc < 3) + return MOD_CONT; + + if ((stricmp(argv[0], "kickban") == 0) + || (stricmp(argv[0], "kb") == 0)) { + u = finduser(argv[1]); + ci = cs_findchan(argv[2]); + if (!u || !ci) + return MOD_CONT; + + if (argc >= 4) { + target = myStrGetToken(argv[3], ' ', 0); + reason = myStrGetTokenRemainder(argv[3], ' ', 1); + } + 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) == 0) { + bot_raw_ban(u, ci, u->nick, "Oops!"); + } else { + u2 = finduser(target); + if (u2 && ci->c && is_on_chan(ci->c, u2)) { + if (!reason && !is_protected(u2)) + bot_raw_ban(u, ci, target, "Requested"); + else if (!is_protected(u2)) + bot_raw_ban(u, ci, target, reason); + } + } + } + } + + if (target) + free(target); + if (reason) + free(reason); + + return MOD_CONT; +} diff --git a/src/core/bs_fantasy_owner.c b/src/core/bs_fantasy_owner.c new file mode 100644 index 000000000..934d3ccca --- /dev/null +++ b/src/core/bs_fantasy_owner.c @@ -0,0 +1,88 @@ +/* BotServ core fantasy functions + * + * (C) 2003-2008 Anope Team + * Contact us at info@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + * $Id$ + * + */ +/*************************************************************************/ + +#include "module.h" + +int do_fantasy(int argc, char **argv); + +/** + * Create the hook, and tell anope about it. + * @param argc Argument count + * @param argv Argument list + * @return MOD_CONT to allow the module, MOD_STOP to stop it + **/ +int AnopeInit(int argc, char **argv) +{ + EvtHook *hook; + + moduleAddAuthor("Anope"); + moduleAddVersion + ("$Id$"); + moduleSetType(CORE); + + /* No need to load of we don't support owner */ + if (!ircd->owner) { + alog("Your ircd doesn't support the owner channelmode; bs_fantasy_owner won't be loaded"); + return MOD_STOP; + } + + hook = createEventHook(EVENT_BOT_FANTASY, do_fantasy); + moduleAddEventHook(hook); + + return MOD_CONT; +} + +/** + * Unload the module + **/ +void AnopeFini(void) +{ + +} + +/** + * Handle owner/deowner fantasy commands. + * @param argc Argument count + * @param argv Argument list + * @return MOD_CONT or MOD_STOP + **/ +int do_fantasy(int argc, char **argv) +{ + User *u; + ChannelInfo *ci; + + if (argc < 3) + return MOD_CONT; + + if (stricmp(argv[0], "deowner") == 0) { + u = finduser(argv[1]); + ci = cs_findchan(argv[2]); + if (!u || !ci) + return MOD_CONT; + + if (is_founder(u, ci)) + bot_raw_mode(u, ci, ircd->ownerunset, u->nick); + } else if (stricmp(argv[0], "owner") == 0) { + u = finduser(argv[1]); + ci = cs_findchan(argv[2]); + if (!u || !ci) + return MOD_CONT; + + if (is_founder(u, ci)) + bot_raw_mode(u, ci, ircd->ownerset, u->nick); + } + + return MOD_CONT; +} diff --git a/src/core/bs_fantasy_seen.c b/src/core/bs_fantasy_seen.c new file mode 100644 index 000000000..75abdd26b --- /dev/null +++ b/src/core/bs_fantasy_seen.c @@ -0,0 +1,139 @@ +/* BotServ core fantasy functions + * + * (C) 2003-2008 Anope Team + * Contact us at info@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + * $Id$ + * + */ +/*************************************************************************/ + +#include "module.h" + +int do_fantasy(int argc, char **argv); + +/** + * Create the hook, and tell anope about it. + * @param argc Argument count + * @param argv Argument list + * @return MOD_CONT to allow the module, MOD_STOP to stop it + **/ +int AnopeInit(int argc, char **argv) +{ + EvtHook *hook; + + moduleAddAuthor("Anope"); + moduleAddVersion + ("$Id$"); + moduleSetType(CORE); + + hook = createEventHook(EVENT_BOT_FANTASY, do_fantasy); + moduleAddEventHook(hook); + + return MOD_CONT; +} + +/** + * Unload the module + **/ +void AnopeFini(void) +{ + +} + +/** + * Handle seen fantasy command. + * @param argc Argument count + * @param argv Argument list + * @return MOD_CONT or MOD_STOP + **/ +int do_fantasy(int argc, char **argv) +{ + User *u; + ChannelInfo *ci; + User *u2; + NickAlias *na; + ChanAccess *access; + char buf[BUFSIZE]; + char *target = NULL; + + if (argc < 4) + return MOD_CONT; + + if (stricmp(argv[0], "seen") == 0) { + u = finduser(argv[1]); + ci = cs_findchan(argv[2]); + if (!u || !ci) + return MOD_CONT; + + target = myStrGetToken(argv[3], ' ', 0); + + if (stricmp(ci->bi->nick, target) == 0) { + /* 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); + } + /* free myStrGetToken(ed) variable target (#851) */ + Anope_Free(target); + } + + return MOD_CONT; +} diff --git a/src/core/bs_help.c b/src/core/bs_help.c new file mode 100644 index 000000000..7d34ef705 --- /dev/null +++ b/src/core/bs_help.c @@ -0,0 +1,67 @@ +/* BotServ core functions + * + * (C) 2003-2008 Anope Team + * Contact us at info@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + * $Id$ + * + */ +/*************************************************************************/ + +#include "module.h" + +int do_help(User * u); + +/** + * Create the help command, and tell anope about it. + * @param argc Argument count + * @param argv Argument list + * @return MOD_CONT to allow the module, MOD_STOP to stop it + **/ +int AnopeInit(int argc, char **argv) +{ + Command *c; + + moduleAddAuthor("Anope"); + moduleAddVersion("$Id$"); + moduleSetType(CORE); + c = createCommand("HELP", do_help, NULL, -1, -1, -1, -1, -1); + moduleAddCommand(BOTSERV, c, MOD_UNIQUE); + + + return MOD_CONT; +} + +/** + * Unload the module + **/ +void AnopeFini(void) +{ + +} + + + +/** + * The /bs help command. + * @param u The user who issued the command + * @param MOD_CONT to continue processing other modules, MOD_STOP to stop processing. + **/ +int do_help(User * u) +{ + char *cmd = strtok(NULL, ""); + + if (!cmd) { + notice_help(s_BotServ, u, BOT_HELP); + moduleDisplayHelp(4, u); + notice_help(s_BotServ, u, BOT_HELP_FOOTER, BSMinUsers); + } else { + mod_help_cmd(s_BotServ, u, BOTSERV, cmd); + } + return MOD_CONT; +} diff --git a/src/core/bs_info.c b/src/core/bs_info.c new file mode 100644 index 000000000..281ba0055 --- /dev/null +++ b/src/core/bs_info.c @@ -0,0 +1,282 @@ +/* BotServ core functions + * + * (C) 2003-2008 Anope Team + * Contact us at info@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + * + * $Id$ + * + */ +/*************************************************************************/ + +#include "module.h" + +int do_info(User * u); +void send_bot_channels(User * u, BotInfo * bi); +void myBotServHelp(User * u); + +/** + * Create the info command, and tell anope about it. + * @param argc Argument count + * @param argv Argument list + * @return MOD_CONT to allow the module, MOD_STOP to stop it + **/ +int AnopeInit(