Debian Codegraph @

modules/memoserv/main.c

raw
1 /*
2 * Copyright (c) 2005 Atheme Development Group
3 * Rights to this code are documented in doc/LICENSE.
4 *
5 * This file contains the main() routine.
6 *
7 */
8
9 #include "atheme.h"
10 #include <limits.h>
11
12 DECLARE_MODULE_V1
13 (
14 "memoserv/main", false, _modinit, _moddeinit,
15 PACKAGE_STRING,
16 VENDOR_STRING
17 );
18
19 static void on_user_identify(user_t *u);
20 static void on_user_away(user_t *u);
21
22 service_t *memosvs = NULL;
23 /*struct memoserv_conf *memosvs_conf;*/
24 unsigned int maxmemos;
25
26 void _modinit(module_t *m)
27 {
28 hook_add_event("user_identify");
29 hook_add_user_identify(on_user_identify);
30
31 hook_add_event("user_away");
32 hook_add_user_away(on_user_away);
33
34 memosvs = service_add("memoserv", NULL);
35
36 add_uint_conf_item("MAXMEMOS", &memosvs->conf_table, 0, &maxmemos, 1, INT_MAX, 30);
37 }
38
39 void _moddeinit(module_unload_intent_t intent)
40 {
41 hook_del_user_identify(on_user_identify);
42 hook_del_user_away(on_user_away);
43
44 if (memosvs != NULL)
45 service_delete(memosvs);
46 }
47
48 static void on_user_identify(user_t *u)
49 {
50 myuser_t *mu = u->myuser;
51
52 if (mu->memoct_new > 0)
53 {
54 notice(memosvs->me->nick, u->nick, ngettext(N_("You have %d new memo."),
55 N_("You have %d new memos."),
56 mu->memoct_new), mu->memoct_new);
57 notice(memosvs->me->nick, u->nick, _("To read them, type /%s%s READ NEW"),
58 ircd->uses_rcommand ? "" : "msg ", memosvs->disp);
59 }
60 if (mu->memos.count >= maxmemos)
61 {
62 notice(memosvs->me->nick, u->nick, _("Your memo inbox is full! Please "
63 "delete memos you no longer need."));
64 }
65 }
66
67 static void on_user_away(user_t *u)
68 {
69 myuser_t *mu;
70 mynick_t *mn;
71
72 if (u->flags & UF_AWAY)
73 return;
74 mu = u->myuser;
75 if (mu == NULL)
76 {
77 mn = mynick_find(u->nick);
78 if (mn != NULL && myuser_access_verify(u, mn->owner))
79 mu = mn->owner;
80 }
81 if (mu == NULL)
82 return;
83 if (mu->memoct_new > 0)
84 {
85 notice(memosvs->me->nick, u->nick, ngettext(N_("You have %d new memo."),
86 N_("You have %d new memos."),
87 mu->memoct_new), mu->memoct_new);
88 notice(memosvs->me->nick, u->nick, _("To read them, type /%s%s READ NEW"),
89 ircd->uses_rcommand ? "" : "msg ", memosvs->disp);
90 }
91 if (mu->memos.count >= maxmemos)
92 {
93 notice(memosvs->me->nick, u->nick, _("Your memo inbox is full! Please "
94 "delete memos you no longer need."));
95 }
96 }
97
98 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
99 * vim:ts=8
100 * vim:sw=8
101 * vim:noexpandtab
102 */