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