1 /************************************************************************
2 * IRC - Internet Relay Chat, doc/example_module.c
3 * Copyright (C) 2001 Hybrid Development Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 1, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 /* List of ircd includes from ../include/ */
29 /* Declare the void's initially up here, as modules dont have an
30 * include file, we will normally have client_p, source_p, parc
33 * client_p == client issuing command
34 * source_p == where the command came from
35 * parc == the number of parameters
36 * parv == an array of the parameters
39 static int munreg_test(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[]);
40 static int mclient_test(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[]);
41 static int mserver_test(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[]);
42 static int mrclient_test(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[]);
43 static int moper_test(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[]);
45 /* Show the commands this module can handle in a msgtab
46 * and give the msgtab a name, here its test_msgtab
49 struct Message test_msgtab
= {
50 "TEST", /* the /COMMAND you want */
51 0, /* SET TO ZERO -- number of times command used by clients */
52 0, /* SET TO ZERO -- number of times command used by clients */
53 0, /* SET TO ZERO -- number of times command used by clients */
54 MFLG_SLOW
, /* ALWAYS SET TO MFLG_SLOW */
56 /* the functions to call for each handler. If not using the generic
57 * handlers, the first param is the function to call, the second is the
58 * required number of parameters. NOTE: If you specify a min para of 2,
59 * then parv[1] must *also* be non-empty.
62 {munreg_test
, 0}, /* function call for unregistered clients, 0 parms required */
63 {mclient_test
, 0}, /* function call for local clients, 0 parms required */
64 {mrclient_test
, 0}, /* function call for remote clients, 0 parms required */
65 {mserver_test
, 0}, /* function call for servers, 0 parms required */
66 mg_ignore
, /* function call for ENCAP, unused in this test */
67 {moper_test
, 0} /* function call for operators, 0 parms required */
71 * There are also some macros for the above function calls and parameter counts.
74 * mg_ignore: ignore the command when it comes from certain types
75 * mg_not_oper: tell the client it requires being an operator
76 * mg_reg: prevent the client using this if registered
77 * mg_unreg: prevent the client using this if unregistered
79 * These macros assume a parameter count of zero; you do not set it.
80 * For further details, see include/msg.h
84 /* The mapi_clist_av1 indicates which commands (struct Message)
85 * should be loaded from the module. The list should be terminated
88 mapi_clist_av1 test_clist
[] = { &test_msgtab
, NULL
};
90 /* The mapi_hlist_av1 indicates which hook functions we need to be able to
91 * call. We need to declare an integer, then add the name of the hook
92 * function to call and a pointer to this integer. The list should be
93 * terminated with NULLs.
95 int doing_example_hook
;
96 mapi_hlist_av1 test_hlist
[] = {
97 { "doing_example_hook", &doing_example_hook
, },
101 /* The mapi_hfn_list_av1 declares the hook functions which other modules can
102 * call. The first parameter is the name of the hook, the second is a void
103 * returning function, with arbitrary parameters casted to (hookfn). This
104 * list must be terminated with NULLs.
106 static void show_example_hook(void *unused
);
108 mapi_hfn_list_av1 test_hfnlist
[] = {
109 { "doing_example_hook", (hookfn
) show_example_hook
},
113 /* Here we tell it what to do when the module is loaded */
117 /* Nothing to do for the example module. */
118 /* The init function should return -1 on failure,
119 which will cause the module to be unloaded,
120 otherwise 0 to indicate success. */
124 /* here we tell it what to do when the module is unloaded */
128 /* Again, nothing to do. */
131 /* DECLARE_MODULE_AV1() actually declare the MAPI header. */
133 /* The first argument is the name */
135 /* The second argument is the function to call on load */
137 /* And the function to call on unload */
139 /* Then the MAPI command list */
141 /* Next the hook list, if we have one. */
143 /* Then the hook function list, if we have one */
145 /* And finally the version number of this module. */
146 "$Revision: 3161 $");
148 /* Any of the above arguments can be NULL to indicate they aren't used. */
153 * parv[1] = parameter
156 /* Here we have the functions themselves that we declared above,
157 * and the fairly normal C coding
160 munreg_test(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
164 sendto_one_notice(source_p
, ":You are unregistered and sent no parameters");
168 sendto_one_notice(source_p
, ":You are unregistered and sent parameter: %s", parv
[1]);
171 /* illustration of how to call a hook function */
172 call_hook(doing_example_hook
, NULL
);
179 * parv[1] = parameter
182 mclient_test(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
186 sendto_one_notice(source_p
, ":You are a normal user, and sent no parameters");
190 sendto_one_notice(source_p
, ":You are a normal user, and send parameters: %s", parv
[1]);
193 /* illustration of how to call a hook function */
194 call_hook(doing_example_hook
, NULL
);
201 * parv[1] = parameter
204 mrclient_test(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
208 sendto_one_notice(source_p
, ":You are a remote client, and sent no parameters");
212 sendto_one_notice(source_p
, ":You are a remote client, and sent parameters: %s", parv
[1]);
219 * parv[1] = parameter
222 mserver_test(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
226 sendto_one_notice(source_p
, ":You are a server, and sent no parameters");
230 sendto_one_notice(source_p
, ":You are a server, and sent parameters: %s", parv
[1]);
237 * parv[1] = parameter
240 moper_test(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
244 sendto_one_notice(source_p
, ":You are an operator, and sent no parameters");
248 sendto_one_notice(source_p
, ":You are an operator, and sent parameters: %s", parv
[1]);
254 show_example_hook(void *unused
)
256 sendto_realops_snomask(SNO_GENERAL
, L_ALL
, "Called example hook!");
259 /* END OF EXAMPLE MODULE */