ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/memoserv/main.C
Revision: 1.6
Committed: Sun Sep 9 20:05:51 2007 UTC (19 years, 1 month ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.5: +4 -3 lines
Log Message:
- changed configurations to the c++ stdlib
- more #defines to enum
- removed getopt.h and link.h from the system as they were unused
- reworked logstreams
- added an itoa with old syntax
- made klines objects
- moved some global variables into appropriate classes
- fixed boost.foreach's compiler workaround #if's
- allow other files to add exceptions with ADD_EXCEPTION
- changed mynick_t to c++ object
- moved servers.h out of atheme.h
- corrected PING from inspircd 1.2

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