/*------------------------------------------------------------------------------------------------- * Name: unreal_addon * Author: Jens 'DukePyrolator' Voss * * Date: 02.01.2005 * Version: 1.3.0 *------------------------------------------------------------------------------------------------- * Supported IRCD: Unreal 3.2 * Tested with: Unreal 3.2 (stable) * Requires: Anope 1.7.2+ and MySQL *------------------------------------------------------------------------------------------------- * new commands: * * - /ns set alogin * turn automatic login on identify or update on or off * * - /ns set ajoin * set, list or modify your ajoin channels * * - /ns set realname * you can set a realname for your nick * it is also shown in /ns info * * - /ns set vhost * request a vhost and turn your vhost on/off * * - /os swhois * set a swhois to a user * (services oper only) * * - /os helpop * you can set special modes for some users (like helpop) * opermodes like +oOAaN are NOT supported! (security risk) * (services admin only) * * - /os snomask * you can set a snomask for a nick (or a bot) * (services oper only) * * - /os vhost * list,add,delete,accept and reject vhosts/vhost requests * (services oper only) * * You can enable/disable all features with #define/#undef. * * If you want to enable the new vhost system I suggest to * disable hostserv. (services.conf) * * *------------------------------------------------------------------------------------------------- * * If you found a bug, please send me a Mail or contact me on irc.anope.org #anope * you can get the latest version of this module from http://dev.anope.de/unreal_addon.c * *------------------------------------------------------------------------------------------------- * Change log: * v1.3.0 05/02/2005 - replaced nearly all notice() by notice_user() * v1.2.9 05/02/2005 - added some additional checks and an error message (GLOBOPS) * to prevent a possible segfault caused by an invalid value in field "alogin" * v1.2.8 02/01/2005 - added a new command "nickserv set vhost group" to get the vHost from the main nickname in your group * v1.2.7 29/12/2004 - fixed a crashbug in ns_set() reported by Mekonikum * v1.2.6 06/12/2004 - fixed a memory leak in do_on_identify (mysql_free_result) * found with valgrind (http://valgrind.kde.org/) * v1.2.5 28/09/2004 - fixed a random crashbug in do_info2() (I hope so) * - fixed a small bug in os_vhost() reported by crazytoon * v1.2.4 12/09/2004 - fixed some memory leaks * v1.2.3 29/08/2004 - fixed a crashbug with nicks containing a '\' * v1.2.2 21/08/2004 - fixed a bug in set_vhost (thx to Trystan for help) * - removed some useless code * v1.2.1 18/08/2004 - fixed potential segfault in os_snomask * v1.2.0 15/08/2004 - fixed hundreds of memleaks caused by myStrGetToken ... * - fixed some small errors with help * v1.1.9 14/08/2004 - "vhostsetter" was not set by "vhost pending ackall" * v1.1.8 12/07/2004 - new vhosts are now ON by default * v1.1.7 30/06/2004 - fixed 2 bugs in set_vhost where a vhost is not set correctly sometimes * reported by crazytoon * v1.1.6 26/06/2004 - fixed a little bug in os_vhost * v1.1.5 25/06/2004 - fixed another crashbug with NULL pointer in os_vhost reported by Chris * v1.1.4 20/06/2004 - fixed a crashbug in os_vhost reported by Chris * - fixed some minor bugs * v1.1.3 19/06/2004 - fixed crashbug caused by an unchecked parameter * reported by Certus, Chris and FatihAg * v1.1.2 12/06/2004 - fixed compile error with older gcc reported by hexa * v1.1.1 10/06/2004 - fixed some possible compile errors * v1.1.0 06/06/2004 - finished vhost system * - renamed module from "misc_addon_mysql" to "unreal_addon" * - fixed some little bugs * v1.0.4 20/05/2004 - removed some old debugging messages and changed mysql tables * for new vhost requesting system * v1.0.3 18/05/2004 - you can now store passwords for ajoin channels * Syntax is: /nickserv set ajoin #chan1,#chan2,#chan3 pass1,pass2,pass3 * only supported in Unreal3.2.1 or later * v1.0.2 17/05/2004 - fixed a crashbug in ns_help_set() * v1.0.1 15/05/2004 - added a routine to remove expired/dropped nicks from database * v1.0.0 15/05/2004 - first release *------------------------------------------------------------------------------------------------- * * internal infos: * field vhostreqstatus: * 0 - no vhost requested * 1 - request open * 2 - request accepted, user have to be notified * 3 - request rejected, user have to be notified * 4 - new vhost added manuallly, user have to be notified * 5 - vhost deleted manually, user have to be notified * *---------------------------------------------------------------------------------------------------*/ /* #undef to disable */ #define USE_AJOIN #define USE_SWHOIS #define USE_HELPOP #define USE_SNOMASK #define USE_REALNAME #define USE_NS_INFO /* the new vhost system is disabled by default.*/ /* if you want to enable it, make sure you disable hostserv! */ #define USE_VHOSTREQ /* sometimes I forget to undefine this ... sorry ;-) */ /* sets the delay between checks for expired/dropped nicks */ #define PURGETIME "2h" /* language definition */ /* alogin */ #define ALOGIN_SYNTAX "Syntax: \002SET ALOGIN {\037ON\037|\037OFF\037|\037SILENT\037}\002 " #define ALOGIN_SYNTAX2 "\002/msg NickServ HELP SET ALOGIN\002 for more information" #define ALOGIN_HELP1 "This sets the automatically login on identify ON or OFF." #define ALOGIN_HELP2 "Set ALOGIN to SILENT if you dont want to receive the messages." #define ALOGIN_HELP3 "Default is ON." #define ALOGIN_NOTICE_IS_ON "ALOGIN option is already \002ON\002" #define ALOGIN_NOTICE_IS_NOW_ON "ALOGIN option is now \002ON\002" #define ALOGIN_NOTICE_IS_OFF "ALOGIN option is already \002OFF\002" #define ALOGIN_NOTICE_IS_NOW_OFF "ALOGIN option is now \002OFF\002" #define ALOGIN_NOTICE_IS_SIL "ALOGIN option is already \002SILENT\002" #define ALOGIN_NOTICE_IS_NOW_SIL "ALOGIN option is now \002SILENT\002" /* vhost */ #define VHOST_NS_SYNTAX "Syntax: \002SET VHOST {\037ON\037|\037OFF\037|\037GROUP\037|\037vhost\037}\002" #define VHOST_NS_SYNTAX2 "\002/msg NickServ HELP SET VHOST\002 for more information." #define VHOST_NS_HELP1 "You can request a new vhost or turn your existing vhost on or off." #define VHOST_NS_HELP2 "The \002GROUP\002 command allows you to get the vhost from the main nickname in your nickgroup." #define VHOST_NOTICE_VHOST "Setting your vhost..." #define VHOST_NOTICE_NO_VHOST "You have no vhost to turn on or off" #define VHOST_NOTICE_IS_ON "Your vhost is already \2ON\2" #define VHOST_NOTICE_IS_NOW_ON "Your vhost is now \2ON\2" #define VHOST_NOTICE_IS_OFF "Your vhost is already \2OFF\2" #define VHOST_NOTICE_IS_NOW_OFF "Your vhost is now \2OFF\2" #define VHOST_NOTICE_NEW_VHOST "vHost information: A new vHost for your nick has been set." #define VHOST_NOTICE_DEL_VHOST "vHost information: Your vHost has been deleted." #define VHOST_NOTICE_REJECT "vHost information: Your vHost request has been rejected." #define VHOST_NOTICE_ACCEPT "vHost information: Your vHost request has been accepted." #define VHOST_NOTICE_REQUEST1 "Your vHost request has been sent. Please have some patience" #define VHOST_NOTICE_REQUEST2 "while waiting for acknowledgement by an operator and wait at" #define VHOST_NOTICE_REQUEST3 "least 24 hours until you ask an operator for activation." #define VHOST_OS_SYNTAX "Syntax: \002VHOST {\037ADD\037|\037DEL\037|\037LIST\037|\037PENDING\037} <\037nick\037>\002 " #define VHOST_OS_SYNTAX2 "\002/msg OperServ HELP VHOST\002 for more information" #define VHOST_OS_HELP1 " \002VHOST ADD \037nick\037 \037vhost\037\002" #define VHOST_OS_HELP2 " Adds a vhost for a nick" #define VHOST_OS_HELP3 " \002VHOST DEL \037nick\037\002" #define VHOST_OS_HELP4 " Deletes a vhost of a nick" #define VHOST_OS_HELP5 " \002VHOST LIST \037[searchstring]\037\002" #define VHOST_OS_HELP6 " Without a nickname this lists all" #define VHOST_OS_HELP7 " the vhosts which are set." #define VHOST_OS_HELP8 " With a parameter you can select" #define VHOST_OS_HELP9 " vhosts to list. (try it out)" #define VHOST_OS_HELP10 " \002VHOST PENDING\002" #define VHOST_OS_HELP11 " do a \002/OPERSERV HELP VHOST PENDING\002 " #define VHOST_OS_HELP12 " for more information" #define VHOST_OS_NOTICE_ADDED_TO_LIST "%s has been added to the vhost list" #define VHOST_OS_NOTICE_REMOVED_FROM_LIST "%s has been removed from the vhost list" #define VHOST_OS_NOTICE_NOT_IN_LIST "%s is not in the vhost list" #define VHOST_OS_PEN_SYNTAX "Syntax: \002 VHOST PENDING {\037LIST\037|\037ACK\037|\037DEL\037|\037ACKALL\037} <\037nick\037>\002" #define VHOST_OS_PEN_SYNTAX2 "\002/msg OperServ HELP VHOST PENDING\002 for more information" #define VHOST_OS_PEN_HELP1 " \002VHOST PENDING \037list\037\002" #define VHOST_OS_PEN_HELP2 " Lists the pending vhosts" #define VHOST_OS_PEN_HELP3 " \002VHOST PENDING \037ack\037 \037nick\037\002" #define VHOST_OS_PEN_HELP4 " Activates a vhost for a user who" #define VHOST_OS_PEN_HELP5 " is in the pending list." #define VHOST_OS_PEN_HELP6 " \002VHOST PENDING \037del\037 \037nick\037\002" #define VHOST_OS_PEN_HELP7 " Rejects a vhost in the pending list." #define VHOST_OS_PEN_HELP8 " \002VHOST PENDING \037ackall\037\002" #define VHOST_OS_PEN_HELP9 " Activates all vhosts in the pending list." #define VHOST_OS_PEN_NOTICE_NOT_IN_LIST "%s is not in the vhost request list" /* ajoin */ #define AJOIN_SYNTAX "Syntax: \002SET AJOIN { \037#chan1,#chan2,...\037|\037OFF\037|\037LIST\037 } \002" #define AJOIN_SYNTAX2 "\002/msg NickServ HELP SET AJOIN\002 for more information." #define AJOIN_HELP1 "This sets your ajoin channels. If you have set ajoin channels" #define AJOIN_HELP2 "you're joined automatically in this channels on identify" #define AJOIN_HELP3 "if you have set alogin to ON or type /msg NickServ update" #define AJOIN_NOTICE_AJOIN "Joining your ajoin channels %s" #define AJOIN_NOTICE_AJOINLIST "Your ajoin channels are: %s" #define AJOIN_NOTICE_AJOINLIST_NEW "Your ajoin channels are now %s" #define AJOIN_NOTICE_EMPTY_LIST "You have no ajoin channels set" #define AJOIN_NOTICE_EMPTY_LIST2 "The ajoin list is now empty" #define AJOIN_NOTICE_MAX_AJOIN "The chanlist is too long. The max. length of it is 511 chars" /* realname */ #define REALNAME_SYNTAX "Syntax: \002SET REALNAME \037realname\037\002" #define REALNAME_SYNTAX2 "\002/msg NickServ HELP SET REALNAME\002 for more information" #define REALNAME_HELP1 "This sets your realname. Your realname will be shown if you" #define REALNAME_HELP2 "type \002/msg NickServ INFO \037nick\037\002 or do a \002/whois \037nick\037\002." #define REALNAME_HELP3 "Your realname is automatically set on identify if you have set" #define REALNAME_HELP4 "alogin to ON or type /msg NickServ update." #define REALNAME_NOTICE_SET "Setting your realname to: %s" #define REALNAME_NOTICE_NEW "Your realname is now: %s" /* swhois */ #define SWHOIS_SYNTAX "Syntax: \002SWHOIS {\037ADD\037|\037DEL\037|\037LIST\037} [\037nick\037] [\037swhois\037]\002" #define SWHOIS_SYNTAX2 "\002/msg OperServ HELP SWHOIS\002 for more information" #define SWHOIS_HELP1 "Adds, removes or lists a swhois." #define SWHOIS_NOTICE_SWHOIS "Setting your swhois..." #define SWHOIS_NOTICE_TOO_LONG "The swhois is too long. The max. length is 280 chars" #define SWHOIS_NOTICE_ADDED_TO_LIST "%s has been added to the swhois list" #define SWHOIS_NOTICE_REMOVED_FROM_LIST "%s has been removed from the swhois list" #define SWHOIS_NOTICE_NOT_IN_LIST "%s is not in the swhois list" /* helpop */ #define HELPOP_SYNTAX "Syntax: \002HELPOP {\037ADD\037|\037DEL\037|\037LIST\037} [\037nick\037] [\037modes\037]\002" #define HELPOP_SYNTAX2 "\002/msg OperServ HELP HELPOP\002 for more information" #define HELPOP_HELP1 "Adds, removes or lists a helpop." #define HELPOP_HELP2 "You can add helpops with the modes you define." #define HELPOP_HELP3 "Note that oper flags (oOAN etc) don't work!" #define HELPOP_HELP4 "Example: " #define HELPOP_HELP5 "\002/msg OperServ HELPOP ADD \037Helper\037 \037+hW\037\002" #define HELPOP_HELP6 "This adds the modes +hW (helpop and whois notify) to the user Helper" #define HELPOP_NOTICE_HELPOP "Setting your helpop..." #define HELPOP_NOTICE_TOO_LONG "there are too much modes. The max. lenght is 32 chars" #define HELPOP_NOTICE_ADDED_TO_LIST "%s has been added to the helpop list" #define HELPOP_NOTICE_REMOVED_FROM_LIST "%s has been removed from the helpop list" #define HELPOP_NOTICE_NOT_IN_LIST "%s is not in the helpop list" /* snomask */ #define SNOMASK_SYNTAX "Syntax: \002SNOMASK {\037ADD\037|\037DEL\037|\037LIST\037} [\037nick\037] [\037modes\037]\002" #define SNOMASK_SYNTAX2 "\002/msg OperServ HELP SNOMASK\002 for more information" #define SNOMASK_HELP1 "Adds, removes or lists snomasks." #define SNOMASK_HELP2 "SNOMASK stands for '\002S\002ervice \002NO\002tice \002MASK\002', it (mainly) controls which" #define SNOMASK_HELP3 "server notices you will receive." #define SNOMASK_HELP4 "Do a \002/helpop ?snomask\002 for getting a complete list of possible snomasks." #define SNOMASK_NOTICE_SNOMASK "Setting your snomask..." #define SNOMASK_NOTICE_TOO_LONG "there are too much modes. The max lenght is 32 chars" #define SNOMASK_NOTICE_ADDED_TO_LIST "%s has been added to the snomask list" #define SNOMASK_NOTICE_REMOVED_FROM_LIST "%s has been removed from the snomask list" #define SNOMASK_NOTICE_NOT_IN_LIST "%s is not in the snomask list" /* stuff */ #define NOTICE_NO_REGISTERED_NICK "%s is not a registered nick" #define NOTICE_EMPTY_LIST "List is empty" /**********************************/ /***** END OF HELP DEFINITION *****/ /**********************************/ /*************************************************************************************************************************/ /******** DO NOT CHANGE BELOW THIS LINE UNLESS YOU KNOW WHAT ARE YOU DOING !!!!!!! **************************************/ /*************************************************************************************************************************/ #include "module.h" #define __USE_GNU #include #define AUTHOR "Jens 'DukePyrolator' Voss " #define VERSION "1.4.0" static MYSQL *mysql; static MYSQL_RES *res; static MYSQL_ROW row; char *myresult = ""; char *qbuf1, *qbuf2, *qbuf3; char *quote(char *arg); extern int do_mysql; int svsjoin = 0; int snomask = 0; int swhois = 0; int svsmode = 0; int os_vhost(User *u); int os_swhois(User *u); int os_helpop(User *u); int os_snomask(User *u); int ns_set(User *u); int do_on_identify(User *u); extern int debug; int do_info2(User *u); /* its a copy of the do_info() from nickserv.c but contains some changes */ extern NickRequest *findrequestnick(const char *nick); extern char *getvHost(char *nick); int my_isvalidchar(const char c); int set_vhost(User *u, char *vhoststring); int is_valid_vhost(User *u, char *rawhostmask); void get_from_db(char *nick, char *type); void add_to_db(NickAlias *na, char *type, char *arg); int mydb_init(void); int do_query(char *query); int purgedb(int argc, char *argv[]); /* help */ int ns_help_set(User *u); int ns_help_set_vhost(User *u); int ns_help_set_alogin(User *u); int ns_help_set_ajoin(User *u); int ns_help_set_realname(User *u); int os_help_vhost(User *u); int os_help_vhost_pending(User *u); int os_help_swhois(User *u); int os_help_helpop(User *u); int os_help_snomask(User *u); void help_operserv(User *u); /*************************************************************************************************/ /* start */ int AnopeInit(int argc, char **argv) { Command *c; #ifndef USE_MYSQL alog("[unreal_addon] MYSQL is not enabled. This module requires MYSQL !"); alog("[unreal_addon] Module not loaded."); return MOD_STOP; #endif if (!do_mysql) { alog("[unreal_addon] MYSQL is not configured. Please edit your services.conf ."); alog("[unreal_addon] Module not loaded."); return MOD_STOP; } if (!stricmp(ircd->name, "UnrealIRCd 3.2.x")) { svsjoin = 1; snomask = 1; swhois = 1; svsmode = 1;} /* activate mysql connection and stop if failed */ if (mydb_init()) return MOD_STOP; c = createCommand("SET", ns_set, NULL, -1, -1, -1, -1, -1); moduleAddCommand(NICKSERV, c, MOD_HEAD); c = createCommand("IDENTIFY", do_on_identify, NULL, -1, -1, -1, -1, -1); moduleAddCommand(NICKSERV, c, MOD_TAIL); c = createCommand("ID", do_on_identify, NULL, -1, -1, -1, -1, -1); moduleAddCommand(NICKSERV, c, MOD_TAIL); c = createCommand("UPDATE", do_on_identify, NULL, -1, -1, -1, -1, -1); moduleAddCommand(NICKSERV, c, MOD_TAIL); c = createCommand("LOGIN", do_on_identify, NULL, -1, -1, -1, -1, -1); moduleAddCommand(NICKSERV, c, MOD_UNIQUE); #ifdef USE_NS_INFO c = createCommand("INFO", do_info2, NULL, -1, -1, -1, -1, -1); moduleAddCommand(NICKSERV, c, MOD_HEAD); #endif #ifdef USE_SWHOIS if (swhois) { c = createCommand("SWHOIS", os_swhois, is_services_oper, -1, -1, -1, -1, -1); moduleAddCommand(OPERSERV, c, MOD_HEAD); moduleAddHelp(c,os_help_swhois); } #endif #ifdef USE_HELPOP if (svsmode) { c = createCommand("HELPOP", os_helpop, is_services_admin, -1, -1, -1, -1, -1); moduleAddCommand(OPERSERV, c, MOD_HEAD); moduleAddHelp(c, os_help_helpop); } #endif #ifdef USE_SNOMASK if (snomask) { c = createCommand("SNOMASK", os_snomask, is_services_oper, -1, -1, -1, -1, -1); moduleAddCommand(OPERSERV, c, MOD_HEAD); moduleAddHelp(c, os_help_snomask); } #endif #ifdef USE_VHOSTREQ if (ircd->vhost && ircd->vident) { c = createCommand("VHOST", os_vhost, is_services_oper, -1, -1, -1, -1, -1); moduleAddCommand(OPERSERV, c, MOD_HEAD); moduleAddHelp(c, os_help_vhost); c = createCommand("VHOST PENDING", NULL, NULL, -1, -1, -1, -1, -1); moduleAddCommand(OPERSERV, c, MOD_TAIL); moduleAddHelp(c, os_help_vhost_pending); c = createCommand("SET VHOST", NULL, NULL, -1, -1, -1, -1, -1); moduleAddCommand(NICKSERV, c, MOD_TAIL); moduleAddHelp(c,ns_help_set_vhost); } #endif /* help */ c = createCommand("HELP", ns_help_set, NULL, -1, -1, -1, -1, -1); moduleAddCommand(NICKSERV, c, MOD_TAIL); c = createCommand("SET ALOGIN", NULL, NULL, -1, -1, -1, -1, -1); moduleAddCommand(NICKSERV, c, MOD_TAIL); moduleAddHelp(c,ns_help_set_alogin); #ifdef USE_AJOIN c = createCommand("SET AJOIN", NULL, NULL, -1, -1, -1, -1, -1); moduleAddCommand(NICKSERV, c, MOD_TAIL); moduleAddHelp(c,ns_help_set_ajoin); #endif #ifdef USE_REALNAME if (ircd->chgreal) { c = createCommand("SET REALNAME", NULL, NULL, -1, -1, -1, -1, -1); moduleAddCommand(NICKSERV, c, MOD_TAIL); moduleAddHelp(c,ns_help_set_realname); } #endif moduleSetOperHelp(help_operserv); purgedb(0,NULL); moduleAddAuthor(AUTHOR); moduleAddVersion(VERSION); return MOD_CONT; } /***************************************************************************************************/ /* stop */ void AnopeFini(void) { mysql_close(mysql); moduleDelCallback("PURGEDB"); } /***************************************************************************************************/ /***************************************************************************************************/ /* help */ int ns_help_set_alogin(User *u) { notice_user(s_NickServ, u, ALOGIN_SYNTAX); notice_user(s_NickServ, u, ALOGIN_HELP1); notice_user(s_NickServ, u, ALOGIN_HELP2); notice_user(s_NickServ, u, ALOGIN_HELP3); return MOD_CONT; } int ns_help_set_ajoin(User *u) { notice_user(s_NickServ, u, AJOIN_SYNTAX); notice_user(s_NickServ, u, AJOIN_HELP1); notice_user(s_NickServ, u, AJOIN_HELP2); notice_user(s_NickServ, u, AJOIN_HELP3); return MOD_CONT; } int ns_help_set_realname(User *u) { notice_user(s_NickServ, u, REALNAME_SYNTAX); notice_user(s_NickServ, u, REALNAME_HELP1); notice_user(s_NickServ, u, REALNAME_HELP2); notice_user(s_NickServ, u, REALNAME_HELP3); notice_user(s_NickServ, u, REALNAME_HELP4); return MOD_CONT; } int ns_help_set_vhost(User *u) { notice_user(s_NickServ, u, VHOST_NS_SYNTAX); notice_user(s_NickServ, u, VHOST_NS_HELP1); notice_user(s_NickServ, u, VHOST_NS_HELP2); return MOD_CONT; } int os_help_swhois(User *u) { notice_user(s_OperServ, u, SWHOIS_SYNTAX); notice_user(s_OperServ, u, SWHOIS_HELP1); return MOD_CONT; } int os_help_helpop(User *u) { notice_user(s_OperServ, u, HELPOP_SYNTAX); notice_user(s_OperServ, u, HELPOP_HELP1); notice_user(s_OperServ, u, HELPOP_HELP2); notice_user(s_OperServ, u, HELPOP_HELP3); notice_user(s_OperServ, u, HELPOP_HELP4); notice_user(s_OperServ, u, HELPOP_HELP5); notice_user(s_OperServ, u, HELPOP_HELP6); return MOD_CONT; } int os_help_snomask(User *u) { notice_user(s_OperServ, u, SNOMASK_SYNTAX); notice_user(s_OperServ, u, SNOMASK_HELP1); notice_user(s_OperServ, u, SNOMASK_HELP2); notice_user(s_OperServ, u, SNOMASK_HELP3); notice_user(s_OperServ, u, SNOMASK_HELP4); return MOD_CONT; } int os_help_vhost(User *u) { notice_user(s_OperServ, u, VHOST_OS_SYNTAX); notice_user(s_OperServ, u, VHOST_OS_HELP1); notice_user(s_OperServ, u, VHOST_OS_HELP2); notice_user(s_OperServ, u, VHOST_OS_HELP3); notice_user(s_OperServ, u, VHOST_OS_HELP4); notice_user(s_OperServ, u, VHOST_OS_HELP5); notice_user(s_OperServ, u, VHOST_OS_HELP6); notice_user(s_OperServ, u, VHOST_OS_HELP7); notice_user(s_OperServ, u, VHOST_OS_HELP8); notice_user(s_OperServ, u, VHOST_OS_HELP9); notice_user(s_OperServ, u, VHOST_OS_HELP10); notice_user(s_OperServ, u, VHOST_OS_HELP11); notice_user(s_OperServ, u, VHOST_OS_HELP12); return MOD_CONT; } int os_help_vhost_pending(User *u) { notice_user(s_OperServ, u, VHOST_OS_PEN_SYNTAX); notice_user(s_OperServ, u, VHOST_OS_PEN_HELP1); notice_user(s_OperServ, u, VHOST_OS_PEN_HELP2); notice_user(s_OperServ, u, VHOST_OS_PEN_HELP3); notice_user(s_OperServ, u, VHOST_OS_PEN_HELP4); notice_user(s_OperServ, u, VHOST_OS_PEN_HELP5); notice_user(s_OperServ, u, VHOST_OS_PEN_HELP6); notice_user(s_OperServ, u, VHOST_OS_PEN_HELP7); notice_user(s_OperServ, u, VHOST_OS_PEN_HELP8); notice_user(s_OperServ, u, VHOST_OS_PEN_HELP9); return MOD_CONT; } void help_operserv(User *u) { #ifdef USE_VHOSTREQ if (ircd->vhost) { notice_user(s_OperServ, u, " VHOST Administrate the vhosts"); } #endif #ifdef USE_SWHOIS if (swhois) { notice_user(s_OperServ, u, " SWHOIS Administrate the swhoises"); } #endif #ifdef USE_HELPOP if (svsmode) { notice_user(s_OperServ, u, " HELPOP Administrate the helpops"); } #endif #ifdef USE_SNOMASK if (snomask) { notice_user(s_OperServ, u, " SNOMASK Administrate the snomasks"); } #endif } int ns_help_set(User *u) { char *temp = moduleGetLastBuffer(); char *option = myStrGetTokenRemainder(temp,' ',0); if (option && stricmp(option, "SET")==0) { notice_user(s_NickServ, u, "Additional Commands:"); notice_user(s_NickServ, u, " ALOGIN Sets Alogin (on/off/silent)"); #ifdef USE_VHOSTREQ if (ircd->vhost) { notice_user(s_NickServ, u, " VHOST Request your vhost"); } #endif #ifdef USE_AJOIN if (svsjoin) { notice_user(s_NickServ, u, " AJOIN Sets your autojoin channels"); } #endif #ifdef USE_REALNAME if (ircd->chgreal) { notice_user(s_NickServ, u, " REALNAME Sets your realname"); } #endif } if (option) free(option); return MOD_CONT; } /***************************************************************************************************/ /***************************************************************************************************/ /* vhost */ int os_vhost(User *u) { char *temp = moduleGetLastBuffer(); char *cmd = myStrGetToken(temp,' ',0); char *option1 = myStrGetToken(temp,' ',1); char *option2 = myStrGetTokenRemainder(temp,' ',2); char *query = malloc(MAX_SQL_BUF); NickAlias *target; int i = 1; if (!cmd) { notice_user(s_OperServ, u, VHOST_OS_SYNTAX); notice_user(s_OperServ, u, VHOST_OS_SYNTAX2); goto MODSTOP; } if (stricmp(cmd, "ADD")==0) { if (!option1 || !option2) { notice_user(s_OperServ, u, VHOST_OS_SYNTAX); notice_user(s_OperServ, u, VHOST_OS_SYNTAX2); goto MODSTOP; } target = findnick(option1); if (!target) { notice_user(s_OperServ, u, NOTICE_NO_REGISTERED_NICK, option1); goto MODSTOP; } if (!is_valid_vhost(u,option2)) { goto MODSTOP; } add_to_db(target, "vhost", option2); add_to_db(target, "vhoststatus", "1"); add_to_db(target, "v_setter", u->na->nc->display); if (findnick(option1)) { /* send notice if nick is online */ notice(s_NickServ, option1, VHOST_NOTICE_NEW_VHOST); add_to_db(target, "vhostreqstatus", "0"); } else { /* send notice on next identify */ add_to_db(target, "vhostreqstatus", "4"); } notice_user(s_OperServ, u, VHOST_OS_NOTICE_ADDED_TO_LIST, option1); goto MODSTOP; } if (stricmp(cmd, "DEL")==0) { if (!option1) { notice_user(s_OperServ, u, VHOST_OS_SYNTAX); notice_user(s_OperServ, u, VHOST_OS_SYNTAX2); goto MODSTOP; } target = findnick(option1); if (!target) { notice_user(s_OperServ, u, NOTICE_NO_REGISTERED_NICK, option1); goto MODSTOP; } get_from_db(target->nick, "vhost"); if (!myresult ) { notice_user(s_OperServ, u, VHOST_OS_NOTICE_NOT_IN_LIST, option1); goto MODSTOP; } add_to_db(target, "vhoststatus", "0"); add_to_db(target, "vhost", ""); add_to_db(target, "v_setter", u->na->nc->display); /* stores the nickgroup of the user, who deleted the entry */ if (findnick(option1)) { /* send notice if nick is online */ notice(s_NickServ, option1, VHOST_NOTICE_DEL_VHOST); add_to_db(target, "vhostreqstatus", "0"); } else { /* send notice von next identify */ add_to_db(target, "vhostreqstatus", "5"); } notice_user(s_OperServ, u, VHOST_OS_NOTICE_REMOVED_FROM_LIST, option1); goto MODSTOP; } if (stricmp(cmd, "LIST")==0) { if (option1) { snprintf(query,MAX_SQL_BUF,"SELECT nick, vhost, v_setter FROM anope_unreal_addon " "WHERE vhost IS NOT NULL " "AND ( nick LIKE '%%%s%%' OR vhost LIKE '%%%s%%' OR v_setter LIKE '%%%s%%') " "ORDER by `nick`;",option1, option1, option1); } else { snprintf(query,MAX_SQL_BUF,"SELECT nick, vhost, v_setter FROM anope_unreal_addon " "WHERE vhost IS NOT NULL ORDER by nick;"); } do_query(query); res = mysql_store_result(mysql); if (mysql_num_rows(res) > 0) { while ((row = mysql_fetch_row(res)) != NULL) { notice_user(s_OperServ, u,"#%2i Nick: \002%-16s\002 vhost: \002%-35s\002 (%s)",i, row[0] ? row[0] : "NULL" ,row[1] ? row[1] : "NULL" ,row[2] ? row[2] :"NULL" ); i++; } mysql_free_result(res); goto MODSTOP; } notice_user(s_OperServ, u, NOTICE_EMPTY_LIST); mysql_free_result(res); /* free unused memory */ goto MODSTOP; } if (stricmp(cmd, "PENDING")==0) { /* list, ack, del, ackall */ if (!option1) { notice_user(s_OperServ, u, VHOST_OS_PEN_SYNTAX); notice_user(s_OperServ, u, VHOST_OS_PEN_SYNTAX2); goto MODSTOP; } if (stricmp(option1, "LIST")==0) { snprintf(query,MAX_SQL_BUF, "SELECT nick, vhostreq FROM anope_unreal_addon " "WHERE vhostreqstatus = '1' " "AND vhostreq IS NOT NULL ORDER by nick;"); do_query(query); res = mysql_store_result(mysql); if (mysql_num_rows(res) > 0) { while ((row = mysql_fetch_row(res)) != NULL) { notice_user(s_OperServ, u,"#%2i Nick: \002%-16s\002 vhost: \002%-35s\002",i, row[0] ? row[0] : "NULL" , row[1] ? row[1] : "NULL" ); i++; } mysql_free_result(res); goto MODSTOP; } notice_user(s_OperServ, u, NOTICE_EMPTY_LIST); mysql_free_result(res); /* free unused memory */ goto MODSTOP; } if (stricmp(option1, "ACKALL")==0) { snprintf(query,MAX_SQL_BUF,"SELECT nick, vhostreq FROM anope_unreal_addon " "WHERE vhostreqstatus = '1' " "AND vhostreq IS NOT NULL;"); do_query(query); res = mysql_store_result(mysql); if (mysql_num_rows(res) > 0) { while ((row = mysql_fetch_row(res)) != NULL) { if (findnick(row[0])) { /* send notice if nick is online */ notice(s_NickServ, row[0], VHOST_NOTICE_NEW_VHOST); qbuf1 = quote(row[1]); qbuf2 = quote(u->na->nc->display); qbuf3 = quote(row[0]); snprintf(query,MAX_SQL_BUF,"UPDATE anope_unreal_addon " "SET vhost='%s', vhoststatus='1', " "vhostreq = NULL, vhostreqstatus = '0', " "v_setter = '%s' " "WHERE nick= '%s';", qbuf1, qbuf2, qbuf3); free(qbuf1); free(qbuf2); free(qbuf3); do_query(query); } else { /* update and send notice on next identify */ qbuf1 = quote(row[1]); qbuf2 = quote(u->na->nc->display); qbuf3 = quote(row[0]); snprintf(query,MAX_SQL_BUF,"UPDATE anope_unreal_addon " "SET vhost='%s', vhoststatus='1', " "vhostreq = NULL, vhostreqstatus = '2', " "v_setter = '%s' " "WHERE nick ='%s';", qbuf1, qbuf2, qbuf3); free(qbuf1); free(qbuf2); free(qbuf3); do_query(query); } } notice_user(s_OperServ, u, "All vHosts accepted"); } else { notice_user(s_OperServ, u, NOTICE_EMPTY_LIST); } mysql_free_result(res); /* free unused memory */ goto MODSTOP; } if (stricmp(option1, "ACK")==0) { if (!option2) { notice_user(s_OperServ, u, VHOST_OS_SYNTAX); notice_user(s_OperServ, u, VHOST_OS_SYNTAX2); goto MODSTOP; } target = findnick(option2); if (!target) { notice_user(s_OperServ, u, NOTICE_NO_REGISTERED_NICK, option2); goto MODSTOP; } get_from_db(option2, "vhostreqstatus"); if (!(stricmp(myresult,"1")==0)) { notice_user(s_OperServ, u, VHOST_OS_PEN_NOTICE_NOT_IN_LIST, option2); goto MODSTOP; } get_from_db(option2, "vhostreq"); qbuf3 = quote(myresult); add_to_db(target, "vhost", qbuf3); free(qbuf3); add_to_db(target, "vhoststatus", "1"); add_to_db(target, "vhostreq", ""); add_to_db(target, "v_setter", u->na->nc->display); if (findnick(option2)) { /* send notice if nick is online */ notice(s_NickServ, option2, VHOST_NOTICE_ACCEPT); add_to_db(target, "vhostreqstatus", "0"); } else { /* send notice von next identify */ add_to_db(target, "vhostreqstatus", "2"); } notice_user(s_OperServ, u, "The vhost for user %s has been acknowledged", option2); goto MODSTOP; } if (stricmp(option1, "DEL")==0) { if (!option2) { notice_user(s_OperServ, u, VHOST_OS_SYNTAX); notice_user(s_OperServ, u, VHOST_OS_SYNTAX2); goto MODSTOP; } target = findnick(option2); if (!target) { notice_user(s_OperServ, u, NOTICE_NO_REGISTERED_NICK, option1); goto MODSTOP; } get_from_db(option2, "vhostreqstatus"); if (!myresult || !(stricmp(myresult,"1")==0)) { notice_user(s_OperServ, u, VHOST_OS_PEN_NOTICE_NOT_IN_LIST, option2); goto MODSTOP; } add_to_db(target, "vhostreq", ""); if (findnick(option2)) { /* send notice if nick is online */ notice(s_NickServ, option2, VHOST_NOTICE_REJECT); add_to_db(target, "vhostreqstatus", "0"); } else { /* send notice von next identify */ add_to_db(target, "vhostreqstatus", "3"); } notice_user(s_OperServ, u, "The vhost request for user %s has been rejected.", option2); goto MODSTOP; } } notice_user(s_OperServ, u, VHOST_OS_SYNTAX); notice_user(s_OperServ, u, VHOST_OS_SYNTAX2); MODSTOP: free(query); if (cmd) free(cmd); if (option1) free(option1); if (option2) free(option2); return MOD_STOP; } /* end of vhost */ /****************************************************************************************************/ /* swhois */ int os_swhois(User *u) { char *temp = moduleGetLastBuffer(); char *cmd = myStrGetToken(temp,' ',0); char *option1 = myStrGetToken(temp,' ',1); char *option2 = myStrGetTokenRemainder(temp,' ',2); char *query = malloc(MAX_SQL_BUF); NickAlias *target; int i = 1; if (!cmd) { notice_user(s_OperServ, u, SWHOIS_SYNTAX); notice_user(s_OperServ, u, SWHOIS_SYNTAX2); goto MODSTOP; } if (stricmp(cmd, "ADD")==0) { if (!option1 || !option2) { notice_user(s_OperServ, u, SWHOIS_SYNTAX); notice_user(s_OperServ, u, SWHOIS_SYNTAX2); goto MODSTOP; } target = findnick(option1); if (!target) { notice_user(s_OperServ, u, NOTICE_NO_REGISTERED_NICK, option1); goto MODSTOP; } if (strlen(option2) > 280) { notice_user(s_OperServ, u, SWHOIS_NOTICE_TOO_LONG); goto MODSTOP; } add_to_db(target, "swhois", option2); add_to_db(target, "s_setter", u->na->nc->display); /* stores the nickgroup of the user, who added or modified the entry */ notice_user(s_OperServ, u, SWHOIS_NOTICE_ADDED_TO_LIST, option1); send_cmd(s_NickServ, "SWHOIS %s :%s",option1, option2); goto MODSTOP; } if (stricmp(cmd, "DEL")==0) { if (!option1) { notice_user(s_OperServ, u, SWHOIS_SYNTAX); notice_user(s_OperServ, u, SWHOIS_SYNTAX2); goto MODSTOP; } target = findnick(option1); if (!target) { notice_user(s_OperServ, u, NOTICE_NO_REGISTERED_NICK, option1); goto MODSTOP; } get_from_db(target->nick, "swhois"); if (!myresult || stricmp(myresult, "")==0) { notice_user(s_OperServ, u, SWHOIS_NOTICE_NOT_IN_LIST, option1); goto MODSTOP; } add_to_db(target, "swhois", ""); add_to_db(target, "s_setter", u->na->nc->display); /* stores the nickgroup of the user, who deleted the entry */ notice_user(s_OperServ, u, SWHOIS_NOTICE_REMOVED_FROM_LIST, option1); send_cmd(s_NickServ, "SWHOIS %s :", option1); goto MODSTOP; } if (stricmp(cmd, "LIST")==0) { if (option1) { snprintf(query,MAX_SQL_BUF, "SELECT nick, swhois, s_setter FROM anope_unreal_addon " "WHERE swhois IS NOT NULL " "AND ( nick LIKE '%%%s%%' OR swhois LIKE '%%%s%%' OR s_setter LIKE '%%%s%%') " "ORDER by nick;",option1, option1, option1); } else { snprintf(query,MAX_SQL_BUF, "SELECT nick, swhois, s_setter FROM anope_unreal_addon " "WHERE swhois IS NOT NULL ORDER by nick;"); } do_query(query); res = mysql_store_result(mysql); if (mysql_num_rows(res) > 0) { while ((row = mysql_fetch_row(res)) != NULL) { notice_user(s_OperServ, u,"#%2i Nick: \002%-16s\002 swhois: \002%-35s\002 (%s)",i, row[0] ? row[0] : "NULL" ,row[1] ? row[1] : "NULL" ,row[2] ? row[2] :"NULL" ); i++; } mysql_free_result(res); goto MODSTOP; } notice_user(s_OperServ, u, NOTICE_EMPTY_LIST); mysql_free_result(res); /* free unused memory */ goto MODSTOP; } notice_user(s_OperServ, u, SWHOIS_SYNTAX); notice_user(s_OperServ, u, SWHOIS_SYNTAX2); MODSTOP: free(query); if (cmd) free(cmd); if (option1) free(option1); if (option2) free(option2); return MOD_STOP; } /* end of swhois */ /***************************************************************************************************/ /* helpop */ int os_helpop(User *u) { char *temp = moduleGetLastBuffer(); char *cmd = myStrGetToken(temp,' ',0); char *option1 = myStrGetToken(temp,' ',1); char *option2 = myStrGetTokenRemainder(temp,' ',2); char *query = malloc(MAX_SQL_BUF); NickAlias *target; int i = 1; if (!cmd) { notice_user(s_OperServ, u, HELPOP_SYNTAX); notice_user(s_OperServ, u, HELPOP_SYNTAX2); goto MODSTOP; } if (stricmp(cmd, "ADD")==0) { if (!option1 || !option2) { notice_user(s_OperServ, u, HELPOP_SYNTAX); notice_user(s_OperServ, u, HELPOP_SYNTAX2); goto MODSTOP; } target = findnick(option1); if (!target) { notice_user(s_OperServ, u, NOTICE_NO_REGISTERED_NICK, option1); goto MODSTOP; } if (strlen(option2) > 32) { notice_user(s_OperServ, u, HELPOP_NOTICE_TOO_LONG); goto MODSTOP; } /* perhaps there should be only one command to make mysql access faster */ add_to_db(target, "helpop", option2); add_to_db(target, "h_setter", u->na->nc->display); /* stores the nickgroup of the user, who added or modified the entry */ notice_user(s_OperServ, u, HELPOP_NOTICE_ADDED_TO_LIST, option1); send_cmd(s_NickServ, "SVS2MODE %s :%s",option1, option2); /* helpop modes are set from nickserv and not from operserv */ goto MODSTOP; } if (stricmp(cmd, "DEL")==0) { if (!option1) { notice_user(s_OperServ, u, HELPOP_SYNTAX); notice_user(s_OperServ, u, HELPOP_SYNTAX2); goto MODSTOP; } target = findnick(option1); if (!target) { notice_user(s_OperServ, u, NOTICE_NO_REGISTERED_NICK, option1); goto MODSTOP; } get_from_db(target->nick, "helpop"); if (!myresult || stricmp(myresult, "")==0) { notice_user(s_OperServ, u, HELPOP_NOTICE_NOT_IN_LIST, option1); goto MODSTOP; } add_to_db(target, "helpop", ""); add_to_db(target, "h_setter", u->na->nc->display); /* stores the nickgroup of the user, who deleted the entry */ notice_user(s_OperServ, u, HELPOP_NOTICE_REMOVED_FROM_LIST, option1); goto MODSTOP; } if (stricmp(cmd, "LIST")==0) { if (option1) { snprintf(query,MAX_SQL_BUF, "SELECT nick,helpop,h_setter FROM anope_unreal_addon " "WHERE helpop IS NOT NULL " "AND ( nick LIKE '%%%s%%' OR helpop LIKE '%%%s%%' OR h_setter LIKE '%%%s%%') " "ORDER by nick;", option1, option1, option1); } else { snprintf(query,MAX_SQL_BUF, "SELECT nick,helpop,h_setter FROM anope_unreal_addon " "WHERE helpop IS NOT NULL ORDER by nick;"); } do_query(query); res = mysql_store_result(mysql); if (mysql_num_rows(res) > 0) { while ((row = mysql_fetch_row(res)) != NULL) { notice_user(s_OperServ, u,"#%2i Nick: \002%-16s\002 modes: \002%-10s\002 (%s)",i, row[0] ? row[0] : "NULL" ,row[1] ? row[1] : "NULL" ,row[2] ? row[2] :"NULL" ); i++; } mysql_free_result(res); goto MODSTOP; } notice_user(s_OperServ, u, NOTICE_EMPTY_LIST); mysql_free_result(res); /* free unused memory */ goto MODSTOP; } notice_user(s_OperServ, u, HELPOP_SYNTAX); notice_user(s_OperServ, u, HELPOP_SYNTAX2); MODSTOP: if (query) free(query); if (cmd) free(cmd); if (option1) free(option1); if (option2) free(option2); return MOD_STOP; } /* end of helpop */ /***************************************************************************************************/ /* snomask */ int os_snomask(User *u) { char *temp = moduleGetLastBuffer(); char *cmd = myStrGetToken(temp,' ',0); char *option1 = myStrGetToken(temp,' ',1); char *option2 = myStrGetTokenRemainder(temp,' ',2); char *query = malloc(MAX_SQL_BUF); NickAlias *target; int i = 1; if (!cmd) { notice_user(s_OperServ, u, SNOMASK_SYNTAX); notice_user(s_OperServ, u, SNOMASK_SYNTAX2); goto MODSTOP; } if (stricmp(cmd, "ADD")==0) { if (!option1 || !option2) { notice_user(s_OperServ, u, SNOMASK_SYNTAX); notice_user(s_OperServ, u, SNOMASK_SYNTAX2); goto MODSTOP; } target = findnick(option1); if (!target) { notice_user(s_OperServ, u, NOTICE_NO_REGISTERED_NICK, option1); goto MODSTOP; } if (strlen(option2) > 32) { notice_user(s_OperServ, u, SNOMASK_NOTICE_TOO_LONG); goto MODSTOP; } add_to_db(target, "snomasks", option2); add_to_db(target, "m_setter", u->na->nc->display); /* stores the nickgroup of the user, who added or modified the entry */ notice_user(s_OperServ, u, SNOMASK_NOTICE_ADDED_TO_LIST, option1); send_cmd(s_NickServ, "SVSSNO %s :%s",option1, option2); /* nickserv is right */ goto MODSTOP; } if (stricmp(cmd, "DEL")==0) { if (!option1) { notice_user(s_OperServ, u, SNOMASK_SYNTAX); notice_user(s_OperServ, u, SNOMASK_SYNTAX2); goto MODSTOP; } target = findnick(option1); if (!target) { notice_user(s_OperServ, u, NOTICE_NO_REGISTERED_NICK, option1); goto MODSTOP; } get_from_db(target->nick, "snomasks"); if (!myresult || stricmp(myresult, "")==0) { notice_user(s_OperServ, u, SNOMASK_NOTICE_NOT_IN_LIST, option1); goto MODSTOP; } add_to_db(target, "snomasks", ""); add_to_db(target, "m_setter", u->na->nc->display); /* stores the nickgroup of the user, who deleted the entry */ notice_user(s_OperServ, u, SNOMASK_NOTICE_REMOVED_FROM_LIST, option1); goto MODSTOP; } if (stricmp(cmd, "LIST")==0) { if (option1) { snprintf(query,MAX_SQL_BUF, "SELECT nick,snomasks,m_setter FROM anope_unreal_addon " "WHERE snomasks IS NOT NULL " "AND (nick LIKE '%%%s%%' OR snomasks LIKE '%%%s%%' OR m_setter LIKE '%%%s%%') " "ORDER by nick;",option1, option1, option1); } else { snprintf(query,MAX_SQL_BUF, "SELECT nick,snomasks,m_setter FROM anope_unreal_addon " "WHERE snomasks IS NOT NULL ORDER by nick;"); } do_query(query); res = mysql_store_result(mysql); if (mysql_num_rows(res) > 0) { while ((row = mysql_fetch_row(res)) != NULL) { notice_user(s_OperServ, u,"#%2i Nick: \002%-16s\002 snomask: \002%-10s\002 (%s)",i, row[0] ? row[0] : "NULL" ,row[1] ? row[1] : "NULL" ,row[2] ? row[2] :"NULL" ); i++; } mysql_free_result(res); goto MODSTOP; } notice_user(s_OperServ, u, NOTICE_EMPTY_LIST); mysql_free_result(res); /* free unused memory */ goto MODSTOP; } notice_user(s_OperServ, u, SNOMASK_SYNTAX); notice_user(s_OperServ, u, SNOMASK_SYNTAX2); MODSTOP: if (cmd) free(cmd); if (option1) free(option1); if (option2) free(option2); return MOD_STOP; } /* end of snomask */ /***************************************************************************************************/ /* /nickserv set ... */ int ns_set(User *u) { char *temp = moduleGetLastBuffer(); char *cmd = myStrGetToken(temp,' ',0); char *option1 = myStrGetToken(temp,' ',1); if (!cmd) { goto MODCONT; } if (!nick_identified(u)) { notice_lang(s_NickServ, u, NICK_IDENTIFY_REQUIRED, s_NickServ); goto MODSTOP; } if (stricmp(cmd, "alogin")==0) { if (option1) { if (stricmp(option1,"on")==0) { get_from_db(u->nick, "alogin"); if (stricmp(myresult,"1")==0) { notice_user(s_NickServ, u, ALOGIN_NOTICE_IS_ON); goto MODSTOP; } add_to_db(u->na, "alogin", "1"); notice_user(s_NickServ, u, ALOGIN_NOTICE_IS_NOW_ON); goto MODSTOP; } if (stricmp(option1,"off")==0) { get_from_db(u->nick, "alogin"); if (stricmp(myresult,"0")==0) { notice_user(s_NickServ, u, ALOGIN_NOTICE_IS_OFF); goto MODSTOP; } add_to_db(u->na, "alogin", "0"); notice_user(s_NickServ, u, ALOGIN_NOTICE_IS_NOW_OFF); goto MODSTOP; } if (stricmp(option1,"silent")==0) { get_from_db(u->nick, "alogin"); if (stricmp(myresult,"2")==0) { notice_user(s_NickServ, u, ALOGIN_NOTICE_IS_SIL); goto MODSTOP; } add_to_db(u->na, "alogin", "2"); notice_user(s_NickServ, u, ALOGIN_NOTICE_IS_NOW_SIL); goto MODSTOP; } } notice_user(s_NickServ, u, ALOGIN_SYNTAX); notice_user(s_NickServ, u, ALOGIN_SYNTAX2); goto MODSTOP; } #ifdef USE_AJOIN if (svsjoin) { if (stricmp(cmd, "ajoin")==0) { if (!option1) { notice_user(s_NickServ, u, AJOIN_SYNTAX); notice_user(s_NickServ, u, AJOIN_SYNTAX2); goto MODSTOP; } if (stricmp(option1, "list")==0) { get_from_db(u->nick,"ajoin"); if (myresult) { notice_user(s_NickServ, u, AJOIN_NOTICE_AJOINLIST, myresult); /* your ajoin chans are ... */ } else { notice_user(s_NickServ, u, AJOIN_NOTICE_EMPTY_LIST); /* you have no ajoin chans set */ } goto MODSTOP; } if (stricmp(option1, "off")==0) { add_to_db(u->na, "ajoin", ""); notice_user(s_NickServ, u, AJOIN_NOTICE_EMPTY_LIST2); /* your ajoin list is now empty */ goto MODSTOP; } if (option1) free(option1); option1 = myStrGetTokenRemainder(temp,' ',1); /* get full line including the channel passwords */ if (strlen(option1) > 511) { notice_user(s_NickServ, u, AJOIN_NOTICE_MAX_AJOIN); /* ajoin list too long */ goto MODSTOP; } add_to_db(u->na, "ajoin", option1); notice_user(s_NickServ, u, AJOIN_NOTICE_AJOINLIST_NEW, option1); /* your ajoin chans are now: ... */ goto MODSTOP; } } #endif #ifdef USE_REALNAME if (ircd->chgreal) { if (stricmp(cmd, "realname")==0) { if (option1) { free(option1); option1 = myStrGetTokenRemainder(temp,' ',1); add_to_db(u->na, "realname", option1); send_cmd(s_NickServ, "CHGNAME %s %s", u->nick, option1); change_user_realname(u, option1); /* update internal struct */ notice_user(s_NickServ, u, REALNAME_NOTICE_NEW, option1); goto MODSTOP; } notice_user(s_NickServ, u, REALNAME_SYNTAX); notice_user(s_NickServ, u, REALNAME_SYNTAX2); goto MODSTOP; } } #endif #ifdef USE_VHOSTREQ if (ircd->vhost) { if (stricmp(cmd, "vhost") == 0) { if (!option1) { notice_user(s_NickServ, u, VHOST_NS_SYNTAX); notice_user(s_NickServ, u, VHOST_NS_SYNTAX2); goto MODSTOP; } if (stricmp(option1,"on")==0) { get_from_db(u->nick, "vhost"); if (!myresult || (strlen(myresult) < 2)) { notice_user(s_NickServ, u, VHOST_NOTICE_NO_VHOST); goto MODSTOP; } get_from_db(u->nick, "vhoststatus"); if (stricmp(myresult,"1")==0) { notice_user(s_NickServ, u, VHOST_NOTICE_IS_ON); goto MODSTOP; } add_to_db(u->na, "vhoststatus", "1"); notice_user(s_NickServ, u, VHOST_NOTICE_IS_NOW_ON); goto MODSTOP; } if (stricmp(option1,"off")==0) { get_from_db(u->nick, "vhost"); if (!myresult || (strlen(myresult) < 2)) { notice_user(s_NickServ, u, VHOST_NOTICE_NO_VHOST); goto MODSTOP; } get_from_db(u->nick, "vhoststatus"); if (stricmp(myresult,"0")==0) { notice_user(s_NickServ, u, VHOST_NOTICE_IS_OFF); goto MODSTOP; } add_to_db(u->na, "vhoststatus", "0"); notice_user(s_NickServ, u, VHOST_NOTICE_IS_NOW_OFF); goto MODSTOP; } /* grouping */ if (stricmp(option1,"group")==0) { get_from_db(u->na->nc->display, "vhost"); if (!myresult) { notice_user(s_NickServ, u, "No vHost to set"); goto MODSTOP; } if (strlen(myresult) < 3) { notice_user(s_NickServ, u, "No vHost to set"); goto MODSTOP; } notice_user(s_NickServ, u, "Adding vHost \002%s\002 to your nick", myresult ); qbuf3 = quote(myresult); add_to_db(u->na, "vhost", qbuf3); free(qbuf3); add_to_db(u->na, "vhoststatus", "0"); add_to_db(u->na, "vhostreqstatus", "0"); add_to_db(u->na, "v_setter", "NS GROUP"); goto MODSTOP; } if (!is_valid_vhost(u, option1)) { goto MODSTOP; } add_to_db(u->na, "vhostreqstatus", "1"); add_to_db(u->na, "vhostreq", option1); notice_user(s_NickServ, u, VHOST_NOTICE_REQUEST1); notice_user(s_NickServ, u, VHOST_NOTICE_REQUEST2); notice_user(s_NickServ, u, VHOST_NOTICE_REQUEST3); send_cmd(s_NickServ, "GLOBOPS \2%s\2 has requested a new vhost (\2%s\2). Do \2/operserv vhost pending list\2 to view the pending vhosts\002", u->nick, option1); goto MODSTOP; } } #endif goto MODCONT; MODSTOP: if (cmd) free(cmd); if (option1) free(option1); return MOD_STOP; MODCONT: if (cmd) free(cmd); if (option1) free(option1); return MOD_CONT; } /* end of nickserv set */ /****************************************************************************************************/ /* identify */ int do_on_identify(User *u) { char *temp = moduleGetLastBuffer(); char *buf; char *query = malloc(MAX_SQL_BUF); int alogin_ = 0; int silent_ = 0; int nologin_ = 0; int novhost_ = 0; int nojoin_ = 0; int noswhois_ = 0; int nohelpop_ = 0; int nosnomask_ = 0; int norealname_ = 0; /* stop if nick is not identified */ if (!nick_identified(u)) { return MOD_CONT; } /* get options from commandline */ if (temp) { /* temp can be NULL if triggered by "/ns update" */ if (stristr(temp,"nologin")) { nologin_ = 1; } if (stristr(temp,"novhost")) { novhost_ = 1; } if (stristr(temp,"nojoin")) { nojoin_ = 1; } if (stristr(temp,"noswhois")) { noswhois_ = 1; } if (stristr(temp,"nohelpop")) { nohelpop_ = 1; } if (stristr(temp,"nosnomask")) { nosnomask_ = 1; } if (stristr(temp,"norealname")){ norealname_ = 1; } } /* 0 1 2 3 4 5 6 7 8 */ qbuf1 = quote(u->nick); snprintf(query,MAX_SQL_BUF, "SELECT alogin, vhoststatus, vhost, ajoin, swhois, helpop, snomasks, realname, vhostreqstatus " "FROM anope_unreal_addon WHERE nick = '%s';", qbuf1); free(qbuf1); do_query(query); res = mysql_store_result(mysql); if (mysql_num_rows(res) > 0) { row=mysql_fetch_row(res); if (!row[0]) { send_cmd(s_NickServ, "GLOBOPS ERROR! unreal_addon: field \"alogin\" for user \"%s\" contains an invalid value! (NULL)", u->nick); return MOD_STOP; } if (stricmp(row[0],"1")==0) { alogin_ = 1; } if (stricmp(row[0],"2")==0) { alogin_ = 1; silent_ = 1; } if ((alogin_ || silent_) && !nologin_) { /* alogin on ? */ #ifdef USE_VHOSTREQ if (ircd->vhost) if (stricmp(row[1],"1")==0) { if (!novhost_) { if (!silent_) { notice_user(s_NickServ, u, VHOST_NOTICE_VHOST); } set_vhost(u, row[2]); } } } #endif #ifdef USE_SWHOIS if (swhois) { if (row[4] && strlen(row[4]) > 0) { /* swhois */ if (!noswhois_) { if (!silent_) { notice_user(s_NickServ, u, SWHOIS_NOTICE_SWHOIS); } send_cmd(s_NickServ, "SWHOIS %s :%s",u->nick, row[4]); } } } #endif #ifdef USE_HELPOP if (svsmode) { if (row[5] && strlen(row[5]) > 0) { /* user modes */ if (!nohelpop_) { if (!silent_) { notice_user(s_NickServ, u, HELPOP_NOTICE_HELPOP); } send_cmd(s_NickServ, "SVS2MODE %s %s", u->nick, row[5]); } } } #endif #ifdef USE_SNOMASK if (snomask) { if (row[6] && strlen(row[6]) > 0) { /* snomask */ if (!nosnomask_) { if (!silent_) { notice_user(s_NickServ, u, "Setting your snomask..."); } send_cmd(s_NickServ, "SVSSNO %s %s", u->nick, row[6]); } } } #endif #ifdef USE_REALNAME if (ircd->chgreal) { if (row[7] && strlen(row[7]) > 0) { /* realname */ if (!norealname_) { if (!silent_) { notice_user(s_NickServ, u, REALNAME_NOTICE_SET, row[7]); } send_cmd(s_NickServ, "CHGNAME %s %s", u->nick, row[7]); change_user_realname(u, row[7]); /* update internal struct */ } } } #endif #ifdef USE_AJOIN if (svsjoin) { if (row[3] && strlen(row[3]) > 0) { /* ajoin */ if (!nojoin_) { if (!silent_) { notice_user(s_NickServ, u, AJOIN_NOTICE_AJOIN, row[3]); } send_cmd(s_NickServ, "SVSJOIN %s %s", u->nick, row[3]); } } } #endif #ifdef USE_VHOSTREQ if (ircd->vhost) { if (row[8] && strlen(row[8]) > 0) { /* information notice about vhost requesting */ buf = sstrdup(row[8]); if (stricmp(buf,"2")==0) { notice_user(s_NickServ, u, VHOST_NOTICE_ACCEPT); add_to_db(u->na, "vhostreqstatus", "0"); } if (stricmp(buf,"3")==0) { notice_user(s_NickServ, u, VHOST_NOTICE_REJECT); add_to_db(u->na, "vhostreqstatus", "0"); } if (stricmp(buf,"4")==0) { notice_user(s_NickServ, u, VHOST_NOTICE_NEW_VHOST); add_to_db(u->na, "vhostreqstatus", "0"); } if (stricmp(buf,"5")==0) { notice_user(s_NickServ, u, VHOST_NOTICE_DEL_VHOST); add_to_db(u->na, "vhostreqstatus", "0"); } free(buf); } } #endif } mysql_free_result(res); /* release unused memory */ free(query); return MOD_CONT; } /* end of identify */ /*****************************************************************************************************/ /* nickserv info */ /* I copied the whole do_info() from nickserv.c and did some modifications */ int do_info2(User * u) { char *nick = strtok(NULL, " "); char *param = strtok(NULL, " "); NickAlias *na; NickRequest *nr = NULL; int is_servadmin = is_services_admin(u); char *vHost; if (!nick) { syntax_error(s_NickServ, u, "INFO", NICK_INFO_SYNTAX); } else if (!(na = findnick(nick))) { if ((nr = findrequestnick(nick))) { notice_lang(s_NickServ, u, NICK_IS_PREREG); if (param && stricmp(param, "ALL") == 0 && is_servadmin) { notice_lang(s_NickServ, u, NICK_INFO_EMAIL, nr->email); } else { if (is_servadmin) { notice_lang(s_NickServ, u, NICK_INFO_FOR_MORE, s_NickServ, nr->nick); } } } else { notice_lang(s_NickServ, u, NICK_X_NOT_REGISTERED, nick); } } else if (na->status & NS_VERBOTEN) { if (is_oper(u) && na->last_usermask) notice_lang(s_NickServ, u, NICK_X_FORBIDDEN_OPER, nick, na->last_usermask, (na->last_realname ? na->last_realname : getstring(u->na, NO_REASON))); else notice_lang(s_NickServ, u, NICK_X_FORBIDDEN, nick); } else { struct tm *tm; char buf[BUFSIZE], *end, *query; const char *commastr = getstring(u->na, COMMA_SPACE); int need_comma = 0; int nick_online = 0; int show_hidden = 0; if (na->status & (NS_RECOGNIZED | NS_IDENTIFIED)) { nick_online = 1; } if (param && stricmp(param, "ALL") == 0 && u->na && ((nick_identified(u) && (na->nc == u->na->nc)) || is_servadmin)) { show_hidden = 1; } notice_lang(s_NickServ, u, NICK_INFO_REALNAME, na->nick, na->last_realname); if ((nick_identified(u) && (na->nc == u->na->nc)) || is_servadmin) { if (nick_is_services_root(na->nc)) { notice_lang(s_NickServ, u, NICK_INFO_SERVICES_ROOT, na->nick); } else if (nick_is_services_admin(na->nc)) { notice_lang(s_NickServ, u, NICK_INFO_SERVICES_ADMIN, na->nick); } else if (nick_is_services_oper(na->nc)) { notice_lang(s_NickServ, u, NICK_INFO_SERVICES_OPER, na->nick); } } else { if (nick_is_services_root(na->nc) && !(na->nc->flags & NI_HIDE_STATUS)) { notice_lang(s_NickServ, u, NICK_INFO_SERVICES_ROOT, na->nick); } else if (nick_is_services_admin(na->nc) && !(na->nc->flags & NI_HIDE_STATUS)) { notice_lang(s_NickServ, u, NICK_INFO_SERVICES_ADMIN, na->nick); } else if (nick_is_services_oper(na->nc) && !(na->nc->flags & NI_HIDE_STATUS)) { notice_lang(s_NickServ, u, NICK_INFO_SERVICES_OPER, na->nick); } } if (nick_online) { if (show_hidden || !(na->nc->flags & NI_HIDE_MASK)) { notice_lang(s_NickServ, u, NICK_INFO_ADDRESS_ONLINE, na->last_usermask); } else { notice_lang(s_NickServ, u, NICK_INFO_ADDRESS_ONLINE_NOHOST, na->nick); } } else { if (show_hidden || !(na->nc->flags & NI_HIDE_MASK)) { notice_lang(s_NickServ, u, NICK_INFO_ADDRESS, na->last_usermask); } } tm = localtime(&na->time_registered); strftime_lang(buf, sizeof(buf), u, STRFTIME_DATE_TIME_FORMAT, tm); notice_lang(s_NickServ, u, NICK_INFO_TIME_REGGED, buf); if (!nick_online) { tm = localtime(&na->last_seen); strftime_lang(buf, sizeof(buf), u, STRFTIME_DATE_TIME_FORMAT, tm); notice_lang(s_NickServ, u, NICK_INFO_LAST_SEEN, buf); } if (na->last_quit && (show_hidden || !(na->nc->flags & NI_HIDE_QUIT))) { notice_lang(s_NickServ, u, NICK_INFO_LAST_QUIT, na->last_quit); } if (na->nc->url) { notice_lang(s_NickServ, u, NICK_INFO_URL, na->nc->url); } if (na->nc->email && (show_hidden || !(na->nc->flags & NI_HIDE_EMAIL))) { notice_lang(s_NickServ, u, NICK_INFO_EMAIL, na->nc->email); } if (na->nc->icq) { notice_lang(s_NickServ, u, NICK_INFO_ICQ, na->nc->icq); } if (show_hidden) { if (s_HostServ) { if (getvHost(na->nick) != NULL) { vHost = smalloc(strlen(getvHost(na->nick)) + 2); bzero(vHost, sizeof(vHost)); snprintf(vHost, strlen(getvHost(na->nick)) + 2, "%s", getvHost(na->nick)); notice_lang(s_NickServ, u, NICK_INFO_VHOST, vHost); free(vHost); } } /* [unreal_addon] */ /* 0 1 2 3 4 5 */ qbuf1 = quote(nick); query = malloc(MAX_SQL_BUF); snprintf(query,MAX_SQL_BUF, "SELECT vhost, ajoin, swhois, helpop, snomasks, realname " "FROM `anope_unreal_addon` WHERE `nick` = '%s';", qbuf1); free(qbuf1); do_query(query); res = mysql_store_result(mysql); if (mysql_num_rows(res) > 0) { row=mysql_fetch_row(res); #ifdef USE_VHOSTREQ if (row[0] && strlen(row[0]) > 0) { notice_user(s_NickServ, u," vhost: %s", row[0]); } #endif #ifdef USE_AJOIN if (row[1] && strlen(row[1]) > 0) { notice_user(s_NickServ, u," ajoin chans: %s", row[1]); } #endif #ifdef USE_SWHOIS if (row[2] && strlen(row[2]) > 0) { notice_user(s_NickServ, u," swhois: %s", row[2]); } #endif #ifdef USE_HELPOP if (row[3] && strlen(row[3]) > 0) { notice_user(s_NickServ, u," helpop modes: %s", row[3]); } #endif #ifdef USE_SNOMASK if (row[4] && strlen(row[4]) > 0) { notice_user(s_NickServ, u," snomask: %s", row[4]); } #endif } free(query); mysql_free_result(res); /* free unused memory */ /* [/unreal_addon] */ if (na->nc->greet) { notice_lang(s_NickServ, u, NICK_INFO_GREET, na->nc->greet); } *buf = 0; end = buf; if (na->nc->flags & NI_KILLPROTECT) { end += snprintf(end, sizeof(buf) - (end - buf), "%s", getstring(u->na, NICK_INFO_OPT_KILL)); need_comma = 1; } if (na->nc->flags & NI_SECURE) { end += snprintf(end, sizeof(buf) - (end - buf), "%s%s", need_comma ? commastr : "", getstring(u->na, NICK_INFO_OPT_SECURE)); need_comma = 1; } if (na->nc->flags & NI_PRIVATE) { end += snprintf(end, sizeof(buf) - (end - buf), "%s%s", need_comma ? commastr : "", getstring(u->na, NICK_INFO_OPT_PRIVATE)); need_comma = 1; } if (na->nc->flags & NI_MSG) { end += snprintf(end, sizeof(buf) - (end - buf), "%s%s", need_comma ? commastr : "", getstring(u->na, NICK_INFO_OPT_MSG)); need_comma = 1; } notice_lang(s_NickServ, u, NICK_INFO_OPTIONS, *buf ? buf : getstring(u->na, NICK_INFO_OPT_NONE)); if (na->status & NS_NO_EXPIRE) notice_lang(s_NickServ, u, NICK_INFO_NO_EXPIRE); } if (!show_hidden && ((u->na && (na->nc == u->na->nc) && nick_identified(u)) || is_servadmin)) { notice_lang(s_NickServ, u, NICK_INFO_FOR_MORE, s_NickServ,na->nick); } } return MOD_STOP; } /* end of nickserv info */ /***************************************************************************************************/ int my_isvalidchar(const char c) { if(isalnum(c)||(c=='.')||(c=='-')){return 1;}else{return 0;} } /***************************************************************************************************/ int set_vhost(User *u, char *vhoststring) { char *vIdent = NULL; char *hostmask = NULL; if (strchr(vhoststring,'@')) { vIdent = myStrGetOnlyToken(vhoststring,'@',0); if (vIdent) { if(strlen(vIdent) > 0) { /* send_cmd(s_NickServ, "CHGIDENT %s %s", u->nick, vIdent); */ if (u->vident) free(u->vident); u->vident = sstrdup(vIdent); } } hostmask = myStrGetTokenRemainder(vhoststring,'@',1); if (hostmask) { /* send_cmd(s_NickServ, "CHGHOST %s %s", u->nick, hostmask); */ if (u->vhost) free(u->vhost); u->vhost = sstrdup(hostmask); } } else { /* send_cmd(s_NickServ, "CHGHOST %s %s", u->nick, vhoststring); */ if (u->vhost) free(u->vhost); u->vhost = sstrdup(vhoststring); } anope_cmd_vhost_on(u->nick, u->vident, u->vhost); if (vIdent) free(vIdent); if (hostmask) free(hostmask); return MOD_CONT; } /****************************************************************************************************/ int is_valid_vhost(User *u, char *rawhostmask) { char *vIdent = NULL; char *s; char *hostmask = malloc(HOSTMAX); vIdent = myStrGetOnlyToken(rawhostmask,'@',0); if (vIdent) { rawhostmask = myStrGetTokenRemainder(rawhostmask,'@',1); if (!rawhostmask) { notice_user(s_NickServ, u, VHOST_NS_SYNTAX); notice_user(s_NickServ, u, VHOST_NS_SYNTAX2); goto is_false; } if (strlen(vIdent) > USERMAX - 1) { notice_lang(s_NickServ, u, HOST_SET_IDENTTOOLONG, USERMAX); goto is_false; } else { for (s = vIdent; *s; s++) { if (!my_isvalidchar(*s)) { notice_lang(s_HostServ, u, HOST_SET_IDENT_ERROR); goto is_false; } } } } if (strlen(rawhostmask) < HOSTMAX - 1) { snprintf(hostmask, HOSTMAX - 1, "%s", rawhostmask); } else { notice_lang(s_HostServ, u, HOST_SET_TOOLONG, HOSTMAX); goto is_false; } if (!isValidHost(hostmask, 3)) { notice_lang(s_HostServ, u, HOST_SET_ERROR); goto is_false; } goto is_true; is_false: if (vIdent) free(vIdent); if (hostmask) free(hostmask); return 0; is_true: if (vIdent) free(vIdent); if (hostmask) free(hostmask); return 1; } /****************************************************************************************************/ /* MySQL Input/Output functions */ /****************************************************************************************************/ void get_from_db(char *nick, char *type) { char *query = malloc(MAX_SQL_BUF); qbuf1 = quote(nick); snprintf(query,MAX_SQL_BUF,"SELECT %s FROM anope_unreal_addon WHERE nick = '%s';", type, qbuf1); free(qbuf1); do_query(query); res = mysql_store_result(mysql); if (mysql_num_rows(res) > 0) { row=mysql_fetch_row(res); myresult = row[0]; } else { myresult = ""; } free(query); mysql_free_result(res); } /****************************************************************************************************/ void add_to_db(NickAlias *na, char *type, char *arg) { char *query = malloc(MAX_SQL_BUF); qbuf1 = quote(na->nick); snprintf(query,MAX_SQL_BUF,"SELECT nick FROM anope_unreal_addon WHERE nick = '%s';", qbuf1); free(qbuf1); do_query(query); res = mysql_store_result(mysql); if (mysql_num_rows(res) > 0) { /* exists this nick already in the database? */ /* UPDATE */ if (strlen(arg) == 0) { /* set to NULL */ qbuf1 = quote(na->nick); snprintf(query,MAX_SQL_BUF,"UPDATE anope_unreal_addon SET %s= NULL WHERE nick='%s';", type, qbuf1); free(qbuf1); } else { qbuf1 = quote(arg); qbuf2 = quote(na->nick); snprintf(query,MAX_SQL_BUF,"UPDATE anope_unreal_addon SET %s='%s' WHERE nick='%s';", type, qbuf1, qbuf2); free(qbuf1); free(qbuf2); } } else { /* INSERT */ qbuf1 = quote(na->nick); qbuf2 = quote(na->nc->display); qbuf3 = quote(arg); snprintf(query,MAX_SQL_BUF, "INSERT INTO anope_unreal_addon (nick, nickgroup, %s) " "VALUES ('%s','%s','%s');", type, qbuf1, qbuf2, qbuf3); free(qbuf1); free(qbuf2); free(qbuf3); }; do_query(query); /* releasing unused memory */ free(query); mysql_free_result(res); } /*****************************************************************************************************/ int mydb_init(void) { /* initializing mysql connection */ char *query; mysql = mysql_init(NULL); if (MysqlSock) { if ((!mysql_real_connect(mysql, MysqlHost, MysqlUser, MysqlPass, MysqlName, MysqlPort, MysqlSock, 0))) { alog("[unreal_addon] Cant connect to MySQL: %s\n", mysql_error(mysql)); alog("misc_addon_mysql.so: unloading..."); return MOD_STOP; } } else { if ((!mysql_real_connect(mysql, MysqlHost, MysqlUser, MysqlPass, MysqlName, MysqlPort, NULL, 0))) { alog("[unreal_addon] Cant connect to MySQL: %s\n", mysql_error(mysql)); alog("misc_addon_mysql.so: unloading..."); return MOD_STOP; } } if (mysql_select_db(mysql, MysqlName)) { alog("[unreal_addon] Cant connect to MySQL: %s\n", mysql_error(mysql)); alog("misc_addon_mysql.so: unloading..."); return MOD_STOP; } /* checking for table and create it, if not found */ query = malloc(MAX_SQL_BUF); snprintf(query,MAX_SQL_BUF,"SHOW TABLES LIKE 'anope_unreal_addon';"); do_query(query); res = mysql_store_result(mysql); if (mysql_num_rows(res) == 0) { /* dont change the order of the fields or you break some other stuff */ /* add new fields only to the end */ snprintf(query, MAX_SQL_BUF, "CREATE TABLE anope_unreal_addon (" "nick varchar(32) not null, PRIMARY KEY (nick), " "nickgroup varchar(32), " "alogin CHAR(1) DEFAULT '1', " "vhoststatus CHAR(1) DEFAULT '0', " "vhost TEXT, " "ajoin TEXT, " "swhois TEXT, " "helpop TINYTEXT, " "snomasks TINYTEXT, " "realname TINYTEXT, " "s_setter varchar(32), " "h_setter varchar(32), " "m_setter varchar(32), " "v_setter varchar(32), " "vhostreqstatus CHAR(1) DEFAULT '0', " "vhostreq TEXT);"); do_query(query); alog("[unreal_addon] Created table anope_unreal_addon"); } if (query) free(query); mysql_free_result(res); return 0; } /*************************************************************************************************/ int do_query(char *query) { int result, slen; slen = strlen(query); /* if (debug) alog("***Debug*** %s", query); */ mysql_ping(mysql); /* checks for mysql connection and reconnect */ result = mysql_real_query(mysql, query , slen); if (result) { log_perror(mysql_error(mysql)); return result; } return 0; } /***************************************************************************************************/ char *quote(char *arg) { int slen; char *qbuf; if (!arg) return ""; slen = strlen(arg); qbuf = malloc((1 + (slen * 2)) * sizeof(char)); mysql_real_escape_string(mysql,qbuf, arg, slen); return qbuf; } /******************************************************************************************************/ /* deletes expired and dropped nicks from database */ int purgedb(int argc, char *argv[]) { char *query = malloc(MAX_SQL_BUF); snprintf(query, MAX_SQL_BUF, "DELETE anope_unreal_addon.* FROM anope_unreal_addon " "LEFT JOIN anope_ns_alias ON anope_unreal_addon.nick=anope_ns_alias.nick " "WHERE anope_ns_alias.nick IS NULL;"); do_query(query); res = mysql_store_result(mysql); if (debug) { if (mysql_affected_rows(mysql) > 0) { send_cmd(NULL, "SENDSNO e :*services* [unreal_addon] purged database: %lu old entries removed", (unsigned long) mysql_affected_rows(mysql)); alog("[unreal_addon] purged database: %lu old entries removed", (unsigned long) mysql_affected_rows(mysql)); } } moduleAddCallback("PURGEDB",time(NULL)+dotime(PURGETIME),purgedb,0,NULL); mysql_free_result(res); free(query); return MOD_CONT; } /********************************* END OF FILE *******************************************************/