ms_check.c

Go to the documentation of this file.
00001 /* MemoServ core functions
00002  *
00003  * (C) 2003-2007 Anope Team
00004  * Contact us at info@anope.org
00005  *
00006  * Please read COPYING and README for further details.
00007  *
00008  * Based on the original code of Epona by Lara.
00009  * Based on the original code of Services by Andy Church. 
00010  * 
00011  * $Id: ms_check.c 1265 2007-08-26 15:33:06Z geniusdex $
00012  *
00013  */
00014 /*************************************************************************/
00015 
00016 #include "module.h"
00017 
00018 int do_memocheck(User * u);
00019 void myMemoServHelp(User * u);
00020 
00027 int AnopeInit(int argc, char **argv)
00028 {
00029     Command *c;
00030 
00031     moduleAddAuthor("Anope");
00032     moduleAddVersion("$Id: ms_check.c 1265 2007-08-26 15:33:06Z geniusdex $");
00033     moduleSetType(CORE);
00034     c = createCommand("CHECK", do_memocheck, NULL, MEMO_HELP_CHECK, -1, -1,
00035                       -1, -1);
00036     moduleAddCommand(MEMOSERV, c, MOD_UNIQUE);
00037     moduleSetMemoHelp(myMemoServHelp);
00038 
00039     return MOD_CONT;
00040 }
00041 
00045 void AnopeFini(void)
00046 {
00047 
00048 }
00049 
00050 
00051 
00056 void myMemoServHelp(User * u)
00057 {
00058     notice_lang(s_MemoServ, u, MEMO_HELP_CMD_CHECK);
00059 }
00060 
00066 int do_memocheck(User * u)
00067 {
00068     NickAlias *na = NULL;
00069     MemoInfo *mi = NULL;
00070     int i, found = 0;
00071     char *recipient = strtok(NULL, "");
00072     struct tm *tm;
00073     char timebuf[64];
00074 
00075     if (!recipient) {
00076         syntax_error(s_MemoServ, u, "CHECK", MEMO_CHECK_SYNTAX);
00077         return MOD_CONT;
00078     } else if (!nick_recognized(u)) {
00079         notice_lang(s_MemoServ, u, NICK_IDENTIFY_REQUIRED, s_NickServ);
00080         return MOD_CONT;
00081     } else if (!(na = findnick(recipient))) {
00082         notice_lang(s_MemoServ, u, NICK_X_NOT_REGISTERED, recipient);
00083         return MOD_CONT;
00084     }
00085 
00086     if ((na->status & NS_VERBOTEN)) {
00087         notice_lang(s_MemoServ, u, NICK_X_FORBIDDEN, recipient);
00088         return MOD_CONT;
00089     }
00090 
00091     mi = &na->nc->memos;
00092 
00093 /* Okay, I know this looks strange but we wanna get the LAST memo, so we
00094     have to loop backwards */
00095 
00096     for (i = (mi->memocount - 1); i >= 0; i--) {
00097         if (!stricmp(mi->memos[i].sender, u->na->nc->display)) {
00098             found = 1;          /* Yes, we've found the memo */
00099 
00100             tm = localtime(&mi->memos[i].time);
00101             strftime_lang(timebuf, sizeof(timebuf), u,
00102                           STRFTIME_DATE_TIME_FORMAT, tm);
00103 
00104             if (mi->memos[i].flags & MF_UNREAD)
00105                 notice_lang(s_MemoServ, u, MEMO_CHECK_NOT_READ, na->nick,
00106                             timebuf);
00107             else
00108                 notice_lang(s_MemoServ, u, MEMO_CHECK_READ, na->nick,
00109                             timebuf);
00110             break;
00111         }
00112     }
00113 
00114     if (!found)
00115         notice_lang(s_MemoServ, u, MEMO_CHECK_NO_MEMO, na->nick);
00116 
00117     return MOD_CONT;
00118 }

Generated on Sun Dec 30 09:26:47 2007 for Anope by  doxygen 1.5.1-20070107