diff options
Diffstat (limited to 'modules/extra')
-rw-r--r-- | modules/extra/cs_appendtopic.cpp | 227 | ||||
-rw-r--r-- | modules/extra/cs_enforce.cpp | 444 | ||||
-rw-r--r-- | modules/extra/cs_set_misc.cpp | 196 | ||||
-rw-r--r-- | modules/extra/cs_tban.cpp | 209 | ||||
-rw-r--r-- | modules/extra/hs_request.cpp | 835 | ||||
-rw-r--r-- | modules/extra/m_helpchan.cpp | 47 | ||||
-rw-r--r-- | modules/extra/m_ssl.cpp | 142 | ||||
-rw-r--r-- | modules/extra/mysql/db_mysql.h | 211 | ||||
-rw-r--r-- | modules/extra/mysql/db_mysql_execute.cpp | 159 | ||||
-rw-r--r-- | modules/extra/mysql/db_mysql_read.cpp | 618 | ||||
-rw-r--r-- | modules/extra/mysql/db_mysql_write.cpp | 1040 | ||||
-rw-r--r-- | modules/extra/ns_maxemail.cpp | 169 | ||||
-rw-r--r-- | modules/extra/ns_set_misc.cpp | 213 |
13 files changed, 4510 insertions, 0 deletions
diff --git a/modules/extra/cs_appendtopic.cpp b/modules/extra/cs_appendtopic.cpp new file mode 100644 index 000000000..03f20ba6c --- /dev/null +++ b/modules/extra/cs_appendtopic.cpp @@ -0,0 +1,227 @@ +/* cs_appendtopic.c - Add text to a channels topic + * + * (C) 2003-2010 Anope Team + * Contact us at team@anope.org + * + * Based on the original module by SGR <Alex_SGR@ntlworld.com> + * Included in the Anope module pack since Anope 1.7.9 + * Anope Coder: GeniusDex <geniusdex@anope.org> + * + * Please read COPYING and README for further details. + * + * Send bug reports to the Anope Coder instead of the module + * author, because any changes since the inclusion into anope + * are not supported by the original author. + */ + +/*************************************************************************/ + +#include "module.h" + +#define AUTHOR "SGR" + +/* ------------------------------------------------------------ + * Name: cs_appendtopic + * Author: SGR <Alex_SGR@ntlworld.com> + * Date: 31/08/2003 + * ------------------------------------------------------------ + * + * This module has no configurable options. For information on + * this module, load it and refer to /ChanServ APPENDTOPIC HELP + * + * Thanks to dengel, Rob and Certus for all there support. + * Especially Rob, who always manages to show me where I have + * not allocated any memory. Even if it takes a few weeks of + * pestering to get him to look at it. + * + * ------------------------------------------------------------ + */ + +/* ---------------------------------------------------------------------- */ +/* DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING */ +/* ---------------------------------------------------------------------- */ + +enum +{ + LNG_CHAN_HELP, + LNG_CHAN_HELP_APPENDTOPIC, + LNG_APPENDTOPIC_SYNTAX, + LNG_NUM_STRINGS +}; + +static Module *me; + +class CommandCSAppendTopic : public Command +{ + public: + CommandCSAppendTopic() : Command("APPENDTOPIC", 2, 2) + { + } + + CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + { + const char *chan = params[0].c_str(); + const char *newtopic = params[1].c_str(); + char topic[1024]; + Channel *c = findchan(chan); + ChannelInfo *ci; + + if (c) + ci = c->ci; + + if (!c) + notice_lang(Config.s_ChanServ, u, CHAN_X_NOT_IN_USE, chan); + else if (!check_access(u, ci, CA_TOPIC)) + notice_lang(Config.s_ChanServ, u, ACCESS_DENIED); + else + { + if (ci->last_topic) + { + snprintf(topic, sizeof(topic), "%s %s", ci->last_topic, newtopic); + delete [] ci->last_topic; + } + else + strscpy(topic, newtopic, sizeof(topic)); + + ci->last_topic = *topic ? sstrdup(topic) : NULL; + ci->last_topic_setter = u->nick; + ci->last_topic_time = time(NULL); + + if (c->topic) + delete [] c->topic; + c->topic = *topic ? sstrdup(topic) : NULL; + c->topic_setter = u->nick; + if (ircd->topictsbackward) + c->topic_time = c->topic_time - 1; + else + c->topic_time = ci->last_topic_time; + + if (!check_access(u, ci, CA_TOPIC)) + Alog() << Config.s_ChanServ << ": " << u->GetMask() << " changed topic of " << c->name << " as services admin."; + if (ircd->join2set && whosends(ci) == ChanServ) + { + ChanServ->Join(c); + ircdproto->SendMode(NULL, c, "+o %s", Config.s_ChanServ); // XXX + } + ircdproto->SendTopic(whosends(ci), c, u->nick.c_str(), topic); + if (ircd->join2set && whosends(ci) == ChanServ) + ChanServ->Part(c); + } + return MOD_CONT; + } + + bool OnHelp(User *u, const ci::string &subcommand) + { + me->NoticeLang(Config.s_ChanServ, u, LNG_APPENDTOPIC_SYNTAX); + u->SendMessage(Config.s_ChanServ, " "); + me->NoticeLang(Config.s_ChanServ, u, LNG_CHAN_HELP_APPENDTOPIC); + + return true; + } + + void OnSyntaxError(User *u, const ci::string &subcommand) + { + me->NoticeLang(Config.s_ChanServ, u, LNG_APPENDTOPIC_SYNTAX); + } + + void OnServHelp(User *u) + { + me->NoticeLang(Config.s_ChanServ, u, LNG_CHAN_HELP); + } +}; + +class CSAppendTopic : public Module +{ + public: + CSAppendTopic(const std::string &modname, const std::string &creator) : Module(modname, creator) + { + me = this; + + this->SetAuthor(AUTHOR); + this->SetType(SUPPORTED); + + this->AddCommand(ChanServ, new CommandCSAppendTopic()); + + /* English (US) */ + const char* langtable_en_us[] = { + /* LNG_CHAN_HELP */ + " APPENDTOPIC Add text to a channels topic", + /* LNG_CHAN_HELP_APPENDTOPIC */ + "This command allows users to append text to a currently set\n" + "channel topic. When TOPICLOCK is on, the topic is updated and\n" + "the new, updated topic is locked.", + /* LNG_APPENDTOPIC_SYNTAX */ + "Syntax: APPENDTOPIC channel text\n" + }; + + /* Dutch (NL) */ + const char* langtable_nl[] = { + /* LNG_CHAN_HELP */ + " APPENDTOPIC Voeg tekst aan een kanaal onderwerp toe", + /* LNG_CHAN_HELP_APPENDTOPIC */ + "Dit command stelt gebruikers in staat om text toe te voegen\n" + "achter het huidige onderwerp van een kanaal. Als TOPICLOCK aan\n" + "staat, zal het onderwerp worden bijgewerkt en zal het nieuwe,\n" + "bijgewerkte topic worden geforceerd.", + /* LNG_APPENDTOPIC_SYNTAX */ + "Gebruik: APPENDTOPIC kanaal tekst\n" + }; + + /* German (DE) */ + const char* langtable_de[] = { + /* LNG_CHAN_HELP */ + " APPENDTOPIC Fьgt einen Text zu einem Channel-Topic hinzu.", + /* LNG_CHAN_HELP_APPENDTOPIC */ + "Dieser Befehl erlaubt Benutzern, einen Text zu dem vorhandenen Channel-Topic\n" + "hinzuzufьgen. Wenn TOPICLOCK gesetzt ist, wird das Topic aktualisiert\n" + "und das neue, aktualisierte Topic wird gesperrt.", + /* LNG_APPENDTOPIC_SYNTAX */ + "Syntax: APPENDTOPIC Channel Text\n" + }; + + /* Portuguese (PT) */ + const char* langtable_pt[] = { + /* LNG_CHAN_HELP */ + " APPENDTOPIC Adiciona texto ao tуpico de um canal", + /* LNG_CHAN_HELP_APPENDTOPIC */ + "Este comando permite aos usuбrios anexar texto a um tуpico de canal\n" + "jб definido. Quando TOPICLOCK estб ativado, o tуpico й atualizado e\n" + "o novo tуpico й travado.", + /* LNG_APPENDTOPIC_SYNTAX */ + "Sintaxe: APPENDTOPIC canal texto\n" + }; + + /* Russian (RU) */ + const char* langtable_ru[] = { + /* LNG_CHAN_HELP */ + " APPENDTOPIC Добавляет текст к топику канала", + /* LNG_CHAN_HELP_APPENDTOPIC */ + "Данная команда позволяет добавить текст к топику, который установлен на указанном\n" + "канале. Если активирован режим TOPICLOCK, топик будет обновлен и заблокирован.\n" + "Примечание: текст будет ДОБАВЛЕН к топику, то есть старый топик удален НЕ БУДЕТ.\n", + /* LNG_APPENDTOPIC_SYNTAX */ + "Синтаксис: APPENDTOPIC #канал текст\n" + }; + + /* Italian (IT) */ + const char* langtable_it[] = { + /* LNG_CHAN_HELP */ + " APPENDTOPIC Aggiunge del testo al topic di un canale", + /* LNG_CHAN_HELP_APPENDTOPIC */ + "Questo comando permette agli utenti di aggiungere del testo ad un topic di un canale\n" + "giа impostato. Se TOPICLOCK и attivato, il topic viene aggiornato e il nuovo topic\n" + "viene bloccato.", + /* LNG_APPENDTOPIC_SYNTAX */ + "Sintassi: APPENDTOPIC canale testo\n" + }; + + this->InsertLanguage(LANG_EN_US, LNG_NUM_STRINGS, langtable_en_us); + this->InsertLanguage(LANG_NL, LNG_NUM_STRINGS, langtable_nl); + this->InsertLanguage(LANG_DE, LNG_NUM_STRINGS, langtable_de); + this->InsertLanguage(LANG_PT, LNG_NUM_STRINGS, langtable_pt); + this->InsertLanguage(LANG_RU, LNG_NUM_STRINGS, langtable_ru); + this->InsertLanguage(LANG_IT, LNG_NUM_STRINGS, langtable_it); + } +}; + +MODULE_INIT(CSAppendTopic) diff --git a/modules/extra/cs_enforce.cpp b/modules/extra/cs_enforce.cpp new file mode 100644 index 000000000..c4cfbecc9 --- /dev/null +++ b/modules/extra/cs_enforce.cpp @@ -0,0 +1,444 @@ +/* cs_enforce - Add a /cs ENFORCE command to enforce various set + * options and channelmodes on a channel. + * + * (C) 2003-2010 Anope Team + * Contact us at team@anope.org + * + * Included in the Anope module pack since Anope 1.7.9 + * Anope Coder: GeniusDex <geniusdex@anope.org> + * + * Please read COPYING and README for further details. + * + * Send any bug reports to the Anope Coder, as he will be able + * to deal with it best. + */ + +#include "module.h" + +#define AUTHOR "Anope" + +enum +{ + LNG_CHAN_HELP, + LNG_ENFORCE_SYNTAX, + LNG_CHAN_HELP_ENFORCE, + LNG_CHAN_HELP_ENFORCE_R_ENABLED, + LNG_CHAN_HELP_ENFORCE_R_DISABLED, + LNG_CHAN_RESPONSE, + LNG_NUM_STRINGS +}; + +static Module *me; + +class CommandCSEnforce : public Command +{ + private: + void DoSet(Channel *c) + { + ChannelInfo *ci; + + if (!(ci = c->ci)) + return; + + if (ci->HasFlag(CI_SECUREOPS)) + this->DoSecureOps(c); + if (ci->HasFlag(CI_RESTRICTED)) + this->DoRestricted(c); + } + + void DoModes(Channel *c) + { + if (c->HasMode(CMODE_REGISTEREDONLY)) + this->DoCModeR(c); + } + + void DoSecureOps(Channel *c) + { + ChannelInfo *ci; + bool hadsecureops = false; + + if (!(ci = c->ci)) + return; + + Alog(LOG_DEBUG) << "[cs_enforce] Enforcing SECUREOPS on " << c->name; + + /* Dirty hack to allow chan_set_correct_modes to work ok. + * We pretend like SECUREOPS is on so it doesn't ignore that + * part of the code. This way we can enforce SECUREOPS even + * if it's off. + */ + if (!ci->HasFlag(CI_SECUREOPS)) + { + ci->SetFlag(CI_SECUREOPS); + hadsecureops = true; + } + + for (CUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) + { + UserContainer *uc = *it; + + chan_set_correct_modes(uc->user, c, 0); + } + + if (hadsecureops) + ci->UnsetFlag(CI_SECUREOPS); + } + + void DoRestricted(Channel *c) + { + ChannelInfo *ci; + int16 old_nojoin_level; + char mask[BUFSIZE]; + const char *reason; + + if (!(ci = c->ci)) + return; + + Alog(LOG_DEBUG) << "[cs_enforce] Enforcing RESTRICTED on " << c->name; + + old_nojoin_level = ci->levels[CA_NOJOIN]; + if (ci->levels[CA_NOJOIN] < 0) + ci->levels[CA_NOJOIN] = 0; + + for (CUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ) + { + UserContainer *uc = *it++; + + if (check_access(uc->user, ci, CA_NOJOIN)) + { + get_idealban(ci, uc->user, mask, sizeof(mask)); + reason = getstring(uc->user, CHAN_NOT_ALLOWED_TO_JOIN); + c->SetMode(NULL, CMODE_BAN, mask); + c->Kick(NULL, uc->user, "%s", reason); + } + } + + ci->levels[CA_NOJOIN] = old_nojoin_level; + } + + void DoCModeR(Channel *c) + { + ChannelInfo *ci; + char mask[BUFSIZE]; + const char *reason; + + if (!(ci = c->ci)) + return; + + Alog(LOG_DEBUG) << "[cs_enforce] Enforcing mode +R on " << c->name; + + for (CUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ) + { + UserContainer *uc = *it++; + + if (!uc->user->IsIdentified()) + { + get_idealban(ci, uc->user, mask, sizeof(mask)); + reason = getstring(uc->user, CHAN_NOT_ALLOWED_TO_JOIN); + if (!c->HasMode(CMODE_REGISTERED)) + c->SetMode(NULL, CMODE_BAN, mask); + c->Kick(NULL, uc->user, "%s", reason); + } + } + } + public: + CommandCSEnforce() : Command("ENFORCE", 1, 2) + { + } + + CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + { + const char *chan = params[0].c_str(); + ci::string what = params.size() > 1 ? params[1] : ""; + Channel *c = findchan(chan); + ChannelInfo *ci; + + if (c) + ci = c->ci; + + if (!c) + notice_lang(Config.s_ChanServ, u, CHAN_X_NOT_IN_USE, chan); + else if (!check_access(u, ci, CA_AKICK)) + notice_lang(Config.s_ChanServ, u, ACCESS_DENIED); + else + { + if (what.empty() || what == "SET") + { + this->DoSet(c); + me->NoticeLang(Config.s_ChanServ, u, LNG_CHAN_RESPONSE, !what.empty() ? what.c_str() : "SET"); + } + else if (what == "MODES") + { + this->DoModes(c); + me->NoticeLang(Config.s_ChanServ, u, LNG_CHAN_RESPONSE, what.c_str()); + } + else if (what == "SECUREOPS") + { + this->DoSecureOps(c); + me->NoticeLang(Config.s_ChanServ, u, LNG_CHAN_RESPONSE, what.c_str()); + } + else if (what == "RESTRICTED") + { + this->DoRestricted(c); + me->NoticeLang(Config.s_ChanServ, u, LNG_CHAN_RESPONSE, what.c_str()); + } + else if (what == "+R") + { + this->DoCModeR(c); + me->NoticeLang(Config.s_ChanServ, u, LNG_CHAN_RESPONSE, what.c_str()); + } + else + this->OnSyntaxError(u, ""); + } + + return MOD_CONT; + } + + bool OnHelp(User *u, const ci::string &subcommand) + { + me->NoticeLang(Config.s_ChanServ, u, LNG_ENFORCE_SYNTAX); + u->SendMessage(Config.s_ChanServ, " "); + me->NoticeLang(Config.s_ChanServ, u, LNG_CHAN_HELP_ENFORCE); + u->SendMessage(Config.s_ChanServ, " "); + if (ModeManager::FindChannelModeByName(CMODE_REGISTERED)) + me->NoticeLang(Config.s_ChanServ, u, LNG_CHAN_HELP_ENFORCE_R_ENABLED); + else + me->NoticeLang(Config.s_ChanServ, u, LNG_CHAN_HELP_ENFORCE_R_DISABLED); + + return true; + } + + void OnSyntaxError(User *u, const ci::string &subcommand) + { + me->NoticeLang(Config.s_ChanServ, u, LNG_ENFORCE_SYNTAX); + } + + void OnServHelp(User *u) + { + me->NoticeLang(Config.s_ChanServ, u, LNG_CHAN_HELP); + } +}; + +class CSEnforce : public Module +{ + public: + CSEnforce(const std::string &modname, const std::string &creator) : Module(modname, creator) + { + me = this; + + this->SetAuthor(AUTHOR); + this->SetType(SUPPORTED); + + this->AddCommand(ChanServ, new CommandCSEnforce()); + + /* English (US) */ + const char* langtable_en_us[] = { + /* LNG_CHAN_HELP */ + " ENFORCE Enforce various channel modes and set options", + /* LNG_ENFORCE_SYNTAX */ + "Syntax: \002ENFORCE \037channel\037 [\037what\037]\002", + /* LNG_CHAN_HELP_ENFORCE */ + "Enforce various channel modes and set options. The \037channel\037\n" + "option indicates what channel to enforce the modes and options\n" + "on. The \037what\037 option indicates what modes and options to\n" + "enforce, and can be any of SET, SECUREOPS, RESTRICTED, MODES,\n" + "or +R. When left out, it defaults to SET.\n" + " \n" + "If \037what\037 is SET, it will enforce SECUREOPS and RESTRICTED\n" + "on the users currently in the channel, if they are set. Give\n" + "SECUREOPS to enforce the SECUREOPS option, even if it is not\n" + "enabled. Use RESTRICTED to enfore the RESTRICTED option, also\n" + "if it's not enabled.", + /* LNG_CHAN_HELP_ENFORCE_R_ENABLED */ + "If \037what\037 is MODES, it will enforce channelmode +R if it is\n" + "set. If +R is specified for \037what\037, the +R channelmode will\n" + "also be enforced, but even if it is not set. If it is not set,\n" + "users will be banned to ensure they don't just rejoin.", + /* LNG_CHAN_HELP_ENFORCE_R_DISABLED */ + "If \037what\037 is MODES, nothing will be enforced, since it would\n" + "enforce modes that the current ircd does not support. If +R is\n" + "specified for \037what\037, an equalivant of channelmode +R on\n" + "other ircds will be enforced. All users that are in the channel\n" + "but have not identified for their nickname will be kicked and\n" + "banned from the channel.", + /* LNG_CHAN_RESPONSE */ + "Enforced %s" + }; + + /* Dutch (NL) */ + const char* langtable_nl[] = { + /* LNG_CHAN_HELP */ + " ENFORCE Forceer enkele kanaalmodes en set-opties", + /* LNG_ENFORCE_SYNTAX */ + "Syntax: \002ENFORCE \037kanaal\037 [\037wat\037]\002", + /* LNG_CHAN_HELP_ENFORCE */ + "Forceer enkele kannalmodes en set-opties. De \037kanaal\037 optie\n" + "geeft aan op welk kanaal de modes en opties geforceerd moeten\n" + "worden. De \037wat\037 optie geeft aan welke modes en opties\n" + "geforceerd moeten worden; dit kan SET, SECUREOPS, RESTRICTED,\n" + "MODES, of +R zijn. Indien weggelaten is dit standaard SET.\n" + " \n" + "Als er voor \037wat\037 SET wordt ingevuld, zullen SECUREOPS en\n" + "RESTRICTED geforceerd worden op de gebruikers in het kanaal,\n" + "maar alleen als die opties aangezet zijn voor het kanaal. Als\n" + "SECUREOPS of RESTRICTED wordt gegeven voor \037wat\037 zal die optie\n" + "altijd geforceerd worden, ook als die niet is aangezet.", + /* LNG_CHAN_HELP_ENFORCE_R_ENABLED */ + "Als er voor \037wat\037 MODES wordt ingevuld, zal kanaalmode +R worden\n" + "geforceerd, als die op het kanaal aan staat. Als +R wordt ingevuld,\n" + "zal kanaalmode +R worden geforceerd, maar ook als die niet aan" + "staat voor het kanaal. Als +R niet aan staat, zullen alle ook\n" + "gebanned worden om te zorgen dat ze niet opnieuw het kanaal binnen\n" + "kunnen komen.", + /* LNG_CHAN_HELP_ENFORCE_R_DISABLED */ + "Als er voor \037wat\037 MODES wordt ingevuld, zal er niks gebeuren.\n" + "Normaal gesproken wordt er een kanaalmode geforceerd die op deze\n" + "server niet ondersteund wordt. Als +R wordt ingevuld voor \037wat\037\n" + "zullen alle gebruikers die in het kanaal zitten maar zich niet\n" + "hebben geidentificeerd voor hun nick uit het kanaal gekicked en\n" + "verbannen worden.", + /* LNG_CHAN_RESPONSE */ + "Enforced %s" + }; + + /* German (DE) */ + const char* langtable_de[] = { + /* LNG_CHAN_HELP */ + " ENFORCE Erzwingt verschieden Modes und SET Optionen", + /* LNG_ENFORCE_SYNTAX */ + "Syntax: \002ENFORCE \037Channel\037 [\037was\037]\002", + /* LNG_CHAN_HELP_ENFORCE */ + "Erzwingt verschieden Modes und SET Optionen. Die \037Channel\037\n" + "Option zeigt dir den Channel an, indem Modes und Optionen\n" + "zu erzwingen sind. Die \037was\037 Option zeigt dir welche Modes\n" + "und Optionen zu erzwingen sind. Die kцnnen nur SET, SECUREOPS,\n" + "RESTRICTED, MODES oder +R sein.Default ist SET.\n" + " \n" + "Wenn \037was\037 SET ist, wird SECUREOPS und RESTRICTED\n" + "auf die User die z.Z.in Channel sind erzwungen, wenn sie AN sind.\n" + "Benutze SECUREOPS oder RESTRICTED , um die Optionen einzeln\n" + "zu erzwingen, also wenn sie nicht eingeschaltet sind.", + /* LNG_CHAN_HELP_ENFORCE_R_ENABLED */ + "Wenn \037was\037 MODES ist, wird das ChannelMode +R erzwungen\n" + "falls an. Wenn \037was\037 +R ist, wird +R erzwungen aber eben\n" + "wenn noch nicht als Channel-Mode ist. Wenn +R noch nicht als\n" + "Channel-Mode war werden alle User aus den Channel gebannt um\n" + "sicher zu sein das sie nicht rejoinen.", + /* LNG_CHAN_HELP_ENFORCE_R_DISABLED */ + "Wenn \037was\037 MODES ist, wird nichts erzwungen weil es MODES seine\n" + "kцnnen die dein IRCD nicht unterstьtzt. Wenn \037was\037 +R ist\n" + "oder ein Modes was auf ein anderen IRCD gleich +R ist, wird es\n" + "erzwungen. Alle User die nicht fьr deren Nicknamen identifiziert\n" + "sind werden aus den Channel gekickt und gebannt.", + /* LNG_CHAN_RESPONSE */ + "Erzwungen %s" + }; + + /* Portuguese (PT) */ + const char* langtable_pt[] = { + /* LNG_CHAN_HELP */ + " ENFORCE Verifica o cumprimento de vбrios modos de canal e opзхes ajustadas", + /* LNG_ENFORCE_SYNTAX */ + "Sintaxe: \002ENFORCE \037canal\037 [\037opзгo\037]\002", + /* LNG_CHAN_HELP_ENFORCE */ + "Verifica o cumprimento de vбrios modos de canal e opзхes ajustadas.\n" + "O campo \037canal\037 indica qual canal deve ter os modos e opзхes verificadas\n" + "O campo \037opзгo\037 indica quais modos e opзхes devem ser verificadas,\n" + "e pode ser: SET, SECUREOPS, RESTRICTED, MODES ou +R\n" + "Quando deixado em branco, o padrгo й SET.\n" + " \n" + "Se \037opзгo\037 for SET, serгo verificadas as opзхes SECUREOPS e RESTRICTED\n" + "para usuбrios que estiverem no canal, caso elas estejam ativadas. Use\n" + "SECUREOPS para verificar a opзгo SECUREOPS, mesmo que ela nгo esteja ativada\n" + "Use RESTRICTED para verificar a opзгo RESTRICTED, mesmo que ela nгo esteja\n" + "ativada.", + /* LNG_CHAN_HELP_ENFORCE_R_ENABLED */ + "Se \037opзгo\037 for MODES, serб verificado o modo de canal +R caso ele\n" + "esteja ativado. Se +R for especificado para \037opзгo\037, o modo de canal\n" + "+R tambйm serб verificado, mesmo que ele nгo esteja ativado. Se ele nгo\n" + "estiver ativado, os usuбrios serгo banidos para evitar que reentrem no canal.", + /* LNG_CHAN_HELP_ENFORCE_R_DISABLED */ + "Se \037opзгo\037 for MODES, nada serб verificado, visto que isto poderia\n" + "verificar modos que o IRCd atual nгo suporta. Se +R for especificado\n" + "para \037opзгo\037, um equivalente ao modo de canal +R em outros IRCds\n" + "serб verificado. Todos os usuбrios que estгo no canal, mas nгo estejam\n" + "identificados para seus nicks serгo kickados e banidos do canal.", + /* LNG_CHAN_RESPONSE */ + "Verificado %s" + }; + + /* Russian (RU) */ + const char* langtable_ru[] = { + /* LNG_CHAN_HELP */ + " ENFORCE Перепроверка и установка различных режимов и опций канала", + /* LNG_ENFORCE_SYNTAX */ + "Синтаксис: \002ENFORCE \037#канал\037 \037параметр\037\002", + /* LNG_CHAN_HELP_ENFORCE */ + "Перепроверка и установка различных режимов и опций канала.\n" + "\037Параметр\037 указывает какие опции или режимы канала должны быть\n" + "перепроверены. В качестве параметра могут быть указаны: SET, SECUREOPS,\n" + "RESTRICTED, MODES, или +R. Если параметр не указан, по-умолчанию будет SET.\n" + " \n" + "Если в качестве \037параметра\037 указано SET, будут перепроверены опции\n" + "SECUREOPS и RESTRICTED относительно пользователей на указанном канале\n" + "(при условии, что опции включены). Отдельно указанный параметр SECUREOPS\n" + "применит опцию SECUREOPS (даже если она \037НЕ\037 установлена). Параметр\n" + "RESTRICTED применит опцию RESTRICTED (даже если она \037НЕ\037 установлена)", + /* LNG_CHAN_HELP_ENFORCE_R_ENABLED */ + "Если в качестве \037параметра\037 указано MODES, будет перепроверен режим +R\n" + "(если он установлен). Отдельно указанный параметр \037+R\037 применит\n" + "канальный режим +R, даже если он не установлен, и забанит всех пользователей,\n" + "которые не идентифицировались к своему нику или не имеют зарегистрированного ника.", + /* LNG_CHAN_HELP_ENFORCE_R_DISABLED */ + "Если в качестве \037параметра\037 указано MODES, перепроверка осуществлена\n" + "НЕ БУДЕТ, так как текущий IRCD не поддерживает необходимые режимы.\n" + "Отдельно указанный параметр \037+R\037 применит канальный режим, эквивалентный\n" + "режиму +R и забанит всех пользователей, которые не идентифицировались к своему\n" + "нику или не имеют зарегистрированного ника.", + /* LNG_CHAN_RESPONSE */ + "Перепроверено: %s" + }; + + /* Italian (IT) */ + const char* langtable_it[] = { + /* LNG_CHAN_HELP */ + " ENFORCE Forza diversi modi di canale ed opzioni SET", + /* LNG_ENFORCE_SYNTAX */ + "Sintassi: \002ENFORCE \037canale\037 [\037cosa\037]\002", + /* LNG_CHAN_HELP_ENFORCE */ + "Forza diversi modi di canale ed opzioni SET. Il parametro \037canale\037\n" + "indica il canale sul quale forzare i modi e le opzioni. Il parametro\n" + "\037cosa\037 indica i modi e le opzioni da forzare, e possono essere\n" + "qualsiasi delle opzioni SET, SECUREOPS, RESTRICTED, MODES, o +R.\n" + "Se non specificato, viene sottointeso SET.\n" + " \n" + "Se \037cosa\037 и SET, forzerа SECUREOPS e RESTRICTED sugli utenti\n" + "attualmente nel canale, se sono impostati. Specifica SECUREOPS per\n" + "forzare l'opzione SECUREOPS, anche se non и attivata. Specifica\n" + "RESTRICTED per forzare l'opzione RESTRICTED, anche se non и\n" + "attivata.", + /* LNG_CHAN_HELP_ENFORCE_R_ENABLED */ + "Se \037cosa\037 и MODES, forzerа il modo del canale +R se и impostato.\n" + "Se +R и specificato per \037cosa\037, il modo del canale +R verrа\n" + "forzato, anche se non и impostato. Se non и impostato, gli utenti\n" + "verranno bannati per assicurare che non rientrino semplicemente.", + /* LNG_CHAN_HELP_ENFORCE_R_DISABLED */ + "Se \037cosa\037 и MODES, niente verrа forzato, siccome forzerebbe\n" + "dei modi che l'ircd in uso non supporterebbe. Se +R и specificato\n" + "per \037cosa\037, un modo equivalente a +R sui altri ircd verrа\n" + "forzato. Tutti gli utenti presenti nel canale ma non identificati\n" + "per il loro nickname verranno bannati ed espulsi dal canale.\n", + /* LNG_CHAN_RESPONSE */ + "Forzato %s" + }; + + this->InsertLanguage(LANG_EN_US, LNG_NUM_STRINGS, langtable_en_us); + this->InsertLanguage(LANG_NL, LNG_NUM_STRINGS, langtable_nl); + this->InsertLanguage(LANG_DE, LNG_NUM_STRINGS, langtable_de); + this->InsertLanguage(LANG_PT, LNG_NUM_STRINGS, langtable_pt); + this->InsertLanguage(LANG_RU, LNG_NUM_STRINGS, langtable_ru); + this->InsertLanguage(LANG_IT, LNG_NUM_STRINGS, langtable_it); + } +}; + +MODULE_INIT(CSEnforce) diff --git a/modules/extra/cs_set_misc.cpp b/modules/extra/cs_set_misc.cpp new file mode 100644 index 000000000..453e242a3 --- /dev/null +++ b/modules/extra/cs_set_misc.cpp @@ -0,0 +1,196 @@ +/* + * + * (C) 2003-2010 Anope Team + * Contact us at team@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. + */ + +/*************************************************************************/ + +#include "module.h" + +class CommandCSSetMisc : public Command +{ + std::string Desc; + public: + CommandCSSetMisc(const ci::string &cname, const std::string &desc, const ci::string &cpermission = "") : Command(cname, 1, 2, cpermission), Desc(desc) + { + } + + CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + { + ChannelInfo *ci = cs_findchan(params[0]); + assert(ci); + + ci->Shrink("chanserv:" + std::string(this->name.c_str())); + if (params.size() > 1) + { + ci->Extend("chanserv:" + std::string(this->name.c_str()), new ExtensibleItemRegular<ci::string>(params[1])); + notice_lang(Config.s_ChanServ, u, CHAN_SETTING_CHANGED, this->name.c_str(), ci->name.c_str(), params[1].c_str()); + } + else + { + notice_lang(Config.s_ChanServ, u, CHAN_SETTING_UNSET, this->name.c_str(), ci->name.c_str()); + } + + return MOD_CONT; + } + + void OnSyntaxError(User *u, const ci::string &) + { + syntax_error(Config.s_ChanServ, u, "SET", CHAN_SET_SYNTAX); + } + + void OnServHelp(User *u) + { + u->SendMessage(Config.s_ChanServ, " %-10s %s", this->name.c_str(), this->Desc.c_str()); + } +}; + +class CommandCSSASetMisc : public CommandCSSetMisc +{ + public: + CommandCSSASetMisc(const ci::string &cname, const std::string &desc) : CommandCSSetMisc(cname, desc, "chanserv/saset/" + cname) + { + } + + void OnSyntaxError(User *u, const ci::string &) + { + syntax_error(Config.s_ChanServ, u, "SASET", CHAN_SASET_SYNTAX); + } +}; + +class CSSetMisc : public Module +{ + struct CommandInfo + { + std::string Name; + std::string Desc; + bool ShowHidden; + + CommandInfo(const std::string &name, const std::string &desc, bool showhidden) : Name(name), Desc(desc), ShowHidden(showhidden) { } + }; + + std::map<std::string, CommandInfo *> Commands; + + void RemoveAll() + { + if (Commands.empty()) + return; + + Command *set = FindCommand(ChanServ, "SET"); + Command *saset = FindCommand(ChanServ, "SASET"); + + if (!set && !saset) + return; + + for (std::map<std::string, CommandInfo *>::const_iterator it = this->Commands.begin(), it_end = this->Commands.end(); it != it_end; ++it) + { + if (set) + set->DelSubcommand(it->first.c_str()); + if (saset) + saset->DelSubcommand(it->first.c_str()); + delete it->second; + } + + this->Commands.clear(); + } + + public: + CSSetMisc(const std::string &modname, const std::string &creator) : Module(modname, creator) + { + this->SetAuthor("Anope"); + this->SetType(CORE); + + Implementation i[] = { I_OnReload, I_OnChanInfo, I_OnDatabaseWriteMetadata, I_OnDatabaseReadMetadata }; + ModuleManager::Attach(i, this, 4); + + OnReload(true); + } + + ~CSSetMisc() + { + RemoveAll(); + } + + void OnReload(bool) + { + RemoveAll(); + + Command *set = FindCommand(ChanServ, "SET"); + Command *saset = FindCommand(ChanServ, "SASET"); + if (!set && !saset) + return; + + ConfigReader config; + + for (int i = 0; true; ++i) + { + std::string cname = config.ReadValue("cs_set_misc", "name", "", i); + if (cname.empty()) + break; + std::string desc = config.ReadValue("cs_set_misc", "desc", "", i); + bool showhidden = config.ReadFlag("cs_set_misc", "operonly", "no", i); + + CommandInfo *info = new CommandInfo(cname, desc, showhidden); + if (!this->Commands.insert(std::make_pair(cname, info)).second) + { + Alog() << "cs_set_misc: Warning, unable to add duplicate entry " << cname; + delete info; + continue; + } + + if (set) + set->AddSubcommand(new CommandCSSetMisc(cname.c_str(), desc)); + if (saset) + saset->AddSubcommand(new CommandCSSASetMisc(cname.c_str(), desc)); + } + } + + void OnChanInfo(User *u, ChannelInfo *ci, bool ShowHidden) + { + for (std::map<std::string, CommandInfo *>::const_iterator it = this->Commands.begin(), it_end = this->Commands.end(); it != it_end; ++it) + { + if (!ShowHidden && it->second->ShowHidden) + continue; + + ci::string value; + if (ci->GetExtRegular("chanserv:" + it->first, value)) + { + u->SendMessage(Config.s_ChanServ, " %s: %s", it->first.c_str(), value.c_str()); + } + } + } + + void OnDatabaseWriteMetadata(void (*WriteMetadata)(const std::string &, const std::string &), ChannelInfo *ci) + { + for (std::map<std::string, CommandInfo *>::const_iterator it = this->Commands.begin(), it_end = this->Commands.end(); it != it_end; ++it) + { + ci::string value; + + if (ci->GetExtRegular("chanserv:" + it->first, value)) + { + WriteMetadata(it->first, ":" + std::string(value.c_str())); + } + } + } + + EventReturn OnDatabaseReadMetadata(ChannelInfo *ci, const std::string &key, const std::vector<std::string> ¶ms) + { + for (std::map<std::string, CommandInfo *>::const_iterator it = this->Commands.begin(), it_end = this->Commands.end(); it != it_end; ++it) + { + if (key == it->first) + { + ci->Extend("chanserv:" + it->first, new ExtensibleItemRegular<ci::string>(params[0].c_str())); + } + } + + return EVENT_CONTINUE; + } +}; + +MODULE_INIT(CSSetMisc) diff --git a/modules/extra/cs_tban.cpp b/modules/extra/cs_tban.cpp new file mode 100644 index 000000000..844606222 --- /dev/null +++ b/modules/extra/cs_tban.cpp @@ -0,0 +1,209 @@ +/* cs_tban.c - Bans the user for a given length of time + * + * (C) 2003-2010 Anope Team + * Contact us at team@anope.org + * + * Based on the original module by Rob <rob@anope.org> + * Included in the Anope module pack since Anope 1.7.8 + * Anope Coder: Rob <rob@anope.org> + * + * Please read COPYING and README for further details. + * + * Send bug reports to the Anope Coder instead of the module + * author, because any changes since the inclusion into anope + * are not supported by the original author. + */ +/*************************************************************************/ + +#include "module.h" + +#define AUTHOR "Rob" + +void mySendResponse(User *u, const char *channel, char *mask, const char *time); + +void addBan(Channel *c, time_t timeout, char *banmask); +int canBanUser(Channel *c, User *u, User *u2); + +void mAddLanguages(); + +static Module *me = NULL; + +enum +{ + TBAN_HELP, + TBAN_SYNTAX, + TBAN_HELP_DETAIL, + TBAN_RESPONSE, + LANG_NUM_STRINGS +}; + +class CommandCSTBan : public Command +{ + public: + CommandCSTBan() : Command("TBAN", 3, 3) + { + } + + CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + { + char mask[BUFSIZE]; + Channel *c; + User *u2 = NULL; + + const char *chan = params[0].c_str(); + const char *nick = params[1].c_str(); + const char *time = params[2].c_str(); + + if (!(c = findchan(chan))) + notice_lang(Config.s_ChanServ, u, CHAN_X_NOT_IN_USE, chan); + else if (!(u2 = finduser(nick))) + notice_lang(Config.s_ChanServ, u, NICK_X_NOT_IN_USE, nick); + else + if (canBanUser(c, u, u2)) + { + get_idealban(c->ci, u2, mask, sizeof(mask)); + addBan(c, dotime(time), mask); + mySendResponse(u, chan, mask, time); + } + + return MOD_CONT; + } + + bool OnHelp(User *u, const ci::string &subcommand) + { + this->OnSyntaxError(u, ""); + u->SendMessage(Config.s_ChanServ, " "); + me->NoticeLang(Config.s_ChanServ, u, TBAN_HELP_DETAIL); + + return true; + } + + void OnSyntaxError(User *u, const ci::string &subcommand) + { + me->NoticeLang(Config.s_ChanServ, u, TBAN_SYNTAX); + } + + void OnServHelp(User *u) + { + me->NoticeLang(Config.s_ChanServ, u, TBAN_HELP); + } +}; + +class CSTBan : public Module +{ + public: + CSTBan(const std::string &modname, const std::string &creator) : Module(modname, creator) + { + me = this; + + this->AddCommand(ChanServ, new CommandCSTBan()); + + this->SetAuthor(AUTHOR); + this->SetType(SUPPORTED); + + const char* langtable_en_us[] = { + " TBAN Bans the user for a given length of time", + "Syntax: TBAN channel nick time", + "Bans the given user from a channel for a specified length of\n" + "time. If the ban is removed before by hand, it will NOT be replaced.", + "%s banned from %s, will auto-expire in %s" + }; + + const char* langtable_nl[] = { + " TBAN Verban een gebruiker voor een bepaalde tijd", + "Syntax: TBAN kanaal nick tijd", + "Verbant de gegeven gebruiken van het gegeven kanaal voor de\n" + "gegeven tijdsduur. Als de verbanning eerder wordt verwijderd,\n" + "zal deze NIET worden vervangen.", + "%s verbannen van %s, zal verlopen in %s" + }; + + const char* langtable_de[] = { + " TBAN Bant ein User fьr eine bestimmte Zeit aus ein Channel", + "Syntax: TBAN Channel Nickname Zeit", + "Bant ein User fьr eine bestimmte Zeit aus ein Channel\n" + "Wenn der Ban manuell entfernt wird, wird es NICHT ersetzt.", + "%s gebannt von %s, wird auto-auslaufen in %s" + }; + + const char* langtable_pt[] = { + " TBAN Bane o usuбrio por um determinado perнodo de tempo", + "Sintaxe: TBAN canal nick tempo", + "Bane de um canal o usuбrio especificado por um determinado perнodo de\n" + "tempo. Se o ban for removido manualmente antes do tempo, ele nгo serб recolocado.", + "%s foi banido do %s, irб auto-expirar em %s" + }; + + const char* langtable_ru[] = { + " TBAN Банит пользователя на указанный промежуток времени", + "Синтаксис: TBAN #канал ник время", + "Банит пользователя на указанный промежуток времени в секундах\n" + "Примечание: удаленный вручную (до своего истечения) бан НЕ БУДЕТ\n" + "переустановлен сервисами автоматически!", + "Установленный бан %s на канале %s истечет через %s секунд" + }; + + const char* langtable_it[] = { + " TBAN Banna l'utente per un periodo di tempo specificato", + "Sintassi: TBAN canale nick tempo", + "Banna l'utente specificato da un canale per un periodo di tempo\n" + "specificato. Se il ban viene rimosso a mano prima della scadenza, NON verrа rimpiazzato.", + "%s bannato da %s, scadrа automaticamente tra %s" + }; + + this->InsertLanguage(LANG_EN_US, LANG_NUM_STRINGS, langtable_en_us); + this->InsertLanguage(LANG_NL, LANG_NUM_STRINGS, langtable_nl); + this->InsertLanguage(LANG_DE, LANG_NUM_STRINGS, langtable_de); + this->InsertLanguage(LANG_PT, LANG_NUM_STRINGS, langtable_pt); + this->InsertLanguage(LANG_RU, LANG_NUM_STRINGS, langtable_ru); + this->InsertLanguage(LANG_IT, LANG_NUM_STRINGS, langtable_it); + } +}; + +void mySendResponse(User *u, const char *channel, char *mask, const char *time) +{ + me->NoticeLang(Config.s_ChanServ, u, TBAN_RESPONSE, mask, channel, time); +} + +class TempBan : public CallBack +{ + private: + std::string chan; + std::string mask; + + public: + TempBan(time_t seconds, const std::string &channel, const std::string &banmask) : CallBack(me, seconds), chan(channel), mask(banmask) { } + + void Tick(time_t ctime) + { + Channel *c; + + if ((c = findchan(chan)) && c->ci) + c->RemoveMode(NULL, CMODE_BAN, mask); + } +}; + +void addBan(Channel *c, time_t timeout, char *banmask) +{ + c->SetMode(NULL, CMODE_BAN, banmask); + + new TempBan(timeout, c->name, banmask); +} + +int canBanUser(Channel * c, User * u, User * u2) +{ + ChannelInfo *ci = c->ci; + int ok = 0; + if (!check_access(u, ci, CA_BAN)) + notice_lang(Config.s_ChanServ, u, ACCESS_DENIED); + else if (is_excepted(ci, u2)) + notice_lang(Config.s_ChanServ, u, CHAN_EXCEPTED, u2->nick.c_str(), ci->name.c_str()); + else if (u2->IsProtected()) + notice_lang(Config.s_ChanServ, u, ACCESS_DENIED); + else + ok = 1; + + return ok; +} + +MODULE_INIT(CSTBan) diff --git a/modules/extra/hs_request.cpp b/modules/extra/hs_request.cpp new file mode 100644 index 000000000..7ca2bc9ca --- /dev/null +++ b/modules/extra/hs_request.cpp @@ -0,0 +1,835 @@ +/* hs_request.c - Add request and activate functionality to HostServ, + * along with adding +req as optional param to HostServ list. + * + * (C) 2003-2010 Anope Team + * Contact us at team@anope.org + * + * Based on the original module by Rob <rob@anope.org> + * Included in the Anope module pack since Anope 1.7.11 + * Anope Coder: GeniusDex <geniusdex@anope.org> + * + * Please read COPYING and README for further details. + * + * Send bug reports to the Anope Coder instead of the module + * author, because any changes since the inclusion into anope + * are not supported by the original author. + */ + +#include "module.h" + +#define AUTHOR "Rob" + +/* Configuration variables */ +int HSRequestMemoUser = 0; +int HSRequestMemoOper = 0; +int HSRequestMemoSetters = 0; + +/* Language defines */ +enum +{ + LNG_REQUEST_SYNTAX, + LNG_REQUESTED, + LNG_REQUEST_WAIT, + LNG_REQUEST_MEMO, + LNG_ACTIVATE_SYNTAX, + LNG_ACTIVATED, + LNG_ACTIVATE_MEMO, + LNG_REJECT_SYNTAX, + LNG_REJECTED, + LNG_REJECT_MEMO, + LNG_REJECT_MEMO_REASON, + LNG_NO_REQUEST, + LNG_HELP, + LNG_HELP_SETTER, + LNG_HELP_REQUEST, + LNG_HELP_ACTIVATE, + LNG_HELP_ACTIVATE_MEMO, + LNG_HELP_REJECT, + LNG_HELP_REJECT_MEMO, + LNG_WAITING_SYNTAX, + LNG_HELP_WAITING, + LNG_NUM_STRINGS +}; + +void my_add_host_request(char *nick, char *vIdent, char *vhost, char *creator, time_t tmp_time); +int my_isvalidchar(const char c); +void my_memo_lang(User *u, const char *name, int z, int number, ...); +void req_send_memos(User *u, char *vIdent, char *vHost); + +void my_load_config(); +void my_add_languages(); + +struct HostRequest +{ + std::string ident; + std::string host; + time_t time; +}; + +std::map<ci::string, HostRequest *> Requests; + +static Module *me; + +class CommandHSRequest : public Command +{ + public: + CommandHSRequest() : Command("REQUEST", 1, 1) + { + } + + CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + { + const char *nick; + const char *rawhostmask = params[0].c_str(); + char *hostmask = new char[Config.HostLen]; + NickAlias *na; + char *s; + char *vIdent = NULL; + time_t now = time(NULL); + + nick = u->nick.c_str(); + + vIdent = myStrGetOnlyToken(rawhostmask, '@', 0); /* Get the first substring, @ as delimiter */ + if (vIdent) + { + rawhostmask = myStrGetTokenRemainder(rawhostmask, '@', 1); /* get the remaining string */ + if (!rawhostmask) + { + me->NoticeLang(Config.s_HostServ, u, LNG_REQUEST_SYNTAX); + delete [] vIdent; + delete [] hostmask; + return MOD_CONT; + } + if (strlen(vIdent) > Config.UserLen) + { + notice_lang(Config.s_HostServ, u, HOST_SET_IDENTTOOLONG, Config.UserLen); + delete [] vIdent; + delete [] rawhostmask; + delete [] hostmask; + return MOD_CONT; + } + else + for (s = vIdent; *s; ++s) + if (!my_isvalidchar(*s)) + { + notice_lang(Config.s_HostServ, u, HOST_SET_IDENT_ERROR); + delete [] vIdent; + delete [] rawhostmask; + delete [] hostmask; + return MOD_CONT; + } + if (!ircd->vident) + { + notice_lang(Config.s_HostServ, u, HOST_NO_VIDENT); + delete [] vIdent; + delete [] rawhostmask; + delete [] hostmask; + return MOD_CONT; + } + } + if (strlen(rawhostmask) < Config.HostLen) + snprintf(hostmask, Config.HostLen, "%s", rawhostmask); + else + { + notice_lang(Config.s_HostServ, u, HOST_SET_TOOLONG, Config.HostLen); + if (vIdent) + { + delete [] vIdent; + delete [] rawhostmask; + } + delete [] hostmask; + return MOD_CONT; + } + + if (!isValidHost(hostmask, 3)) + { + notice_lang(Config.s_HostServ, u, HOST_SET_ERROR); + if (vIdent) + { + delete [] vIdent; + delete [] rawhostmask; + } + delete [] hostmask; + return MOD_CONT; + } + + if ((na = findnick(nick))) + { + if ((HSRequestMemoOper || HSRequestMemoSetters) && Config.MSSendDelay > 0 && u && u->lastmemosend + Config.MSSendDelay > now) + { + me->NoticeLang(Config.s_HostServ, u, LNG_REQUEST_WAIT, Config.MSSendDelay); + u->lastmemosend = now; + if (vIdent) + { + delete [] vIdent; + delete [] rawhostmask; + } + delete [] hostmask; + return MOD_CONT; + } + my_add_host_request(const_cast<char *>(nick), vIdent, hostmask, const_cast<char *>(u->nick.c_str()), now); + + me->NoticeLang(Config.s_HostServ, u, LNG_REQUESTED); + req_send_memos(u, vIdent, hostmask); + Alog() << "New vHost Requested by " << nick; + } + else + notice_lang(Config.s_HostServ, u, HOST_NOREG, nick); + + if (vIdent) + { + delete [] vIdent; + delete [] rawhostmask; + } + delete [] hostmask; + + return MOD_CONT; + } + + bool OnHelp(User *u, const ci::string &subcommand) + { + me->NoticeLang(Config.s_HostServ, u, LNG_REQUEST_SYNTAX); + u->SendMessage(Config.s_HostServ, " "); + me->NoticeLang(Config.s_HostServ, u, LNG_HELP_REQUEST); + + return true; + } + + void OnSyntaxError(User *u, const ci::string &subcommand) + { + me->NoticeLang(Config.s_HostServ, u, LNG_REQUEST_SYNTAX); + } + + void OnServHelp(User *u) + { + me->NoticeLang(Config.s_HostServ, u, LNG_HELP); + } +}; + +class CommandHSActivate : public Command +{ + public: + CommandHSActivate() : Command("ACTIVATE", 1, 1, "hostserv/set") + { + } + + CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + { + const char *nick = params[0].c_str(); + NickAlias *na; + + if ((na = findnick(nick))) + { + std::map<ci::string, HostRequest *>::iterator it = Requests.find(na->nick); + if (it != Requests.end()) + { + na->hostinfo.SetVhost(it->second->ident, it->second->host, u->nick, it->second->time); + delete it->second; + Requests.erase(it); + + if (HSRequestMemoUser) + my_memo_lang(u, na->nick, 2, LNG_ACTIVATE_MEMO); + + me->NoticeLang(Config.s_HostServ, u, LNG_ACTIVATED, nick); + Alog() << "Host Request for " << nick << " activated by " << u->nick; + } + else + me->NoticeLang(Config.s_HostServ, u, LNG_NO_REQUEST, nick); + } + else + notice_lang(Config.s_HostServ, u, NICK_X_NOT_REGISTERED, nick); + + return MOD_CONT; + } + + bool OnHelp(User *u, const ci::string &subcommand) + { + me->NoticeLang(Config.s_HostServ, u, LNG_ACTIVATE_SYNTAX); + u->SendMessage(Config.s_HostServ, " "); + me->NoticeLang(Config.s_HostServ, u, LNG_HELP_ACTIVATE); + if (HSRequestMemoUser) + me->NoticeLang(Config.s_HostServ, u, LNG_HELP_ACTIVATE_MEMO); + + return true; + } + + void OnSyntaxError(User *u, const ci::string &subcommand) + { + me->NoticeLang(Config.s_HostServ, u, LNG_ACTIVATE_SYNTAX); + } + + void OnServHelp(User *u) + { + me->NoticeLang(Config.s_HostServ, u, LNG_HELP_SETTER); + } +}; + +class CommandHSReject : public Command +{ + public: + CommandHSReject() : Command("REJECT", 1, 2, "hostserv/set") + { + } + + CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + { + const char *nick = params[0].c_str(); + const char *reason = params.size() > 1 ? params[1].c_str() : NULL; + + std::map<ci::string, HostRequest *>::iterator it = Requests.find(nick); + if (it != Requests.end()) + { + delete it->second; + Requests.erase(it); + + if (HSRequestMemoUser) + { + if (reason) + my_memo_lang(u, nick, 2, LNG_REJECT_MEMO_REASON, reason); + else + my_memo_lang(u, nick, 2, LNG_REJECT_MEMO); + } + + me->NoticeLang(Config.s_HostServ, u, LNG_REJECTED, nick); + Alog() << "Host Request for " << nick << " rejected by " << u->nick << " (" << (reason ? reason : "") << ")"; + } + else + me->NoticeLang(Config.s_HostServ, u, LNG_NO_REQUEST, nick); + + return MOD_CONT; + } + + bool OnHelp(User *u, const ci::string &subcommand) + { + me->NoticeLang(Config.s_HostServ, u, LNG_REJECT_SYNTAX); + u->SendMessage(Config.s_HostServ, " "); + me->NoticeLang(Config.s_HostServ, u, LNG_HELP_REJECT); + if (HSRequestMemoUser) + me->NoticeLang(Config.s_HostServ, u, LNG_HELP_REJECT_MEMO); + + return true; + } + + void OnSyntaxError(User *u, const ci::string &subcommand) + { + me->NoticeLang(Config.s_HostServ, u, LNG_REJECT_SYNTAX); + } +}; + +class HSListBase : public Command +{ + protected: + CommandReturn DoList(User *u) + { + char buf[BUFSIZE]; + int counter = 1; + int from = 0, to = 0; + unsigned display_counter = 0; + tm *tm; + + for (std::map<ci::string, HostRequest *>::iterator it = Requests.begin(), it_end = Requests.end(); it != it_end; ++it) + { + HostRequest *hr = it->second; + if (((counter >= from && counter <= to) || (!from && !to)) && display_counter < Config.NSListMax) + { + ++display_counter; + tm = localtime(&hr->time); + strftime(buf, sizeof(buf), getstring(u, STRFTIME_DATE_TIME_FORMAT), tm); + if (!hr->ident.empty()) + notice_lang(Config.s_HostServ, u, HOST_IDENT_ENTRY, counter, it->first.c_str(), hr->ident.c_str(), hr->host.c_str(), it->first.c_str(), buf); + else + notice_lang(Config.s_HostServ, u, HOST_ENTRY, counter, it->first.c_str(), hr->host.c_str(), it->first.c_str(), buf); + } + ++counter; + } + notice_lang(Config.s_HostServ, u, HOST_LIST_FOOTER, display_counter); + + return MOD_CONT; + } + public: + HSListBase(const ci::string &cmd, int min, int max) : Command(cmd, min, max, "hostserv/set") + { + } + + void OnSyntaxError(User *u, const ci::string &subcommand) + { + // no-op + } +}; + +class CommandHSWaiting : public HSListBase +{ + public: + CommandHSWaiting() : HSListBase("WAITING", 0, 0) + { + } + + CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + { + return this->DoList(u); + } + + bool OnHelp(User *u, const ci::string &subcommand) + { + me->NoticeLang(Config.s_HostServ, u, LNG_WAITING_SYNTAX); + u->SendMessage(Config.s_HostServ, " "); + me->NoticeLang(Config.s_HostServ, u, LNG_HELP_WAITING); + + return true; + } +}; + +class HSRequest : public Module +{ + public: + HSRequest(const std::string &modname, const std::string &creator) : Module(modname, creator) + { + me = this; + + this->AddCommand(HostServ, new CommandHSRequest()); + this->AddCommand(HostServ, new CommandHSActivate()); + this->AddCommand(HostServ, new CommandHSReject()); + this->AddCommand(HostServ, new CommandHSWaiting()); + + this->SetAuthor(AUTHOR); + this->SetType(SUPPORTED); + + my_load_config(); + + const char* langtable_en_us[] = { + /* LNG_REQUEST_SYNTAX */ + "Syntax: \002REQUEST \037vhost\037\002", + /* LNG_REQUESTED */ + "Your vHost has been requested", + /* LNG_REQUEST_WAIT */ + "Please wait %d seconds before requesting a new vHost", + /* LNG_REQUEST_MEMO */ + "[auto memo] vHost \002%s\002 has been requested.", + /* LNG_ACTIVATE_SYNTAX */ + "Syntax: \002ACTIVATE \037nick\037\002", + /* LNG_ACTIVATED */ + "vHost for %s has been activated", + /* LNG_ACTIVATE_MEMO */ + "[auto memo] Your requested vHost has been approved.", + /* LNG_REJECT_SYNTAX */ + "Syntax: \002REJECT \037nick\037\002", + /* LNG_REJECTED */ + "vHost for %s has been rejected", + /* LNG_REJECT_MEMO */ + "[auto memo] Your requested vHost has been rejected.", + /* LNG_REJECT_MEMO_REASON */ + "[auto memo] Your requested vHost has been rejected. Reason: %s", + /* LNG_NO_REQUEST */ + "No request for nick %s found.", + /* LNG_HELP */ + " REQUEST Request a vHost for your nick", + /* LNG_HELP_SETTER */ + " ACTIVATE Approve the requested vHost of a user\n" + " REJECT Reject the requested vHost of a user\n" + " WAITING Convenience command for LIST +req", + /* LNG_HELP_REQUEST */ + "Request the given vHost to be actived for your nick by the\n" + "network administrators. Please be patient while your request\n" + "is being considered.", + /* LNG_HELP_ACTIVATE */ + "Activate the requested vHost for the given nick.", + /* LNG_HELP_ACTIVATE_MEMO */ + "A memo informing the user will also be sent.", + /* LNG_HELP_REJECT */ + "Reject the requested vHost for the given nick.", + /* LNG_HELP_REJECT_MEMO */ + "A memo informing the user will also be sent.", + /* LNG_WAITING_SYNTAX */ + "Syntax: \002WAITING\002", + /* LNG_HELP_WAITING */ + "This command is provided for convenience. It is essentially\n" + "the same as performing a LIST +req ." + }; + + const char* langtable_nl[] = { + /* LNG_REQUEST_SYNTAX */ + "Gebruik: \002REQUEST \037vhost\037\002", + /* LNG_REQUESTED */ + "Je vHost is aangevraagd", + /* LNG_REQUEST_WAIT */ + "Wacht %d seconden voor je een nieuwe vHost aanvraagt", + /* LNG_REQUEST_MEMO */ + "[auto memo] vHost \002%s\002 is aangevraagd.", + /* LNG_ACTIVATE_SYNTAX */ + "Gebruik: \002ACTIVATE \037nick\037\002", + /* LNG_ACTIVATED */ + "vHost voor %s is geactiveerd", + /* LNG_ACTIVATE_MEMO */ + "[auto memo] Je aangevraagde vHost is geaccepteerd.", + /* LNG_REJECT_SYNTAX */ + "Gebruik: \002REJECT \037nick\037\002", + /* LNG_REJECTED */ + "vHost voor %s is afgekeurd", + /* LNG_REJECT_MEMO */ + "[auto memo] Je aangevraagde vHost is afgekeurd.", + /* LNG_REJECT_MEMO_REASON */ + "[auto memo] Je aangevraagde vHost is afgekeurd. Reden: %s", + /* LNG_NO_REQUEST */ + "Geen aanvraag voor nick %s gevonden.", + /* LNG_HELP */ + " REQUEST Vraag een vHost aan voor je nick", + /* LNG_HELP_SETTER */ + " ACTIVATE Activeer de aangevraagde vHost voor een gebruiker\n" + " REJECT Keur de aangevraagde vHost voor een gebruiker af\n" + " WAITING Snelkoppeling naar LIST +req", + /* LNG_HELP_REQUEST */ + "Verzoek de gegeven vHost te activeren voor jouw nick bij de\n" + "netwerk beheerders. Het kan even duren voordat je aanvraag\n" + "afgehandeld wordt.", + /* LNG_HELP_ACTIVATE */ + "Activeer de aangevraagde vHost voor de gegeven nick.", + /* LNG_HELP_ACTIVATE_MEMO */ + "Een memo die de gebruiker op de hoogste stelt zal ook worden verstuurd.", + /* LNG_HELP_REJECT */ + "Keur de aangevraagde vHost voor de gegeven nick af.", + /* LNG_HELP_REJECT_MEMO */ + "Een memo die de gebruiker op de hoogste stelt zal ook worden verstuurd.", + /* LNG_WAITING_SYNTAX */ + "Gebruik: \002WAITING\002", + /* LNG_HELP_WAITING */ + "Dit commando is beschikbaar als handigheid. Het is simpelweg\n" + "hetzelfde als LIST +req ." + }; + + const char* langtable_pt[] = { + /* LNG_REQUEST_SYNTAX */ + "Sintaxe: \002REQUEST \037vhost\037\002", + /* LNG_REQUESTED */ + "Seu pedido de vHost foi encaminhado", + /* LNG_REQUEST_WAIT */ + "Por favor, espere %d segundos antes de fazer um novo pedido de vHost", + /* LNG_REQUEST_MEMO */ + "[Auto Memo] O vHost \002%s\002 foi solicitado.", + /* LNG_ACTIVATE_SYNTAX */ + "Sintaxe: \002ACTIVATE \037nick\037\002", + /* LNG_ACTIVATED */ + "O vHost para %s foi ativado", + /* LNG_ACTIVATE_MEMO */ + "[Auto Memo] Seu pedido de vHost foi aprovado.", + /* LNG_REJECT_SYNTAX */ + "Sintaxe: \002REJECT \037nick\037\002", + /* LNG_REJECTED */ + "O vHost de %s foi recusado", + /* LNG_REJECT_MEMO */ + "[Auto Memo] Seu pedido de vHost foi recusado.", + /* LNG_REJECT_MEMO_REASON */ + "[Auto Memo] Seu pedido de vHost foi recusado. Motivo: %s", + /* LNG_NO_REQUEST */ + "Nenhum pedido encontrado para o nick %s.", + /* LNG_HELP */ + " REQUEST Request a vHost for your nick", + /* LNG_HELP_SETTER */ + " ACTIVATE Aprova o pedido de vHost de um usuбrio\n" + " REJECT Recusa o pedido de vHost de um usuбrio\n" + " WAITING Comando para LISTAR +req", + /* LNG_HELP_REQUEST */ + "Solicita a ativaзгo do vHost fornecido em seu nick pelos\n" + "administradores da rede. Por favor, tenha paciкncia\n" + "enquanto seu pedido й analisado.", + /* LNG_HELP_ACTIVATE */ + "Ativa o vHost solicitado para o nick fornecido.", + /* LNG_HELP_ACTIVATE_MEMO */ + "Um memo informando o usuбrio tambйm serб enviado.", + /* LNG_HELP_REJECT */ + "Recusa o pedido de vHost para o nick fornecido.", + /* LNG_HELP_REJECT_MEMO */ + "Um memo informando o usuбrio tambйm serб enviado.", + /* LNG_WAITING_SYNTAX */ + "Sintaxe: \002WAITING\002", + /* LNG_HELP_WAITING */ + "Este comando й usado por conveniкncia. Й essencialmente\n" + "o mesmo que fazer um LIST +req" + }; + + const char* langtable_ru[] = { + /* LNG_REQUEST_SYNTAX */ + "Синтаксис: \002REQUEST \037vHost\037\002", + /* LNG_REQUESTED */ + "Ваш запрос на vHost отправлен.", + /* LNG_REQUEST_WAIT */ + "Пожалуйста, подождите %d секунд, прежде чем запрашивать новый vHost", + /* LNG_REQUEST_MEMO */ + "[авто-сообщение] Был запрошен vHost \002%s\002", + /* LNG_ACTIVATE_SYNTAX */ + "Синтаксис: \002ACTIVATE \037ник\037\002", + /* LNG_ACTIVATED */ + "vHost для %s успешно активирован", + /* LNG_ACTIVATE_MEMO */ + "[авто-сообщение] Запрашиваемый вами vHost утвержден и активирован.", + /* LNG_REJECT_SYNTAX */ + "Синтаксис: \002REJECT \037ник\037\002", + /* LNG_REJECTED */ + "vHost для %s отклонен.", + /* LNG_REJECT_MEMO */ + "[авто-сообщение] Запрашиваемый вами vHost отклонен.", + /* LNG_REJECT_MEMO_REASON */ + "[авто-сообщение] Запрашиваемый вами vHost отклонен. Причина: %s", + /* LNG_NO_REQUEST */ + "Запрос на vHost для ника %s не найден.", + /* LNG_HELP */ + " REQUEST Запрос на vHost для вашего текущего ника", + /* LNG_HELP_SETTER */ + " ACTIVATE Утвердить запрашиваемый пользователем vHost\n" + " REJECT Отклонить запрашиваемый пользователем vHost\n" + " WAITING Список запросов ожидающих обработки (аналог LIST +req)", + /* LNG_HELP_REQUEST */ + "Отправляет запрос на активацию vHost, который будет рассмотрен одним из\n" + "администраторов сети. Просьба проявить терпение, пока запрос\n" + "рассматривается администрацией.", + /* LNG_HELP_ACTIVATE */ + "Утвердить запрашиваемый vHost для указанного ника.", + /* LNG_HELP_ACTIVATE_MEMO */ + "Пользователю будет послано авто-уведомление об активации его запроса.", + /* LNG_HELP_REJECT */ + "Отклонить запрашиваемый vHost для указанного ника.", + /* LNG_HELP_REJECT_MEMO */ + "Пользователю будет послано авто-уведомление об отклонении его запроса.", + /* LNG_WAITING_SYNTAX */ + "Синтаксис: \002WAITING\002", + /* LNG_HELP_WAITING */ + "Данная команда создана для удобства использования и выводит список запросов,\n" + "ожидающих обработки. Аналогичная команда: LIST +req ." + }; + + const char* langtable_it[] = { + /* LNG_REQUEST_SYNTAX */ + "Sintassi: \002REQUEST \037vhost\037\002", + /* LNG_REQUESTED */ + "Il tuo vHost и stato richiesto", + /* LNG_REQUEST_WAIT */ + "Prego attendere %d secondi prima di richiedere un nuovo vHost", + /* LNG_REQUEST_MEMO */ + "[auto memo] и stato richiesto il vHost \002%s\002.", + /* LNG_ACTIVATE_SYNTAX */ + "Sintassi: \002ACTIVATE \037nick\037\002", + /* LNG_ACTIVATED */ + "Il vHost per %s и stato attivato", + /* LNG_ACTIVATE_MEMO */ + "[auto memo] Il vHost da te richiesto и stato approvato.", + /* LNG_REJECT_SYNTAX */ + "Sintassi: \002REJECT \037nick\037\002", + /* LNG_REJECTED */ + "Il vHost per %s и stato rifiutato", + /* LNG_REJECT_MEMO */ + "[auto memo] Il vHost da te richiesto и stato rifiutato.", + /* LNG_REJECT_MEMO_REASON */ + "[auto memo] Il vHost da te richiesto и stato rifiutato. Motivo: %s", + /* LNG_NO_REQUEST */ + "Nessuna richiesta trovata per il nick %s.", + /* LNG_HELP */ + " REQUEST Richiede un vHost per il tuo nick", + /* LNG_HELP_SETTER */ + " ACTIVATE Approva il vHost richiesto di un utente\n" + " REJECT Rifiuta il vHost richiesto di un utente\n" + " WAITING Comando per LIST +req", + /* LNG_HELP_REQUEST */ + "Richiede l'attivazione del vHost specificato per il tuo nick da parte\n" + "degli amministratori di rete. Sei pregato di pazientare finchи la tua\n" + "richiesta viene elaborata.", + /* LNG_HELP_ACTIVATE */ + "Attiva il vHost richiesto per il nick specificato.", + /* LNG_HELP_ACTIVATE_MEMO */ + "Viene inviato un memo per informare l'utente.", + /* LNG_HELP_REJECT */ + "Rifiuta il vHost richiesto per il nick specificato.", + /* LNG_HELP_REJECT_MEMO */ + "Viene inviato un memo per informare l'utente.", + /* LNG_WAITING_SYNTAX */ + "Sintassi: \002WAITING\002", + /* LNG_HELP_WAITING */ + "Questo comando и per comoditа. Praticamente и la stessa cosa che\n" + "eseguire un LIST +req ." + }; + + this->InsertLanguage(LANG_EN_US, LNG_NUM_STRINGS, langtable_en_us); + this->InsertLanguage(LANG_NL, LNG_NUM_STRINGS, langtable_nl); + this->InsertLanguage(LANG_PT, LNG_NUM_STRINGS, langtable_pt); + this->InsertLanguage(LANG_RU, LNG_NUM_STRINGS, langtable_ru); + this->InsertLanguage(LANG_IT, LNG_NUM_STRINGS, langtable_it); + + Implementation i[] = { I_OnPreCommand, I_OnDatabaseRead, I_OnDatabaseWrite }; + ModuleManager::Attach(i, this, 3); + } + + ~HSRequest() + { + /* Clean up all open host requests */ + while (!Requests.empty()) + { + delete Requests.begin()->second; + Requests.erase(Requests.begin()); + } + } + + EventReturn OnPreCommand(User *u, const std::string &service, const ci::string &command, const std::vector<ci::string> ¶ms) + { + if (Config.s_HostServ && service == Config.s_HostServ) + { + if (command == "LIST") + { + ci::string key = params.size() ? params[0] : ""; + + if (!key.empty() && key == "+req") + { + std::vector<ci::string> emptyParams; + Command *c = FindCommand(HostServ, "WAITING"); + c->Execute(u, emptyParams); + return EVENT_STOP; + } + } + } + else if (service == Config.s_NickServ) + { + if (command == "DROP") + { + NickAlias *na = findnick(u->nick); + + if (na) + { + std::map<ci::string, HostRequest *>::iterator it = Requests.find(na->nick); + + if (it != Requests.end()) + { + delete it->second; + Requests.erase(it); + } + } + } + } + + return EVENT_CONTINUE; + } + + EventReturn OnDatabaseRead(const std::vector<std::string> ¶ms) + { + if (params[0] == "HS_REQUEST" && params.size() >= 5) + { + char *vident = params[2] == "(null)" ? NULL : const_cast<char *>(params[2].c_str()); + my_add_host_request(const_cast<char *>(params[1].c_str()), vident, const_cast<char *>(params[3].c_str()), const_cast<char *>(params[1].c_str()), strtol(params[4].c_str(), NULL, 10)); + + return EVENT_STOP; + } + + return EVENT_CONTINUE; + } + + void OnDatabaseWrite(void (*Write)(const std::string &)) + { + for (std::map<ci::string, HostRequest *>::iterator it = Requests.begin(), it_end = Requests.end(); it != it_end; ++it) + { + HostRequest *hr = it->second; + std::stringstream buf; + buf << "HS_REQUEST " << it->first << " " << (hr->ident.empty() ? "(null)" : hr->ident) << " " << hr->host << " " << hr->time; + Write(buf.str()); + } + } +}; + +void my_memo_lang(User *u, const char *name, int z, int number, ...) +{ + va_list va; + char buffer[4096], outbuf[4096]; + char *fmt = NULL; + int lang = LANG_EN_US; + char *s, *t, *buf; + User *u2; + + u2 = finduser(name); + /* Find the users lang, and use it if we cant */ + if (u2 && u2->Account()) + lang = u2->Account()->language; + + /* If the users lang isnt supported, drop back to enlgish */ + if (!me->lang[lang].argc) + lang = LANG_EN_US; + + /* If the requested lang string exists for the language */ + if (me->lang[lang].argc > number) + { + fmt = me->lang[lang].argv[number]; + + buf = sstrdup(fmt); + s = buf; + while (*s) + { + t = s; + s += strcspn(s, "\n"); + if (*s) + *s++ = '\0'; + strscpy(outbuf, t, sizeof(outbuf)); + + va_start(va, number); + vsnprintf(buffer, 4095, outbuf, va); + va_end(va); + memo_send(u, name, buffer, z); + } + delete [] buf; + } + else + Alog() << me->name << ": INVALID language string call, language: [" << lang << "], String [" << number << "]"; +} + +void req_send_memos(User *u, char *vIdent, char *vHost) +{ + int z = 2; + char host[BUFSIZE]; + std::list<std::pair<ci::string, ci::string> >::iterator it, it_end; + + if (vIdent) + snprintf(host, sizeof(host), "%s@%s", vIdent, vHost); + else + snprintf(host, sizeof(host), "%s", vHost); + + if (HSRequestMemoOper == 1) + for (it = Config.Opers.begin(), it_end = Config.Opers.end(); it != it_end; ++it) + { + ci::string nick = it->first; + my_memo_lang(u, nick.c_str(), z, LNG_REQUEST_MEMO, host); + } + if (HSRequestMemoSetters == 1) + { + /* Needs to be rethought because of removal of HostSetters in favor of opertype priv -- CyberBotX + for (i = 0; i < HostNumber; ++i) + my_memo_lang(u, HostSetters[i], z, LNG_REQUEST_MEMO, host);*/ + } +} + +void my_add_host_request(char *nick, char *vIdent, char *vhost, char *creator, time_t tmp_time) +{ + HostRequest *hr = new HostRequest; + hr->ident = vIdent ? vIdent : ""; + hr->host = vhost; + hr->time = tmp_time; + std::map<ci::string, HostRequest *>::iterator it = Requests.find(nick); + if (it != Requests.end()) + { + delete it->second; + Requests.erase(it); + } + Requests.insert(std::make_pair(nick, hr)); +} + +int my_isvalidchar(const char c) +{ + if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '.' || c == '-') + return 1; + else + return 0; +} + +void my_load_config() +{ + ConfigReader config; + HSRequestMemoUser = config.ReadFlag("hs_request", "memouser", "no", 0); + HSRequestMemoOper = config.ReadFlag("hs_request", "memooper", "no", 0); + HSRequestMemoSetters = config.ReadFlag("hs_request", "memosetters", "no", 0); + + Alog(LOG_DEBUG) << "[hs_request] Set config vars: MemoUser=" << HSRequestMemoUser << " MemoOper=" << HSRequestMemoOper << " MemoSetters=" << HSRequestMemoSetters; +} + +MODULE_INIT(HSRequest) diff --git a/modules/extra/m_helpchan.cpp b/modules/extra/m_helpchan.cpp new file mode 100644 index 000000000..c63703f33 --- /dev/null +++ b/modules/extra/m_helpchan.cpp @@ -0,0 +1,47 @@ +/* + * (C) 2003-2010 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +#include "module.h" + +class HelpChannel : public Module +{ + ci::string HelpChan; + + public: + HelpChannel(const std::string &modname, const std::string &creator) : Module(modname, creator) + { + this->SetAuthor("Anope"); + this->SetType(SUPPORTED); + + Implementation i[] = { I_OnChannelModeSet, I_OnReload }; + ModuleManager::Attach(i, this, 2); + + OnReload(true); + } + + EventReturn OnChannelModeSet(Channel *c, ChannelModeName Name, const std::string ¶m) + { + if (Name == CMODE_OP && c && c->ci && c->name == this->HelpChan) + { + User *u = finduser(param); + + if (u) + u->SetMode(OperServ, UMODE_HELPOP); + } + + return EVENT_CONTINUE; + } + + void OnReload(bool) + { + ConfigReader config; + + this->HelpChan = config.ReadValue("m_helpchan", "helpchannel", "", 0).c_str(); + } +}; + +MODULE_INIT(HelpChannel) diff --git a/modules/extra/m_ssl.cpp b/modules/extra/m_ssl.cpp new file mode 100644 index 000000000..0771e6d4c --- /dev/null +++ b/modules/extra/m_ssl.cpp @@ -0,0 +1,142 @@ +/* RequiredLibraries: ssl,crypt */ + +#include "module.h" + +#define OPENSSL_NO_SHA512 +#include <openssl/bio.h> +#include <openssl/ssl.h> +#include <openssl/err.h> +#include <openssl/crypto.h> +#include <openssl/evp.h> + +#define CERTFILE "anope.cert" +#define KEYFILE "anope.key" + +static SSL_CTX *ctx; + +class SSLSocket : public ClientSocket +{ + private: + SSL *sslsock; + + const int RecvInternal(char *buf, size_t sz) const + { + return SSL_read(sslsock, buf, sz); + } + + const int SendInternal(const std::string &buf) const + { + return SSL_write(sslsock, buf.c_str(), buf.size()); + } + public: + SSLSocket(const std::string &nTargetHost, int nPort, const std::string &nBindHost = "", bool nIPv6 = false) : ClientSocket(nTargetHost, nPort, nBindHost, nIPv6) + { + sslsock = SSL_new(ctx); + + if (!sslsock) + throw CoreException("Unable to initialize SSL socket"); + + SSL_set_connect_state(sslsock); + SSL_set_fd(sslsock, sock); + SSL_connect(sslsock); + + UplinkSock = this; + } + + ~SSLSocket() + { + SSL_shutdown(sslsock); + SSL_free(sslsock); + + UplinkSock = NULL; + } + + bool Read(const std::string &buf) + { + process(buf); + return true; + } +}; + +class SSLModule : public Module +{ + public: + SSLModule(const std::string &modname, const std::string &creator) : Module(modname, creator) + { + SSL_load_error_strings(); + SSLeay_add_ssl_algorithms(); + + ctx = SSL_CTX_new(SSLv23_client_method()); + + if (!ctx) + throw ModuleException("Error initializing SSL CTX"); + + if (IsFile(CERTFILE)) + { + if (!SSL_CTX_use_certificate_file(ctx, CERTFILE, SSL_FILETYPE_PEM)) + { + SSL_CTX_free(ctx); + throw ModuleException("Error loading certificate"); + } + } + else + Alog() << "m_ssl: No certificate file found"; + + if (IsFile(KEYFILE)) + { + if (!SSL_CTX_use_PrivateKey_file(ctx, KEYFILE, SSL_FILETYPE_PEM)) + { + SSL_CTX_free(ctx); + throw ModuleException("Error loading private key"); + } + } + else + { + if (IsFile(CERTFILE)) + { + SSL_CTX_free(ctx); + throw ModuleException("Error loading private key - file not found"); + } + else + Alog() << "m_ssl: No private key found"; + } + + this->SetAuthor("Anope"); + this->SetType(SUPPORTED); + this->SetPermanent(true); + + SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv2); + SSL_CTX_set_options(ctx, SSL_OP_TLS_ROLLBACK_BUG | SSL_OP_ALL); + + ModuleManager::Attach(I_OnPreServerConnect, this); + } + + ~SSLModule() + { + SSL_CTX_free(ctx); + } + + EventReturn OnPreServerConnect(Uplink *u, int Number) + { + ConfigReader config; + + if (config.ReadFlag("uplink", "ssl", "no", Number - 1)) + { + try + { + new SSLSocket(u->host, u->port, Config.LocalHost ? Config.LocalHost : "", u->ipv6); + Alog() << "Connected to Server " << Number << " (" << u->host << ":" << u->port << ")"; + } + catch (SocketException& ex) + { + Alog() << "Unable to connect with SSL to server" << Number << " (" << u->host << ":" << u->port << "), " << ex.GetReason(); + } + + return EVENT_ALLOW; + } + + return EVENT_CONTINUE; + } +}; + +MODULE_INIT(SSLModule) diff --git a/modules/extra/mysql/db_mysql.h b/modules/extra/mysql/db_mysql.h new file mode 100644 index 000000000..32a2469c9 --- /dev/null +++ b/modules/extra/mysql/db_mysql.h @@ -0,0 +1,211 @@ +#ifndef DB_MYSQL_H +#define DB_MYSQL_H + +#include "module.h" + +struct NickAliasFlagInfo +{ + std::string Name; + NickNameFlag Flag; +}; + +NickAliasFlagInfo NickAliasFlags[] = { + {"FORBIDDEN", NS_FORBIDDEN}, + {"NOEXPIRE", NS_NO_EXPIRE}, + {"", static_cast<NickNameFlag>(-1)} +}; + +struct NickCoreFlagInfo +{ + std::string Name; + NickCoreFlag Flag; +}; + +NickCoreFlagInfo NickCoreFlags[] = { + {"KILLPROTECT", NI_KILLPROTECT}, + {"SECURE", NI_SECURE}, + {"MSG", NI_MSG}, + {"MEMO_HARDMAX", NI_MEMO_HARDMAX}, + {"MEMO_SIGNON", NI_MEMO_SIGNON}, + {"MEMO_RECEIVE", NI_MEMO_RECEIVE}, + {"PRIVATE", NI_PRIVATE}, + {"HIDE_EMAIL", NI_HIDE_EMAIL}, + {"HIDE_MASK", NI_HIDE_MASK}, + {"HIDE_QUIT", NI_HIDE_QUIT}, + {"KILL_QUICK", NI_KILL_QUICK}, + {"KILL_IMMED", NI_KILL_IMMED}, + {"MEMO_MAIL", NI_MEMO_MAIL}, + {"HIDE_STATUS", NI_HIDE_STATUS}, + {"SUSPENDED", NI_SUSPENDED}, + {"AUTOOP", NI_AUTOOP}, + {"FORBIDDEN", NI_FORBIDDEN}, + {"", static_cast<NickCoreFlag>(-1)} +}; + +struct BotFlagInfo +{ + std::string Name; + BotServFlag Flag; +}; + +BotFlagInfo BotFlags[] = { + {"DONTKICKOPS", BS_DONTKICKOPS}, + {"DONTKICKVOICES", BS_DONTKICKVOICES}, + {"FANTASY", BS_FANTASY}, + {"SYMBIOSIS", BS_SYMBIOSIS}, + {"GREET", BS_GREET}, + {"NOBOT", BS_NOBOT}, + {"KICK_BOLDS", BS_KICK_BOLDS}, + {"KICK_COLORS", BS_KICK_COLORS}, + {"KICK_REVERSES", BS_KICK_REVERSES}, + {"KICK_UNDERLINES", BS_KICK_UNDERLINES}, + {"KICK_BADWORDS", BS_KICK_BADWORDS}, + {"KICK_CAPS", BS_KICK_CAPS}, + {"KICK_FLOOD", BS_KICK_FLOOD}, + {"KICK_REPEAT", BS_KICK_REPEAT}, + {"", static_cast<BotServFlag>(-1)} +}; + +struct ChannelFlagInfo +{ + std::string Name; + ChannelInfoFlag Flag; +}; + +ChannelFlagInfo ChannelFlags[] = { + {"KEEPTOPIC", CI_KEEPTOPIC}, + {"SECUREOPS", CI_SECUREOPS}, + {"PRIVATE", CI_PRIVATE}, + {"TOPICLOCK", CI_TOPICLOCK}, + {"RESTRICTED", CI_RESTRICTED}, + {"PEACE", CI_PEACE}, + {"SECURE", CI_SECURE}, + {"FORBIDDEN", CI_FORBIDDEN}, + {"NO_EXPIRE", CI_NO_EXPIRE}, + {"MEMO_HARDMAX", CI_MEMO_HARDMAX}, + {"OPNOTICE", CI_OPNOTICE}, + {"SECUREFOUNDER", CI_SECUREFOUNDER}, + {"SIGNKICK", CI_SIGNKICK}, + {"SIGNKICK_LEVEL", CI_SIGNKICK_LEVEL}, + {"XOP", CI_XOP}, + {"SUSPENDED", CI_SUSPENDED}, + {"PERSIST", CI_PERSIST}, + {"", static_cast<ChannelInfoFlag>(-1)} +}; + +struct BotServFlagInfo +{ + std::string Name; + BotFlag Flag; +}; + +BotServFlagInfo BotServFlags[] = { + {"PRIVATE", BI_PRIVATE}, + {"", static_cast<BotFlag>(-1)} +}; + +struct MemoFlagInfo +{ + std::string Name; + MemoFlag Flag; +}; + +MemoFlagInfo MemoFlags[] = { + {"UNREAD", MF_UNREAD}, + {"RECEIPT", MF_RECEIPT}, + {"NOTIFYS", MF_NOTIFYS}, + {"", static_cast<MemoFlag>(-1)} +}; + +#define MYSQLPP_MYSQL_HEADERS_BURIED +#include <mysql++/mysql++.h> + +inline std::string SQLAssign(const mysqlpp::String &s) { return s.c_str(); } + +class DBMySQL; +static DBMySQL *me; + +bool ExecuteQuery(mysqlpp::Query &query) +{ + Alog(LOG_DEBUG) << "MySQL: " << query.str(); + + if (!query.execute()) + { + Alog() << "MySQL: error executing query: " << query.error(); + return false; + } + + return true; +} + +mysqlpp::StoreQueryResult StoreQuery(mysqlpp::Query &query) +{ + Alog(LOG_DEBUG) << "MySQL: " << query.str(); + + mysqlpp::StoreQueryResult result = query.store(); + if (!result) + Alog() << "MySQL: error executing query: " << query.error(); + return result; +} + +class DBMySQL : public Module +{ + private: + bool LoadConfig() + { + ConfigReader config; + + Database = config.ReadValue("mysql", "database", "anope", 0); + Server = config.ReadValue("mysql", "server", "127.0.0.1", 0); + SQLUser = config.ReadValue("mysql", "username", "anope", 0); + Password = config.ReadValue("mysql", "password", "", 0); + Port = config.ReadInteger("mysql", "port", "3306", 0, true); + Delay = config.ReadInteger("mysql", "updatedelay", "60", 0, true); + + return !Password.empty(); + } + + public: + mysqlpp::Connection *Con; + mysqlpp::NoExceptions *Ne; + + std::string Database; + std::string Server; + std::string SQLUser; + std::string Password; + unsigned int Port; + unsigned int Delay; + + DBMySQL(const std::string &modname, const std::string &creator) : Module(modname, creator) + { + me = this; + + this->SetAuthor("Anope"); + this->SetType(DATABASE); + + if (!LoadConfig()) + throw ModuleException("Couldn't load config"); + + Con = new mysqlpp::Connection(false); + Ne = new mysqlpp::NoExceptions(Con); + if (!Con->connect(Database.c_str(), Server.c_str(), SQLUser.c_str(), Password.c_str(), Port)) + { + std::string Error = "MySQL: Error connecting to SQL server: "; + Error += Con->error(); + delete Con; + throw ModuleException(Error.c_str()); + } + + mysqlpp::Query query(Con); + query << "SET NAMES 'utf8'"; + ExecuteQuery(query); + } + + virtual ~DBMySQL() + { + delete Ne; + delete Con; + } +}; + +#endif // DB_MYSQL_H diff --git a/modules/extra/mysql/db_mysql_execute.cpp b/modules/extra/mysql/db_mysql_execute.cpp new file mode 100644 index 000000000..2cc6ab6df --- /dev/null +++ b/modules/extra/mysql/db_mysql_execute.cpp @@ -0,0 +1,159 @@ +/* RequiredLibraries: mysqlpp */ + +#include "db_mysql.h" + +class FakeNickCore : public NickCore +{ + public: + FakeNickCore() : NickCore("-SQLUser") + { + NickCoreList.erase(this->display); + } + + ~FakeNickCore() + { + NickCoreList[this->display] = this; + Users.clear(); + } + + bool IsServicesOper() const { return true; } + bool HasCommand(const std::string &) const { return true; } + bool HasPriv(const std::string &) const { return true; } +} SQLCore; + +class FakeUser : public User +{ + public: + FakeUser() : User("-SQLUser", "") + { + this->SetIdent("SQL"); + this->host = sstrdup(Config.ServerName); + this->realname = sstrdup("Fake SQL User"); + this->hostip = sstrdup("255.255.255.255"); + this->vhost = NULL; + this->server = Me; + + UserListByNick.erase("-SQLUser"); + --usercnt; + } + + ~FakeUser() + { + UserListByNick["-SQLUser"] = this; + ++usercnt; + + nc = NULL; + } + + void SetNewNick(const std::string &newnick) { this->nick = newnick; } + + void SendMessage(const std::string &, const char *, ...) { } + void SendMessage(const std::string &, const std::string &) { } + + NickCore *Account() const { return nc; } + const bool IsIdentified(bool) const { return nc ? true : false; } + const bool IsRecognized(bool) const { return true; } +} SQLUser; + +class SQLTimer : public Timer +{ + public: + SQLTimer() : Timer(me->Delay, time(NULL), true) + { + mysqlpp::Query query(me->Con); + query << "TRUNCATE TABLE `anope_commands`"; + ExecuteQuery(query); + } + + void Tick(time_t) + { + mysqlpp::Query query(me->Con); + mysqlpp::StoreQueryResult qres; + + query << "SELECT * FROM `anope_commands`"; + qres = StoreQuery(query); + + if (qres && qres.num_rows()) + { + for (size_t i = 0, end = qres.num_rows(); i < end; ++i) + { + User *u; + NickAlias *na = NULL; + bool logout = false; + + /* If they want -SQLUser to execute the command, use it */ + if (qres[i]["nick"] == "-SQLUser") + { + u = &SQLUser; + u->SetNewNick("-SQLUser"); + u->Login(&SQLCore); + logout = true; + } + else + { + /* See if the nick they want to execute the command is registered */ + na = findnick(SQLAssign(qres[i]["nick"])); + if (na) + { + /* If it is and someone is online using that nick, use them */ + if (!na->nc->Users.empty()) + u = na->nc->Users.front(); + /* Make a fake nick and use that logged in as the nick we want to use */ + else + { + u = &SQLUser; + u->SetNewNick(SQLAssign(qres[i]["nick"])); + u->Login(na->nc); + logout = true; + } + } + else + { + /* Check if someone is online using the nick now */ + u = finduser(SQLAssign(qres[i]["nick"])); + /* If they arent make a fake user, and use them */ + if (!u) + { + u = &SQLUser; + u->SetNewNick(SQLAssign(qres[i]["nick"])); + u->Logout(); + logout = true; + } + } + } + + BotInfo *bi = findbot(SQLAssign(qres[i]["service"])); + if (!bi) + { + Alog() << "Warning: SQL command for unknown service " << qres[i]["service"]; + continue; + } + + mod_run_cmd(bi, u, qres[i]["command"].c_str()); + + if (logout) + u->Logout(); + } + + query << "TRUNCATE TABLE `anope_commands`"; + ExecuteQuery(query); + } + } +}; + +class DBMySQLExecute : public DBMySQL +{ + SQLTimer *_SQLTimer; + public: + DBMySQLExecute(const std::string &modname, const std::string &creator) : DBMySQL(modname, creator) + { + _SQLTimer = new SQLTimer(); + } + + ~DBMySQLExecute() + { + delete _SQLTimer; + } +}; + +MODULE_INIT(DBMySQLExecute) diff --git a/modules/extra/mysql/db_mysql_read.cpp b/modules/extra/mysql/db_mysql_read.cpp new file mode 100644 index 000000000..3ffc82366 --- /dev/null +++ b/modules/extra/mysql/db_mysql_read.cpp @@ -0,0 +1,618 @@ +/* RequiredLibraries: mysqlpp */ + +#include "db_mysql.h" + +static std::vector<std::string> MakeVector(std::string buf) +{ + std::string s; + spacesepstream sep(buf); + std::vector<std::string> params; + + while (sep.GetToken(s)) + { + if (s[0] == ':') + { + s.erase(s.begin()); + if (!s.empty() && !sep.StreamEnd()) + params.push_back(s + " " + sep.GetRemaining()); + else if (!s.empty()) + params.push_back(s); + } + else + params.push_back(s); + } + + return params; +} + +static void LoadDatabase() +{ + mysqlpp::Query query(me->Con); + mysqlpp::StoreQueryResult qres; + + query << "SELECT * FROM `anope_ns_core`"; + qres = StoreQuery(query); + + if (qres) + for (size_t i = 0, end = qres.num_rows(); i < end; ++i) + { + NickCore *nc = new NickCore(SQLAssign(qres[i]["display"])); + nc->pass = SQLAssign(qres[i]["pass"]); + if (qres[i]["email"].size()) + nc->email = sstrdup(qres[i]["email"].c_str()); + if (qres[i]["greet"].size()) + nc->greet = sstrdup(qres[i]["greet"].c_str()); + if (qres[i]["icq"].size()) + nc->icq = atol(qres[i]["icq"].c_str()); + if (qres[i]["url"].size()) + nc->url = sstrdup(qres[i]["url"].c_str()); + + spacesepstream sep(SQLAssign(qres[i]["flags"])); + std::string buf; + while (sep.GetToken(buf)) + for (int j = 0; NickCoreFlags[j].Flag != -1; ++j) + if (NickCoreFlags[j].Name == buf) + nc->SetFlag(NickCoreFlags[j].Flag); + + nc->language = atoi(qres[i]["language"].c_str()); + nc->channelcount = atoi(qres[i]["channelcount"].c_str()); + nc->memos.memomax = atoi(qres[i]["memomax"].c_str()); + } + + query << "SELECT * FROM `anope_ns_access`"; + qres = StoreQuery(query); + + if (qres) + for (size_t i = 0, end = qres.num_rows(); i < end; ++i) + { + NickCore *nc = findcore(qres[i]["display"].c_str()); + if (!nc) + { + Alog() << "MySQL: Got NickCore access entry for nonexistant core " << qres[i]["display"]; + continue; + } + + nc->AddAccess(SQLAssign(qres[i]["access"])); + } + + query << "SELECT * FROM `anope_ns_core_metadata`"; + qres = StoreQuery(query); + + if (qres) + for (size_t i = 0, end = qres.num_rows(); i < end; ++i) + { + NickCore *nc = findcore(qres[i]["display"].c_str()); + if (!nc) + { + Alog() << "MySQL: Got NickCore access entry for nonexistant core " << qres[i]["display"]; + continue; + } + EventReturn MOD_RESULT; + std::vector<std::string> Params = MakeVector(SQLAssign(qres[i]["value"])); + FOREACH_RESULT(I_OnDatabaseReadMetadata, OnDatabaseReadMetadata(nc, SQLAssign(qres[i]["name"]), Params)); + } + + query << "SELECT * FROM `anope_ns_alias`"; + qres = StoreQuery(query); + + if (qres) + for (size_t i = 0, end = qres.num_rows(); i < end; ++i) + { + NickCore *nc = findcore(qres[i]["display"].c_str()); + if (!nc) + { + Alog() << "MySQL: Got NickAlias for nick " << qres[i]["nick"] << " with nonexistant core " << qres[i]["display"]; + continue; + } + + NickAlias *na = new NickAlias(SQLAssign(qres[i]["nick"]), nc); + na->last_quit = sstrdup(qres[i]["last_quit"].c_str()); + na->last_realname = sstrdup(qres[i]["last_realname"].c_str()); + na->last_usermask = sstrdup(qres[i]["last_usermask"].c_str()); + na->time_registered = atol(qres[i]["time_registered"].c_str()); + na->last_seen = atol(qres[i]["last_seen"].c_str()); + + spacesepstream sep(SQLAssign(qres[i]["flags"])); + std::string buf; + while (sep.GetToken(buf)) + for (int j = 0; NickAliasFlags[j].Flag != -1; ++j) + if (NickAliasFlags[j].Name == buf) + na->SetFlag(NickAliasFlags[j].Flag); + } + + query << "SELECT * FROM `anope_ns_alias_metadata`"; + qres = StoreQuery(query); + + if (qres) + for (size_t i = 0, end = qres.num_rows(); i < end; ++i) + { + NickAlias *na = findnick(SQLAssign(qres[i]["nick"])); + if (!na) + { + Alog() << "MySQL: Got metadata for nonexistant nick " << qres[i]["nick"]; + continue; + } + EventReturn MOD_RESULT; + std::vector<std::string> Params = MakeVector(SQLAssign(qres[i]["value"])); + FOREACH_RESULT(I_OnDatabaseReadMetadata, OnDatabaseReadMetadata(na, SQLAssign(qres[i]["name"]), Params)); + } + + query << "SELECT * FROM `anope_bs_core`"; + qres = StoreQuery(query); + + if (qres) + for (size_t i = 0, end = qres.num_rows(); i < end; ++i) + { + BotInfo *bi = findbot(SQLAssign(qres[i]["nick"])); + if (!bi) + bi = new BotInfo(SQLAssign(qres[i]["nick"])); + bi->user = SQLAssign(qres[i]["user"]); + bi->host = SQLAssign(qres[i]["host"]); + bi->real = SQLAssign(qres[i]["rname"]); + + if (qres[i]["flags"].size()) + { + spacesepstream sep(SQLAssign(qres[i]["flags"])); + std::string buf; + while (sep.GetToken(buf)) + for (unsigned j = 0; BotServFlags[j].Flag != -1; ++j) + if (buf == BotServFlags[j].Name) + { + bi->SetFlag(BotServFlags[j].Flag); + break; + } + } + bi->created = atol(qres[i]["created"]); + bi->chancount = atol(qres[i]["chancount"]); + } + + query << "SELECT * FROM `anope_bs_info_metadata`"; + qres = StoreQuery(query); + + if (qres) + for (size_t i = 0, end = qres.num_rows(); i < end; ++i) + { + BotInfo *bi = findbot(SQLAssign(qres[i]["botname"])); + if (!bi) + { + Alog() << "MySQL: BotInfo metadata for nonexistant bot " << qres[i]["botname"]; + continue; + } + + EventReturn MOD_RESULT; + std::vector<std::string> Params = MakeVector(SQLAssign(qres[i]["value"])); + FOREACH_RESULT(I_OnDatabaseReadMetadata, OnDatabaseReadMetadata(bi, SQLAssign(qres[i]["name"]), Params)); + } + + query << "SELECT * FROM `anope_cs_info`"; + qres = StoreQuery(query); + + if (qres) + for (size_t i = 0, end = qres.num_rows(); i < end; ++i) + { + NickCore *nc; + if (qres[i]["founder"].size()) + { + nc = findcore(qres[i]["founder"].c_str()); + if (!nc) + { + Alog() << "MySQL: Channel " << qres[i]["name"] << " with nonexistant founder " << qres[i]["founder"]; + continue; + } + } + + ChannelInfo *ci = new ChannelInfo(SQLAssign(qres[i]["name"])); + ci->founder = nc; + if (qres[i]["successor"].size()) + ci->successor = findcore(qres[i]["successor"].c_str()); + ci->desc = sstrdup(qres[i]["descr"].c_str()); + if (qres[i]["url"].size()) + ci->url = sstrdup(qres[i]["url"].c_str()); + if (qres[i]["email"].size()) + ci->email = sstrdup(qres[i]["email"].c_str()); + ci->time_registered = atol(qres[i]["time_registered"]); + ci->last_used = atol(qres[i]["last_used"]); + if (qres[i]["last_topic"].size()) + ci->last_topic = sstrdup(qres[i]["last_topic"].c_str()); + if (qres[i]["last_topic_setter"].size()) + ci->last_topic_setter = SQLAssign(qres[i]["last_topic_setter"]); + if (qres[i]["last_topic_time"].size()) + ci->last_topic_time = atol(qres[i]["last_topic_time"].c_str()); + if (qres[i]["flags"].size()) + { + std::string buf; + spacesepstream sep(SQLAssign(qres[i]["flags"])); + while (sep.GetToken(buf)) + for (int j = 0; ChannelFlags[j].Flag != -1; ++j) + if (buf == ChannelFlags[j].Name) + { + ci->SetFlag(ChannelFlags[j].Flag); + break; + } + } + if (qres[i]["forbidby"].size()) + ci->forbidby = sstrdup(qres[i]["forbidby"].c_str()); + if (qres[i]["forbidreason"].size()) + ci->forbidreason = sstrdup(qres[i]["forbidreason"].c_str()); + ci->bantype = atoi(qres[i]["bantype"].c_str()); + if (qres[i]["mlock_on"].size()) + { + std::vector<std::string> modes; + std::string buf; + + spacesepstream sep(SQLAssign(qres[i]["mlock_on"])); + while (sep.GetToken(buf)) + modes.push_back(buf); + + ci->Extend("db_mlock_modes_on", new ExtensibleItemRegular<std::vector<std::string> >(modes)); + } + if (qres[i]["mlock_off"].size()) + { + std::vector<std::string> modes; + std::string buf; + + spacesepstream sep(SQLAssign(qres[i]["mlock_off"])); + while (sep.GetToken(buf)) + modes.push_back(buf); + + ci->Extend("db_mlock_modes_off", new ExtensibleItemRegular<std::vector<std::string> >(modes)); + } + if (qres[i]["mlock_params"].size()) + { + std::vector<std::pair<std::string, std::string> > mlp; + std::string buf, buf2; + + spacesepstream sep(SQLAssign(qres[i]["mlock_params"])); + + while (sep.GetToken(buf) && sep.GetToken(buf2)) + mlp.push_back(std::make_pair(buf, buf2)); + + ci->Extend("db_mlp", new ExtensibleItemRegular<std::vector<std::pair<std::string, std::string> > >(mlp)); + } + if (qres[i]["entry_message"].size()) + ci->entry_message = sstrdup(qres[i]["entry_message"].c_str()); + ci->memos.memomax = atoi(qres[i]["memomax"].c_str()); + if (qres[i]["botnick"].size()) + ci->bi = findbot(SQLAssign(qres[i]["botnick"])); + if (ci->bi) + { + if (qres[i]["botflags"].size()) + { + std::string buf; + spacesepstream sep(SQLAssign(qres[i]["botflags"])); + while (sep.GetToken(buf)) + for (int j = 0; BotFlags[j].Flag != -1; ++j) + if (buf == BotFlags[j].Name) + { + ci->botflags.SetFlag(BotFlags[j].Flag); + break; + } + } + } + if (qres[i]["capsmin"].size()) + ci->capsmin = atoi(qres[i]["capsmin"].c_str()); + if (qres[i]["capspercent"].size()) + ci->capspercent = atoi(qres[i]["capspercent"].c_str()); + if (qres[i]["floodlines"].size()) + ci->floodlines = atoi(qres[i]["floodlines"].c_str()); + if (qres[i]["floodsecs"].size()) + ci->floodsecs = atoi(qres[i]["floodsecs"].c_str()); + if (qres[i]["repeattimes"].size()) + ci->repeattimes = atoi(qres[i]["repeattimes"].c_str()); + } + + query << "SELECT * FROM `anope_cs_ttb"; + qres = StoreQuery(query); + + if (qres) + for (size_t i = 0, end = qres.num_rows(); i < end; ++i) + { + ChannelInfo *ci = cs_findchan(SQLAssign(qres[i]["channel"])); + if (!ci) + { + Alog() << "MySQL: Channel ttb for nonexistant channel " << qres[i]["channel"]; + continue; + } + + ci->ttb[atoi(qres[i]["ttb_id"].c_str())] = atoi(qres[i]["value"].c_str()); + } + + query << "SELECT * FROM `anope_bs_badwords`"; + qres = StoreQuery(query); + + if (qres) + for (size_t i = 0, end = qres.num_rows(); i < end; ++i) + { + ChannelInfo *ci = cs_findchan(SQLAssign(qres[i]["channel"])); + if (!ci) + { + Alog() << "MySQL: Channel badwords entry for nonexistant channel " << qres[i]["channel"]; + continue; + } + + BadWordType BWTYPE = BW_ANY; + if (qres[i]["type"] == "SINGLE") + BWTYPE = BW_SINGLE; + else if (qres[i]["type"] == "START") + BWTYPE = BW_START; + else if (qres[i]["type"] == "END") + BWTYPE = BW_END; + ci->AddBadWord(SQLAssign(qres[i]["word"]), BWTYPE); + } + + query << "SELECT * FROM `anope_cs_access`"; + qres = StoreQuery(query); + + if (qres) + for (size_t i = 0, end = qres.num_rows(); i < end; ++i) + { + ChannelInfo *ci = cs_findchan(SQLAssign(qres[i]["channel"])); + if (!ci) + { + Alog() << "MySQL: Channel access entry for nonexistant channel " << qres[i]["channel"]; + continue; + } + NickCore *nc = findcore(qres[i]["display"]); + if (!nc) + { + Alog() << "MySQL: Channel access entry for " << ci->name << " with nonexistant nick " << qres[i]["display"]; + continue; + } + + ci->AddAccess(nc, atoi(qres[i]["level"]), SQLAssign(qres[i]["creator"]), atol(qres[i]["last_seen"])); + } + + query << "SELECT * FROM `anope_cs_akick`"; + qres = StoreQuery(query); + + if (qres) + for (size_t i = 0, end = qres.num_rows(); i < end; ++i) + { + ChannelInfo *ci = cs_findchan(SQLAssign(qres[i]["channel"])); + if (!ci) + { + Alog() << "MySQL: Channel akick entry for nonexistant channel " << qres[i]["channel"]; + continue; + } + NickCore *nc = NULL; + spacesepstream sep(qres[i]["flags"]); + std::string flag, mask; + bool stuck = false; + while (sep.GetToken(flag)) + if (flag == "ISNICK") + nc = findcore(qres[i]["mask"]); + else if (flag == "STUCK") + stuck = true; + AutoKick *ak; + if (nc) + ak = ci->AddAkick(SQLAssign(qres[i]["creator"]), nc, SQLAssign(qres[i]["reason"]), atol(qres[i]["created"].c_str()), atol(qres[i]["last_used"].c_str())); + else + ak = ci->AddAkick(SQLAssign(qres[i]["creator"]), SQLAssign(qres[i]["mask"]), SQLAssign(qres[i]["reason"]), atol(qres[i]["created"].c_str()), atol(qres[i]["last_used"].c_str())); + if (stuck) + ak->SetFlag(AK_STUCK); + if (nc) + ak->SetFlag(AK_ISNICK); + } + + query << "SELECT * FROM `anope_cs_levels`"; + qres = StoreQuery(query); + + if (qres) + for (size_t i = 0, end = qres.num_rows(); i < end; ++i) + { + ChannelInfo *ci = cs_findchan(SQLAssign(qres[i]["channel"])); + if (!ci) + { + Alog() << "MySQL: Channel level entry for nonexistant channel " << qres[i]["channel"]; + continue; + } + ci->levels[atoi(qres[i]["position"])] = atoi(qres[i]["level"]); + } + + query << "SELECT * FROM `anope_cs_info_metadata`"; + qres = StoreQuery(query); + + if (qres) + for (size_t i = 0, end = qres.num_rows(); i < end; ++i) + { + ChannelInfo *ci = cs_findchan(SQLAssign(qres[i]["channel"])); + if (!ci) + { + Alog() << "MySQL: Channel metadata for nonexistant channel " << qres[i]["channel"]; + continue; + } + + EventReturn MOD_RESULT; + std::vector<std::string> Params = MakeVector(SQLAssign(qres[i]["value"])); + FOREACH_RESULT(I_OnDatabaseReadMetadata, OnDatabaseReadMetadata(ci, SQLAssign(qres[i]["name"]), Params)); + } + + query << "SELECT * FROM `anope_ns_request`"; + qres = StoreQuery(query); + + if (qres) + for (size_t i = 0, end = qres.num_rows(); i < end; ++i) + { + NickRequest *nr = new NickRequest(qres[i]["nick"].c_str()); + nr->passcode = SQLAssign(qres[i]["passcode"]); + nr->password = SQLAssign(qres[i]["password"]); + nr->email = sstrdup(qres[i]["email"].c_str()); + nr->requested = atol(qres[i]["requested"].c_str()); + } + + EventReturn MOD_RESULT; + query << "SELECT * FROM `anope_extra`"; + qres = StoreQuery(query); + + if (qres) + for (size_t i = 0, end = qres.num_rows(); i < end; ++i) + { + std::vector<std::string> params = MakeVector(SQLAssign(qres[i]["data"])); + FOREACH_RESULT(I_OnDatabaseRead, OnDatabaseRead(params)); + } + + query << "SELECT * FROM `anope_ns_core_metadata`"; + qres = StoreQuery(query); + + if (qres) + for (size_t i = 0, end = qres.num_rows(); i < end; ++i) + { + NickCore *nc = findcore(qres[i]["nick"].c_str()); + if (nc) + { + std::vector<std::string> params = MakeVector(SQLAssign(qres[i]["value"])); + FOREACH_RESULT(I_OnDatabaseReadMetadata, OnDatabaseReadMetadata(nc, SQLAssign(qres[i]["name"]), params)); + } + } + + query << "SELECT * FROM `anope_ns_alias_metadata`"; + qres = StoreQuery(query); + + if (qres) + for (size_t i = 0, end = qres.num_rows(); i < end; ++i) + { + NickAlias *na = findnick(SQLAssign(qres[i]["nick"])); + if (na) + { + std::vector<std::string> params = MakeVector(SQLAssign(qres[i]["value"])); + FOREACH_RESULT(I_OnDatabaseReadMetadata, OnDatabaseReadMetadata(na, SQLAssign(qres[i]["name"]), params)); + } + } + + query << "SELECT * FROM `anope_cs_info_metadata`"; + qres = StoreQuery(query); + + if (qres) + for (size_t i = 0, end = qres.num_rows(); i < end; ++i) + { + ChannelInfo *ci = cs_findchan(SQLAssign(qres[i]["channel"])); + if (ci) + { + std::vector<std::string> params = MakeVector(SQLAssign(qres[i]["value"])); + FOREACH_RESULT(I_OnDatabaseReadMetadata, OnDatabaseReadMetadata(ci, SQLAssign(qres[i]["name"]), params)); + } + } + + query << "SELECT * FROM `anope_ms_info`"; + qres = StoreQuery(query); + + if (qres) + for (size_t i = 0, end = qres.num_rows(); i < end; ++i) + { + MemoInfo *mi = NULL; + if (qres[i]["serv"] == "NICK") + { + NickCore *nc = findcore(qres[i]["receiver"].c_str()); + if (nc) + mi = &nc->memos; + } + else if (qres[i]["serv"] == "CHAN") + { + ChannelInfo *ci = cs_findchan(SQLAssign(qres[i]["receiver"])); + if (ci) + mi = &ci->memos; + } + if (mi) + { + Memo *m = new Memo(); + mi->memos.push_back(m); + m->sender = SQLAssign(qres[i]["sender"]); + if (mi->memos.size() > 1) + { + m->number = mi->memos[mi->memos.size() - 2]->number + 1; + if (m->number < 1) + { + for (unsigned j = 0; j < mi->memos.size(); ++j) + mi->memos[j]->number = j + 1; + } + } + else + m->number = 1; + m->time = atol(qres[i]["time"].c_str()); + m->text = sstrdup(qres[i]["text"].c_str()); + + if (qres[i]["flags"].size()) + { + spacesepstream sep(SQLAssign(qres[i]["flags"])); + std::string buf; + while (sep.GetToken(buf)) + for (unsigned j = 0; MemoFlags[j].Flag != -1; ++j) + if (MemoFlags[j].Name == buf) + m->SetFlag(MemoFlags[j].Flag); + } + } + } + + query << "SELECT * FROM `anope_os_akills`"; + qres = StoreQuery(query); + + if (qres && SGLine) + for (size_t i = 0, end = qres.num_rows(); i < end; ++i) + { + ci::string user = qres[i]["user"].c_str(); + ci::string host = qres[i]["host"].c_str(); + ci::string by = qres[i]["xby"].c_str(); + std::string reason = SQLAssign(qres[i]["reason"]); + time_t seton = atol(qres[i]["seton"].c_str()); + time_t expires = atol(qres[i]["expire"].c_str()); + + XLine *x = SGLine->Add(NULL, NULL, user + "@" + host, expires, reason); + if (x) + { + x->By = by; + x->Created = seton; + } + } + + query << "SELECT * FROM `anope_os_xlines`"; + qres = StoreQuery(query); + + if (qres) + for (size_t i = 0, end = qres.num_rows(); i < end; ++i) + { + ci::string mask = qres[i]["mask"].c_str(); + ci::string by = qres[i]["xby"].c_str(); + std::string reason = SQLAssign(qres[i]["reason"]); + time_t seton = atol(qres[i]["seton"].c_str()); + time_t expires = atol(qres[i]["expires"].c_str()); + + XLine *x = NULL; + if (qres[i]["type"] == "SNLINE" && SNLine) + x = SNLine->Add(NULL, NULL, mask, expires, reason); + else if (qres[i]["type"] == "SQLINE" && SQLine) + x = SQLine->Add(NULL, NULL, mask, expires, reason); + else if (qres[i]["type"] == "SZLINE" && SZLine) + x = SZLine->Add(NULL, NULL,mask, expires, reason); + if (x) + { + x->By = by; + x->Created = seton; + } + } +} + +class DBMySQLRead : public DBMySQL +{ + public: + DBMySQLRead(const std::string &modname, const std::string &creator) : DBMySQL(modname, creator) + { + Implementation i[] = { I_OnLoadDatabase }; + ModuleManager::Attach(i, this, 1); + } + + ~DBMySQLRead() + { + } + + EventReturn OnLoadDatabase() + { + LoadDatabase(); + + /* No need to ever reload this again, although this should never be triggered again */ + ModuleManager::Detach(I_OnLoadDatabase, this); + + return EVENT_STOP; + } +}; + +MODULE_INIT(DBMySQLRead) diff --git a/modules/extra/mysql/db_mysql_write.cpp b/modules/extra/mysql/db_mysql_write.cpp new file mode 100644 index 000000000..c5c002a7e --- /dev/null +++ b/modules/extra/mysql/db_mysql_write.cpp @@ -0,0 +1,1040 @@ +/* RequiredLibraries: mysqlpp */ + +#include "db_mysql.h" + +static std::string BuildFlagsList(ChannelInfo *ci) +{ + std::string ret; + + for (int i = 0; ChannelFlags[i].Flag != -1; ++i) + if (ci->HasFlag(ChannelFlags[i].Flag)) + ret += " " + ChannelFlags[i].Name; + + if (!ret.empty()) + ret.erase(ret.begin()); + + return ret; +} + +static std::string BuildFlagsList(NickAlias *na) +{ + std::string ret; + + for (int i = 0; NickAliasFlags[i].Flag != -1; ++i) + if (na->HasFlag(NickAliasFlags[i].Flag)) + ret += " " + NickAliasFlags[i].Name; + + if (!ret.empty()) + ret.erase(ret.begin()); + + return ret; +} + +static std::string BuildFlagsList(NickCore *nc) +{ + std::string ret; + + for (int i = 0; NickCoreFlags[i].Flag != -1; ++i) + if (nc->HasFlag(NickCoreFlags[i].Flag)) + ret += " " + NickCoreFlags[i].Name; + + if (!ret.empty()) + ret.erase(ret.begin()); + + return ret; +} + +static std::string BuildFlagsList(Memo *m) +{ + std::string ret; + + for (int i = 0; MemoFlags[i].Flag != -1; ++i) + if (m->HasFlag(MemoFlags[i].Flag)) + ret += " " + MemoFlags[i].Name; + + if (!ret.empty()) + ret.erase(ret.begin()); + + return ret; +} + +static std::string MakeMLock(ChannelInfo *ci, bool status) +{ + std::string ret; + + for (std::list<Mode *>::iterator it = ModeManager::Modes.begin(), it_end = ModeManager::Modes.end(); it != it_end; ++it) + { + if ((*it)->Class == MC_CHANNEL) + { + ChannelMode *cm = dynamic_cast<ChannelMode *>(*it); + + if (ci->HasMLock(cm->Name, status)) + ret += " " + cm->NameAsString; + } + } + + if (!ret.empty()) + ret.erase(ret.begin()); + + return ret; +} + +static inline std::string GetMLockOn(ChannelInfo *ci) +{ + return MakeMLock(ci, true); +} + +static inline std::string GetMLockOff(ChannelInfo *ci) +{ + return MakeMLock(ci, false); +} + +static std::string GetMLockParams(ChannelInfo *ci) +{ + std::string ret; + + for (std::list<Mode *>::iterator it = ModeManager::Modes.begin(), it_end = ModeManager::Modes.end(); it != it_end; ++it) + { + if ((*it)->Class == MC_CHANNEL) + { + ChannelMode *cm = dynamic_cast<ChannelMode *>(*it); + + std::string param; + if (ci->GetParam(cm->Name, param)) + ret += " " + cm->NameAsString + " " + param; + } + } + + if (!ret.empty()) + ret.erase(ret.begin()); + + return ret; +} + +static std::string GetBotFlags(Flags<BotServFlag>& Flags) +{ + std::string buf; + + for (int i = 0; BotFlags[i].Flag != -1; ++i) + if (Flags.HasFlag(BotFlags[i].Flag)) + buf += " " + BotFlags[i].Name; + + if (!buf.empty()) + buf.erase(buf.begin()); + + return buf; +} + +static std::string GetBotServFlags(BotInfo *bi) +{ + std::string buf; + + for (int i = 0; BotServFlags[i].Flag != -1; ++i) + if (bi->HasFlag(BotServFlags[i].Flag)) + buf += " " + BotServFlags[i].Name; + + if (!buf.empty()) + buf.erase(buf.begin());; + + return buf; +} + +static NickAlias *CurNick = NULL; +static NickCore *CurCore = NULL; +static ChannelInfo *CurChannel = NULL; +static BotInfo *CurBot = NULL; + +void Write(const std::string &data) +{ + mysqlpp::Query query(me->Con); + query << "INSERT DELAYED INTO `anope_extra` (data) VALUES(" << mysqlpp::quote << data << ")"; + ExecuteQuery(query); +} + +void WriteMetadata(const std::string &key, const std::string &data) +{ + mysqlpp::Query query(me->Con); + query << "INSERT DELAYED INTO `anope_metadata` (name, value) VALUES(" << mysqlpp::quote << key << ", " << mysqlpp::quote << data << ")"; + ExecuteQuery(query); +} + +void WriteNickMetadata(const std::string &key, const std::string &data) +{ + if (!CurNick) + throw CoreException("WriteNickMetadata without a nick to write"); + + mysqlpp::Query query(me->Con); + query << "INSERT DELAYED INTO `anope_ns_alias_metadata` (nick, name, value) VALUES(" << mysqlpp::quote << CurNick->nick << ", " << mysqlpp::quote << key << ", " << mysqlpp::quote << data << ")"; + ExecuteQuery(query); +} + +void WriteCoreMetadata(const std::string &key, const std::string &data) +{ + if (!CurCore) + throw CoreException("WritCoreMetadata without a core to write"); + + mysqlpp::Query query(me->Con); + query << "INSERT DELAYED INTO `anope_ns_core_metadata` (nick, name, value) VALUES(" << mysqlpp::quote << CurCore->display << ", " << mysqlpp::quote << key << ", " << mysqlpp::quote << data << ")"; + ExecuteQuery(query); +} + +void WriteChannelMetadata(const std::string &key, const std::string &data) +{ + if (!CurChannel) + throw CoreException("WriteChannelMetadata without a channel to write"); + + mysqlpp::Query query(me->Con); + query << "INSERT DELAYED INTO `anope_cs_info_metadata` (channel, name, value) VALUES(" << mysqlpp::quote << CurChannel->name << ", " << mysqlpp::quote << key << ", " << mysqlpp::quote << data << ")"; + ExecuteQuery(query); +} + +void WriteBotMetadata(const std::string &key, const std::string &data) +{ + if (!CurBot) + throw CoreException("WriteBotMetadata without a bot to write"); + + mysqlpp::Query query(me->Con); + query << "INSERT DELAYED INTO `anope_bs_info_metadata` (botname, name, value) VALUES(" << mysqlpp::quote << CurBot->nick << ", " << mysqlpp::quote << key << ", " << mysqlpp::quote << data << ")"; + ExecuteQuery(query); +} + +static void SaveDatabases() +{ + mysqlpp::Query query(me->Con); + + query << "TRUNCATE TABLE `anope_ns_alias`"; + ExecuteQuery(query); + + for (nickalias_map::const_iterator it = NickAliasList.begin(), it_end = NickAliasList.end(); it != it_end; ++it) + me->OnNickRegister(it->second); + + query << "TRUNCATE TABLE `anope_ns_core`"; + ExecuteQuery(query); + query << "TRUNCATE TABLE `anope_ms_info`"; + ExecuteQuery(query); + + for (nickcore_map::const_iterator nit = NickCoreList.begin(), nit_end = NickCoreList.end(); nit != nit_end; ++nit) + { + NickCore *nc = nit->second; + + for (std::vector<std::string>::iterator it = nc->access.begin(), it_end = nc->access.end(); it != it_end; ++it) + { + query << "INSERT DELAYED INTO `anope_ns_access` (display, access) VALUES(" << mysqlpp::quote << nc->display << ", " << mysqlpp::quote << *it << ")"; + ExecuteQuery(query); + } + + for (unsigned j = 0, end = nc->memos.memos.size(); j < end; ++j) + { + Memo *m = nc->memos.memos[j]; + + me->OnMemoSend(NULL, nc, m); + } + } + + + query << "TRUNCATE TABLE `anope_bs_core`"; + ExecuteQuery(query); + + for (botinfo_map::const_iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end; ++it) + me->OnBotCreate(it->second); + + query << "TRUNCATE TABLE `anope_cs_info`"; + ExecuteQuery(query); + query << "TRUNCATE TABLE `anope_bs_badwords`"; + ExecuteQuery(query); + query << "TRUNCATE TABLE `anope_cs_access`"; + ExecuteQuery(query); + query << "TRUNCATE TABLE `anope_cs_akick`"; + ExecuteQuery(query); + query << "TRUNCATE TABLE `anope_cs_levels`"; + ExecuteQuery(query); + + for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end; ++it) + { + ChannelInfo *ci = it->second; + + me->OnChanRegistered(ci); + + for (unsigned j = 0, end = ci->GetBadWordCount(); j < end; ++j) + { + BadWord *bw = ci->GetBadWord(j); + + me->OnBadWordAdd(ci, bw); + } + + for (unsigned j = 0, end = ci->GetAccessCount(); j < end; ++j) + { + ChanAccess *access = ci->GetAccess(j); + + query << "INSERT DELAYED INTO `anope_cs_access` (level, display, channel, last_seen, creator) VALUES('" << access->level << "', " << mysqlpp::quote << access->nc->display << ", " << mysqlpp::quote << ci->name << ", " << access->last_seen << ", " << mysqlpp::quote << access->creator << ") ON DUPLICATE KEY UPDATE level=VALUES(level), last_seen=VALUES(last_seen), creator=VALUES(creator)"; + ExecuteQuery(query); + } + + for (unsigned j = 0, end = ci->GetAkickCount(); j < end; ++j) + { + AutoKick *ak = ci->GetAkick(j); + + me->OnAkickAdd(NULL, ci, ak); + } + + for (int k = 0; k < CA_SIZE; ++k) + { + query << "INSERT DELAYED INTO `anope_cs_levels` (channel, position, level) VALUES(" << mysqlpp::quote << ci->name << ", '" << k << "', '" << ci->levels[k] << "') ON DUPLICATE KEY UPDATE position=VALUES(position), level=VALUES(level)"; + ExecuteQuery(query); + } + + for (unsigned j = 0, end = ci->memos.memos.size(); j < end; ++j) + { + Memo *m = ci->memos.memos[j]; + + me->OnMemoSend(NULL, ci, m); + } + } + + query << "TRUNCATE TABLE `anope_ns_request`"; + ExecuteQuery(query); + + for (nickrequest_map::const_iterator it = NickRequestList.begin(), it_end = NickRequestList.end(); it != it_end; ++it) + me->OnMakeNickRequest(it->second); + + if (SGLine) + for (unsigned i = 0, end = SGLine->GetCount(); i < end; ++i) + me->OnAddAkill(NULL, SGLine->GetEntry(i)); + + if (SZLine) + for (unsigned i = 0, end = SZLine->GetCount(); i < end; ++i) + me->OnAddXLine(NULL, SZLine->GetEntry(i), X_SZLINE); + + if (SQLine) + for (unsigned i = 0, end = SQLine->GetCount(); i < end; ++i) + me->OnAddXLine(NULL, SQLine->GetEntry(i), X_SQLINE); + + if (SNLine) + for (unsigned i = 0, end = SNLine->GetCount(); i < end; ++i) + me->OnAddXLine(NULL, SNLine->GetEntry(i), X_SNLINE); + + for (int i = 0; i < nexceptions; ++i) + { + Exception *ex = &exceptions[i]; + + me->OnExceptionAdd(NULL, ex); + } +} + +class CommandSyncSQL : public Command +{ + public: + CommandSyncSQL(const ci::string &cname) : Command(cname, 0, 0, "operserv/sqlsync") + { + } + + CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + { + notice_lang(Config.s_OperServ, u, OPER_SYNC_UPDATING); + SaveDatabases(); + notice_lang(Config.s_OperServ, u, OPER_SYNC_UPDATED); + return MOD_CONT; + } + + bool OnHelp(User *u, const ci::string &subcommand) + { + notice_help(Config.s_OperServ, u, OPER_HELP_SYNC); + return true; + } + + void OnServHelp(User *u) + { + notice_lang(Config.s_OperServ, u, OPER_HELP_CMD_SQLSYNC); + } +}; + +class DBMySQLWrite : public DBMySQL +{ + public: + DBMySQLWrite(const std::string &modname, const std::string &creator) : DBMySQL(modname, creator) + { + me = this; + + ModuleManager::Attach(I_OnServerConnect, this); + + this->AddCommand(OperServ, new CommandSyncSQL("SQLSYNC")); + + if (uplink_server) + OnServerConnect(); + } + + ~DBMySQLWrite() + { + } + + void OnServerConnect() + { + Implementation i[] = { + /* Misc */ + I_OnSaveDatabase, I_OnPostCommand, + /* NickServ */ + I_OnNickAddAccess, I_OnNickEraseAccess, I_OnNickClearAccess, + I_OnDelCore, I_OnNickForbidden, I_OnNickGroup, I_OnMakeNickRequest, + I_OnDelNickRequest, I_OnNickRegister, I_OnChangeCoreDisplay, + I_OnNickSuspended, + /* ChanServ */ + I_OnAccessAdd, I_OnAccessDel, I_OnAccessChange, I_OnAccessClear, I_OnLevelChange, + I_OnChanForbidden, I_OnDelChan, I_OnChanRegistered, I_OnChanSuspend, + I_OnAkickAdd, I_OnAkickDel, + /* BotServ */ + I_OnBotCreate, I_OnBotChange, I_OnBotDelete, + I_OnBotAssign, I_OnBotUnAssign, + I_OnBadWordAdd, I_OnBadWordDel, + /* MemoServ */ + I_OnMemoSend, I_OnMemoDel, + /* OperServ */ + I_OnAddAkill, I_OnDelAkill, I_OnExceptionAdd, I_OnExceptionDel, + I_OnAddXLine, I_OnDelXLine + }; + ModuleManager::Attach(i, this, 39); + } + + EventReturn OnSaveDatabase() + { + mysqlpp::Query query(me->Con); + + query << "TRUNCATE TABLE `anope_os_core`"; + ExecuteQuery(query); + query << "INSERT DELAYED INTO `anope_os_core` (maxusercnt, maxusertime, akills_count, sglines_count, sqlines_count, szlines_count) VALUES("; + query << maxusercnt << ", " << maxusertime << ", " << (SGLine ? SGLine->GetCount() : 0) << ", " << (SQLine ? SQLine->GetCount() : 0) << ", " << (SNLine ? SNLine->GetCount() : 0) << ", " << (SZLine ? SZLine->GetCount() : 0) << ")"; + ExecuteQuery(query); + + for (nickcore_map::const_iterator it = NickCoreList.begin(), it_end = NickCoreList.end(); it != end; ++it) + { + CurCore = it->second; + FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteCoreMetadata, CurCore)); + } + + for (nickalias_map::const_iterator it = NickAliasList.begin(), it_end = NickAliasList.end(); it != it_end; ++it) + { + CurNick = it->second; + FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteNickMetadata, CurNick)); + } + + for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChanelList.end(); it != it_end; ++it) + { + CurChannel = it->second; + FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteChannelMetadata, CurChannel)); + } + + for (botinfo_map::const_iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end; ++it) + { + CurBot = it->second; + FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteBotMetadata, CurBot)); + + /* This is for the core bots, bots added by users are already handled by an event */ + query << "INSERT DELAYED INTO `anope_bs_core` (nick, user, host, rname, flags, created, chancount) VALUES("; + query << mysqlpp::quote << CurBot->nick << ", " << mysqlpp::quote << CurBot->user << ", " << mysqlpp::quote << CurBot->host; + query << ", " << mysqlpp::quote << CurBot->real << ", '" << GetBotServFlags(CurBot) << "', " << CurBot->created << ", "; + query << CurBot->chancount << ") ON DUPLICATE KEY UPDATE nick=VALUES(nick), user=VALUES(user), host=VALUES(host), rname=VALUES(rname), flags=VALUES(flags), created=VALUES(created), chancount=VALUES(created)"; + ExecuteQuery(query); + } + + FOREACH_MOD(I_OnDatabaseWrite, OnDatabaseWrite(Write)); + + return EVENT_CONTINUE; + } + + void OnPostCommand(User *u, const std::string &service, const ci::string &command, const std::vector<ci::string> ¶ms) + { + mysqlpp::Query query(me->Con); + + if (service == Config.s_NickServ) + { + if (u->Account() && ((command == "SET" && !params.empty()) || (command == "SASET" && u->Account()->HasCommand("nickserv/saset") && params.size() > 1))) + { + ci::string cmd = (command == "SET" ? params[0] : params[1]); + NickCore *nc = (command == "SET" ? u->Account() : findcore(params[0])); + if (!nc) + return; + if (cmd == "PASSWORD" && params.size() > 1) + { + query << "UPDATE `anope_ns_core` SET `pass` = " << mysqlpp::quote << nc->pass << " WHERE `display` = " << mysqlpp::quote << nc->display; + ExecuteQuery(query); + } + else if (cmd == "LANGUAGE" && params.size() > 1) + { + query << "UPDATE `anope_ns_core` SET `language` = " << nc->language << " WHERE `display` = " << mysqlpp::quote << nc->display; + ExecuteQuery(query); + } + else if (cmd == "URL") + { + query << "UPDATE `anope_ns_core` SET `url` = " << mysqlpp::quote << (nc->url ? nc->url : "") << " WHERE `display` = " << mysqlpp::quote << nc->display; + ExecuteQuery(query); + } + else if (cmd == "EMAIL") + { + query << "UPDATE `anope_ns_core` SET `email` = " << mysqlpp::quote << (nc->email ? nc->email : "") << " WHERE `display` = " << mysqlpp::quote << nc->display; + ExecuteQuery(query); + } + else if (cmd == "ICQ") + { + query << "UPDATE `anope_ns_core` SET `icq` = " << (nc->icq ? nc->icq : 0) << " WHERE `display` = " << mysqlpp::quote << nc->display; + ExecuteQuery(query); + } + else if (cmd == "GREET") + { + query << "UPDATE `anope_ns_core` SET `greet` = " << mysqlpp::quote << (nc->greet ? nc->greet : "") << " WHERE `display` = " << mysqlpp::quote << nc->display; + ExecuteQuery(query); + } + else if (cmd == "KILL" || cmd == "SECURE" || cmd == "PRIVATE" || cmd == "MSG" || cmd == "HIDE" || cmd == "AUTOOP") + { + query << "UPDATE `anope_ns_core` SET `flags` = '" << BuildFlagsList(nc) << "' WHERE `display` = " << mysqlpp::quote << nc->display; + ExecuteQuery(query); + } + } + } + else if (service == Config.s_ChanServ) + { + if (command == "SET" && u->Account() && params.size() > 1) + { + ChannelInfo *ci = cs_findchan(params[0]); + if (!ci) + return; + if (!u->Account()->HasPriv("chanserv/set") && check_access(u, ci, CA_SET)) + return; + if (params[1] == "FOUNDER" && ci->founder) + { + query << "UPDATE `anope_cs_info` SET `founder` = " << mysqlpp::quote << ci->founder->display << " WHERE `name` = " << mysqlpp::quote << ci->name; + ExecuteQuery(query); + } + else if (params[1] == "SUCCESSOR") + { + query << "UPDATE `anope_cs_info` SET `successor` = " << mysqlpp::quote << (ci->successor ? ci->successor->display : "") << " WHERE `name` = " << mysqlpp::quote << ci->name; + ExecuteQuery(query); + } + else if (params[1] == "DESC") + { + query << "UPDATE `anope_cs_info` SET `descr` = " << mysqlpp::quote << ci->desc << " WHERE `name` = " << mysqlpp::quote << ci->name; + ExecuteQuery(query); + } + else if (params[1] == "URL") + { + query << "UPDATE `anope_cs_info` SET `url` = " << mysqlpp::quote << (ci->url ? ci->url : "") << " WHERE `name` = " << mysqlpp::quote << ci->name; + ExecuteQuery(query); + } + else if (params[1] == "EMAIL") + { + query << "UPDATE `anope_cs_info` SET `email` = " << mysqlpp::quote << (ci->email ? ci->email : "") << " WHERE `name` = " << mysqlpp::quote << ci->name; + ExecuteQuery(query); + } + else if (params[1] == "ENTRYMSG") + { + query << "UPDATE `anope_cs_info` SET `entry_message` = " << mysqlpp::quote << (ci->entry_message ? ci->entry_message : "") << " WHERE `name` = " << mysqlpp::quote << ci->name; + ExecuteQuery(query); + } + else if (params[1] == "MLOCK") + { + query << "UPDATE `anope_cs_info` SET `mlock_on` = '" << GetMLockOn(ci) << "' WHERE `name` = " << mysqlpp::quote << ci->name; + ExecuteQuery(query); + query << "UPDATE `anope_cs_info` SET `mlock_off` = '" << GetMLockOff(ci) << "' WHERE `name` = " << mysqlpp::quote << ci->name; + ExecuteQuery(query); + query << "UPDATE `anope_cs_info` SET `mlock_params` = '" << GetMLockParams(ci) << "' WHERE `name` = " << mysqlpp::quote << ci->name; + ExecuteQuery(query); + } + else if (params[1] == "BANTYPE") + { + query << "UPDATE `anope_cs_info` SET `bantype` = " << ci->bantype << " WHERE `name` = " << mysqlpp::quote << ci->name; + ExecuteQuery(query); + } + else if (params[1] == "KEEPTOPIC" || params[1] == "TOPICLOCK" || params[1] == "PRIVATE" || params[1] == "SECUREOPS" || params[1] == "SECUREFOUNDER" || params[1] == "RESTRICTED" || params[1] == "SECURE" || params[1] == "SIGNKICK" || params[1] == "OPNOTICE" || params[1] == "XOP" || params[1] == "PEACE" || params[1] == "PERSIST" || params[1] == "NOEXPIRE") + { + query << "UPDATE `anope_cs_info` SET `flags` = '" << BuildFlagsList(ci) << "' WHERE `name` = " << mysqlpp::quote << ci->name; + ExecuteQuery(query); + } + } + } + else if (Config.s_BotServ && service == Config.s_BotServ) + { + if (command == "KICK" && params.size() > 2) + { + ChannelInfo *ci = cs_findchan(params[0]); + if (!ci) + return; + if (!check_access(u, ci, CA_SET) && !u->Account()->HasPriv("botserv/administration")) + return; + if (params[1] == "BADWORDS" || params[1] == "BOLDS" || params[1] == "CAPS" || params[1] == "COLORS" || params[1] == "FLOOD" || params[1] == "REPEAT" || params[1] == "REVERSES" || params[1] == "UNDERLINES") + { + if (params[2] == "ON" || params[2] == "OFF") + { + for (int i = 0; i < TTB_SIZE; ++i) + { + query << "INSERT DELAYED INTO `anope_cs_ttb` (channel, ttb_id, value) VALUES(" << mysqlpp::quote << ci->name << ", " << i << ", " << ci->ttb[i] << ") ON DUPLICATE KEY UPDATE channel=VALUES(channel), ttb_id=VALUES(ttb_id), value=VALUES(value)"; + ExecuteQuery(query); + } + query << "UPDATE `anope_cs_info` SET `botflags` = '" << GetBotFlags(ci->botflags) << "' WHERE `name` = " << mysqlpp::quote << ci->name; + ExecuteQuery(query); + + if (params[1] == "CAPS") + { + query << "UPDATE `anope_cs_info` SET `capsmin` = " << ci->capsmin << ", `capspercent` = " << ci->capspercent << " WHERE `name` = " << mysqlpp::quote << ci->name; + ExecuteQuery(query); + } + else if (params[1] == "FLOOD") + { + query << "UPDATE `anope_cs_info` SET `floodlines` = " << ci->floodlines << ", `floodsecs` = " << ci->floodsecs << " WHERE `name` = " << mysqlpp::quote << ci->name; + ExecuteQuery(query); + } + else if (params[1] == "REPEAT") + { + query << "UPDATE `anope_cs_info` SET `repeattimes` = " << ci->repeattimes << " WHERE `name` = " << mysqlpp::quote << ci->name; + ExecuteQuery(query); + } + } + } + } + else if (command == "SET" && params.size() > 2) + { + ChannelInfo *ci = cs_findchan(params[0]); + if (ci && !check_access(u, ci, CA_SET) && !u->Account()->HasPriv("botserv/administration")) + return; + BotInfo *bi = NULL; + if (!ci) + bi = findbot(params[0]); + if (bi && params[1] == "PRIVATE" && u->Account()->HasPriv("botserv/set/private")) + { + query << "UPDATE `anope_bs_core` SET `flags` = '" << GetBotServFlags(bi) << "' WHERE `nick` = " << mysqlpp::quote << bi->nick; + ExecuteQuery(query); + } + else if (!ci) + return; + else if (params[1] == "DONTKICKOPS" || params[1] == "DONTKICKVOICES" || params[1] == "FANTASY" || params[1] == "GREET" || params[1] == "SYMBIOSIS" || params[1] == "NOBOT") + { + query << "UPDATE `anope_cs_info` SET `botflags` = '" << GetBotFlags(ci->botflags) << "' WHERE `name` = " << mysqlpp::quote << ci->name; + ExecuteQuery(query); + } + } + } + } + + void OnNickAddAccess(NickCore *nc, const std::string &entry) + { + mysqlpp::Query query(me->Con); + query << "INSERT DELAYED INTO `anope_ns_access` (display, access) VALUES(" << mysqlpp::quote << nc->display << ", " << mysqlpp::quote << entry << ")"; + ExecuteQuery(query); + } + + void OnNickEraseAccess(NickCore *nc, const std::string &entry) + { + mysqlpp::Query query(me->Con); + query << "DELETE FROM `anope_ns_access` WHERE `display` = " << mysqlpp::quote << nc->display << " AND `access` = " << mysqlpp::quote << entry; + ExecuteQuery(query); + } + + void OnNickClearAccess(NickCore *nc) + { + mysqlpp::Query query(me->Con); + query << "DELETE FROM `anope_ns_access` WHERE `display` = " << mysqlpp::quote << nc->display; + ExecuteQuery(query); + } + + void OnDelCore(NickCore *nc) + { + mysqlpp::Query query(me->Con); + query << "DELETE FROM `anope_cs_access` WHERE `display` = " << mysqlpp::quote << nc->display; + ExecuteQuery(query); + query << "DELETE FROM `anope_cs_akick` WHERE `mask` = " << mysqlpp::quote << nc->display; + ExecuteQuery(query); + query << "DELETE FROM `anope_ns_access` WHERE `display` = " << mysqlpp::quote << nc->display; + ExecuteQuery(query); + query << "DELETE FROM `anope_ns_alias` WHERE `display` = " << mysqlpp::quote << nc->display; + ExecuteQuery(query); + query << "DELETE FROM `anope_ns_core` WHERE `display` = " << mysqlpp::quote << nc->display; + ExecuteQuery(query); + query << "DELETE FROM `anope_ms_info` WHERE `receiver` = " << mysqlpp::quote << nc->display; + ExecuteQuery(query); + } + + void OnNickForbidden(NickAlias *na) + { + std::string flags = BuildFlagsList(na); + mysqlpp::Query query(me->Con); + query << "UPDATE `anope_ns_alias` SET `flags` = '" << (!flags.empty() ? flags : "") << "' WHERE `nick` = " << mysqlpp::quote << na->nick; + ExecuteQuery(query); + } + + void OnNickGroup(User *u, NickAlias *) + { + OnNickRegister(findnick(u->nick)); + } + + void OnMakeNickRequest(NickRequest *nr) + { + mysqlpp::Query query(me->Con); + query << "INSERT DELAYED INTO `anope_ns_request` (nick, passcode, password, email, requested) VALUES(" << mysqlpp::quote << nr->nick << ", "; + query << mysqlpp::quote << nr->passcode << ", " << mysqlpp::quote << nr->password << ", " << mysqlpp::quote << nr->email << ", '"; + query << nr->requested << "')"; + ExecuteQuery(query); + } + + void OnDelNickRequest(NickRequest *nr) + { + mysqlpp::Query query(me->Con); + query << "DELETE FROM `anope_ns_request` WHERE `nick` = " << mysqlpp::quote << nr->nick; + ExecuteQuery(query); + } + + void OnNickRegister(NickAlias *na) + { + std::string flags = BuildFlagsList(na); + mysqlpp::Query query(me->Con); + query << "INSERT DELAYED INTO `anope_ns_alias` (nick, last_quit, last_realname, last_usermask, time_registered, last_seen, flags, display) VALUES("; + query << mysqlpp::quote << na->nick << ", " << mysqlpp::quote << (na->last_quit ? na->last_quit : "") << ", "; + query << mysqlpp::quote << (na->last_realname ? na->last_realname : "") << ", "; + query << mysqlpp::quote << (na->last_usermask ? na->last_usermask : "") << ", " << na->time_registered << ", " << na->last_seen; + query << ", '" << (!flags.empty() ? flags : "") << "', " << mysqlpp::quote << na->nc->display << ") "; + query << "ON DUPLICATE KEY UPDATE last_quit=VALUES(last_quit), last_realname=VALUES(last_realname), last_usermask=VALUES(last_usermask), time_registered=VALUES(time_registered), last_seen=VALUES(last_seen), flags=VALUES(flags), display=VALUES(display)"; + ExecuteQuery(query); + + flags = BuildFlagsList(na->nc); + query << "INSERT DELAYED INTO `anope_ns_core` (display, pass, email, greet, icq, url, flags, language, channelcount, memomax) VALUES("; + query << mysqlpp::quote << na->nc->display << ", " << mysqlpp::quote << na->nc->pass << ", "; + query << mysqlpp::quote << (na->nc->email ? na->nc->email : "") << ", " << mysqlpp::quote << (na->nc->greet ? na->nc->greet : ""); + query << ", " << na->nc->icq << ", " << mysqlpp::quote << (na->nc->url ? na->nc->url : ""); + query << ", '" << (!flags.empty() ? flags : "") << "', " << na->nc->language << ", " << na->nc->channelcount << ", "; + query << na->nc->memos.memomax << ") "; + query << "ON DUPLICATE KEY UPDATE pass=VALUES(pass), email=VALUES(email), greet=VALUES(greet), icq=VALUES(icq), flags=VALUES(flags), language=VALUES(language), "; + query << "channelcount=VALUES(channelcount), memomax=VALUES(memomax)"; + ExecuteQuery(query); + } + + void OnChangeCoreDisplay(NickCore *nc, const std::string &newdisplay) + { + mysqlpp::Query query(me->Con); + query << "UPDATE `anope_ns_core` SET `display` = " << mysqlpp::quote << newdisplay << " WHERE `display` = " << mysqlpp::quote << nc->display; + ExecuteQuery(query); + query << "UPDATE `anope_ns_alias` SET `display` = " << mysqlpp::quote << newdisplay << " WHERE `display` = " << mysqlpp::quote << nc->display; + ExecuteQuery(query); + query << "UPDATE `anope_ns_access` SET `display` = " << mysqlpp::quote << newdisplay << " WHERE `display` = " << mysqlpp::quote << nc->display; + ExecuteQuery(query); + query << "UPDATE `anope_cs_access` SET `display` = " << mysqlpp::quote << newdisplay << " WHERE `display` = " << mysqlpp::quote << nc->display; + ExecuteQuery(query); + query << "UPDATE `anope_cs_info` SET `founder` = " << mysqlpp::quote << newdisplay << " WHERE `founder` = " << mysqlpp::quote << nc->display; + ExecuteQuery(query); + query << "UPDATE `anope_cs_info` SET `successor` = " << mysqlpp::quote << newdisplay << " WHERE `successor` = " << mysqlpp::quote << nc->display; + ExecuteQuery(query); + query << "UPDATE `anope_ms_info` SET `receiver` = " << mysqlpp::quote << newdisplay << " WHERE `receiver` = " << mysqlpp::quote << nc->display; + ExecuteQuery(query); + } + + void OnNickSuspend(NickAlias *na) + { + mysqlpp::Query query(me->Con); + query << "UPDATE `anope_ns_core` SET `flags` = '" << BuildFlagsList(na->nc) << "' WHERE `display` = " << mysqlpp::quote << na->nc->display; + ExecuteQuery(query); + } + + void OnAccessAdd(ChannelInfo *ci, User *u, NickAlias *na, int level) + { + mysqlpp::Query query(me->Con); + query << "INSERT DELAYED INTO `anope_cs_access` (level, display, channel, last_seen, creator) VALUES (" << level << ", " << mysqlpp::quote << na->nc->display << ", " << mysqlpp::quote << ci->name << ", " << time(NULL) << ", " << mysqlpp::quote << u->nick << ")"; + ExecuteQuery(query); + } + + void OnAccessDel(ChannelInfo *ci, User *u, NickCore *nc) + { + mysqlpp::Query query(me->Con); + query << "DELETE FROM `anope_cs_access` WHERE `display` = " << mysqlpp::quote << nc->display << " AND `channel` = " << mysqlpp::quote << ci->name; + ExecuteQuery(query); + } + + void OnAccessChange(ChannelInfo *ci, User *u, NickAlias *na, int level) + { + mysqlpp::Query query(me->Con); + query << "INSERT DELAYED INTO `anope_cs_access` (level, display, channel, last_seen, creator) VALUES (" << level << ", " << mysqlpp::quote << na->nc->display << ", " << mysqlpp::quote << ci->name << ", " << time(NULL) << ", " << mysqlpp::quote << u->nick << ") ON DUPLICATE KEY UPDATE level=VALUES(level), display=VALUES(display), channel=VALUES(channel), last_seen=VALUES(last_seen), creator=VALUES(creator)"; + ExecuteQuery(query); + } + + void OnAccessClear(ChannelInfo *ci, User *u) + { + mysqlpp::Query query(me->Con); + query << "DELETE FROM `anope_cs_access` WHERE `channel` = " << mysqlpp::quote << ci->name; + ExecuteQuery(query); + } + + void OnLevelChange(User *u, ChannelInfo *ci, int pos, int what) + { + mysqlpp::Query query(me->Con); + + if (pos >= 0) + { + query << "UPDATE `anope_cs_levels` SET `level` = " << what << " WHERE `channel` = " << mysqlpp::quote << ci->name << " AND `position` = " << pos; + ExecuteQuery(query); + } + else + for (int i = 0; i < CA_SIZE; ++i) + { + query << "UPDATE `anope_cs_levels` SET `level` = " << ci->levels[i] << " WHERE `channel` = " << mysqlpp::quote << ci->name << " AND `position` = " << i; + ExecuteQuery(query); + } + } + + void OnChanForbidden(ChannelInfo *ci) + { + mysqlpp::Query query(me->Con); + query << "INSERT DELAYED INTO `anope_cs_info` (name, time_registered, last_used, flags, forbidby, forbidreason) VALUES ("; + query << mysqlpp::quote << ci->name << ", " << ci->time_registered << ", " << ci->last_used << ", '" << BuildFlagsList(ci) << "', " << mysqlpp::quote << ci->forbidby << ", " << mysqlpp::quote << ci->forbidreason << ")"; + ExecuteQuery(query); + } + + void OnDelChan(ChannelInfo *ci) + { + mysqlpp::Query query(me->Con); + query << "DELETE FROM `anope_cs_access` WHERE `channel` = " << mysqlpp::quote << ci->name; + ExecuteQuery(query); + query << "DELETE FROM `anope_cs_akick` WHERE `channel` = " << mysqlpp::quote << ci->name; + ExecuteQuery(query); + query << "DELETE FROM `anope_cs_info` WHERE `name` = " << mysqlpp::quote << ci->name; + ExecuteQuery(query); + query << "DELETE FROM `anope_cs_levels` WHERE `channel` = " << mysqlpp::quote << ci->name; + ExecuteQuery(query); + query << "DELETE From `anope_cs_ttb` WHERE `channel` = " << mysqlpp::quote << ci->name; + ExecuteQuery(query); + query << "DELETE FROM `anope_bs_badwords` WHERE `channel` = " << mysqlpp::quote << ci->name; + ExecuteQuery(query); + } + + void OnChanRegistered(ChannelInfo *ci) + { + mysqlpp::Query query(me->Con); + std::string flags = BuildFlagsList(ci), mlockon = GetMLockOn(ci), mlockoff = GetMLockOff(ci), mlockparams = GetMLockParams(ci); + query << "INSERT DELAYED INTO `anope_cs_info` (name, founder, successor, descr, url, email, time_registered, last_used, last_topic, last_topic_setter, last_topic_time, flags, forbidby, forbidreason, bantype, mlock_on, mlock_off, mlock_params, entry_message, memomax, botnick, botflags, capsmin, capspercent, floodlines, floodsecs, repeattimes) VALUES("; + query << mysqlpp::quote << ci->name << ", " << mysqlpp::quote << (ci->founder ? ci->founder->display : "") << ", "; + query << mysqlpp::quote << (ci->successor ? ci->successor->display : "") << ", " << mysqlpp::quote << ci->desc << ", "; + query << mysqlpp::quote << (ci->url ? ci->url : "") << ", " << mysqlpp::quote << (ci->email ? ci->email : "") << ", "; + query << ci->time_registered << ", " << ci->last_used << ", " << mysqlpp::quote << (ci->last_topic ? ci->last_topic : ""); + query << ", " << mysqlpp::quote << (!ci->last_topic_setter.empty() ? ci->last_topic_setter : ""); + query << ", " << ci->last_topic_time << ", '" << (!flags.empty() ? flags : "") << "', "; + query << mysqlpp::quote << (ci->forbidby ? ci->forbidby : "") << ", " << mysqlpp::quote << (ci->forbidreason ? ci->forbidreason : "") << ", " << ci->bantype << ", '"; + query << mlockon << "', '" << mlockoff << "', '"; + query << mlockparams << "', " << mysqlpp::quote << (ci->entry_message ? ci->entry_message : "") << ", "; + query << ci->memos.memomax << ", " << mysqlpp::quote << (ci->bi ? ci->bi->nick : "") << ", '" << GetBotFlags(ci->botflags); + query << "', " << ci->capsmin << ", " << ci->capspercent << ", " << ci->floodlines; + query << ", " << ci->floodsecs << ", " << ci->repeattimes << ") "; + query << "ON DUPLICATE KEY UPDATE founder=VALUES(founder), successor=VALUES(successor), descr=VALUES(descr), url=VALUES(url), email=VALUES(email), time_registered=VALUES(time_registered), last_used=VALUES(last_used), last_topic=VALUES(last_topic), last_topic_setter=VALUES(last_topic_setter), last_topic_time=VALUES(last_topic_time), flags=VALUES(flags), forbidby=VALUES(forbidby), forbidreason=VALUES(forbidreason), bantype=VALUES(bantype), mlock_on=VALUES(mlock_on), mlock_off=VALUES(mlock_off), mlock_params=VALUES(mlock_params), entry_message=VALUES(entry_message), memomax=VALUES(memomax), botnick=VALUES(botnick), botflags=VALUES(botflags), capsmin=VALUES(capsmin), capspercent=VALUES(capspercent), floodlines=VALUES(floodlines), floodsecs=VALUES(floodsecs), repeattimes=VALUES(repeattimes)"; + ExecuteQuery(query); + } + + void OnChanSuspend(ChannelInfo *ci) + { + mysqlpp::Query query(me->Con); + query << "UPDATE `anope_cs_info` SET `flags` = '" << BuildFlagsList(ci) << "' WHERE `name` = " << mysqlpp::quote << ci->name; + ExecuteQuery(query); + query << "UPDATE `anope_cs_info` SET `forbidby` = " << mysqlpp::quote << ci->forbidby << " WHERE `name` = " << mysqlpp::quote << ci->name; + ExecuteQuery(query); + query << "UPDATE `anope_cs_info` SET `forbidreason` = " << mysqlpp::quote << ci->forbidreason << " WHERE `name` = " << mysqlpp::quote << ci->name; + ExecuteQuery(query); + } + + void OnAkickAdd(ChannelInfo *ci, AutoKick *ak) + { + mysqlpp::Query query(me->Con); + query << "INSERT DELAYED INTO `anope_cs_akick` (channel, flags, mask, reason, creator, created, last_used) VALUES("; + query << mysqlpp::quote << ci->name << ", '"; + if (ak->HasFlag(AK_ISNICK)) + query << "ISNICK "; + if (ak->HasFlag(AK_STUCK)) + query << "STUCK "; + query << "', " << mysqlpp::quote << (ak->HasFlag(AK_ISNICK) ? ak->nc->display : ak->mask) << ", "; + query << mysqlpp::quote << ak->reason << ", " << mysqlpp::quote << ak->creator << ", " << ak->addtime; + query << ", " << ak->last_used << ")"; + ExecuteQuery(query); + } + + void OnAkickDel(ChannelInfo *ci, AutoKick *ak) + { + mysqlpp::Query query(me->Con); + query << "DELETE FROM `anope_cs_akick` WHERE `channel`= " << mysqlpp::quote << ci->name << " AND `mask` = " << mysqlpp::quote << (ak->HasFlag(AK_ISNICK) ? ak->nc->display : ak->mask); + ExecuteQuery(query); + } + + void OnBotCreate(BotInfo *bi) + { + mysqlpp::Query query(me->Con); + query << "INSERT DELAYED INTO `anope_bs_core` (nick, user, host, rname, flags, created, chancount) VALUES("; + query << mysqlpp::quote << bi->nick << ", " << mysqlpp::quote << bi->user << ", " << mysqlpp::quote << bi->host << ", "; + query << mysqlpp::quote << bi->real << ", '" << GetBotServFlags(bi) << "', " << bi->created << ", " << bi->chancount << ") "; + query << "ON DUPLICATE KEY UPDATE nick=VALUES(nick), user=VALUES(user), host=VALUES(host), rname=VALUES(rname), flags=VALUES(flags), created=VALUES(created), chancount=VALUES(chancount)"; + ExecuteQuery(query); + } + + void OnBotChange(BotInfo *bi) + { + OnBotCreate(bi); + } + + void OnBotDelete(BotInfo *bi) + { + mysqlpp::Query query(me->Con); + query << "DELETE FROM `anope_bs_core` WHERE `nick` = " << mysqlpp::quote << bi->nick; + ExecuteQuery(query); + query << "UPDATE `anope_cs_info` SET `botnick` = '' WHERE `botnick` = " << mysqlpp::quote << bi->nick; + ExecuteQuery(query); + } + + EventReturn OnBotAssign(User *sender, ChannelInfo *ci, BotInfo *bi) + { + mysqlpp::Query query(me->Con); + query << "UPDATE `anope_cs_info` SET `botnick` = " << mysqlpp::quote << bi->nick << " WHERE `name` = " << mysqlpp::quote << ci->name; + ExecuteQuery(query); + return EVENT_CONTINUE; + } + + EventReturn OnBotUnAssign(User *sender, ChannelInfo *ci) + { + mysqlpp::Query query(me->Con); + query << "UPDATE `anope_cs_info` SET `botnick` = '' WHERE `name` = " << mysqlpp::quote << ci->name; + ExecuteQuery(query); + return EVENT_CONTINUE; + } + + void OnBadWordAdd(ChannelInfo *ci, BadWord *bw) + { + mysqlpp::Query query(me->Con); + query << "INSERT DELAYED INTO `anope_bs_badwords` (channel, word, type) VALUES(" << mysqlpp::quote << ci->name << ", " << mysqlpp::quote << bw->word << ", '"; + switch (bw->type) + { + case BW_SINGLE: + query << "SINGLE"; + break; + case BW_START: + query << "START"; + break; + case BW_END: + query << "END"; + break; + default: + query << "ANY"; + } + query << "') ON DUPLICATE KEY UPDATE channel=VALUES(channel), word=VALUES(word), type=VALUES(type)"; + ExecuteQuery(query); + } + + void OnBadWordDel(ChannelInfo *ci, BadWord *bw) + { + mysqlpp::Query query(me->Con); + query << "DELETE FROM `anope_bs_badwords` WHERE `channel` = " << mysqlpp::quote << ci->name << " AND `word` = " << mysqlpp::quote << bw->word << " AND `type` = '"; + switch (bw->type) + { + case BW_SINGLE: + query << "SINGLE"; + break; + case BW_START: + query << "START"; + break; + case BW_END: + query << "END"; + break; + default: + query << "ANY"; + } + query << "'"; + ExecuteQuery(query); + } + + void OnMemoSend(User *, NickCore *nc, Memo *m) + { + mysqlpp::Query query(me->Con); + query << "INSERT DELAYED INTO `anope_ms_info` (receiver, number, flags, time, sender, text, serv) VALUES("; + query << mysqlpp::quote << nc->display << ", " << m->number << ", '" << BuildFlagsList(m) << "', " << m->time << ", "; + query << mysqlpp::quote << m->sender << ", " << mysqlpp::quote << m->text << ", 'NICK')"; + ExecuteQuery(query); + } + + void OnMemoSend(User *, ChannelInfo *ci, Memo *m) + { + mysqlpp::Query query(me->Con); + query << "INSERT DELAYED INTO `anope_ms_info` (receiver, number, flags, time, sender, text, serv) VALUES("; + query << mysqlpp::quote << ci->name << ", " << m->number << ", '" << BuildFlagsList(m) << "', " << m->time << ", "; + query << mysqlpp::quote << m->sender << ", " << mysqlpp::quote << m->text << ", 'CHAN')"; + ExecuteQuery(query); + } + + void OnMemoDel(NickCore *nc, MemoInfo *mi, int number) + { + mysqlpp::Query query(me->Con); + if (number) + query << "DELETE FROM `anope_ms_info` WHERE `receiver` = " << mysqlpp::quote << nc->display << " AND `number` = " << number; + else + query << "DELETE FROM `anope_ms_info` WHERE `receiver` = " << mysqlpp::quote << nc->display; + ExecuteQuery(query); + } + + void OnMemoDel(ChannelInfo *ci, MemoInfo *mi, int number) + { + mysqlpp::Query query(me->Con); + if (number) + query << "DELETE FROM `anope_ms_info` WHERE `receiver` = " << mysqlpp::quote << ci->name << " AND `number` = " << number; + else + query << "DELETE FROM `anope_ms_info` WHERE `receiver` = " << mysqlpp::quote << ci->name; + ExecuteQuery(query); + } + + EventReturn OnAddAkill(User *, XLine *ak) + { + mysqlpp::Query query(me->Con); + query << "INSERT DELAYED INTO `anope_os_akills` (user, host, xby, reason, seton, expire) VALUES("; + query << mysqlpp::quote << ak->GetUser().c_str() << ", " << mysqlpp::quote << ak->GetHost().c_str() << ", " << mysqlpp::quote << ak->By.c_str(); + query << ", " << mysqlpp::quote << ak->Reason << ", " << ak->Created << ", " << ak->Expires << ")"; + ExecuteQuery(query); + return EVENT_CONTINUE; + } + + void OnDelAkill(User *, XLine *ak) + { + mysqlpp::Query query(me->Con); + if (ak) + query << "DELETE FROM `anope_os_akills` WHERE `host` = " << mysqlpp::quote << ak->GetHost().c_str(); + else + query << "TRUNCATE TABLE `anope_os_akills`"; + ExecuteQuery(query); + } + + EventReturn OnExceptionAdd(User *, Exception *ex) + { + mysqlpp::Query query(me->Con); + query << "INSERT DELAYED INTO `anope_os_exceptions` (mask, slimit, who, reason, time, expires) VALUES("; + query << mysqlpp::quote << ex->mask << ", " << ex->limit << ", " << mysqlpp::quote << ex->who << ", "; + query << mysqlpp::quote << ex->reason << ", " << ex->time << ", " << ex->expires << ")"; + ExecuteQuery(query); + return EVENT_CONTINUE; + } + + void OnExceptionDel(User *, Exception *ex) + { + mysqlpp::Query query(me->Con); + query << "DELETE FROM `anope_os_exceptions` WHERE `mask` = " << mysqlpp::quote << ex->mask; + ExecuteQuery(query); + } + + EventReturn OnAddXLine(User *, XLine *x, XLineType Type) + { + mysqlpp::Query query(me->Con); + query << "INSERT DELAYED INTO `anope_os_sxlines` (type, mask, xby, reason, seton, expire) VALUES('"; + query << (Type == X_SNLINE ? "SNLINE" : (Type == X_SQLINE ? "SQLINE" : "SZLINE")) << "', "; + query << mysqlpp::quote << x->Mask.c_str() << ", " << mysqlpp::quote << x->By.c_str() << ", " << mysqlpp::quote << x->Reason; + query << ", " << x->Created << ", " << x->Expires << ")"; + ExecuteQuery(query); + return EVENT_CONTINUE; + } + + void OnDelXLine(User *, XLine *x, XLineType Type) + { + mysqlpp::Query query(me->Con); + if (x) + { + query << "DELETE FROM `anope_os_xlines` WHERE `mask` = " << mysqlpp::quote << x->Mask.c_str() << " AND `type` = '"; + query << (Type == X_SNLINE ? "SNLINE" : (Type == X_SQLINE ? "SQLINE" : "SZLINE")) << "'"; + } + else + query << "DELETE FROM `anope_os_xlines` WHERE `type` = '" << (Type == X_SNLINE ? "SNLINE" : (Type == X_SQLINE ? "SQLINE" : "SZLINE")) << "'"; + ExecuteQuery(query); + } +}; + +MODULE_INIT(DBMySQLWrite) diff --git a/modules/extra/ns_maxemail.cpp b/modules/extra/ns_maxemail.cpp new file mode 100644 index 000000000..89ffd90da --- /dev/null +++ b/modules/extra/ns_maxemail.cpp @@ -0,0 +1,169 @@ +/* ns_maxemail.c - Limit the amount of times an email address + * can be used for a NickServ account. + * + * (C) 2003-2010 Anope Team + * Contact us at team@anope.org + * + * Included in the Anope module pack since Anope 1.7.9 + * Anope Coder: GeniusDex <geniusdex@anope.org> + * + * Please read COPYING and README for further details. + * + * Send any bug reports to the Anope Coder, as he will be able + * to deal with it best. + */ + +#include "module.h" + +#define AUTHOR "Anope" + +void my_load_config(); +void my_add_languages(); +bool check_email_limit_reached(const char *email, User * u); + +int NSEmailMax = 0; + +enum +{ + LNG_NSEMAILMAX_REACHED, + LNG_NSEMAILMAX_REACHED_ONE, + LNG_NUM_STRINGS +}; + +static Module *me; + +class NSMaxEmail : public Module +{ + public: + NSMaxEmail(const std::string &modname, const std::string &creator) : Module(modname, creator) + { + me = this; + + this->SetAuthor(AUTHOR); + this->SetType(SUPPORTED); + + ModuleManager::Attach(I_OnReload, this); + ModuleManager::Attach(I_OnPreCommand, this); + + my_load_config(); + + const char *langtable_en_us[] = { + /* LNG_NSEMAILMAX_REACHED */ + "The given email address has reached it's usage limit of %d users.", + /* LNG_NSEMAILMAX_REACHED_ONE */ + "The given email address has reached it's usage limit of 1 user." + }; + + const char *langtable_nl[] = { + /* LNG_NSEMAILMAX_REACHED */ + "Het gegeven email adres heeft de limiet van %d gebruikers bereikt.", + /* LNG_NSEMAILMAX_REACHED_ONE */ + "Het gegeven email adres heeft de limiet van 1 gebruiker bereikt." + }; + + const char *langtable_de[] = { + /* LNG_NSEMAILMAX_REACHED */ + "Die angegebene eMail hat die limit Begrenzung von %d User erreicht.", + /* LNG_NSEMAILMAX_REACHED_ONE */ + "Die angegebene eMail hat die limit Begrenzung von 1 User erreicht." + }; + + const char *langtable_pt[] = { + /* LNG_NSEMAILMAX_REACHED */ + "O endereзo de email fornecido alcanзou seu limite de uso de %d usuбrios.", + /* LNG_NSEMAILMAX_REACHED_ONE */ + "O endereзo de email fornecido alcanзou seu limite de uso de 1 usuбrio." + }; + + const char *langtable_ru[] = { + /* LNG_NSEMAILMAX_REACHED */ + "Указанный вами email-адрес используется максимально допустимое кол-во раз: %d", + /* LNG_NSEMAILMAX_REACHED_ONE */ + "Указанный вами email-адрес уже кем-то используется." + }; + + const char *langtable_it[] = { + /* LNG_NSEMAILMAX_REACHED */ + "L'indirizzo email specificato ha raggiunto il suo limite d'utilizzo di %d utenti.", + /* LNG_NSEMAILMAX_REACHED_ONE */ + "L'indirizzo email specificato ha raggiunto il suo limite d'utilizzo di 1 utente." + }; + + this->InsertLanguage(LANG_EN_US, LNG_NUM_STRINGS, langtable_en_us); + this->InsertLanguage(LANG_NL, LNG_NUM_STRINGS, langtable_nl); + this->InsertLanguage(LANG_DE, LNG_NUM_STRINGS, langtable_de); + this->InsertLanguage(LANG_PT, LNG_NUM_STRINGS, langtable_pt); + this->InsertLanguage(LANG_RU, LNG_NUM_STRINGS, langtable_ru); + this->InsertLanguage(LANG_IT, LNG_NUM_STRINGS, langtable_it); + } + + void OnReload(bool started) + { + my_load_config(); + } + + EventReturn OnPreCommand(User *u, const std::string &service, const ci::string &command, const std::vector<ci::string> ¶ms) + { + if (service == Config.s_NickServ) + { + if (command == "REGISTER") + { + if (check_email_limit_reached(params.size() > 1 ? params[1].c_str() : NULL, u)) + return EVENT_STOP; + } + else if (command == "SET") + { + ci::string set = params[0]; + const char *email = params.size() > 1 ? params[1].c_str() : NULL; + + if (set == "email" && check_email_limit_reached(email, u)) + return EVENT_STOP; + } + } + + return EVENT_CONTINUE; + } +}; + +int count_email_in_use(const char *email, User * u) +{ + int count = 0; + + if (!email) + return 0; + + for (nickcore_map::const_iterator it = NickCoreList.begin(), it_end = NickCoreList.end(); it != it_end; ++it) + { + NickCore *nc = it->second; + + if (!(u->Account() && u->Account() == nc) && nc->email && !stricmp(nc->email, email)) + ++count; + } + + return count; +} + +bool check_email_limit_reached(const char *email, User * u) +{ + if (NSEmailMax < 1 || !email) + return false; + + if (count_email_in_use(email, u) < NSEmailMax) + return false; + + if (NSEmailMax == 1) + me->NoticeLang(Config.s_NickServ, u, LNG_NSEMAILMAX_REACHED_ONE); + else + me->NoticeLang(Config.s_NickServ, u, LNG_NSEMAILMAX_REACHED, NSEmailMax); + + return true; +} + +void my_load_config() +{ + ConfigReader config; + NSEmailMax = config.ReadInteger("ns_maxemail", "maxemails", "0", 0, false); + Alog(LOG_DEBUG) << "[ns_maxemail] NSEmailMax set to " << NSEmailMax; +} + +MODULE_INIT(NSMaxEmail) diff --git a/modules/extra/ns_set_misc.cpp b/modules/extra/ns_set_misc.cpp new file mode 100644 index 000000000..00d7d2adf --- /dev/null +++ b/modules/extra/ns_set_misc.cpp @@ -0,0 +1,213 @@ +/* + * + * (C) 2003-2010 Anope Team + * Contact us at team@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. + */ + +/*************************************************************************/ + +#include "module.h" + +class CommandNSSetMisc : public Command +{ + private: + std::string Desc; + + protected: + CommandReturn RealExecute(User *u, const std::vector<ci::string> ¶ms) + { + NickCore *nc = findcore(params[0]); + assert(nc); + + nc->Shrink("nickserv:" + std::string(this->name.c_str())); + if (params.size() > 1) + { + nc->Extend("nickserv:" + std::string(this->name.c_str()), new ExtensibleItemRegular<ci::string>(params[1])); + notice_lang(Config.s_NickServ, u, CHAN_SETTING_CHANGED, this->name.c_str(), nc->display, params[1].c_str()); + } + else + { + notice_lang(Config.s_NickServ, u, CHAN_SETTING_UNSET, this->name.c_str(), nc->display); + } + + return MOD_CONT; + } + + public: + CommandNSSetMisc(const ci::string &cname, const std::string &desc, const ci::string &cpermission = "") : Command(cname, 0, 1, cpermission), Desc(desc) + { + } + + CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + { + std::vector<ci::string> realparams = params; + realparams.insert(realparams.begin(), u->Account()->display); + return RealExecute(u, realparams); + } + + void OnSyntaxError(User *u, const ci::string &) + { + syntax_error(Config.s_NickServ, u, "SET", NICK_SET_SYNTAX); + } + + void OnServHelp(User *u) + { + u->SendMessage(Config.s_NickServ, " %-10s %s", this->name.c_str(), this->Desc.c_str()); + } +}; + +class CommandNSSASetMisc : public CommandNSSetMisc +{ + public: + CommandNSSASetMisc(const ci::string &cname, const std::string &desc) : CommandNSSetMisc(cname, desc, "nickserv/saset/" + cname) + { + this->MinParams = 1; + this->MaxParams = 2; + } + + CommandReturn Execute(User *u, const std::vector<ci::string> ¶ms) + { + return RealExecute(u, params); + } + + void OnSyntaxError(User *u, const ci::string &) + { + syntax_error(Config.s_NickServ, u, "SASET", NICK_SASET_SYNTAX); + } +}; + +class NSSetMisc : public Module +{ + struct CommandInfo + { + std::string Name; + std::string Desc; + bool ShowHidden; + + CommandInfo(const std::string &name, const std::string &desc, bool showhidden) : Name(name), Desc(desc), ShowHidden(showhidden) { } + }; + + std::map<std::string, CommandInfo *> Commands; + + void RemoveAll() + { + if (Commands.empty()) + return; + + Command *set = FindCommand(NickServ, "SET"); + Command *saset = FindCommand(NickServ, "SASET"); + + if (!set && !saset) + return; + + for (std::map<std::string, CommandInfo *>::const_iterator it = this->Commands.begin(), it_end = this->Commands.end(); it != it_end; ++it) + { + if (set) + set->DelSubcommand(it->first.c_str()); + if (saset) + saset->DelSubcommand(it->first.c_str()); + delete it->second; + } + + this->Commands.clear(); + } + + public: + NSSetMisc(const std::string &modname, const std::string &creator) : Module(modname, creator) + { + this->SetAuthor("Anope"); + this->SetType(CORE); + + Implementation i[] = { I_OnReload, I_OnNickInfo, I_OnDatabaseWriteMetadata, I_OnDatabaseReadMetadata }; + ModuleManager::Attach(i, this, 4); + + OnReload(true); + } + + ~NSSetMisc() + { + RemoveAll(); + } + + void OnReload(bool) + { + RemoveAll(); + + Command *set = FindCommand(NickServ, "SET"); + Command *saset = FindCommand(NickServ, "SASET"); + if (!set && !saset) + return; + + ConfigReader config; + + for (int i = 0; true; ++i) + { + std::string cname = config.ReadValue("ns_set_misc", "name", "", i); + if (cname.empty()) + break; + std::string desc = config.ReadValue("ns_set_misc", "desc", "", i); + bool showhidden = config.ReadFlag("ns_set_misc", "operonly", "no", i); + + CommandInfo *info = new CommandInfo(cname, desc, showhidden); + if (!this->Commands.insert(std::make_pair(cname, info)).second) + { + Alog() << "ns_set_misc: Warning, unable to add duplicate entry " << cname; + delete info; + continue; + } + + if (set) + set->AddSubcommand(new CommandNSSetMisc(cname.c_str(), desc)); + if (saset) + saset->AddSubcommand(new CommandNSSASetMisc(cname.c_str(), desc)); + } + } + + void OnNickInfo(User *u, NickAlias *na, bool ShowHidden) + { + for (std::map<std::string, CommandInfo *>::const_iterator it = this->Commands.begin(), it_end = this->Commands.end(); it != it_end; ++it) + { + if (!ShowHidden && it->second->ShowHidden) + continue; + + ci::string value; + if (na->nc->GetExtRegular("nickserv:" + it->first, value)) + { + u->SendMessage(Config.s_NickServ, " %s: %s", it->first.c_str(), value.c_str()); + } + } + } + + void OnDatabaseWriteMetadata(void (*WriteMetadata)(const std::string &, const std::string &), NickCore *nc) + { + for (std::map<std::string, CommandInfo *>::const_iterator it = this->Commands.begin(), it_end = this->Commands.end(); it != it_end; ++it) + { + ci::string value; + + if (nc->GetExtRegular("nickserv:" + it->first, value)) + { + WriteMetadata(it->first, ":" + std::string(value.c_str())); + } + } + } + + EventReturn OnDatabaseReadMetadata(NickCore *nc, const std::string &key, const std::vector<std::string> ¶ms) + { + for (std::map<std::string, CommandInfo *>::const_iterator it = this->Commands.begin(), it_end = this->Commands.end(); it != it_end; ++it) + { + if (key == it->first) + { + nc->Extend("nickserv:" + it->first, new ExtensibleItemRegular<ci::string>(params[0].c_str())); + } + } + + return EVENT_CONTINUE; + } +}; + +MODULE_INIT(NSSetMisc) |