1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
#include "module.h"
#define AUTHOR "Anope"
#define VERSION "1"
/**
* Default setting to be used if no confing value is found
**/
#define DEFAULT_SETTING "moo"
int mShowSetting(User *u);
int mReadConfig(int argc, char **argv);
char *setting;
int AnopeInit(int argc, char **argv) {
Command *c;
EvtHook *hook;
int status = 0;
setting = NULL;
mReadConfig(0,NULL);
c = createCommand("SHOW",mShowSetting,NULL,-1,-1,-1,-1,-1);
status = moduleAddCommand(HOSTSERV, c, MOD_HEAD);
hook = createEventHook(EVENT_RELOAD, mReadConfig);
status = moduleAddEventHook(hook);
if(status!=MOD_ERR_OK) {
return MOD_STOP;
}
return MOD_CONT;
}
/**
* free the globals when we close
**/
void AnopeFini(void) {
if(setting)
free(setting);
}
/**
* Simple function to show the user the current config setting
**/
int mShowSetting(User *u) {
notice(s_HostServ,u->nick,"Setting in use is [%s]",setting);
return MOD_CONT;
}
/**
* Load the config setting up, this will be called whenever
* the EVENT_RELOAD event is recived.
**/
int mReadConfig(int argc, char **argv) {
char *tmp=NULL;
Directive d[] = {{"HSConfigSetting", {{PARAM_STRING, PARAM_RELOAD, &tmp}}}};
moduleGetConfigDirective(d);
if(setting) {
free(setting);
}
if(tmp) {
setting = tmp;
} else {
setting = sstrdup(DEFAULT_SETTING);
}
return MOD_CONT;
}
/* EOF */
|