cs_topic.c

Go to the documentation of this file.
00001 /* ChanServ core functions
00002  *
00003  * (C) 2003-2007 Anope Team
00004  * Contact us at info@anope.org
00005  *
00006  * Please read COPYING and README for further details.
00007  *
00008  * Based on the original code of Epona by Lara.
00009  * Based on the original code of Services by Andy Church. 
00010  * 
00011  * $Id: cs_topic.c 1322 2007-12-28 19:12:02Z geniusdex $
00012  *
00013  */
00014 /*************************************************************************/
00015 
00016 #include "module.h"
00017 
00018 int do_cs_topic(User * u);
00019 void myChanServHelp(User * u);
00020 
00027 int AnopeInit(int argc, char **argv)
00028 {
00029     Command *c;
00030 
00031     moduleAddAuthor("Anope");
00032     moduleAddVersion("$Id: cs_topic.c 1322 2007-12-28 19:12:02Z geniusdex $");
00033     moduleSetType(CORE);
00034 
00035     c = createCommand("TOPIC", do_cs_topic, NULL, CHAN_HELP_TOPIC, -1, -1,
00036                       -1, -1);
00037     moduleAddCommand(CHANSERV, c, MOD_UNIQUE);
00038 
00039     moduleSetChanHelp(myChanServHelp);
00040 
00041     return MOD_CONT;
00042 }
00043 
00047 void AnopeFini(void)
00048 {
00049 
00050 }
00051 
00056 void myChanServHelp(User * u)
00057 {
00058     notice_lang(s_ChanServ, u, CHAN_HELP_CMD_TOPIC);
00059 }
00060 
00066 int do_cs_topic(User * u)
00067 {
00068     char *chan = strtok(NULL, " ");
00069     char *topic = strtok(NULL, "");
00070 
00071     Channel *c;
00072     ChannelInfo *ci;
00073 
00074     if (!chan) {
00075         syntax_error(s_ChanServ, u, "TOPIC", CHAN_TOPIC_SYNTAX);
00076     } else if (!(c = findchan(chan))) {
00077         notice_lang(s_ChanServ, u, CHAN_X_NOT_IN_USE, chan);
00078     } else if (!(ci = c->ci)) {
00079         notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, c->name);
00080     } else if (ci->flags & CI_VERBOTEN) {
00081         notice_lang(s_ChanServ, u, CHAN_X_FORBIDDEN, ci->name);
00082     } else if (!is_services_admin(u) && !check_access(u, ci, CA_TOPIC)) {
00083         notice_lang(s_ChanServ, u, PERMISSION_DENIED);
00084     } else {
00085         if (ci->last_topic)
00086             free(ci->last_topic);
00087         ci->last_topic = topic ? sstrdup(topic) : NULL;
00088         strscpy(ci->last_topic_setter, u->nick, NICKMAX);
00089         ci->last_topic_time = time(NULL);
00090 
00091         if (c->topic)
00092             free(c->topic);
00093         c->topic = topic ? sstrdup(topic) : NULL;
00094         strscpy(c->topic_setter, u->nick, NICKMAX);
00095         if (ircd->topictsbackward) {
00096             c->topic_time = c->topic_time - 1;
00097         } else {
00098             c->topic_time = ci->last_topic_time;
00099         }
00100 
00101         if (is_services_admin(u) && !check_access(u, ci, CA_TOPIC))
00102             alog("%s: %s!%s@%s changed topic of %s as services admin.",
00103                  s_ChanServ, u->nick, u->username, u->host, c->name);
00104         if (ircd->join2set) {
00105             if (whosends(ci) == s_ChanServ) {
00106                 anope_cmd_join(s_ChanServ, c->name, c->creation_time);
00107                 anope_cmd_mode(NULL, c->name, "+o %s", s_ChanServ);
00108             }
00109         }
00110         anope_cmd_topic(whosends(ci), c->name, u->nick, topic ? topic : "",
00111                         c->topic_time);
00112         if (ircd->join2set) {
00113             if (whosends(ci) == s_ChanServ) {
00114                 anope_cmd_part(s_ChanServ, c->name, NULL);
00115             }
00116         }
00117     }
00118     return MOD_CONT;
00119 }

Generated on Sun Dec 30 09:26:47 2007 for Anope by  doxygen 1.5.1-20070107