Anope IRC Services  Version 1.8
ms_info.c
Go to the documentation of this file.
1 /* MemoServ 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 myMemoServHelp(User * u);
19 
26 int AnopeInit(int argc, char **argv)
27 {
28  Command *c;
29 
30  moduleAddAuthor("Anope");
31  moduleAddVersion(VERSION_STRING);
33  c = createCommand("INFO", do_info, NULL, -1, MEMO_HELP_INFO, -1,
34  MEMO_SERVADMIN_HELP_INFO, MEMO_SERVADMIN_HELP_INFO);
37 
38  return MOD_CONT;
39 }
40 
44 void AnopeFini(void)
45 {
46 
47 }
48 
49 
50 
55 static void myMemoServHelp(User * u)
56 {
57  notice_lang(s_MemoServ, u, MEMO_HELP_CMD_INFO);
58 }
59 
65 static int do_info(User * u)
66 {
67  MemoInfo *mi;
68  NickAlias *na = NULL;
69  ChannelInfo *ci = NULL;
70  char *name = strtok(NULL, " ");
71  int is_servadmin = is_services_admin(u);
72  int hardmax = 0;
73 
74  if (is_servadmin && name && *name != '#') {
75  na = findnick(name);
76  if (!na) {
77  notice_lang(s_MemoServ, u, NICK_X_NOT_REGISTERED, name);
78  return MOD_CONT;
79  } else if (na->status & NS_VERBOTEN) {
80  notice_lang(s_MemoServ, u, NICK_X_FORBIDDEN, name);
81  return MOD_CONT;
82  }
83  mi = &na->nc->memos;
84  hardmax = na->nc->flags & NI_MEMO_HARDMAX ? 1 : 0;
85  } else if (name && *name == '#') {
86  ci = cs_findchan(name);
87  if (!ci) {
88  notice_lang(s_MemoServ, u, CHAN_X_NOT_REGISTERED, name);
89  return MOD_CONT;
90  } else if (ci->flags & CI_VERBOTEN) {
91  notice_lang(s_MemoServ, u, CHAN_X_FORBIDDEN, name);
92  return MOD_CONT;
93  } else if (!check_access(u, ci, CA_MEMO)) {
94  notice_lang(s_MemoServ, u, ACCESS_DENIED);
95  return MOD_CONT;
96  }
97  mi = &ci->memos;
98  hardmax = ci->flags & CI_MEMO_HARDMAX ? 1 : 0;
99  } else if (name) { /* It's not a chan and we aren't services admin */
100  notice_lang(s_MemoServ, u, ACCESS_DENIED);
101  return MOD_CONT;
102  } else { /* !name */
103  if (!nick_identified(u)) {
104  notice_lang(s_MemoServ, u, NICK_IDENTIFY_REQUIRED, s_NickServ);
105  return MOD_CONT;
106  }
107  mi = &u->na->nc->memos;
108  hardmax = u->na->nc->flags & NI_MEMO_HARDMAX ? 1 : 0;
109  }
110 
111  if (name && (ci || na->nc != u->na->nc)) {
112 
113  if (!mi->memocount) {
114  notice_lang(s_MemoServ, u, MEMO_INFO_X_NO_MEMOS, name);
115  } else if (mi->memocount == 1) {
116  if (mi->memos[0].flags & MF_UNREAD)
117  notice_lang(s_MemoServ, u, MEMO_INFO_X_MEMO_UNREAD, name);
118  else
119  notice_lang(s_MemoServ, u, MEMO_INFO_X_MEMO, name);
120  } else {
121  int count = 0, i;
122  for (i = 0; i < mi->memocount; i++) {
123  if (mi->memos[i].flags & MF_UNREAD)
124  count++;
125  }
126  if (count == mi->memocount)
127  notice_lang(s_MemoServ, u, MEMO_INFO_X_MEMOS_ALL_UNREAD,
128  name, count);
129  else if (count == 0)
130  notice_lang(s_MemoServ, u, MEMO_INFO_X_MEMOS, name,
131  mi->memocount);
132  else if (count == 1)
133  notice_lang(s_MemoServ, u, MEMO_INFO_X_MEMOS_ONE_UNREAD,
134  name, mi->memocount);
135  else
136  notice_lang(s_MemoServ, u, MEMO_INFO_X_MEMOS_SOME_UNREAD,
137  name, mi->memocount, count);
138  }
139  if (mi->memomax == 0) {
140  if (hardmax)
141  notice_lang(s_MemoServ, u, MEMO_INFO_X_HARD_LIMIT, name,
142  mi->memomax);
143  else
144  notice_lang(s_MemoServ, u, MEMO_INFO_X_LIMIT, name,
145  mi->memomax);
146  } else if (mi->memomax > 0) {
147  if (hardmax)
148  notice_lang(s_MemoServ, u, MEMO_INFO_X_HARD_LIMIT, name,
149  mi->memomax);
150  else
151  notice_lang(s_MemoServ, u, MEMO_INFO_X_LIMIT, name,
152  mi->memomax);
153  } else {
154  notice_lang(s_MemoServ, u, MEMO_INFO_X_NO_LIMIT, name);
155  }
156 
157  /* I ripped this code out of ircservices 4.4.5, since I didn't want
158  to rewrite the whole thing (it pisses me off). */
159  if (na) {
160  if ((na->nc->flags & NI_MEMO_RECEIVE)
161  && (na->nc->flags & NI_MEMO_SIGNON)) {
162  notice_lang(s_MemoServ, u, MEMO_INFO_X_NOTIFY_ON, name);
163  } else if (na->nc->flags & NI_MEMO_RECEIVE) {
164  notice_lang(s_MemoServ, u, MEMO_INFO_X_NOTIFY_RECEIVE,
165  name);
166  } else if (na->nc->flags & NI_MEMO_SIGNON) {
167  notice_lang(s_MemoServ, u, MEMO_INFO_X_NOTIFY_SIGNON,
168  name);
169  } else {
170  notice_lang(s_MemoServ, u, MEMO_INFO_X_NOTIFY_OFF, name);
171  }
172  }
173 
174  } else { /* !name || (!ci || na->nc == u->na->nc) */
175 
176  if (!mi->memocount) {
177  notice_lang(s_MemoServ, u, MEMO_INFO_NO_MEMOS);
178  } else if (mi->memocount == 1) {
179  if (mi->memos[0].flags & MF_UNREAD)
180  notice_lang(s_MemoServ, u, MEMO_INFO_MEMO_UNREAD);
181  else
182  notice_lang(s_MemoServ, u, MEMO_INFO_MEMO);
183  } else {
184  int count = 0, i;
185  for (i = 0; i < mi->memocount; i++) {
186  if (mi->memos[i].flags & MF_UNREAD)
187  count++;
188  }
189  if (count == mi->memocount)
190  notice_lang(s_MemoServ, u, MEMO_INFO_MEMOS_ALL_UNREAD,
191  count);
192  else if (count == 0)
193  notice_lang(s_MemoServ, u, MEMO_INFO_MEMOS, mi->memocount);
194  else if (count == 1)
195  notice_lang(s_MemoServ, u, MEMO_INFO_MEMOS_ONE_UNREAD,
196  mi->memocount);
197  else
198  notice_lang(s_MemoServ, u, MEMO_INFO_MEMOS_SOME_UNREAD,
199  mi->memocount, count);
200  }
201 
202  if (mi->memomax == 0) {
203  if (!is_servadmin && hardmax)
204  notice_lang(s_MemoServ, u, MEMO_INFO_HARD_LIMIT_ZERO);
205  else
206  notice_lang(s_MemoServ, u, MEMO_INFO_LIMIT_ZERO);
207  } else if (mi->memomax > 0) {
208  if (!is_servadmin && hardmax)
209  notice_lang(s_MemoServ, u, MEMO_INFO_HARD_LIMIT,
210  mi->memomax);
211  else
212  notice_lang(s_MemoServ, u, MEMO_INFO_LIMIT, mi->memomax);
213  } else {
214  notice_lang(s_MemoServ, u, MEMO_INFO_NO_LIMIT);
215  }
216 
217  /* Ripped too. But differently because of a seg fault (loughs) */
218  if ((u->na->nc->flags & NI_MEMO_RECEIVE)
219  && (u->na->nc->flags & NI_MEMO_SIGNON)) {
220  notice_lang(s_MemoServ, u, MEMO_INFO_NOTIFY_ON);
221  } else if (u->na->nc->flags & NI_MEMO_RECEIVE) {
222  notice_lang(s_MemoServ, u, MEMO_INFO_NOTIFY_RECEIVE);
223  } else if (u->na->nc->flags & NI_MEMO_SIGNON) {
224  notice_lang(s_MemoServ, u, MEMO_INFO_NOTIFY_SIGNON);
225  } else {
226  notice_lang(s_MemoServ, u, MEMO_INFO_NOTIFY_OFF);
227  }
228  }
229  return MOD_CONT; /* if (name && (ci || na->nc != u->na->nc)) */
230 }
static int do_info(User *u)
Definition: ms_info.c:65
E NickAlias * findnick(const char *nick)
Definition: db-merger.c:1857
void AnopeFini(void)
Definition: ms_info.c:44
E int nick_identified(User *u)
Definition: nickserv.c:1111
E int check_access(User *user, ChannelInfo *ci, int what)
Definition: chanserv.c:1974
#define NI_MEMO_RECEIVE
Definition: services.h:1295
static void myMemoServHelp(User *u)
Definition: ms_info.c:55
#define NS_VERBOTEN
Definition: services.h:1273
#define CI_VERBOTEN
Definition: services.h:725
MemoInfo memos
Definition: services.h:552
int16 memocount
Definition: services.h:505
#define CI_MEMO_HARDMAX
Definition: services.h:731
MDE void moduleAddAuthor(const char *author)
Definition: modules.c:1772
E void notice_lang(char *source, User *dest, int message,...)
Definition: send.c:169
MDE void moduleSetType(MODType type)
Definition: modules.c:818
NickCore * nc
Definition: services.h:533
uint16 flags
Definition: services.h:492
MDE void moduleSetMemoHelp(void(*func)(User *u))
Definition: modules.c:2102
E char * s_MemoServ
Definition: extern.h:286
uint32 flags
Definition: services.h:669
int16 memomax
Definition: services.h:505
#define NI_MEMO_SIGNON
Definition: services.h:1294
uint16 status
Definition: services.h:532
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
Command * c
Definition: ns_recover.c:17
#define MOD_CONT
Definition: modules.h:54
E int is_services_admin(User *u)
Definition: operserv.c:591
int AnopeInit(int argc, char **argv)
Definition: ms_info.c:26
#define MEMOSERV
Definition: modules.h:58
#define NI_MEMO_HARDMAX
Definition: services.h:1293
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
#define CA_MEMO
Definition: services.h:761
MemoInfo memos
Definition: services.h:690
E ChannelInfo * cs_findchan(const char *chan)
Definition: db-merger.c:2000
uint32 flags
Definition: services.h:548
Memo * memos
Definition: services.h:506
E char * s_NickServ
Definition: extern.h:284
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
#define MF_UNREAD
Definition: services.h:1268
NickAlias * na
Definition: services.h:892
#define MOD_UNIQUE
Definition: module.h:11