os_logonnews.c

Go to the documentation of this file.
00001 /* OperServ core functions
00002  *
00003  * (C) 2003-2013 Anope Team
00004  * Contact us at team@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  *
00012  */
00013 /*************************************************************************/
00014 
00015 #include "module.h"
00016 
00017 static void myOperServHelp(User * u);
00018 static int reload_config(int argc, char **argv);
00019 
00026 int AnopeInit(int argc, char **argv)
00027 {
00028     Command *c;
00029     EvtHook *hook;
00030     char buf[BUFSIZE];
00031 
00032     moduleAddAuthor("Anope");
00033     moduleAddVersion(VERSION_STRING);
00034     moduleSetType(CORE);
00035 
00040     c = createCommand("LOGONNEWS", do_logonnews, is_services_admin,
00041                       NEWS_HELP_LOGON, -1, -1, -1, -1);
00042     snprintf(buf, BUFSIZE, "%d", NewsCount),
00043     c->help_param1 = sstrdup(buf);
00044     moduleAddCommand(OPERSERV, c, MOD_UNIQUE);
00045 
00046     moduleSetOperHelp(myOperServHelp);
00047 
00048     hook = createEventHook(EVENT_RELOAD, reload_config);
00049     if (moduleAddEventHook(hook) != MOD_ERR_OK) {
00050         alog("[\002os_logonnews\002] Can't hook to EVENT_RELOAD event");
00051         return MOD_STOP;
00052     }
00053 
00054     return MOD_CONT;
00055 }
00056 
00060 void AnopeFini(void)
00061 {
00062     Command *c = findCommand(OPERSERV, "LOGONNEWS");
00063     if (c && c->help_param1)
00064     {
00065         free(c->help_param1);
00066         c->help_param1 = NULL;
00067     }
00068 }
00069 
00070 
00075 static void myOperServHelp(User * u)
00076 {
00077     if (is_services_admin(u)) {
00078         notice_lang(s_OperServ, u, OPER_HELP_CMD_LOGONNEWS);
00079     }
00080 }
00081 
00082 
00086 static int reload_config(int argc, char **argv) {
00087     char buf[BUFSIZE];
00088     Command *c;
00089 
00090     if (argc >= 1) {
00091         if (!stricmp(argv[0], EVENT_START)) {
00092             if ((c = findCommand(OPERSERV, "LOGONNEWS"))) {
00093                 free(c->help_param1);
00094                 snprintf(buf, BUFSIZE, "%d", NewsCount),
00095                 c->help_param1 = sstrdup(buf);
00096             }
00097         }
00098     }
00099 
00100     return MOD_CONT;
00101 }
00102 
00103 /* EOF */