#include #define AUTHOR "Vadtec" #define VERSION "0.1.6" /* common defines */ #define ERR_BAD_FP -1 #define ERR_BAD_CHAN -2 #define ERR_BAD_ADMIN -3 #define SUCCESS 1 #define FAILURE 0 #define EXCEPT -1 #define FILE_EXIST 1 #define FILE_NOT_EXIST 0 #define FILE_OTHER_ERROR -1 /* absolute defaults for configureable options*/ #define BOTKILLERDB "botkiller.db" #define BOTKILLERNICK "BotKiller" #define BOTKILLERIDENT "BotKiller" #define BOTKILLERHOST "I.Kill.Botnet.Drones" #define BOTKILLERREALNAME "Bot Killer" #define BOTKILLERMODES NULL #define BOTKILLERAKILLLIMIT "3" #define BOTKILLERAKILLONE "1d" #define BOTKILLERAKILLTWO "7d" /* typedefs */ typedef struct chanrec chanrec; /* structs */ struct chanrec { int num; char *name; char *admin; char *reason; chanrec *next; }; /* globals */ int i = 0; // general counter int *db_fp = ERR_BAD_FP; // int pointer for the db, make it global for simplicity /* pointers to the configurable options */ char *_botkillerdb = NULL; char *_botkillernick = NULL; char *_botkillerident = NULL; char *_botkillerhost = NULL; char *_botkillerrealname = NULL; char *_botkillermodes = NULL; char *_botkillerakilllimit = NULL; char *_botkillerakillone = NULL; char *_botkillerakilltwo = NULL; /* Directives structure to hold the configurable options */ // Thanks to Rob for pointing out how to make this work with a for loop. Directive _botkiller_confvals[][1] = { { { "BotKillerDB", { { PARAM_STRING, PARAM_RELOAD, &_botkillerdb } } } }, { { "BotKillerNick", { { PARAM_STRING, PARAM_RELOAD, &_botkillernick } } } }, { { "BotKillerIdent", { { PARAM_STRING, PARAM_RELOAD, &_botkillerident } } } }, { { "BotKillerHost", { { PARAM_STRING, PARAM_RELOAD, &_botkillerhost } } } }, { { "BotKillerRealName", { { PARAM_STRING, PARAM_RELOAD, &_botkillerrealname } } } }, { { "BotKillerModes", { { PARAM_STRING, PARAM_RELOAD, &_botkillermodes } } } }, { { "BotKillerAkillLimit", { { PARAM_STRING, PARAM_RELOAD, &_botkillerakilllimit } } } }, { { "BotKillerAkill1st", { { PARAM_STRING, PARAM_RELOAD, &_botkillerakillone } } } }, { { "BotKillerAkill2nd", { { PARAM_STRING, PARAM_RELOAD, &_botkillerakilltwo } } } } }; /* function prototypes */ int cst_open_db(char *name, int *fp); int cst_close_db(int *fp); int cst_load_db(int *fp); int cst_save_db(int *fp); int cst_read_db(int *fp, int rec); int cst_write_db(int *fp, int rec); int cst_check_file(char *name); int AnopeInit(int argc, char **argv) { moduleAddAuthor(AUTHOR); moduleAddVersion(VERSION); /* Gather the config values from the config file, or use defaults */ for (i=0; i < 9; i++) { moduleGetConfigDirective(_botkiller_confvals[i]); } /* check and set the configurable options */ _botkillerdb = _botkillerdb ? _botkillerdb : BOTKILLERDB; _botkillernick = _botkillernick ? _botkillernick : BOTKILLERNICK; _botkillerident = _botkillerident ? _botkillerident : BOTKILLERNICK; _botkillerhost = _botkillerhost ? _botkillerhost : BOTKILLERHOST; _botkillerrealname = _botkillerrealname ? _botkillerrealname : BOTKILLERREALNAME; _botkillermodes = _botkillermodes ? _botkillermodes : BOTKILLERMODES ? BOTKILLERMODES : ircd->nickservmode; _botkillerakilllimit = _botkillerakilllimit ? _botkillerakilllimit : BOTKILLERAKILLLIMIT; _botkillerakillone = _botkillerakillone ? _botkillerakillone : BOTKILLERAKILLONE; _botkillerakilltwo = _botkillerakilltwo ? _botkillerakilltwo : BOTKILLERAKILLTWO; alog("\n[begin cs_trap]\n DB: %s\n Nick: %s\n Ident: %s\n Host: %s\n Real Name: %s\n Modes: %s\n Akill Limit: %s\n Akill Time 1st: %s\n Akill Time 2nd+: %s\n[end cs_trap]", _botkillerdb, _botkillernick, _botkillerident, _botkillerhost, _botkillerrealname, _botkillermodes, _botkillerakilllimit, _botkillerakillone, _botkillerakilltwo); cst_open_db(_botkillerdb, &db_fp); anope_cmd_bot_nick(_botkillernick, _botkillerident, _botkillerhost, _botkillerrealname, _botkillermodes); return MOD_CONT; } void AnopeFini(void) { cst_close_db(&db_fp); anope_cmd_quit(_botkillernick, "Shutting down..."); } int cst_open_db(char *name, int *fp) { *fp = open(name, O_CREAT | O_EXCL, 0666); if (*fp == ERR_BAD_FP) { alog("\t[cs_trap] Found %s database file, using it.", name); *fp = open(name, O_WRONLY, 0666); if (*fp == ERR_BAD_FP) { alog("\t[cs_trap] ERROR: Unable to open %s for use.", name); *fp = ERR_BAD_FP; return FAILURE; } return SUCCESS; } else { alog("\t[cs_trap] First use of %s. Creating database...", name); return SUCCESS; } return ERR_BAD_FP; } int cst_close_db(int *fp) { if (!close(*fp)) { alog("\t[cs_trap] Closed the database..."); *fp = ERR_BAD_FP; return !SUCCESS; } else { alog("\t[cs_trap] Error closing the database..."); return FAILURE; } return EXCEPT; } int cst_load_db(int *fp) { return EXCEPT; } int cst_save_db(int *fp) { return EXCEPT; } int cst_read_db(int *fp, int rec) { return EXCEPT; } int cst_write_db(int *fp, int rec) { return EXCEPT; } int cst_check_file(char *name) { return FILE_OTHER_ERROR; }