#include "module.h" #define AUTHOR "SGR" #define VERSION "1.21" /* ------------------------------------------------------------ * Name: cs_appendtopic * Author: SGR * Date: 31/08/2003 * ------------------------------------------------------------ * Functions: m_append_to_topic * Limitations: IRCd TOPICLEN. * Tested: Ultimate(2.8.x) + (3-a31), Unreal(3.2), Viagra * ------------------------------------------------------------ * * 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 */ /* ---------------------------------------------------------------------- */ int m_append_to_topic(User * u); void SGR_Module_Help_CHANSERV_APPENDTOPIC(User *u); int SGR_Module_Help_CHANSERV_APPENDTOPIC_FULL(User *u); int AnopeInit(int argc, char **argv) { Command *c; alog("Loading module cs_appendtopic.so"); c = createCommand("APPENDTOPIC",m_append_to_topic,NULL,-1,-1,-1,-1,-1); moduleAddCommand(CHANSERV, c, MOD_HEAD); moduleAddHelp(c,SGR_Module_Help_CHANSERV_APPENDTOPIC_FULL); moduleSetChanHelp(SGR_Module_Help_CHANSERV_APPENDTOPIC); alog("[cs_appendtopic] New command: /msg %s APPENDTOPIC", s_ChanServ); alog("[cs_appendtopic] For information see: /msg %s APPENDTOPIC HELP", s_ChanServ); alog("[cs_appendtopic] Yayness!(tm) - MODULE LOADED AND ACTIVE"); moduleAddAuthor(AUTHOR); moduleAddVersion(VERSION); return MOD_CONT; } void SGR_Module_Help_CHANSERV_APPENDTOPIC(User *u) { notice(s_ChanServ,u->nick, " APPENDTOPIC Add text to a channels topic"); return; } int SGR_Module_Help_CHANSERV_APPENDTOPIC_FULL(User *u) { notice(s_ChanServ, u->nick, "-----------------------------------------------------------------------"); notice(s_ChanServ, u->nick, " Syntax: APPENDTOPIC #Chan text"); notice(s_ChanServ, u->nick, " "); notice(s_ChanServ, u->nick, " This command allows users to add text onto a channels topic. When"); notice(s_ChanServ, u->nick, " TOPICLOCK is on, the topic is updated and the appended (new) form "); notice(s_ChanServ, u->nick, " locked."); notice(s_ChanServ, u->nick, " "); notice(s_ChanServ, u->nick, " Note: This will only append text up to the max legnth of a topic, "); notice(s_ChanServ, u->nick, " usually 307 characters long."); notice(s_ChanServ, u->nick, "-----------------------------------------------------------------------"); return MOD_STOP; } void AnopeFini(void) { alog("Unloading module cs_appendtopic.so"); } int m_append_to_topic(User * u) { char *chan = strtok(NULL, " "); char *newtopic = strtok(NULL, ""); char topic[1024]; ChannelInfo *ci; Channel *c; if (!chan) { notice(s_ChanServ, u->nick, " Syntax: APPENDTOPIC #Chan text"); return MOD_STOP; } if (!newtopic) { notice(s_ChanServ, u->nick, " Syntax: APPENDTOPIC #Chan text"); return MOD_STOP; } /* set the chan c as findchan(chan) for use later - but * 1st check that c is a value */ if (!(c = findchan(chan))) { notice_lang(s_ChanServ, u, CHAN_X_NOT_IN_USE, chan); return MOD_STOP; } if (!(ci = c->ci)) { notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, c->name); return MOD_STOP; } if (ci->flags & CI_VERBOTEN) { notice_lang(s_ChanServ, u, CHAN_X_FORBIDDEN, ci->name); return MOD_STOP; } if (!is_services_admin(u) && !check_access(u, ci, CA_TOPIC)) { notice_lang(s_ChanServ, u, PERMISSION_DENIED); return MOD_STOP; } else { /* ripped from chanserv.c's cs_do_topic [or something like that] * and now modded so much cause of these damn memory segfaults. * */ if (!ci->last_topic) { strcpy(topic, newtopic); } if (ci->last_topic) { snprintf(topic, sizeof(topic), "%s %s", ci->last_topic, newtopic); free(ci->last_topic); } ci->last_topic = topic ? sstrdup(topic) : NULL; strscpy(ci->last_topic_setter, u->nick, NICKMAX); ci->last_topic_time = time(NULL); if (c->topic) { free(c->topic); } c->topic = topic ? sstrdup(topic) : NULL; strscpy(c->topic_setter, u->nick, NICKMAX); #if defined(IRC_DREAMFORGE) && !defined(IRC_ULTIMATE) && !defined(IRC_UNREAL) c->topic_time = c->topic_time - 1; #else c->topic_time = ci->last_topic_time; #endif if (is_services_admin(u) && !check_access(u, ci, CA_TOPIC)) { alog("%s: %s!%s@%s changed topic of %s as services admin.", s_ChanServ, u->nick, u->username, u->host, c->name); } #ifdef IRC_HYBRID if (whosends(ci) == s_ChanServ) { send_cmd(NULL, "SJOIN %ld %s + :%s", time(NULL), c->name, s_ChanServ); send_cmd(NULL, "MODE %s +o %s", c->name, s_ChanServ); } send_cmd(whosends(ci), "TOPIC %s :%s", c->name, c->topic ? c->topic : ""); if (ci->flags & CI_SECURE) { notice(whosends(ci), c->name, "APPENDTOPIC command used by %s", u->nick); } if (whosends(ci) == s_ChanServ) { send_cmd(s_ChanServ, "PART %s", c->name); } #else send_cmd(whosends(ci), "TOPIC %s %s %lu :%s", c->name, u->nick, c->topic_time, topic ? topic : ""); if (ci->flags & CI_SECURE) { notice(whosends(ci), c->name, "APPENDTOPIC command used by %s", u->nick); } #endif } return MOD_CONT; }