]> jfr.im git - irc/rqf/shadowircd.git/blame - extensions/example_module.c
Backed out changeset c04f6578869c
[irc/rqf/shadowircd.git] / extensions / example_module.c
CommitLineData
212380e3 1/************************************************************************
2 * IRC - Internet Relay Chat, doc/example_module.c
3 * Copyright (C) 2001 Hybrid Development Team
4 *
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)
8 * any later version.
9 *
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.
14 *
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.
18 *
212380e3 19 */
20
21/* List of ircd includes from ../include/ */
22#include "stdinc.h"
23#include "modules.h"
24#include "hook.h"
25#include "client.h"
26#include "ircd.h"
27#include "send.h"
28
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
31 * and parv[] where:
32 *
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
37 */
38
39static int munreg_test(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
40static int mclient_test(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
41static int mserver_test(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
42static int mrclient_test(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
43static int moper_test(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
44
45/* Show the commands this module can handle in a msgtab
46 * and give the msgtab a name, here its test_msgtab
47 */
48
49struct 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 */
55
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.
60 */
61 {
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 */
68 }
69};
70/*
71 * There are also some macros for the above function calls and parameter counts.
72 * Here's a list:
73 *
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
78 *
79 * These macros assume a parameter count of zero; you do not set it.
80 * For further details, see include/msg.h
81 */
82
83
84/* The mapi_clist_av1 indicates which commands (struct Message)
85 * should be loaded from the module. The list should be terminated
86 * by a NULL.
87 */
88mapi_clist_av1 test_clist[] = { &test_msgtab, NULL };
89
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.
94 */
95int doing_example_hook;
96mapi_hlist_av1 test_hlist[] = {
97 { "doing_example_hook", &doing_example_hook, },
98 { NULL, NULL }
99};
100
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.
105 */
106static void show_example_hook(void *unused);
107
108mapi_hfn_list_av1 test_hfnlist[] = {
109 { "doing_example_hook", (hookfn) show_example_hook },
110 { NULL, NULL }
111};
112
113/* Here we tell it what to do when the module is loaded */
114static int
115modinit(void)
116{
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. */
121 return 0;
122}
123
124/* here we tell it what to do when the module is unloaded */
125static void
126moddeinit(void)
127{
128 /* Again, nothing to do. */
129}
130
131/* DECLARE_MODULE_AV1() actually declare the MAPI header. */
132DECLARE_MODULE_AV1(
133 /* The first argument is the name */
134 example,
135 /* The second argument is the function to call on load */
136 modinit,
137 /* And the function to call on unload */
138 moddeinit,
139 /* Then the MAPI command list */
140 test_clist,
141 /* Next the hook list, if we have one. */
142 test_hlist,
143 /* Then the hook function list, if we have one */
144 test_hfnlist,
145 /* And finally the version number of this module. */
5366977b 146 "$Revision: 3161 $");
212380e3 147
148/* Any of the above arguments can be NULL to indicate they aren't used. */
149
150
151/*
152 * mr_test
212380e3 153 * parv[1] = parameter
154 */
155
156/* Here we have the functions themselves that we declared above,
157 * and the fairly normal C coding
158 */
159static int
160munreg_test(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
161{
162 if(parc < 2)
163 {
5366977b 164 sendto_one_notice(source_p, ":You are unregistered and sent no parameters");
212380e3 165 }
166 else
167 {
5366977b 168 sendto_one_notice(source_p, ":You are unregistered and sent parameter: %s", parv[1]);
212380e3 169 }
170
171 /* illustration of how to call a hook function */
172 call_hook(doing_example_hook, NULL);
173
174 return 0;
175}
176
177/*
178 * mclient_test
212380e3 179 * parv[1] = parameter
180 */
181static int
182mclient_test(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
183{
184 if(parc < 2)
185 {
5366977b 186 sendto_one_notice(source_p, ":You are a normal user, and sent no parameters");
212380e3 187 }
188 else
189 {
5366977b 190 sendto_one_notice(source_p, ":You are a normal user, and send parameters: %s", parv[1]);
212380e3 191 }
192
193 /* illustration of how to call a hook function */
194 call_hook(doing_example_hook, NULL);
195
196 return 0;
197}
198
199/*
200 * mrclient_test
212380e3 201 * parv[1] = parameter
202 */
203static int
204mrclient_test(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
205{
206 if(parc < 2)
207 {
5366977b 208 sendto_one_notice(source_p, ":You are a remote client, and sent no parameters");
212380e3 209 }
210 else
211 {
5366977b 212 sendto_one_notice(source_p, ":You are a remote client, and sent parameters: %s", parv[1]);
212380e3 213 }
214 return 0;
215}
216
217/*
218 * mserver_test
212380e3 219 * parv[1] = parameter
220 */
221static int
222mserver_test(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
223{
224 if(parc < 2)
225 {
5366977b 226 sendto_one_notice(source_p, ":You are a server, and sent no parameters");
212380e3 227 }
228 else
229 {
5366977b 230 sendto_one_notice(source_p, ":You are a server, and sent parameters: %s", parv[1]);
212380e3 231 }
232 return 0;
233}
234
235/*
236 * moper_test
212380e3 237 * parv[1] = parameter
238 */
239static int
240moper_test(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
241{
242 if(parc < 2)
243 {
5366977b 244 sendto_one_notice(source_p, ":You are an operator, and sent no parameters");
212380e3 245 }
246 else
247 {
5366977b 248 sendto_one_notice(source_p, ":You are an operator, and sent parameters: %s", parv[1]);
212380e3 249 }
250 return 0;
251}
252
253static void
254show_example_hook(void *unused)
255{
256 sendto_realops_snomask(SNO_GENERAL, L_ALL, "Called example hook!");
257}
258
259/* END OF EXAMPLE MODULE */