ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/account.C
Revision: 1.7
Committed: Sun Sep 9 20:05:52 2007 UTC (16 years, 8 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.6: +8 -8 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     * account.C: Account management
3 pippijn 1.2 * Rights to this code are documented in doc/pod/license.pod.
4 pippijn 1.1 *
5 pippijn 1.7 * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team (http://ermyth.schmorp.de)
6 pippijn 1.4 * Copyright © 2005-2007 Atheme Project (http://www.atheme.org)
7 pippijn 1.1 */
8    
9 pippijn 1.7 static char const rcsid[] = "$Id: account.C,v 1.6 2007-09-05 11:23:15 pippijn Exp $";
10 pippijn 1.4
11     #include <boost/foreach.hpp>
12 pippijn 1.1
13     #include "atheme.h"
14     #include <account/myuser.h>
15     #include <account/mynick.h>
16     #include <account/mychan.h>
17     #include <account/chanacs.h>
18     #include "uplink.h" /* XXX, for sendq_flush(curr_uplink->conn); */
19     #include "datastream.h"
20     #include "privs.h"
21    
22     /*
23     * init_accounts()
24     *
25     * Initializes the accounts DTree.
26     *
27     * Inputs:
28     * - none
29     *
30     * Outputs:
31     * - none
32     *
33     * Side Effects:
34     * - if the DTree initialization fails, services will abort.
35     */
36     void
37     init_accounts (void)
38     {
39     #if 0
40     myuser_heap = BlockHeapCreate (sizeof (myuser_t), HEAP_USER);
41     mynick_heap = BlockHeapCreate (sizeof (myuser_t), HEAP_USER);
42     mychan_heap = BlockHeapCreate (sizeof (mychan_t), HEAP_CHANNEL);
43     chanacs_heap = BlockHeapCreate (sizeof (chanacs_t), HEAP_CHANUSER);
44     metadata_heap = BlockHeapCreate (sizeof (metadata_t), HEAP_CHANUSER);
45     #endif
46     }
47    
48     static int
49 pippijn 1.6 expire_myuser_cb (myuser_t::pair_type &mup)
50 pippijn 1.1 {
51 pippijn 1.4 myuser_t *mu = mup.second;
52 pippijn 1.1
53     /* If they're logged in, update lastlogin time.
54     * To decrease db traffic, may want to only do
55     * this if the account would otherwise be
56     * deleted. -- jilles
57     */
58     if (!mu->logins.empty ())
59     {
60     mu->lastlogin = NOW;
61     return 0;
62     }
63    
64     if (MU_HOLD & mu->flags)
65     return 0;
66    
67     if (((NOW - mu->lastlogin) >= nicksvs.expiry) || ((mu->flags & MU_WAITAUTH) && (NOW - mu->registered >= 86400)))
68     {
69     /* Don't expire accounts with privs on them in atheme.conf,
70     * otherwise someone can reregister
71     * them and take the privs -- jilles */
72     if (is_conf_soper (mu))
73     return 0;
74    
75     snoop (_("EXPIRE: \2%s\2 from \2%s\2 "), mu->name, mu->email);
76     slog (LG_REGISTER, "expire_check(): expiring account %s (unused %ds, email %s, nicks %d, chanacs %d)", mu->name, (int) (NOW - mu->lastlogin), mu->email, LIST_LENGTH (&mu->nicks), LIST_LENGTH (&mu->chanacs));
77     mu->refcnt_dec ();
78     }
79    
80     return 0;
81     }
82    
83     void
84     expire_check (void *arg)
85     {
86     mynick_t *mn;
87     mychan_t *mc;
88     user_t *u;
89    
90     /* Let them know about this and the likely subsequent db_save()
91     * right away -- jilles */
92     sendq_flush (curr_uplink->conn);
93    
94     if (nicksvs.expiry != 0)
95     {
96 pippijn 1.6 std::for_each (myuser_t::map.begin (), myuser_t::map.end (), expire_myuser_cb);
97 pippijn 1.1
98 pippijn 1.6 foreach (mynick_t::pair_type &mnp, mynick_t::map)
99 pippijn 1.4 {
100     mn = mnp.second;
101     if ((NOW - mn->lastseen) >= nicksvs.expiry)
102     {
103     if (MU_HOLD & mn->owner->flags)
104     continue;
105    
106     /* do not drop main nick like this */
107     if (!irccasecmp (mn->nick, mn->owner->name))
108     continue;
109    
110     u = user_find_named (mn->nick);
111     if (u != NULL && u->myuser == mn->owner)
112     {
113     /* still logged in, bleh */
114     mn->lastseen = NOW;
115     mn->owner->lastlogin = NOW;
116     continue;
117     }
118    
119     snoop (_("EXPIRE: \2%s\2 from \2%s\2"), mn->nick, mn->owner->name);
120     slog (LG_REGISTER, "expire_check(): expiring nick %s (unused %ds, account %s)", mn->nick, NOW - mn->lastseen, mn->owner->name);
121 pippijn 1.7 mn->refcnt_dec ();
122 pippijn 1.4 }
123     }
124 pippijn 1.1 }
125 pippijn 1.4
126 pippijn 1.1 if (chansvs.expiry != 0)
127     {
128 pippijn 1.7 foreach (mychan_t::pair_type &mp, mychan_t::map)
129 pippijn 1.5 {
130     mc = mp.second;
131     if ((NOW - mc->used) >= 86400 - 3660)
132     {
133     /* keep last used time accurate to
134     * within a day, making sure an active
135     * channel will never get "Last used"
136     * in /cs info -- jilles */
137     if (mc->isused ())
138     {
139     mc->used = NOW;
140     slog (LG_DEBUG, "expire_check(): updating last used time on %s because it appears to be still in use", mc->name);
141     continue;
142     }
143     }
144    
145     if ((NOW - mc->used) >= chansvs.expiry)
146     {
147     if (MC_HOLD & mc->flags)
148     continue;
149    
150     snoop (_("EXPIRE: \2%s\2 from \2%s\2"), mc->name, mc->founder_names ());
151     slog (LG_REGISTER, "expire_check(): expiring channel %s (unused %ds, founder %s, chanacs %d)",
152     mc->name,
153     NOW - mc->used,
154     mc->founder_names (),
155     LIST_LENGTH (&mc->chanacs));
156    
157     mc->callback.drop (mc);
158     if ((config_options.chan && irccasecmp (mc->name, config_options.chan)) || !config_options.chan)
159     part (mc->name, chansvs.nick);
160    
161     mc->refcnt_dec ();
162     }
163     }
164 pippijn 1.1 }
165     }
166    
167     static int
168 pippijn 1.6 check_myuser_cb (myuser_t::pair_type &mup)
169 pippijn 1.1 {
170 pippijn 1.4 myuser_t *mu = mup.second;
171 pippijn 1.1 mynick_t *mn;
172    
173     if (MU_OLD_ALIAS & mu->flags)
174     {
175     slog (LG_REGISTER, "db_check(): converting previously linked nick %s to a standalone nick", mu->name);
176     mu->flags &= ~MU_OLD_ALIAS;
177     mu->del_metadata ("private:alias:parent");
178     }
179    
180     if (!nicksvs.no_nick_ownership)
181     {
182 pippijn 1.7 mn = mynick_t::find (mu->name);
183 pippijn 1.1 if (mn == NULL)
184     {
185     slog (LG_REGISTER, "db_check(): adding missing nick %s", mu->name);
186 pippijn 1.7 mn = mynick_t::create (mu, mu->name);
187 pippijn 1.1 mn->registered = mu->registered;
188     mn->lastseen = mu->lastlogin;
189     }
190     else if (mn->owner != mu)
191     {
192     slog (LG_REGISTER, "db_check(): replacing nick %s owned by %s with %s", mn->nick, mn->owner->name, mu->name);
193 pippijn 1.7 mn->refcnt_dec ();
194     mn = mynick_t::create (mu, mu->name);
195 pippijn 1.1 mn->registered = mu->registered;
196     mn->lastseen = mu->lastlogin;
197     }
198     }
199    
200     return 0;
201     }
202    
203     void
204     db_check ()
205     {
206 pippijn 1.6 std::for_each (myuser_t::map.begin (), myuser_t::map.end (), check_myuser_cb);
207 pippijn 1.1 }