/** * main.C: This file contains the main() routine. * * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team * Rights to this code are as documented in COPYING. * * * Portions of this file were derived from sources bearing the following license: * Copyright © 2005 Atheme Development Group * Rights to this code are documented in doc/pod/license.pod. * * $Id: main.C,v 1.8 2007/09/22 14:27:27 pippijn Exp $ */ #include "atheme.h" #include "confparse.h" #include #include #include static char const rcsid[] = "$Id: main.C,v 1.8 2007/09/22 14:27:27 pippijn Exp $"; REGISTER_MODULE ("memoserv/main", false, "The Ermyth Team "); cmdvec ms_cmdtree; helpvec ms_helptree; /* main services client routine */ static void memoserv (sourceinfo_t *si, int parc, char *parv[]) { char *cmd; char *text; char orig[BUFSIZE]; /* this should never happen */ if (parv[0][0] == '&') { slog (LG_ERROR, "services(): got parv with local channel: %s", parv[0]); return; } /* make a copy of the original for debugging */ strlcpy (orig, parv[parc - 1], BUFSIZE); /* lets go through this to get the command */ cmd = strtok (parv[parc - 1], " "); text = strtok (NULL, ""); if (!cmd) return; if (*cmd == '\001') { handle_ctcp_common (si, cmd, text); return; } /* take the command through the hash table */ command_exec_split (si->service, si, cmd, text, ms_cmdtree); } static void on_config_ready (void) { if (memosvs.me) del_service (memosvs.me); memosvs.me = add_service (memosvs.nick, memosvs.user, memosvs.host, memosvs.real, memoserv, ms_cmdtree); memosvs.disp = memosvs.me->disp; } static void on_user_identify (user_t *u) { myuser_t *mu = u->myuser; if (mu->memoct_new > 0) notice (memosvs.nick, u->nick, ngettext (N_("You have %d new memo."), N_("You have %d new memos."), mu->memoct_new), mu->memoct_new); } static void on_user_away (user_t *u) { myuser_t *mu; mynick_t *mn; if (u->flags & UF_AWAY) return; mu = u->myuser; if (mu == NULL) { mn = mynick_t::find (u->nick); if (mn != NULL && mn->owner->access_verify (u)) mu = mn->owner; } if (mu == NULL) return; if (mu->memoct_new > 0) { notice (memosvs.nick, u->nick, ngettext (N_("You have %d new memo."), N_("You have %d new memos."), mu->memoct_new), mu->memoct_new); } } bool _modinit (module *m) { ConfTable::callback.ready.attach (on_config_ready); user_t::callback.identify.attach (on_user_identify); user_t::callback.away.attach (on_user_away); if (!cold_start) { memosvs.me = add_service (memosvs.nick, memosvs.user, memosvs.host, memosvs.real, memoserv, ms_cmdtree); memosvs.disp = memosvs.me->disp; } return true; } void _moddeinit () { if (memosvs.me) { del_service (memosvs.me); memosvs.me = NULL; } user_t::callback.away.detach (on_user_away); user_t::callback.identify.detach (on_user_identify); ConfTable::callback.ready.detach (on_config_ready); }