Anope IRC Services  Version 1.8
ms_cancel.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_cancel(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("CANCEL", do_cancel, NULL, MEMO_HELP_CANCEL, -1, -1,
34  -1, -1);
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_CANCEL);
58 }
59 
65 static int do_cancel(User * u)
66 {
67  int ischan;
68  int isforbid;
69  char *name = strtok(NULL, " ");
70  MemoInfo *mi;
71 
72  if (!name) {
73  syntax_error(s_MemoServ, u, "CANCEL", MEMO_CANCEL_SYNTAX);
74 
75  } else if (!nick_recognized(u)) {
76  notice_lang(s_MemoServ, u, NICK_IDENTIFY_REQUIRED, s_NickServ);
77 
78  } else if (!(mi = getmemoinfo(name, &ischan, &isforbid))) {
79  if (isforbid) {
81  ischan ? CHAN_X_FORBIDDEN :
82  NICK_X_FORBIDDEN, name);
83  } else {
85  ischan ? CHAN_X_NOT_REGISTERED :
86  NICK_X_NOT_REGISTERED, name);
87  }
88  } else {
89  int i;
90 
91  for (i = mi->memocount - 1; i >= 0; i--) {
92  if ((mi->memos[i].flags & MF_UNREAD)
93  && !stricmp(mi->memos[i].sender, u->na->nc->display)
94  && (!(mi->memos[i].flags & MF_NOTIFYS))) {
95  delmemo(mi, mi->memos[i].number);
96  notice_lang(s_MemoServ, u, MEMO_CANCELLED, name);
97  return MOD_CONT;
98  }
99  }
100 
101  notice_lang(s_MemoServ, u, MEMO_CANCEL_NONE);
102  }
103  return MOD_CONT;
104 }
char sender[NICKMAX]
Definition: services.h:494
E int stricmp(const char *s1, const char *s2)
Definition: compat.c:58
int16 memocount
Definition: services.h:505
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
E void notice_lang(char *source, User *dest, int message,...)
Definition: send.c:169
MDE void moduleSetType(MODType type)
Definition: modules.c:818
E int nick_recognized(User *u)
Definition: nickserv.c:1131
NickCore * nc
Definition: services.h:533
char * display
Definition: services.h:542
uint16 flags
Definition: services.h:492
MDE void moduleSetMemoHelp(void(*func)(User *u))
Definition: modules.c:2102
#define MF_NOTIFYS
Definition: services.h:1270
E char * s_MemoServ
Definition: extern.h:286
void AnopeFini(void)
Definition: ms_cancel.c:44
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
Command * c
Definition: ns_recover.c:17
int AnopeInit(int argc, char **argv)
Definition: ms_cancel.c:26
uint32 number
Definition: services.h:491
#define MOD_CONT
Definition: modules.h:54
static int do_cancel(User *u)
Definition: ms_cancel.c:65
static void myMemoServHelp(User *u)
Definition: ms_cancel.c:55
#define MEMOSERV
Definition: modules.h:58
E int delmemo(MemoInfo *mi, int num)
Definition: memoserv.c:364
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
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
E MemoInfo * getmemoinfo(const char *name, int *ischan, int *isforbid)
Definition: memoserv.c:144
#define MF_UNREAD
Definition: services.h:1268
NickAlias * na
Definition: services.h:892
#define MOD_UNIQUE
Definition: module.h:11