ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/memoserv/main.C
Revision: 1.5
Committed: Tue Aug 28 22:18:30 2007 UTC (19 years, 1 month ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.4: +3 -3 lines
Log Message:
added type traits

File Contents

# User Rev Content
1 pippijn 1.1 /*
2 pippijn 1.4 * Copyright © 2005 Atheme Development Group
3 pippijn 1.2 * Rights to this code are documented in doc/pod/license.pod.
4 pippijn 1.1 *
5     * This file contains the main() routine.
6     *
7 pippijn 1.5 * $Id: main.C,v 1.4 2007-08-28 17:08:09 pippijn Exp $
8 pippijn 1.1 */
9    
10     #include "atheme.h"
11 pippijn 1.4 #include <ermyth/module.h>
12 pippijn 1.1 #include <account/mynick.h>
13     #include <account/myuser.h>
14    
15 pippijn 1.5 static char const rcsid[] = "$Id: main.C,v 1.4 2007-08-28 17:08:09 pippijn Exp $";
16 pippijn 1.1
17 pippijn 1.4 REGISTER_MODULE ("memoserv/main", false, "The Ermyth Team <http://ermyth.schmorp.de>");
18 pippijn 1.1
19     cmdvec ms_cmdtree;
20     helpvec ms_helptree;
21    
22     /* main services client routine */
23     static void
24     memoserv (sourceinfo_t *si, int parc, char *parv[])
25     {
26     char *cmd;
27     char *text;
28     char orig[BUFSIZE];
29    
30     /* this should never happen */
31     if (parv[0][0] == '&')
32     {
33     slog (LG_ERROR, "services(): got parv with local channel: %s", parv[0]);
34     return;
35     }
36    
37     /* make a copy of the original for debugging */
38     strlcpy (orig, parv[parc - 1], BUFSIZE);
39    
40     /* lets go through this to get the command */
41     cmd = strtok (parv[parc - 1], " ");
42     text = strtok (NULL, "");
43    
44     if (!cmd)
45     return;
46     if (*cmd == '\001')
47     {
48     handle_ctcp_common (si, cmd, text);
49     return;
50     }
51    
52     /* take the command through the hash table */
53 pippijn 1.4 command_exec_split (si->service, si, cmd, text, ms_cmdtree);
54 pippijn 1.1 }
55    
56     static void
57 pippijn 1.4 on_config_ready (void)
58 pippijn 1.1 {
59     if (memosvs.me)
60     del_service (memosvs.me);
61    
62     memosvs.me = add_service (memosvs.nick, memosvs.user, memosvs.host, memosvs.real, memoserv, ms_cmdtree);
63     memosvs.disp = memosvs.me->disp;
64     }
65    
66     static void
67 pippijn 1.4 on_user_identify (user_t *u)
68 pippijn 1.1 {
69     myuser_t *mu = u->myuser;
70    
71     if (mu->memoct_new > 0)
72     notice (memosvs.nick, u->nick, ngettext (N_("You have %d new memo."), N_("You have %d new memos."), mu->memoct_new), mu->memoct_new);
73     }
74    
75     static void
76 pippijn 1.4 on_user_away (user_t *u)
77 pippijn 1.1 {
78     myuser_t *mu;
79     mynick_t *mn;
80    
81     if (u->flags & UF_AWAY)
82     return;
83     mu = u->myuser;
84     if (mu == NULL)
85     {
86     mn = mynick_find (u->nick);
87 pippijn 1.5 if (mn != NULL && mn->owner->access_verify (u))
88 pippijn 1.1 mu = mn->owner;
89     }
90     if (mu == NULL)
91     return;
92     if (mu->memoct_new > 0)
93     {
94     notice (memosvs.nick, u->nick, ngettext (N_("You have %d new memo."), N_("You have %d new memos."), mu->memoct_new), mu->memoct_new);
95     }
96     }
97    
98 pippijn 1.4 bool
99     _modinit (module *m)
100     {
101     ConfTable::callback.ready.attach (on_config_ready);
102     user_t::callback.identify.attach (on_user_identify);
103     user_t::callback.away.attach (on_user_away);
104    
105     if (!cold_start)
106     {
107     memosvs.me = add_service (memosvs.nick, memosvs.user, memosvs.host, memosvs.real, memoserv, ms_cmdtree);
108     memosvs.disp = memosvs.me->disp;
109     }
110    
111     return true;
112     }
113    
114     void
115     _moddeinit ()
116     {
117     if (memosvs.me)
118     {
119     del_service (memosvs.me);
120     memosvs.me = NULL;
121     }
122    
123     user_t::callback.away.detach (on_user_away);
124     user_t::callback.identify.detach (on_user_identify);
125     ConfTable::callback.ready.detach (on_config_ready);
126     }