| 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-2006 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:44 pippijn Exp $ |
| 13 |
*/ |
| 14 |
|
| 15 |
#include "atheme.h" |
| 16 |
#include "confparse.h" |
| 17 |
#include <ermyth/module.h> |
| 18 |
|
| 19 |
static char const rcsid[] = "$Id: main.C,v 1.7 2007-09-16 18:54:44 pippijn Exp $"; |
| 20 |
|
| 21 |
REGISTER_MODULE ("operserv/main", false, "The Ermyth Team <http://ermyth.xinutec.org>"); |
| 22 |
|
| 23 |
static void on_config_ready (void); |
| 24 |
|
| 25 |
cmdvec os_cmdtree; |
| 26 |
helpvec os_helptree; |
| 27 |
|
| 28 |
/* main services client routine */ |
| 29 |
static void |
| 30 |
operserv (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, os_cmdtree); |
| 60 |
} |
| 61 |
|
| 62 |
static void |
| 63 |
on_config_ready (void) |
| 64 |
{ |
| 65 |
if (opersvs.me) |
| 66 |
del_service (opersvs.me); |
| 67 |
|
| 68 |
opersvs.me = add_service (opersvs.nick, opersvs.user, opersvs.host, opersvs.real, operserv, os_cmdtree); |
| 69 |
opersvs.disp = opersvs.me->disp; |
| 70 |
} |
| 71 |
|
| 72 |
bool |
| 73 |
_modinit (module *m) |
| 74 |
{ |
| 75 |
ConfTable::callback.ready.attach (on_config_ready); |
| 76 |
|
| 77 |
if (!cold_start) |
| 78 |
{ |
| 79 |
opersvs.me = add_service (opersvs.nick, opersvs.user, opersvs.host, opersvs.real, operserv, os_cmdtree); |
| 80 |
opersvs.disp = opersvs.me->disp; |
| 81 |
} |
| 82 |
|
| 83 |
return true; |
| 84 |
} |
| 85 |
|
| 86 |
void |
| 87 |
_moddeinit () |
| 88 |
{ |
| 89 |
if (opersvs.me) |
| 90 |
{ |
| 91 |
del_service (opersvs.me); |
| 92 |
opersvs.me = NULL; |
| 93 |
} |
| 94 |
|
| 95 |
ConfTable::callback.ready.detach (on_config_ready); |
| 96 |
} |