Anope IRC Services  Version 1.8
os_modinfo.c
Go to the documentation of this file.
1 /* OperServ core functions
2  *
3  * (C) 2003-2014 Anope Team
4  * Contact us at team@anope.org
5  *
6  * Please read COPYING and README for further details.
7  *
8  * Based on the original code of Epona by Lara.
9  * Based on the original code of Services by Andy Church.
10  *
11  *
12  */
13 /*************************************************************************/
14 
15 #include "module.h"
16 
17 static int do_modinfo(User * u);
18 static void myOperServHelp(User * u);
19 static int showModuleMsgLoaded(MessageHash * msgList, char *mod_name, User * u);
20 static int showModuleCmdLoaded(CommandHash * cmdList, char *mod_name, User * u);
21 
28 int AnopeInit(int argc, char **argv)
29 {
30  Command *c;
31 
32  moduleAddAuthor("Anope");
33  moduleAddVersion(VERSION_STRING);
35  c = createCommand("MODINFO", do_modinfo, NULL, -1, -1, -1, -1,
36  OPER_HELP_MODINFO);
38 
40 
41  return MOD_CONT;
42 }
43 
47 void AnopeFini(void)
48 {
49 
50 }
51 
52 
57 static void myOperServHelp(User * u)
58 {
59  notice_lang(s_OperServ, u, OPER_HELP_CMD_MODINFO);
60 }
61 
67 static int do_modinfo(User * u)
68 {
69  char *file;
70  struct tm tm;
71  char timebuf[64];
72  Module *m;
73  int idx = 0;
74 
75  file = strtok(NULL, "");
76  if (!file) {
77  syntax_error(s_OperServ, u, "MODINFO", OPER_MODULE_INFO_SYNTAX);
78  return MOD_CONT;
79  }
80  m = findModule(file);
81  if (m) {
82  tm = *localtime(&m->time);
83  strftime_lang(timebuf, sizeof(timebuf), u,
84  STRFTIME_DATE_TIME_FORMAT, &tm);
85  notice_lang(s_OperServ, u, OPER_MODULE_INFO_LIST, m->name,
86  m->version ? m->version : "?",
87  m->author ? m->author : "?", timebuf);
88  for (idx = 0; idx < MAX_CMD_HASH; idx++) {
89  showModuleCmdLoaded(HOSTSERV[idx], m->name, u);
90  showModuleCmdLoaded(OPERSERV[idx], m->name, u);
91  showModuleCmdLoaded(NICKSERV[idx], m->name, u);
92  showModuleCmdLoaded(CHANSERV[idx], m->name, u);
93  showModuleCmdLoaded(BOTSERV[idx], m->name, u);
94  showModuleCmdLoaded(MEMOSERV[idx], m->name, u);
95  showModuleCmdLoaded(HELPSERV[idx], m->name, u);
96  showModuleMsgLoaded(IRCD[idx], m->name, u);
97 
98  }
99  } else {
100  notice_lang(s_OperServ, u, OPER_MODULE_NO_INFO, file);
101  }
102  return MOD_CONT;
103 }
104 
105 static int showModuleCmdLoaded(CommandHash * cmdList, char *mod_name, User * u)
106 {
107  Command *c;
109  int display = 0;
110 
111  for (current = cmdList; current; current = current->next) {
112  for (c = current->c; c; c = c->next) {
113  if ((c->mod_name) && (stricmp(c->mod_name, mod_name) == 0)) {
114  notice_lang(s_OperServ, u, OPER_MODULE_CMD_LIST,
115  c->service, c->name);
116  display++;
117  }
118  }
119  }
120  return display;
121 }
122 
123 static int showModuleMsgLoaded(MessageHash * msgList, char *mod_name, User * u)
124 {
125  Message *msg;
126  MessageHash *mcurrent;
127  int display = 0;
128  for (mcurrent = msgList; mcurrent; mcurrent = mcurrent->next) {
129  for (msg = mcurrent->m; msg; msg = msg->next) {
130  if ((msg->mod_name) && (stricmp(msg->mod_name, mod_name) == 0)) {
131  notice_lang(s_OperServ, u, OPER_MODULE_MSG_LIST,
132  msg->name);
133  display++;
134  }
135  }
136  }
137  return display;
138 }
Command * next
Definition: modules.h:202
int AnopeInit(int argc, char **argv)
Definition: os_modinfo.c:28
CommandHash * next
Definition: modules.h:208
void AnopeFini(void)
Definition: os_modinfo.c:47
char * mod_name
Definition: modules.h:215
static Channel * current
Definition: channels.c:427
Command * c
Definition: modules.h:207
#define MAX_CMD_HASH
Definition: modules.h:51
MessageHash * next
Definition: modules.h:222
E int stricmp(const char *s1, const char *s2)
Definition: compat.c:58
static int showModuleCmdLoaded(CommandHash *cmdList, char *mod_name, User *u)
Definition: os_modinfo.c:105
#define IRCD
Definition: modules.h:63
char * service
Definition: modules.h:195
MDE void moduleAddAuthor(const char *author)
Definition: modules.c:1772
E void syntax_error(char *service, User *u, const char *command, int msgnum)
Definition: language.c:295
#define HOSTSERV
Definition: modules.h:56
E void notice_lang(char *source, User *dest, int message,...)
Definition: send.c:169
MDE void moduleSetType(MODType type)
Definition: modules.c:818
char * version
Definition: modules.h:141
#define OPERSERV
Definition: modules.h:62
static void myOperServHelp(User *u)
Definition: os_modinfo.c:57
E char * s_OperServ
Definition: extern.h:289
MDE Module * findModule(char *name)
Definition: modules.c:473
char * name
Definition: modules.h:174
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
Command * c
Definition: ns_recover.c:17
#define CHANSERV
Definition: modules.h:60
#define BOTSERV
Definition: modules.h:57
MDE void moduleSetOperHelp(void(*func)(User *u))
Definition: modules.c:2126
#define MOD_CONT
Definition: modules.h:54
char * name
Definition: modules.h:137
char * mod_name
Definition: modules.h:194
static int showModuleMsgLoaded(MessageHash *msgList, char *mod_name, User *u)
Definition: os_modinfo.c:123
#define HELPSERV
Definition: modules.h:61
#define MEMOSERV
Definition: modules.h:58
char * author
Definition: modules.h:142
Definition: modules.h:99
MDE Command * createCommand(const char *name, int(*func)(User *u), int(*has_priv)(User *u), int help_all, int help_reg, int help_oper, int help_admin, int help_root)
Definition: modules.c:987
Message * m
Definition: modules.h:221
time_t time
Definition: modules.h:140
E int strftime_lang(char *buf, int size, User *u, int format, struct tm *tm)
Definition: language.c:240
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
char * name
Definition: modules.h:212
static int do_modinfo(User *u)
Definition: os_modinfo.c:67
#define NICKSERV
Definition: modules.h:59
#define MOD_UNIQUE
Definition: module.h:11
Message * next
Definition: modules.h:216