00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "module.h"
00017 int do_list(User * u);
00018 int list_memo_callback(User * u, int num, va_list args);
00019 int list_memo(User * u, int index, MemoInfo * mi, int *sent_header,
00020 int new, const char *chan);
00021 void myMemoServHelp(User * u);
00022
00029 int AnopeInit(int argc, char **argv)
00030 {
00031 Command *c;
00032
00033 moduleAddAuthor("Anope");
00034 moduleAddVersion("$Id: ms_list.c 1345 2008-01-13 12:54:14Z geniusdex $");
00035 moduleSetType(CORE);
00036 c = createCommand("LIST", do_list, NULL, MEMO_HELP_LIST, -1, -1, -1,
00037 -1);
00038 moduleAddCommand(MEMOSERV, c, MOD_UNIQUE);
00039 moduleSetMemoHelp(myMemoServHelp);
00040
00041 return MOD_CONT;
00042 }
00043
00047 void AnopeFini(void)
00048 {
00049
00050 }
00051
00052
00053
00058 void myMemoServHelp(User * u)
00059 {
00060 notice_lang(s_MemoServ, u, MEMO_HELP_CMD_LIST);
00061 }
00062
00068 int do_list(User * u)
00069 {
00070 char *param = strtok(NULL, " "), *chan = NULL;
00071 ChannelInfo *ci;
00072 MemoInfo *mi;
00073 Memo *m;
00074 int i;
00075
00076 if (param && *param == '#') {
00077 chan = param;
00078 param = strtok(NULL, " ");
00079 if (!(ci = cs_findchan(chan))) {
00080 notice_lang(s_MemoServ, u, CHAN_X_NOT_REGISTERED, chan);
00081 return MOD_CONT;
00082 } else if (ci->flags & CI_VERBOTEN) {
00083 notice_lang(s_MemoServ, u, CHAN_X_FORBIDDEN, chan);
00084 return MOD_CONT;
00085 } else if (!check_access(u, ci, CA_MEMO)) {
00086 notice_lang(s_MemoServ, u, ACCESS_DENIED);
00087 return MOD_CONT;
00088 }
00089 mi = &ci->memos;
00090 } else {
00091 if (!nick_identified(u)) {
00092 notice_lang(s_MemoServ, u, NICK_IDENTIFY_REQUIRED, s_NickServ);
00093 return MOD_CONT;
00094 }
00095 mi = &u->na->nc->memos;
00096 }
00097 if (param && !isdigit(*param) && stricmp(param, "NEW") != 0) {
00098 syntax_error(s_MemoServ, u, "LIST", MEMO_LIST_SYNTAX);
00099 } else if (mi->memocount == 0) {
00100 if (chan)
00101 notice_lang(s_MemoServ, u, MEMO_X_HAS_NO_MEMOS, chan);
00102 else
00103 notice_lang(s_MemoServ, u, MEMO_HAVE_NO_MEMOS);
00104 } else {
00105 int sent_header = 0;
00106 if (param && isdigit(*param)) {
00107 process_numlist(param, NULL, list_memo_callback, u,
00108 mi, &sent_header, chan);
00109 } else {
00110 if (param) {
00111 for (i = 0, m = mi->memos; i < mi->memocount; i++, m++) {
00112 if (m->flags & MF_UNREAD)
00113 break;
00114 }
00115 if (i == mi->memocount) {
00116 if (chan)
00117 notice_lang(s_MemoServ, u, MEMO_X_HAS_NO_NEW_MEMOS,
00118 chan);
00119 else
00120 notice_lang(s_MemoServ, u, MEMO_HAVE_NO_NEW_MEMOS);
00121 return MOD_CONT;
00122 }
00123 }
00124 for (i = 0, m = mi->memos; i < mi->memocount; i++, m++) {
00125 if (param && !(m->flags & MF_UNREAD))
00126 continue;
00127 list_memo(u, i, mi, &sent_header, param != NULL, chan);
00128 }
00129 }
00130 }
00131 return MOD_CONT;
00132 }
00133
00141 int list_memo_callback(User * u, int num, va_list args)
00142 {
00143 MemoInfo *mi = va_arg(args, MemoInfo *);
00144 int *sent_header = va_arg(args, int *);
00145 const char *chan = va_arg(args, const char *);
00146 int i;
00147
00148 for (i = 0; i < mi->memocount; i++) {
00149 if (mi->memos[i].number == num)
00150 break;
00151 }
00152
00153 return list_memo(u, i, mi, sent_header, 0, chan);
00154 }
00155
00166 int list_memo(User * u, int index, MemoInfo * mi, int *sent_header,
00167 int new, const char *chan)
00168 {
00169 Memo *m;
00170 char timebuf[64];
00171 struct tm tm;
00172
00173 if (index < 0 || index >= mi->memocount)
00174 return 0;
00175 if (!*sent_header) {
00176 if (chan) {
00177 notice_lang(s_MemoServ, u,
00178 new ? MEMO_LIST_CHAN_NEW_MEMOS :
00179 MEMO_LIST_CHAN_MEMOS, chan, s_MemoServ, chan);
00180 } else {
00181 notice_lang(s_MemoServ, u,
00182 new ? MEMO_LIST_NEW_MEMOS : MEMO_LIST_MEMOS,
00183 u->nick, s_MemoServ);
00184 }
00185 notice_lang(s_MemoServ, u, MEMO_LIST_HEADER);
00186 *sent_header = 1;
00187 }
00188 m = &mi->memos[index];
00189 tm = *localtime(&m->time);
00190 strftime_lang(timebuf, sizeof(timebuf),
00191 u, STRFTIME_DATE_TIME_FORMAT, &tm);
00192 timebuf[sizeof(timebuf) - 1] = 0;
00193 notice_lang(s_MemoServ, u, MEMO_LIST_FORMAT,
00194 (m->flags & MF_UNREAD) ? '*' : ' ',
00195 m->number, m->sender, timebuf);
00196 return 1;
00197 }