Anope IRC Services  Version 1.8
cs_info.c
Go to the documentation of this file.
1 /* ChanServ 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_info(User * u);
18 static void myChanServHelp(User * u);
19 
26 int AnopeInit(int argc, char **argv)
27 {
28  Command *c;
29 
30  moduleAddAuthor("Anope");
31  moduleAddVersion(VERSION_STRING);
33 
34  c = createCommand("INFO", do_info, NULL, CHAN_HELP_INFO, -1,
35  CHAN_SERVADMIN_HELP_INFO, CHAN_SERVADMIN_HELP_INFO,
36  CHAN_SERVADMIN_HELP_INFO);
38 
40 
41  return MOD_CONT;
42 }
43 
47 void AnopeFini(void)
48 {
49 
50 }
51 
52 
53 
58 static void myChanServHelp(User * u)
59 {
60  notice_lang(s_ChanServ, u, CHAN_HELP_CMD_INFO);
61 }
62 
68 static int do_info(User * u)
69 {
70 /* SADMINS and users, who have identified for a channel, can now cause it's
71  * Enstry Message and Successor to be displayed by supplying the ALL parameter.
72  * Syntax: INFO channel [ALL]
73  * -TheShadow (29 Mar 1999)
74  */
75  char *chan = strtok(NULL, " ");
76  char *param = strtok(NULL, " ");
77  ChannelInfo *ci;
78  char buf[BUFSIZE], *end;
79  struct tm *tm;
80  int need_comma = 0;
81  const char *commastr = getstring(u->na, COMMA_SPACE);
82  int is_servadmin = is_services_admin(u);
83  int show_all = 0;
84  time_t expt;
85 
86  if (!chan) {
87  syntax_error(s_ChanServ, u, "INFO", CHAN_INFO_SYNTAX);
88  } else if (!(ci = cs_findchan(chan))) {
89  notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, chan);
90  } else if (ci->flags & CI_VERBOTEN) {
91  if (is_oper(u) && ci->forbidby)
92  notice_lang(s_ChanServ, u, CHAN_X_FORBIDDEN_OPER, chan,
93  ci->forbidby,
94  (ci->forbidreason ? ci->
95  forbidreason : getstring(u->na, NO_REASON)));
96  else
97  notice_lang(s_ChanServ, u, CHAN_X_FORBIDDEN, chan);
98  } else if (!ci->founder) {
99  /* Paranoia... this shouldn't be able to happen */
100  delchan(ci);
101  notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, chan);
102  } else {
103 
104  /* Should we show all fields? Only for sadmins and identified users */
105  if (param && stricmp(param, "ALL") == 0 &&
106  (check_access(u, ci, CA_INFO) || is_servadmin))
107  show_all = 1;
108 
109  notice_lang(s_ChanServ, u, CHAN_INFO_HEADER, chan);
110  notice_lang(s_ChanServ, u, CHAN_INFO_NO_FOUNDER,
111  ci->founder->display);
112 
113  if (show_all && ci->successor)
114  notice_lang(s_ChanServ, u, CHAN_INFO_NO_SUCCESSOR,
115  ci->successor->display);
116 
117  notice_lang(s_ChanServ, u, CHAN_INFO_DESCRIPTION, ci->desc);
118  tm = localtime(&ci->time_registered);
119  strftime_lang(buf, sizeof(buf), u, STRFTIME_DATE_TIME_FORMAT, tm);
120  notice_lang(s_ChanServ, u, CHAN_INFO_TIME_REGGED, buf);
121  tm = localtime(&ci->last_used);
122  strftime_lang(buf, sizeof(buf), u, STRFTIME_DATE_TIME_FORMAT, tm);
123  notice_lang(s_ChanServ, u, CHAN_INFO_LAST_USED, buf);
124  if (ci->last_topic
125  && (show_all || (!(ci->mlock_on & anope_get_secret_mode())
126  && (!ci->c
127  || !(ci->c->
128  mode & anope_get_secret_mode()))))) {
129  notice_lang(s_ChanServ, u, CHAN_INFO_LAST_TOPIC,
130  ci->last_topic);
131  notice_lang(s_ChanServ, u, CHAN_INFO_TOPIC_SET_BY,
132  ci->last_topic_setter);
133  }
134 
135  if (ci->entry_message && show_all)
136  notice_lang(s_ChanServ, u, CHAN_INFO_ENTRYMSG,
137  ci->entry_message);
138  if (ci->url)
139  notice_lang(s_ChanServ, u, CHAN_INFO_URL, ci->url);
140  if (ci->email)
141  notice_lang(s_ChanServ, u, CHAN_INFO_EMAIL, ci->email);
142 
143  if (show_all) {
144  notice_lang(s_ChanServ, u, CHAN_INFO_BANTYPE, ci->bantype);
145 
146  end = buf;
147  *end = 0;
148  if (ci->flags & CI_KEEPTOPIC) {
149  end += snprintf(end, sizeof(buf) - (end - buf), "%s",
150  getstring(u->na, CHAN_INFO_OPT_KEEPTOPIC));
151  need_comma = 1;
152  }
153  if (ci->flags & CI_OPNOTICE) {
154  end += snprintf(end, sizeof(buf) - (end - buf), "%s%s",
155  need_comma ? commastr : "",
156  getstring(u->na, CHAN_INFO_OPT_OPNOTICE));
157  need_comma = 1;
158  }
159  if (ci->flags & CI_PEACE) {
160  end += snprintf(end, sizeof(buf) - (end - buf), "%s%s",
161  need_comma ? commastr : "",
162  getstring(u->na, CHAN_INFO_OPT_PEACE));
163  need_comma = 1;
164  }
165  if (ci->flags & CI_PRIVATE) {
166  end += snprintf(end, sizeof(buf) - (end - buf), "%s%s",
167  need_comma ? commastr : "",
168  getstring(u->na, CHAN_INFO_OPT_PRIVATE));
169  need_comma = 1;
170  }
171  if (ci->flags & CI_RESTRICTED) {
172  end += snprintf(end, sizeof(buf) - (end - buf), "%s%s",
173  need_comma ? commastr : "",
174  getstring(u->na,
175  CHAN_INFO_OPT_RESTRICTED));
176  need_comma = 1;
177  }
178  if (ci->flags & CI_SECURE) {
179  end += snprintf(end, sizeof(buf) - (end - buf), "%s%s",
180  need_comma ? commastr : "",
181  getstring(u->na, CHAN_INFO_OPT_SECURE));
182  need_comma = 1;
183  }
184  if (ci->flags & CI_SECUREOPS) {
185  end += snprintf(end, sizeof(buf) - (end - buf), "%s%s",
186  need_comma ? commastr : "",
187  getstring(u->na, CHAN_INFO_OPT_SECUREOPS));
188  need_comma = 1;
189  }
190  if (ci->flags & CI_SECUREFOUNDER) {
191  end += snprintf(end, sizeof(buf) - (end - buf), "%s%s",
192  need_comma ? commastr : "",
193  getstring(u->na,
194  CHAN_INFO_OPT_SECUREFOUNDER));
195  need_comma = 1;
196  }
197  if ((ci->flags & CI_SIGNKICK)
198  || (ci->flags & CI_SIGNKICK_LEVEL)) {
199  end +=
200  snprintf(end, sizeof(buf) - (end - buf), "%s%s",
201  need_comma ? commastr : "", getstring(u->na,
202  CHAN_INFO_OPT_SIGNKICK));
203  need_comma = 1;
204  }
205  if (ci->flags & CI_TOPICLOCK) {
206  end += snprintf(end, sizeof(buf) - (end - buf), "%s%s",
207  need_comma ? commastr : "",
208  getstring(u->na, CHAN_INFO_OPT_TOPICLOCK));
209  need_comma = 1;
210  }
211  if (ci->flags & CI_XOP) {
212  end += snprintf(end, sizeof(buf) - (end - buf), "%s%s",
213  need_comma ? commastr : "",
214  getstring(u->na, CHAN_INFO_OPT_XOP));
215  need_comma = 1;
216  }
217  notice_lang(s_ChanServ, u, CHAN_INFO_OPTIONS,
218  *buf ? buf : getstring(u->na, CHAN_INFO_OPT_NONE));
219  notice_lang(s_ChanServ, u, CHAN_INFO_MODE_LOCK,
220  get_mlock_modes(ci, 1));
221 
222  }
223  if (show_all) {
224  if (ci->flags & CI_NO_EXPIRE) {
225  notice_lang(s_ChanServ, u, CHAN_INFO_NO_EXPIRE);
226  } else {
227  if (is_servadmin) {
228  expt = ci->last_used + CSExpire;
229  tm = localtime(&expt);
230  strftime_lang(buf, sizeof(buf), u,
231  STRFTIME_DATE_TIME_FORMAT, tm);
232  notice_lang(s_ChanServ, u, CHAN_INFO_EXPIRE, buf);
233  }
234  }
235  }
236  if (ci->flags & CI_SUSPENDED) {
237  notice_lang(s_ChanServ, u, CHAN_X_SUSPENDED, ci->forbidby,
238  (ci->forbidreason ? ci->
239  forbidreason : getstring(u->na, NO_REASON)));
240  }
241 
242  if (!show_all && (check_access(u, ci, CA_INFO) || is_servadmin))
243  notice_lang(s_ChanServ, u, NICK_INFO_FOR_MORE, s_ChanServ,
244  ci->name);
245 
246  }
247  return MOD_CONT;
248 }
char * url
Definition: services.h:660
E int is_oper(User *user)
Definition: users.c:937
#define CI_SUSPENDED
Definition: services.h:743
static int do_info(User *u)
Definition: cs_info.c:68
E int snprintf(char *buf, size_t size, const char *fmt,...)
Definition: compat.c:37
#define CI_OPNOTICE
Definition: services.h:733
void AnopeFini(void)
Definition: cs_info.c:47
#define CI_RESTRICTED
Definition: services.h:719
time_t last_used
Definition: services.h:664
#define CI_NO_EXPIRE
Definition: services.h:729
E int check_access(User *user, ChannelInfo *ci, int what)
Definition: chanserv.c:1974
E int stricmp(const char *s1, const char *s2)
Definition: compat.c:58
#define CI_SECURE
Definition: services.h:723
#define CI_VERBOTEN
Definition: services.h:725
#define CI_SECUREFOUNDER
Definition: services.h:735
#define getstring(na, index)
Definition: extern.h:731
#define CI_SECUREOPS
Definition: services.h:713
MDE void moduleAddAuthor(const char *author)
Definition: modules.c:1772
E char * get_mlock_modes(ChannelInfo *ci, int complete)
Definition: chanserv.c:130
E int anope_get_secret_mode()
Definition: ircd.c:1226
E void syntax_error(char *service, User *u, const char *command, int msgnum)
Definition: language.c:295
char name[CHANMAX]
Definition: services.h:654
E void notice_lang(char *source, User *dest, int message,...)
Definition: send.c:169
MDE void moduleSetType(MODType type)
Definition: modules.c:818
char last_topic_setter[NICKMAX]
Definition: services.h:666
char * forbidreason
Definition: services.h:671
char * last_topic
Definition: services.h:665
#define CA_INFO
Definition: services.h:788
#define CI_PRIVATE
Definition: services.h:715
int16 bantype
Definition: services.h:673
#define CI_PEACE
Definition: services.h:721
char * email
Definition: services.h:661
char * display
Definition: services.h:542
uint32 flags
Definition: services.h:669
char * entry_message
Definition: services.h:688
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
struct channel_ * c
Definition: services.h:692
MDE void moduleSetChanHelp(void(*func)(User *u))
Definition: modules.c:2090
#define CI_KEEPTOPIC
Definition: services.h:711
Command * c
Definition: ns_recover.c:17
#define CHANSERV
Definition: modules.h:60
#define CI_XOP
Definition: services.h:741
#define MOD_CONT
Definition: modules.h:54
E int delchan(ChannelInfo *ci)
Definition: chanserv.c:2063
E int is_services_admin(User *u)
Definition: operserv.c:591
#define CI_SIGNKICK
Definition: services.h:737
int AnopeInit(int argc, char **argv)
Definition: cs_info.c:26
#define CI_SIGNKICK_LEVEL
Definition: services.h:739
static void myChanServHelp(User *u)
Definition: cs_info.c:58
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
E int CSExpire
Definition: extern.h:404
#define CI_TOPICLOCK
Definition: services.h:717
time_t time_registered
Definition: services.h:663
E ChannelInfo * cs_findchan(const char *chan)
Definition: db-merger.c:2000
E char * s_ChanServ
Definition: extern.h:285
char * desc
Definition: services.h:659
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
NickCore * founder
Definition: services.h:655
char * forbidby
Definition: services.h:670
#define BUFSIZE
Definition: config.h:47
uint32 mlock_on
Definition: services.h:681
NickAlias * na
Definition: services.h:892
#define MOD_UNIQUE
Definition: module.h:11
NickCore * successor
Definition: services.h:656