Anope IRC Services  Version 1.8
ms_check.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_memocheck(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("CHECK", do_memocheck, NULL, MEMO_HELP_CHECK, -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_CHECK);
58 }
59 
65 static int do_memocheck(User * u)
66 {
67  NickAlias *na = NULL;
68  MemoInfo *mi = NULL;
69  int i, found = 0;
70  char *recipient = strtok(NULL, "");
71  struct tm *tm;
72  char timebuf[64];
73 
74  if (!recipient) {
75  syntax_error(s_MemoServ, u, "CHECK", MEMO_CHECK_SYNTAX);
76  return MOD_CONT;
77  } else if (!nick_recognized(u)) {
78  notice_lang(s_MemoServ, u, NICK_IDENTIFY_REQUIRED, s_NickServ);
79  return MOD_CONT;
80  } else if (!(na = findnick(recipient))) {
81  notice_lang(s_MemoServ, u, NICK_X_NOT_REGISTERED, recipient);
82  return MOD_CONT;
83  }
84 
85  if ((na->status & NS_VERBOTEN)) {
86  notice_lang(s_MemoServ, u, NICK_X_FORBIDDEN, recipient);
87  return MOD_CONT;
88  }
89 
90  mi = &na->nc->memos;
91 
92 /* Okay, I know this looks strange but we wanna get the LAST memo, so we
93  have to loop backwards */
94 
95  for (i = (mi->memocount - 1); i >= 0; i--) {
96  if (!stricmp(mi->memos[i].sender, u->na->nc->display)) {
97  found = 1; /* Yes, we've found the memo */
98 
99  tm = localtime(&mi->memos[i].time);
100  strftime_lang(timebuf, sizeof(timebuf), u,
101  STRFTIME_DATE_TIME_FORMAT, tm);
102 
103  if (mi->memos[i].flags & MF_UNREAD)
104  notice_lang(s_MemoServ, u, MEMO_CHECK_NOT_READ, na->nick,
105  timebuf);
106  else
107  notice_lang(s_MemoServ, u, MEMO_CHECK_READ, na->nick,
108  timebuf);
109  break;
110  }
111  }
112 
113  if (!found)
114  notice_lang(s_MemoServ, u, MEMO_CHECK_NO_MEMO, na->nick);
115 
116  return MOD_CONT;
117 }
char sender[NICKMAX]
Definition: services.h:494
void AnopeFini(void)
Definition: ms_check.c:44
E NickAlias * findnick(const char *nick)
Definition: db-merger.c:1857
E int stricmp(const char *s1, const char *s2)
Definition: compat.c:58
#define NS_VERBOTEN
Definition: services.h:1273
MemoInfo memos
Definition: services.h:552
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
static int do_memocheck(User *u)
Definition: ms_check.c:65
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
E char * s_MemoServ
Definition: extern.h:286
int AnopeInit(int argc, char **argv)
Definition: ms_check.c:26
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
static void myMemoServHelp(User *u)
Definition: ms_check.c:55
char * nick
Definition: services.h:526
#define MEMOSERV
Definition: modules.h: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
time_t time
Definition: services.h:493
Memo * memos
Definition: services.h:506
E int strftime_lang(char *buf, int size, User *u, int format, struct tm *tm)
Definition: language.c:240
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