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 |
* |
19 |
* $Id$ |
20 |
*/ |
21 |
|
22 |
/* List of ircd includes from ../include/ |
23 |
* These ones are necessary to build THIS module... |
24 |
*/ |
25 |
|
26 |
#include "stdinc.h" /* includes setup.h */ |
27 |
|
28 |
#include "client.h" /* Required for IsClient, etc. */ |
29 |
|
30 |
#include "send.h" /* sendto_one, most useful function of all time */ |
31 |
|
32 |
#include "parse.h" |
33 |
|
34 |
#include "modules.h" /* includes msg.h; use for the msgtab */ |
35 |
|
36 |
/* OTHER USEFUL INCLUDES: |
37 |
* |
38 |
* #include "handlers.h" <-- include this file to be able to use default |
39 |
* functions in place of your own 'Access Denied' kind of function |
40 |
* |
41 |
* #include "numeric.h" <-- include this file to be able to use form_str, |
42 |
* standard message formats (see messages.tab and *.lang in messages/) |
43 |
* Examples are strewn all across the ircd code, so just grep a bit to |
44 |
* find one! |
45 |
* |
46 |
* #include "irc_string.h" <-- best to include this if you use *any* |
47 |
* string comparison or parsing functions, although they may be available |
48 |
* natively for your OS the prototypes in irc_string.h may be required for |
49 |
* others. */ |
50 |
|
51 |
/* |
52 |
* Declare the void's initially up here, as modules don't have an |
53 |
* include file, we will normally have client_p, source_p, parc |
54 |
* and parv[] where: |
55 |
* |
56 |
* client_p == client issuing command |
57 |
* source_p == where the command came from |
58 |
* parc == the number of parameters |
59 |
* parv == an array of the parameters |
60 |
*/ |
61 |
|
62 |
|
63 |
/* |
64 |
* mr_test |
65 |
* parv[0] = sender prefix |
66 |
* parv[1] = parameter |
67 |
*/ |
68 |
|
69 |
/* |
70 |
* Here we have the functions themselves that we declared above, |
71 |
* and the fairly normal C coding |
72 |
*/ |
73 |
static void |
74 |
mr_test(struct Client *client_p, struct Client *source_p, |
75 |
int parc, char *parv[]) |
76 |
{ |
77 |
if (parc == 1) |
78 |
sendto_one(source_p, ":%s NOTICE %s :You are unregistered and sent no parameters", |
79 |
me.name, source_p->name); |
80 |
else |
81 |
sendto_one(source_p, ":%s NOTICE %s :You are unregistered and sent parameter: %s", |
82 |
me.name, source_p->name, parv[1]); |
83 |
} |
84 |
|
85 |
/* |
86 |
* m_test |
87 |
* parv[0] = sender prefix |
88 |
* parv[1] = parameter |
89 |
*/ |
90 |
static void |
91 |
m_test(struct Client *client_p, struct Client *source_p, |
92 |
int parc, char *parv[]) |
93 |
{ |
94 |
if (parc == 1) |
95 |
sendto_one(source_p, ":%s NOTICE %s :You are a normal user, and sent no parameters", |
96 |
me.name, source_p->name); |
97 |
else |
98 |
sendto_one(source_p, ":%s NOTICE %s :You are a normal user, and send parameters: %s", |
99 |
me.name, source_p->name, parv[1]); |
100 |
} |
101 |
|
102 |
/* |
103 |
* ms_test |
104 |
* parv[0] = sender prefix |
105 |
* parv[1] = parameter |
106 |
*/ |
107 |
static void |
108 |
ms_test(struct Client *client_p, struct Client *source_p, |
109 |
int parc, char *parv[]) |
110 |
{ |
111 |
if (parc == 1) |
112 |
{ |
113 |
if (IsServer(source_p)) |
114 |
sendto_one(source_p, ":%s NOTICE %s :You are a server, and sent no parameters", |
115 |
me.name, source_p->name); |
116 |
else |
117 |
sendto_one(source_p, ":%s NOTICE %s :You are a remote client, and sent no parameters", |
118 |
me.name, source_p->name); |
119 |
} |
120 |
else |
121 |
{ |
122 |
if (IsServer(source_p)) |
123 |
sendto_one(source_p, ":%s NOTICE %s :You are a server, and sent parameters: %s", |
124 |
me.name, source_p->name, parv[1]); |
125 |
else |
126 |
sendto_one(source_p, ":%s NOTICE %s :You are a remote client, and sent parameters: %s", |
127 |
me.name, source_p->name, parv[1]); |
128 |
} |
129 |
} |
130 |
|
131 |
/* |
132 |
* mo_test |
133 |
* parv[0] = sender prefix |
134 |
* parv[1] = parameter |
135 |
*/ |
136 |
static void |
137 |
mo_test(struct Client *client_p, struct Client *source_p, |
138 |
int parc, char *parv[]) |
139 |
{ |
140 |
if (parc == 1) |
141 |
sendto_one(source_p, ":%s NOTICE %s :You are an operator, and sent no parameters", |
142 |
me.name, source_p->name); |
143 |
else |
144 |
sendto_one(source_p, ":%s NOTICE %s :You are an operator, and sent parameters: %s", |
145 |
me.name, source_p->name, parv[1]); |
146 |
} |
147 |
|
148 |
/* |
149 |
* Show the commands this module can handle in a msgtab |
150 |
* and give the msgtab a name, here its test_msgtab |
151 |
*/ |
152 |
static struct Message test_msgtab = { |
153 |
|
154 |
/* Fields are in order: |
155 |
*-> "COMMAND", 0, 0, parc_count, maxparc, MFLG_SLOW, 0, |
156 |
* |
157 |
* where: |
158 |
* COMMAND == the /command you want |
159 |
* parc_count == the number of parameters needed |
160 |
* (the clients name is one param, parv[0]) |
161 |
* maxparc == the maximum parameters we allow |
162 |
* the 0's and MFLG_SLOW should not be changed.. |
163 |
*/ |
164 |
|
165 |
/* |
166 |
* This would add the command "TEST" which requires no additional |
167 |
* parameters |
168 |
*/ |
169 |
"TEST", 0, 0, 1, MAXPARA, MFLG_SLOW, 0, |
170 |
|
171 |
/* Fields are in order: |
172 |
*-> {unregged, regged, remote, encap, oper, dummy} |
173 |
* |
174 |
* where: |
175 |
* unregged == function to call for unregistered clients |
176 |
* regged == function to call for normal users |
177 |
* remote == function to call for servers/remote users |
178 |
* encap == function to call for encap'd server/remote commands |
179 |
* oper == function to call for operators |
180 |
* dummy == function called when client is quarantined |
181 |
* |
182 |
* There are also some pre-coded functions for use: |
183 |
* m_unregistered: prevent the client using this if unregistered |
184 |
* m_not_oper: tell the client it requires being an operator |
185 |
* m_ignore: ignore the command when it comes from certain types |
186 |
* rfc1459_command_send_error: give an error when the command comes from certain types |
187 |
*/ |
188 |
{ mr_test, m_test, ms_test, m_ignore, mo_test, m_ignore } |
189 |
|
190 |
/* It is normal for unregistered functions to be prefixed with mr_ |
191 |
* " " normal users to be prefixed with m_ |
192 |
* " " remote clients to be prefixed with ms_ |
193 |
* " " operators to be prefixed with mo_ |
194 |
*/ |
195 |
}; |
196 |
/* That's the msgtab finished */ |
197 |
|
198 |
/* Here we tell it what to do when the module is loaded */ |
199 |
static void |
200 |
module_init(void) |
201 |
{ |
202 |
/* This will add the commands in test_msgtab (which is above) */ |
203 |
mod_add_cmd(&test_msgtab); |
204 |
} |
205 |
|
206 |
/* here we tell it what to do when the module is unloaded */ |
207 |
static void |
208 |
module_exit(void) |
209 |
{ |
210 |
/* This will remove the commands in test_msgtab (which is above) */ |
211 |
mod_del_cmd(&test_msgtab); |
212 |
} |
213 |
|
214 |
struct module module_entry = { |
215 |
.node = { NULL, NULL, NULL }, |
216 |
.name = NULL, |
217 |
.version = "$Revision$", |
218 |
.handle = NULL, |
219 |
.modinit = module_init, |
220 |
.modexit = module_exit, |
221 |
.flags = 0 |
222 |
}; |
223 |
|
224 |
/* END OF EXAMPLE MODULE */ |