ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/memoserv/main.C
Revision: 1.1
Committed: Thu Jul 19 08:24:54 2007 UTC (19 years, 2 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Log Message:
initial import. the most important changes since Atheme are:
- fixed many memory leaks
- fixed many bugs
- converted to C++ and use more STL containers
- added a (not very enhanced yet) perl module
- greatly improved XML-RPC speed
- added a JSON-RPC module with code from json-cpp
- added a valgrind memcheck module to operserv
- added a more object oriented base64 implementation
- added a specialised unit test framework
- improved stability
- use gettimeofday() if available
- reworked adding/removing commands
- MemoServ IGNORE DEL can now remove indices

File Contents

# User Rev Content
1 pippijn 1.1 /*
2     * Copyright © 2005 Atheme Development Group
3     * Rights to this code are documented in doc/LICENSE.
4     *
5     * This file contains the main() routine.
6     *
7     * $Id: main.c 7895 2007-03-06 02:40:03Z pippijn $
8     */
9    
10     #include "atheme.h"
11     #include <account/mynick.h>
12     #include <account/myuser.h>
13    
14     static char const rcsid[] = "$Id";
15    
16     struct ms_main_listeners : callback::has_listeners
17     {
18     };
19    
20     ms_main_listeners listeners;
21    
22     DECLARE_MODULE_V1 ("memoserv/main", false, _modinit, _moddeinit, rcsid, "The Ermyth Team <http://ermyth.schmorp.de>");
23    
24     static void on_user_identify (void *vptr);
25     static void on_user_away (void *vptr);
26    
27     cmdvec ms_cmdtree;
28     helpvec ms_helptree;
29    
30     /* main services client routine */
31     static void
32     memoserv (sourceinfo_t *si, int parc, char *parv[])
33     {
34     char *cmd;
35     char *text;
36     char orig[BUFSIZE];
37    
38     /* this should never happen */
39     if (parv[0][0] == '&')
40     {
41     slog (LG_ERROR, "services(): got parv with local channel: %s", parv[0]);
42     return;
43     }
44    
45     /* make a copy of the original for debugging */
46     strlcpy (orig, parv[parc - 1], BUFSIZE);
47    
48     /* lets go through this to get the command */
49     cmd = strtok (parv[parc - 1], " ");
50     text = strtok (NULL, "");
51    
52     if (!cmd)
53     return;
54     if (*cmd == '\001')
55     {
56     handle_ctcp_common (si, cmd, text);
57     return;
58     }
59    
60     /* take the command through the hash table */
61     command_exec_split (si->service, si, cmd, text, &ms_cmdtree);
62     }
63    
64     static void
65     memoserv_config_ready (void *unused)
66     {
67     if (memosvs.me)
68     del_service (memosvs.me);
69    
70     memosvs.me = add_service (memosvs.nick, memosvs.user, memosvs.host, memosvs.real, memoserv, ms_cmdtree);
71     memosvs.disp = memosvs.me->disp;
72    
73     hook_del_hook ("config_ready", memoserv_config_ready);
74     }
75    
76     void
77     _modinit (module_t *m)
78     {
79     hook_add_event ("config_ready");
80     hook_add_hook ("config_ready", memoserv_config_ready);
81    
82     hook_add_event ("user_identify");
83     hook_add_hook ("user_identify", on_user_identify);
84    
85     hook_add_event ("user_away");
86     hook_add_hook ("user_away", on_user_away);
87    
88     if (!cold_start)
89     {
90     memosvs.me = add_service (memosvs.nick, memosvs.user, memosvs.host, memosvs.real, memoserv, ms_cmdtree);
91     memosvs.disp = memosvs.me->disp;
92     }
93     }
94    
95     void
96     _moddeinit (void)
97     {
98     if (memosvs.me)
99     {
100     del_service (memosvs.me);
101     memosvs.me = NULL;
102     }
103     }
104    
105     static void
106     on_user_identify (void *vptr)
107     {
108     user_t *u = static_cast<user_t *> (vptr);
109     myuser_t *mu = u->myuser;
110    
111     if (mu->memoct_new > 0)
112     notice (memosvs.nick, u->nick, ngettext (N_("You have %d new memo."), N_("You have %d new memos."), mu->memoct_new), mu->memoct_new);
113     }
114    
115     static void
116     on_user_away (void *vptr)
117     {
118     user_t *u = static_cast<user_t *> (vptr);
119     myuser_t *mu;
120     mynick_t *mn;
121    
122     if (u->flags & UF_AWAY)
123     return;
124     mu = u->myuser;
125     if (mu == NULL)
126     {
127     mn = mynick_find (u->nick);
128     if (mn != NULL && myuser_access_verify (u, mn->owner))
129     mu = mn->owner;
130     }
131     if (mu == NULL)
132     return;
133     if (mu->memoct_new > 0)
134     {
135     notice (memosvs.nick, u->nick, ngettext (N_("You have %d new memo."), N_("You have %d new memos."), mu->memoct_new), mu->memoct_new);
136     }
137     }
138    
139     /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
140     * vim:ts=8
141     * vim:sw=8
142     * vim:noexpandtab
143     */