diff --git a/doc/conf/modules.full.conf b/doc/conf/modules.full.conf index 94698b89f..8da9d6ac2 100644 --- a/doc/conf/modules.full.conf +++ b/doc/conf/modules.full.conf @@ -164,6 +164,7 @@ loadmodule "chanmodes/secureonly"; /* +z */ /*** User modes ***/ +loadmodule "usermodes/bot"; /* +B */ loadmodule "usermodes/noctcp"; /* +T */ loadmodule "usermodes/censor"; /* +G */ diff --git a/include/h.h b/include/h.h index a0f8c45c2..66722c1dc 100644 --- a/include/h.h +++ b/include/h.h @@ -411,7 +411,6 @@ extern MODVAR long UMODE_NETADMIN; /* 0x10000 Network Admin */ extern MODVAR long UMODE_COADMIN; /* 0x80000 Co Admin */ extern MODVAR long UMODE_WHOIS; /* 0x100000 gets notice on /whois */ extern MODVAR long UMODE_KIX; /* 0x200000 usermode +q */ -extern MODVAR long UMODE_BOT; /* 0x400000 User is a bot */ extern MODVAR long UMODE_SECURE; /* 0x800000 User is a secure connect */ extern MODVAR long UMODE_VICTIM; /* 0x8000000 Intentional Victim */ extern MODVAR long UMODE_DEAF; /* 0x10000000 Deaf */ diff --git a/include/modules.h b/include/modules.h index c51482617..1ecf8ede8 100644 --- a/include/modules.h +++ b/include/modules.h @@ -745,6 +745,7 @@ extern char *moddata_client_get(aClient *acptr, char *varname); #define HOOKTYPE_CAN_SAJOIN 80 #define HOOKTYPE_WHOIS 81 #define HOOKTYPE_CHECK_INIT 82 +#define HOOKTYPE_WHO_STATUS 83 /* Hook return values */ #define HOOK_CONTINUE 0 diff --git a/src/modules/m_mode.c b/src/modules/m_mode.c index a0528329c..616f3d0c6 100644 --- a/src/modules/m_mode.c +++ b/src/modules/m_mode.c @@ -1850,12 +1850,6 @@ DLLFUNC CMD_FUNC(_m_umode) RunHook2(HOOKTYPE_LOCAL_OPER, sptr, 0); } - if ((sptr->umodes & UMODE_BOT) && !(setflags & UMODE_BOT) && MyClient(sptr)) - { - /* now +B */ - do_cmd(sptr, sptr, "BOTMOTD", 1, parv); - } - if (!(setflags & UMODE_OPER) && IsOper(sptr)) IRCstats.operators++; diff --git a/src/modules/m_who.c b/src/modules/m_who.c index 78684607d..3b47b8532 100644 --- a/src/modules/m_who.c +++ b/src/modules/m_who.c @@ -356,7 +356,7 @@ int i = 1; } if (!IsAnOper(sptr)) - *umodes = *umodes & (UMODE_OPER | UMODE_LOCOP | UMODE_SADMIN | UMODE_ADMIN | UMODE_COADMIN | UMODE_NETADMIN | UMODE_BOT); + *umodes = *umodes & (UMODE_OPER | UMODE_LOCOP | UMODE_SADMIN | UMODE_ADMIN | UMODE_COADMIN | UMODE_NETADMIN); if (*umodes == 0) return -1; } @@ -634,6 +634,7 @@ static void make_who_status(aClient *sptr, aClient *acptr, aChannel *channel, Member *cm, char *status, int cansee) { int i = 0; +Hook *h; if (acptr->user->away) status[i++] = 'G'; @@ -643,9 +644,13 @@ int i = 0; if (IsARegNick(acptr)) status[i++] = 'r'; - if (acptr->umodes & UMODE_BOT) - status[i++] = 'B'; - + for (h = Hooks[HOOKTYPE_WHO_STATUS]; h; h = h->next) + { + int ret = (*(h->func.intfunc))(sptr, acptr, channel, cm, status, cansee); + if (ret != 0) + status[i++] = (char)ret; + } + if (IsAnOper(acptr) && (!IsHideOper(acptr) || sptr == acptr || IsAnOper(sptr))) status[i++] = '*'; diff --git a/src/modules/m_whois.c b/src/modules/m_whois.c index b49ae34c5..b8fd0e306 100644 --- a/src/modules/m_whois.c +++ b/src/modules/m_whois.c @@ -317,9 +317,6 @@ DLLFUNC int m_whois(aClient *cptr, aClient *sptr, int parc, char *parv[]) if (IsHelpOp(acptr) && !hideoper && !user->away) sendto_one(sptr, rpl_str(RPL_WHOISHELPOP), me.name, parv[0], name); - if (acptr->umodes & UMODE_BOT) - sendto_one(sptr, rpl_str(RPL_WHOISBOT), me.name, parv[0], name, ircnetwork); - if (acptr->umodes & UMODE_SECURE) sendto_one(sptr, rpl_str(RPL_WHOISSECURE), me.name, parv[0], name, "is using a Secure Connection"); diff --git a/src/modules/usermodes/Makefile.in b/src/modules/usermodes/Makefile.in index 33db98da3..9b27377e9 100644 --- a/src/modules/usermodes/Makefile.in +++ b/src/modules/usermodes/Makefile.in @@ -30,7 +30,7 @@ INCLUDES = ../../include/auth.h ../../include/badwords.h ../../include/channel.h ../../include/version.h ../../include/whowas.h R_MODULES=\ - noctcp.so censor.so + noctcp.so censor.so bot.so MODULES=$(R_MODULES) MODULEFLAGS=@MODULEFLAGS@ @@ -59,3 +59,7 @@ noctcp.so: noctcp.c $(INCLUDES) censor.so: censor.c $(INCLUDES) $(CC) $(CFLAGS) $(MODULEFLAGS) -DDYNAMIC_LINKING \ -o censor.so censor.c + +bot.so: bot.c $(INCLUDES) + $(CC) $(CFLAGS) $(MODULEFLAGS) -DDYNAMIC_LINKING \ + -o bot.so bot.c diff --git a/src/modules/usermodes/bot.c b/src/modules/usermodes/bot.c new file mode 100644 index 000000000..30f4d4347 --- /dev/null +++ b/src/modules/usermodes/bot.c @@ -0,0 +1,99 @@ +/* + * Bot user mode (User mode +B) + * (C) Copyright 2000-.. Bram Matthys (Syzop) and the UnrealIRCd team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 1, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "unrealircd.h" + +#define IsBot(cptr) (cptr->umodes & UMODE_BOT) + +#define WHOIS_BOT_STRING ":%s 335 %s %s :is a \2Bot\2 on %s" + +/* Module header */ +ModuleHeader MOD_HEADER(bot) + = { + "usermodes/bot", + "$Id$", + "User Mode +B", + "3.2-b8-1", + NULL + }; + +/* Global variables */ +long UMODE_BOT = 0L; + +/* Forward declarations */ +int bot_whois(aClient *sptr, aClient *acptr); +int bot_who_status(aClient *sptr, aClient *acptr, aChannel *chptr, Member *cm, char *status, int cansee); +int bot_umode_change(aClient *sptr, long oldmode, long newmode); + +DLLFUNC int MOD_TEST(bot)(ModuleInfo *modinfo) +{ + return MOD_SUCCESS; +} + +DLLFUNC int MOD_INIT(bot)(ModuleInfo *modinfo) +{ + UmodeAdd(modinfo->handle, 'B', UMODE_GLOBAL, NULL, &UMODE_BOT); + + HookAddEx(modinfo->handle, HOOKTYPE_WHOIS, bot_whois); + HookAddEx(modinfo->handle, HOOKTYPE_WHO_STATUS, bot_who_status); + HookAddEx(modinfo->handle, HOOKTYPE_UMODE_CHANGE, bot_umode_change); + + MARK_AS_OFFICIAL_MODULE(modinfo); + return MOD_SUCCESS; +} + +DLLFUNC int MOD_LOAD(bot)(int module_load) +{ + return MOD_SUCCESS; +} + +DLLFUNC int MOD_UNLOAD(bot)(int module_unload) +{ + return MOD_SUCCESS; +} + +int bot_whois(aClient *sptr, aClient *acptr) +{ + if (IsBot(acptr)) + sendto_one(sptr, WHOIS_BOT_STRING, me.name, sptr->name, acptr->name, ircnetwork); + + return 0; +} + +int bot_who_status(aClient *sptr, aClient *acptr, aChannel *chptr, Member *cm, char *status, int cansee) +{ + if (IsBot(acptr)) + return 'B'; + + return 0; +} + +int bot_umode_change(aClient *sptr, long oldmode, long newmode) +{ + if ((newmode & UMODE_BOT) && !(oldmode & UMODE_BOT) && MyClient(sptr)) + { + /* now +B */ + char *parv[2]; + parv[0] = sptr->name; + parv[1] = NULL; + do_cmd(sptr, sptr, "BOTMOTD", 1, parv); + } + + return 0; +} diff --git a/src/umodes.c b/src/umodes.c index eb855ddd1..e0c35a3fe 100644 --- a/src/umodes.c +++ b/src/umodes.c @@ -68,7 +68,6 @@ long UMODE_NETADMIN = 0L; /* Network Admin */ long UMODE_COADMIN = 0L; /* Co Admin */ long UMODE_WHOIS = 0L; /* gets notice on /whois */ long UMODE_KIX = 0L; /* usermode +q */ -long UMODE_BOT = 0L; /* User is a bot */ long UMODE_SECURE = 0L; /* User is a secure connect */ long UMODE_VICTIM = 0L; /* Intentional Victim */ long UMODE_DEAF = 0L; /* Deaf */ @@ -143,7 +142,6 @@ void umode_init(void) UmodeAdd(NULL, 'C', UMODE_GLOBAL, umode_allow_opers, &UMODE_COADMIN); UmodeAdd(NULL, 'W', UMODE_GLOBAL, NULL, &UMODE_WHOIS); UmodeAdd(NULL, 'q', UMODE_GLOBAL, umode_allow_opers, &UMODE_KIX); - UmodeAdd(NULL, 'B', UMODE_GLOBAL, NULL, &UMODE_BOT); UmodeAdd(NULL, 'z', UMODE_GLOBAL, NULL, &UMODE_SECURE); UmodeAdd(NULL, 'v', UMODE_GLOBAL, umode_allow_opers, &UMODE_VICTIM); UmodeAdd(NULL, 'd', UMODE_GLOBAL, NULL, &UMODE_DEAF);